.chat-page {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 140px);
    max-width: 1000px;
    margin: 0 auto;
    width: 100%;
}

/* Полоса с информацией о персонаже */
.chat-character-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 0;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}
.back-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(214, 51, 132, 0.1);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: background 0.2s;
    flex-shrink: 0;
}
.back-btn:hover {
    background: var(--accent);
    color: white;
}
.char-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--accent);
    flex-shrink: 0;
}
.char-details {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px;
}
.char-name {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}
.char-age {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 400;
}
.char-status {
    font-size: 0.8rem;
    color: #48BB78;
    position: relative;
    padding-left: 12px;
}
.char-status::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #48BB78;
}

/* Счётчик сообщений */
.char-messages-left {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(214, 51, 132, 0.08);
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 0.85rem;
    color: var(--accent);
    font-weight: 600;
    white-space: nowrap;
}
.char-messages-left i {
    font-size: 1rem;
}
.char-messages-left .label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 400;
}

/* Область сообщений */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

/* Сообщения */
.message {
    max-width: 80%;
    padding: 12px 14px;
    border-radius: 18px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
    font-size: 0.95rem;
    line-height: 1.5;
    position: relative;
    word-wrap: break-word;
    overflow-wrap: break-word;
}
.message p {
    margin: 0;
    word-break: break-word;
    white-space: pre-wrap;
}
.message.user {
    align-self: flex-end;
    background: var(--accent);
    color: white;
    border-bottom-right-radius: 4px;
}
.message.partner {
    align-self: flex-start;
    background: var(--card-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-light);
    border-bottom-left-radius: 4px;
}
.msg-time {
    font-size: 0.65rem;
    color: inherit;
    opacity: 0.6;
    margin-top: 4px;
    text-align: right;
}

/* Стилизация диалогов */
.message.partner p { display: flex; flex-direction: column; gap: 6px; white-space: normal; }
.dialogue {
    display: block;
    font-weight: 500;
    color: var(--text-primary);
    background: linear-gradient(135deg, rgba(214, 51, 132, 0.14), rgba(233, 30, 99, 0.06));
    border-left: 3px solid var(--accent);
    padding: 7px 11px;
    border-radius: 4px 12px 12px 4px;
    line-height: 1.45;
}
.action {
    display: block;
    font-style: italic;
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding: 0 2px;
}

/* Индикатор печати */
.typing-indicator {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--card-bg);
    border-radius: 18px;
    border: 1px solid var(--border-light);
}
.typing-indicator span {
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* Поле ввода */
.chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 16px 0 0;
    border-top: 1px solid var(--border-light);
    flex-shrink: 0;
}
.delete-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(214, 51, 132, 0.1);
    color: var(--accent);
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.delete-btn:hover {
    background: rgba(214, 51, 132, 0.2);
}
.chat-input {
    flex: 1;
    background: var(--card-bg);
    border: 1px solid var(--border-light);
    border-radius: 20px;
    padding: 12px 16px;
    font-size: 0.95rem;
    color: var(--text-primary);
    font-family: "Inter", sans-serif;
    resize: none;
    max-height: 150px;
    outline: none;
    transition: border-color 0.2s;
    word-wrap: break-word;
    overflow-wrap: break-word;
}
.chat-input:focus {
    border-color: var(--accent);
}
.send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.2s;
}
.send-btn:hover {
    background: var(--accent-hover);
}

/* Попап подтверждения */
.popup-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
.popup-card {
    background: var(--card-bg);
    border-radius: 28px;
    padding: 32px 24px;
    max-width: 360px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 50px rgba(214, 51, 132, 0.3);
    border: 1px solid var(--border-light);
    animation: scaleIn 0.3s ease;
}
@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}
.popup-icon {
    font-size: 2.5rem;
    color: var(--accent);
    margin-bottom: 12px;
}
.popup-title {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}
.popup-text {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-bottom: 24px;
    line-height: 1.4;
}
.popup-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}
.popup-btn {
    padding: 12px 20px;
    border-radius: 14px;
    font-weight: 600;
    font-size: 0.95rem;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    flex: 1;
}
.popup-btn-cancel {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
}
.popup-btn-cancel:hover {
    background: rgba(214, 51, 132, 0.12);
}
.popup-btn-confirm {
    background: linear-gradient(135deg, #D63384, #E91E63);
    color: white;
    box-shadow: 0 4px 12px rgba(214, 51, 132, 0.3);
}
.popup-btn-confirm:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(214, 51, 132, 0.4);
}

/* Адаптив */
@media (max-width: 768px) {
    .chat-character-bar {
        flex-wrap: nowrap;
        gap: 10px;
    }
    .char-messages-left {
        order: 0;
        padding: 4px 10px;
        font-size: 0.8rem;
    }
    .char-messages-left .label {
        display: none;
    }
    .char-messages-left i {
        font-size: 0.9rem;
    }
    .char-age {
        display: block;
    }
}
/* Память персонажа */
.memory-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(214, 51, 132, 0.08);
    color: var(--accent);
    border: none;
    border-radius: 20px;
    padding: 6px 12px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}
.memory-btn:hover { background: var(--accent); color: #fff; }
@media (max-width: 480px) { .memory-btn-label { display: none; } }
.memory-card { position: relative; max-width: 460px; width: 92%; text-align: left; max-height: 80vh; overflow-y: auto; }
.memory-card .popup-icon, .memory-card .popup-title { text-align: center; }
.memory-icon { color: var(--accent); }
.memory-sub { text-align: center; font-size: 0.85rem; }
.memory-close { position: absolute; top: 8px; right: 12px; background: none; border: none; font-size: 1.6rem; color: var(--text-secondary); cursor: pointer; }
.memory-list { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.memory-item { display: flex; align-items: center; gap: 6px; padding: 9px 10px; border-radius: 10px; background: var(--card-bg); border: 1px solid var(--border-light); }
.memory-item.pinned { border-color: var(--accent); background: rgba(214, 51, 132, 0.08); }
.memory-text { flex: 1; font-size: 0.9rem; color: var(--text-primary); line-height: 1.35; }
.memory-act { background: none; border: none; color: var(--text-secondary); cursor: pointer; padding: 4px 6px; border-radius: 6px; }
.memory-act:hover { color: var(--accent); }
.memory-item.pinned [data-act="pin"] { color: var(--accent); }
.memory-empty { text-align: center; color: var(--text-secondary); font-size: 0.9rem; padding: 14px 6px; }

/* Действия под сообщением, ветки, уведомления */
.msg-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.msg-act {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: rgba(214, 51, 132, 0.08);
    color: var(--accent);
    border: none;
    border-radius: 14px;
    padding: 6px 11px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 32px;
}
.msg-act:hover { background: var(--accent); color: #fff; }
.branch-item { display: flex; align-items: center; gap: 8px; padding: 12px; border-radius: 10px; background: var(--card-bg); border: 1px solid var(--border-light); cursor: pointer; }
.branch-item.active { border-color: var(--accent); background: rgba(214, 51, 132, 0.08); }
.branch-name { flex: 1; font-weight: 600; color: var(--text-primary); }
.branch-count { font-size: 0.78rem; color: var(--text-secondary); }
.branch-check { color: var(--accent); }
.chat-toast {
    position: fixed;
    left: 50%;
    bottom: calc(90px + env(safe-area-inset-bottom, 0px));
    transform: translate(-50%, 10px);
    background: rgba(30, 30, 36, 0.96);
    color: #fff;
    padding: 10px 16px;
    border-radius: 20px;
    font-size: 0.88rem;
    opacity: 0;
    transition: opacity 0.25s, transform 0.25s;
    z-index: 10050;
    max-width: 90vw;
    text-align: center;
    pointer-events: none;
}
.chat-toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Режим ИИ: Обычный / Улучшенный */
.mode-bar { display: flex; gap: 8px; padding: 8px 0 0; flex-shrink: 0; }
.mode-chip {
    background: var(--card-bg);
    color: var(--text-secondary);
    border: 1px solid var(--border-light);
    border-radius: 16px;
    padding: 6px 13px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 34px;
}
.mode-chip.active {
    color: #fff;
    background: linear-gradient(135deg, #D63384, #E91E63);
    border-color: transparent;
}
.mode-chip .fa-gem { font-size: 0.72rem; }

/* Групповой чат */
.msg-speaker { display: flex; align-items: center; gap: 7px; margin-bottom: 6px; font-size: 0.8rem; font-weight: 700; color: var(--accent); }
.msg-speaker img { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; border: 1px solid var(--accent); }
.ai-add-btn {
    width: 100%;
    margin-top: 12px;
    background: linear-gradient(135deg, #D63384, #E91E63);
    color: #fff;
    border: none;
    border-radius: 14px;
    padding: 12px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    min-height: 44px;
}
.parts-add { margin-top: 12px; }
.parts-add .form-input { width: 100%; box-sizing: border-box; background: var(--card-bg); border: 1px solid var(--border-light); border-radius: 12px; padding: 10px 12px; color: var(--text-primary); }
.parts-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: var(--card-bg); border: 1px solid var(--border-light); }
.parts-row img { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }
.parts-row .parts-name { flex: 1; font-weight: 600; color: var(--text-primary); }
.parts-row .parts-tag { font-size: 0.72rem; color: var(--text-secondary); }
.parts-row.candidate { cursor: pointer; }
.parts-row.candidate:hover { border-color: var(--accent); }

/* Карточка «лимит исчерпан» */
.limit-card {
    align-self: stretch;
    background: linear-gradient(135deg, rgba(214, 51, 132, 0.16), rgba(156, 39, 176, 0.1));
    border: 1px solid rgba(214, 51, 132, 0.4);
    border-radius: 16px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.limit-card p { margin: 0; color: var(--text-primary); }
.limit-card .limit-hint { color: var(--text-secondary); font-size: 0.88rem; }
.limit-btn {
    border: 1px solid var(--border-light);
    background: var(--card-bg);
    color: var(--text-primary);
    border-radius: 14px;
    padding: 12px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    min-height: 46px;
}
.limit-btn.primary { background: linear-gradient(135deg, #D63384, #E91E63); color: #fff; border-color: transparent; }

/* Proactive: «Может писать первым» */
.proactive-box { margin-top: 14px; padding: 12px; border-radius: 12px; background: rgba(214, 51, 132, 0.08); border: 1px solid rgba(214, 51, 132, 0.3); }
.proactive-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; color: var(--text-primary); }
.proactive-row small { color: var(--text-secondary); }
.proactive-row input { width: 22px; height: 22px; accent-color: #D63384; flex-shrink: 0; }
.proactive-cta { display: block; margin-top: 10px; text-align: center; background: linear-gradient(135deg, #D63384, #E91E63); color: #fff; border-radius: 12px; padding: 11px; font-weight: 700; text-decoration: none; }

/* Фото от персонажа в чате */
.photo-offer-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    background: linear-gradient(135deg, #D63384, #E91E63);
    color: #fff;
    border: none;
    border-radius: 16px;
    padding: 9px 14px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    min-height: 36px;
}
.photo-offer-btn:disabled { opacity: 0.75; cursor: default; }
.chat-photo-wrap { display: block; margin-top: 8px; border-radius: 14px; overflow: hidden; max-width: 220px; }
.chat-photo { display: block; width: 100%; height: auto; border-radius: 14px; }

/* Подсказка после создания персонажа */
.new-char-hint {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 2px 4px;
}
.new-char-hint-text { font-size: 0.85rem; color: var(--text-secondary); }
.new-char-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.starter-chip {
    background: rgba(214, 51, 132, 0.1);
    color: var(--accent);
    border: 1px solid rgba(214, 51, 132, 0.35);
    border-radius: 16px;
    padding: 8px 13px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 36px;
}
.starter-chip:active { background: var(--accent); color: #fff; }

.photo-offer-wrap { position: relative; display: inline-block; }
.photo-hint-bubble {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(20, 10, 20, 0.96);
    color: #fff;
    border: 1px solid rgba(214, 51, 132, 0.5);
    border-radius: 12px;
    padding: 8px 10px;
    font-size: 0.78rem;
    max-width: 220px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
    animation: hintPop 0.25s ease;
}
@keyframes hintPop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.photo-hint-close { background: none; border: none; color: rgba(255,255,255,0.7); font-size: 1rem; cursor: pointer; line-height: 1; flex-shrink: 0; }
