:root {
    --bg-color: #f0f2f5;
    --sidebar-color: #ffffff;
    --primary-color: #0084ff;
    --user-msg: #0084ff;
    --ai-msg: #ffffff;
    --text-main: #1c1e21;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    height: 100vh;
    margin: 0;
    background-color: var(--bg-color);
}

/* Сайдбар */
.sidebar {
    width: 280px;
    min-width: 280px; /* Добавить */
    max-width: 280px; /* Добавить */
    background-color: var(--sidebar-color);
    border-right: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    padding: 20px 10px;
    box-sizing: border-box; /* Важно, чтобы паддинги не раздували ширину */
}

.sidebar h2 {
    padding-left: 15px;
    font-size: 1.2rem;
    color: #333;
}

/* Список контактов */
.contact-item {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    margin: 4px 8px;
    cursor: pointer;
    border-radius: 10px;
    transition: all 0.2s;
}

.contact-item:hover { background: #f5f5f5; }
.contact-item.active { background: #e7f3ff; }

.contact-avatar {
    width: 45px;
    height: 45px;
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    font-size: 1.2rem;
    font-weight: bold;
}

.contact-name { font-weight: 500; font-size: 0.95rem; }

/* Основная область */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    background: #fff;
    position: relative;
}

.chat-header {
    padding: 15px 25px;
    border-bottom: 1px solid #eee;
}

#chat-title { margin: 0; font-size: 1.1rem; }

/* Чат */
.chat-box {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background-color: #e5ddd5; /* Классический фон мессенджера */
    background-image: url('https://www.transparenttextures.com/patterns/cubes.png');
}

.message {
    padding: 10px 15px;
    border-radius: 15px;
    max-width: 70%;
    font-size: 15px;
    line-height: 1.4;
    position: relative;
    box-shadow: 0 1px 1px rgba(0,0,0,0.1);
    animation: slideIn 0.2s ease-out;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    background-color: #dcf8c6;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}

.message.assistant {
    background-color: #fff;
    align-self: flex-start;
    border-bottom-left-radius: 2px;
}

.typing-indicator {
    font-size: 13px;
    color: #666;
    margin-bottom: 10px;
    font-style: italic;
}

/* Аудио */
audio { height: 35px; width: 220px; margin-top: 5px; display: block; }

/* Ввод */
.input-area {
    padding: 15px 20px;
    display: flex;
    gap: 10px;
    background: #f0f0f0;
    align-items: center;
}

#text-input {
    flex-grow: 1;
    padding: 12px 18px;
    border: 1px solid #fff;
    border-radius: 25px;
    outline: none;
}

#send-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: bold;
}

#record-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px;
    transition: transform 0.2s;
}

#record-btn.recording {
    color: #ff4d4f;
    transform: scale(1.2);
}

#reset-btn {
    margin: 10px;
    padding: 10px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
}
/* ... (весь предыдущий CSS остается) ... */

.char-description-box {
    text-align: center;
    padding: 20px;
    margin: 10px auto 20px auto;
    max-width: 80%;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 12px;
    border: 1px dashed #999;
    color: #555;
    font-size: 0.9rem;
    font-style: italic;
    line-height: 1.4;
}

/* Обновим цвета сообщений для красоты */
.message.user { background-color: #0084ff; color: white; }
.message.assistant { background-color: #ffffff; color: #333; }
/* Описание персонажа по центру */
.char-description-box {
    align-self: center;
    text-align: center;
    max-width: 80%;
    background: rgba(255, 255, 255, 0.6);
    padding: 15px;
    border-radius: 12px;
    margin: 10px 0 20px 0;
    font-size: 0.9rem;
    color: #666;
    border: 1px dashed #ccc;
    line-height: 1.4;
}

/* Модальные окна */
.overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.auth-modal {
    background: white;
    padding: 30px;
    border-radius: 20px;
    width: 320px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    text-align: center;
}

.auth-modal h2 { margin-top: 0; color: #333; }

.auth-modal input {
    width: 100%;
    padding: 12px;
    margin: 10px 0;
    border: 1px solid #ddd;
    border-radius: 10px;
    box-sizing: border-box;
}

.auth-modal button {
    width: 100%;
    padding: 12px;
    background: #0084ff;
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-weight: bold;
    margin-top: 10px;
}

.toggle-link {
    margin-top: 15px;
    font-size: 0.9rem;
    color: #0084ff;
    cursor: pointer;
    text-decoration: underline;
}

.user-profile {
    padding: 10px 15px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
}

.chat-audio-player {
    max-width: 100%;
    height: 30px; /* Делаем его компактным */
    margin-top: 5px;
    filter: sepia(20%) hue-rotate(180deg) brightness(95%); /* Немного стилизуем под цвет чата */
}

/* Специфические отступы для сообщений с аудио */
.message audio {
    display: block;
}

/* Правая панель в целом */
.sidebar.right-panel {
    background-color: #ffffff;
    border-left: 1px solid #e0e0e0;
    border-right: none;
    padding: 25px 20px;
    display: flex;
    flex-direction: column;
}

/* Контейнер профиля теперь занимает всю высоту, чтобы прижать промокод к низу */
.user-profile {
    display: flex;
    flex-direction: column;
    height: 100%;
    margin: 0 !important;
    background: transparent !important;
    padding: 0 !important;
}

.profile-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 1px solid #f0f0f0;
}

.profile-header b {
    font-size: 1.1rem;
    color: var(--text-main);
}

.logout-link {
    color: #ff4757;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    transition: opacity 0.2s;
}

.logout-link:hover {
    opacity: 0.7;
}

/* Карточка статистики */
.stats-box {
    background: #f8faff;
    border: 1px solid #eef2f7;
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.03);
}

.stats-box p {
    margin: 8px 0;
    color: #5f6368;
    font-weight: 500;
}

#sub-status {
    color: var(--primary-color);
    font-weight: bold;
}

/* Прогресс-бар */
.progress-bar {
    height: 10px;
    background: #e9ecef;
    border-radius: 10px;
    overflow: hidden;
    margin-top: 12px;
}

#progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #0084ff, #00c6ff);
    width: 0%;
    transition: width 0.5s ease-in-out;
}

/* Секция промокода ВНИЗУ и СЛЕВА */
.promo-section {
    margin-top: auto; /* Это магическое свойство толкает блок в самый низ */
    padding-top: 20px;
    display: flex;
    flex-direction: column;
    align-items: flex-start; /* Прижимает содержимое к левому краю */
    gap: 10px;
}

.promo-section input {
    width: 100%;
    max-width: 200px; /* Ограничиваем ширину, чтобы смотрелось аккуратно */
    padding: 10px 14px;
    border: 1.5px solid #e0e0e0;
    border-radius: 10px;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}

.promo-section input:focus {
    border-color: var(--primary-color);
}

#promo-btn {
    background: #2ed573;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    transition: transform 0.1s, background 0.2s;
}

#promo-btn:hover {
    background: #26af5f;
}

#promo-btn:active {
    transform: scale(0.98);
}

/* --- Адаптивная верстка (Mobile First) --- */
.mobile-only { display: none; }

@media (max-width: 768px) {
    body {
        flex-direction: column;
        overflow-x: hidden; /* Убираем горизонтальную прокрутку */
    }

    .mobile-only { display: block; }

    /* 1. Правая панель (Профиль) — переносим на самый верх */
    .sidebar.right-panel {
        order: 1; /* Поднимаем наверх */
        width: 100% !important;
        max-width: 100% !important;
        height: auto;
        border-left: none;
        border-bottom: 1px solid #ddd;
        padding: 15px;
    }

    /* 2. Левая панель (Контакты) — под профилем */
    .sidebar {
        order: 2; /* Опускаем под профиль */
        width: 100% !important;
        max-width: 100% !important;
        height: auto;
        flex-grow: 1; /* Занимает оставшееся место */
        border-right: none;
        padding-bottom: 20px;
    }

    .promo-section { margin-top: 15px; flex-direction: row; }

    /* 3. Основной контент (Чат) — выезжает поверх всего */
    .main-content {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 100; /* Перекрывает всё */
        transform: translateX(100%); /* Прячем за правым краем экрана */
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1); /* Плавный выезд */
        background: #fff; /* Чтобы не просвечивали контакты */
    }

    /* Когда кликнули на контакт, добавляем класс и чат выезжает */
    body.chat-open .main-content {
        transform: translateX(0);
    }

    /* Кнопка назад в шапке чата */
    .chat-header {
        display: flex;
        align-items: center;
        gap: 15px;
    }

    #back-btn {
        background: none;
        border: none;
        font-size: 1.5rem;
        cursor: pointer;
        color: var(--primary-color);
        padding: 0 5px;
    }

    /* Отступ для клавиатуры */
    .input-area {
        padding-bottom: 25px;
    }
}
#reset-btn:hover { background: #fff1f0; border-color: #ffa39e; }