:root {
    --bg-primary-dark: #202123;      /* Основной фон чата и шапки */
    --bg-secondary-dark: #2d2f3a;   /* Фон сайдбара, фон инпутов, фон сообщений бота (как на скриншоте) */
    --bg-tertiary-dark: #40414f;   /* Фон ховеров, фон кнопки "Новый чат", активных элементов в сайдбаре, фон сообщений юзера */
    --text-primary-light: #ececf1;   /* Основной светлый текст */
    --text-secondary-light: #c5c5d2; /* Вторичный светлый текст (плейсхолдеры, описания, даты) */
    --accent-color-modern: #10a37f;  /* Акцентный цвет (например, для фокуса) */
    --border-color-dark: #434552;    /* Цвет границ */
    --user-msg-bg-dark: var(--bg-tertiary-dark); /* Фон сообщений пользователя */
    --bot-msg-bg-dark: var(--bg-secondary-dark); /* Фон сообщений бота (сделаем чуть темнее основного фона сайдбара) */

    --sidebar-width: 260px;
    --header-height: 56px;
    --border-radius-main: 8px;
    --border-radius-messages: 12px;
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
    --form-height: 76px; /* Высота формы ввода сообщения */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    width: 100%;
    position: fixed; /* Предотвращает странное поведение в Safari */
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-primary-dark);
    color: var(--text-primary-light);
    overflow: hidden;
    font-size: 16px;
    -webkit-tap-highlight-color: transparent; /* Убираем подсветку при тапе на мобильных */
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
    position: relative; /* Для правильного позиционирования дочерних элементов */
}

/* --- Сайдбар --- */
.chat-history-sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background-color: var(--bg-secondary-dark);
    padding: 15px;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed; /* Фиксированная позиция */
    left: 0;
    top: 0;
    transition: transform 0.3s ease-in-out, width 0.3s ease-in-out;
    z-index: 90;
    overflow: hidden; /* Предотвращаем скролл всего сайдбара */
}

/* Контейнер для списка чатов */
.chat-list-container {
    flex-grow: 1;
    overflow-y: auto;
    margin-bottom: 10px;
}

/* Скроллбар для контейнера списка чатов */
.chat-list-container::-webkit-scrollbar { 
    width: 6px;
}
.chat-list-container::-webkit-scrollbar-thumb { 
    background-color: var(--bg-tertiary-dark);
    border-radius: 3px; 
}

/* Футер сайдбара */
.sidebar-footer {
    flex-shrink: 0;
    margin-top: auto;
    padding-top: 10px;
    border-top: 1px solid var(--border-color-dark);
}

/* Стили для контейнера авторизации */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 15px;
    width: 100%;
}

.auth-container #google-signin-container {
    /* Сохраняем место для кнопки Google Sign-In */
    flex-shrink: 0;
}

.auth-container #user-greeting {
    margin-right: 10px;
    color: var(--text-primary-light);
    font-size: 0.9em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
    flex-grow: 1; /* Разрешаем тексту приветствия занимать доступное пространство */
}

/* Общие стили для кнопок в сайдбаре */
.sidebar-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background-color: var(--bg-tertiary-dark);
    color: var(--text-secondary-light);
    border: none;
    border-radius: var(--border-radius-main);
    padding: 6px 10px;
    font-size: 0.85em;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
    height: 34px; /* Фиксированная высота для единообразия */
}

.sidebar-btn i {
    font-size: 1.1em;
}

/* Стили для кнопки выхода */
#logout-button {
    flex-shrink: 0; /* Не позволяем кнопке сжиматься */
}

#logout-button:hover {
    background-color: #c82333;
    color: white;
    border-color: #c82333;
}
/* Удаляем скроллбар для сайдбара, теперь он в chat-list-container */

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    margin-top: 5px; /* Добавляем отступ сверху для лучшего разделения */
    border-top: 1px solid var(--border-color-dark); /* Добавляем верхнюю границу для визуального разделения */
    padding-top: 15px; /* Отступ внутри, чтобы контент не прилипал к границе */
}
.chat-history-sidebar h2 {
    font-size: 0.8em;
    color: var(--text-secondary-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0;
}
.new-chat-button {
    /* Наследуем общие стили для кнопок */
    display: flex;
    align-items: center;
    gap: 6px;
    background-color: var(--bg-tertiary-dark);
    color: var(--text-secondary-light);
    border: none;
    border-radius: var(--border-radius-main);
    padding: 6px 10px;
    font-size: 0.85em;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
    height: 34px; /* Фиксированная высота для единообразия */
}
.new-chat-button i { font-size: 1.1em; }
.new-chat-button:hover { background-color: #4a4b5a; color: var(--text-primary-light); }

/* Добавим класс для кнопки в сайдбаре с hover эффектом */
.sidebar-btn:hover:not(#logout-button) { 
    background-color: #4a4b5a; 
    color: var(--text-primary-light); 
}


#history-list li {
    /* ... существующие стили ... */
    display: flex; /* Чтобы элементы внутри распределялись */
    flex-wrap: wrap; /* Для переноса, если не хватает места */
    align-items: baseline; /* Выравнивание по базовой линии текста */
    justify-content: space-between; /* Раздвинуть основной контент и дату */
}

#history-list li > span:first-of-type { /* Заголовок чата */
    flex-grow: 1; /* Занять доступное место */
    margin-right: 5px; /* Отступ от инфо о боте */
    /* color: var(--text-primary-light); Уже есть */
}

.history-chat-bot-info {
    font-size: 0.75em;
    color: var(--text-secondary-light);
    opacity: 0.7;
    margin-right: 5px; /* Отступ от даты */
    white-space: nowrap;
}

#history-list li .date-span {
    /* ... существующие стили ... */
    white-space: nowrap; /* Чтобы дата не переносилась */
    margin-left: auto; /* Прижать дату к правому краю, если flex-контейнер */
}
/* Уточнение для li, чтобы все элементы выстроились как надо */
#history-list li {
    padding: 10px 12px;
    margin-bottom: 6px;
    border-radius: var(--border-radius-main);
    cursor: pointer;
    transition: background-color 0.2s;
    font-size: 0.95em;
    /* overflow: hidden;  Убираем, т.к. теперь flex и хотим видеть все */
    /* text-overflow: ellipsis; */
    /* white-space: nowrap; */
    color: var(--text-secondary-light);
    display: flex; /* Делаем flex-строкой */
    justify-content: space-between; /* Раздвигаем контент */
    align-items: flex-start; /* Выравниваем по верху, если тексты разной высоты */
}

#history-list li > div.chat-info-container { /* Обертка для заголовка и инфо о боте */
    display: flex;
    flex-direction: column; /* Заголовок и инфо о боте друг под другом */
    flex-grow: 1;
    overflow: hidden; /* Для text-ellipsis на заголовке */
    margin-right: 10px; /* Отступ от даты */
}

#history-list li > div.chat-info-container > span:first-of-type { /* Заголовок чата */
    color: var(--text-primary-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block; /* Чтобы ellipsis работал */
}

.history-chat-bot-info { /* Информация о боте */
    font-size: 0.75em;
    color: var(--text-secondary-light);
    opacity: 0.8;
    margin-top: 2px;
}

#history-list li .date-span { /* Дата */
    font-size: 0.8em;
    color: var(--text-secondary-light);
    opacity: 0.7;
    white-space: nowrap;
    flex-shrink: 0; /* Чтобы дата не сжималась */
    align-self: flex-start; /* Выровнять дату по верху, если заголовок в несколько строк */
    padding-top: 2px; /* Небольшой отступ сверху, если заголовок высокий */
}


/* Стили для списка чатов в стиле Telegram */
#history-list li {
    padding: 8px 12px;
    margin-bottom: 4px;
    border-radius: var(--border-radius-main);
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    font-size: 0.95em;
    color: var(--text-secondary-light);
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-areas: 
        "logo model-name date"
        "logo message-preview date";
    grid-column-gap: 10px;
    grid-row-gap: 2px;
    align-items: center;
    position: relative;
    min-height: 52px; /* Минимальная высота для элемента истории */
}

#history-list li:hover {
    background-color: var(--bg-tertiary-dark);
}

#history-list li.active-chat {
    background-color: var(--bg-tertiary-dark);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Стиль для логотипа модели чата */
.chat-model-logo {
    grid-area: logo;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: rgba(16, 163, 127, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1em;
    font-weight: bold;
    color: var(--text-primary-light);
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.chat-model-logo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Контейнер для информации о чате */
.chat-info-container {
    grid-area: info;
    display: contents; /* Чтобы дочерние элементы заняли правильные ячейки грида */
}

.chat-model-name {
    grid-area: model-name;
    color: var(--text-primary-light);
    font-weight: 500;
    font-size: 0.9em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    align-self: end;
    line-height: 1.2;
    max-width: 100%;
}

.chat-message-preview {
    grid-area: message-preview;
    font-size: 0.85em;
    color: var(--text-secondary-light);
    opacity: 0.9;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    align-self: start;
    line-height: 1.2;
    max-width: 100%;
}

/* Контейнер для даты */
.chat-date-container {
    grid-area: date;
    font-size: 0.75em;
    color: var(--text-secondary-light);
    white-space: nowrap;
    text-align: right;
    align-self: center;
    padding-left: 8px; /* Отступ от информации в чате */
}

/* Дополнительные стили для пустого списка */
#history-list .no-history {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 60px;
    font-style: italic;
    opacity: 0.7;
}

/* Адаптация для мобильных устройств */
@media (max-width: 768px) {
    #history-list li {
        padding: 10px 8px;
        grid-column-gap: 8px;
    }
    
    .chat-model-logo {
        width: 32px;
        height: 32px;
        font-size: 1em;
    }
    
    .chat-model-name {
        font-size: 0.85em;
    }
    
    .chat-message-preview {
        font-size: 0.8em;
    }
    
    .chat-date-container {
        font-size: 0.7em;
    }
}

#clear-all-history-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background-color: transparent;
    color: var(--text-secondary-light);
    border: 1px solid var(--border-color-dark);
    border-radius: var(--border-radius-main);
    cursor: pointer;
    margin-bottom: 8px;
    font-size: 0.9em;
    transition: background-color 0.2s, color 0.2s;
    flex-shrink: 0;
    width: 100%;
    height: 38px; /* Немного выше, чтобы визуально отличалась */
}
#clear-all-history-btn:hover { background-color: #c82333; color: white; border-color: #c82333; }
#clear-all-history-btn::before {
    content: "\F5E8"; /* Иконка корзины из Bootstrap Icons */
    font-family: "bootstrap-icons";
    font-size: 1.1em;
}

.test-formatting-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background-color: #17a2b8;
    color: white;
    border: 1px solid #138496;
    border-radius: var(--border-radius-main);
    cursor: pointer;
    margin-bottom: 8px;
    font-size: 0.9em;
    transition: background-color 0.2s, color 0.2s;
    flex-shrink: 0;
    width: 100%;
    height: 38px;
}

.test-formatting-btn:hover { 
    background-color: #138496; 
}

.test-formatting-btn::before {
    content: "\F4CB"; /* Иконка форматирования из Bootstrap Icons */
    font-family: "bootstrap-icons";
    font-size: 1.1em;
}

.demo-mode-notice {
    font-size: 0.75em;
    color: var(--text-secondary-light);
    opacity: 0.8;
    text-align: center;
    padding: 5px 10px;
    margin-bottom: 5px;
    line-height: 1.3;
    font-style: italic;
    background-color: rgba(16, 163, 127, 0.1);
    border-radius: 4px;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1); /* Тень сверху для визуального отделения */
}

/* Добавим стиль для футера сайдбара на мобильных устройствах */
@media (max-width: 768px) {
    .sidebar-footer {
        background-color: var(--bg-secondary-dark);
        z-index: 111; /* Должен быть выше чем сайдбар, но ниже других элементов UI */
    }
}

/* --- Область чата (Шапка + Интерфейс) --- */
.chat-area-wrapper {
    flex-grow: 1;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-primary-dark);
    overflow: hidden;
    position: relative; /* Для позиционирования дочерних элементов */
    width: calc(100% - var(--sidebar-width)); /* Учитываем ширину сайдбара */
    margin-left: var(--sidebar-width); /* Сдвигаем на ширину сайдбара */
}

/* На мобильных устройствах область чата должна занимать всю ширину */
@media (max-width: 768px) {
    .chat-area-wrapper {
        width: 100%;
        margin-left: 0;
    }
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
    height: var(--header-height);
    background-color: var(--bg-primary-dark);
    border-bottom: 1px solid var(--border-color-dark);
    flex-shrink: 0;
    position: relative;
}
.app-header h1 { font-size: 1.1em; font-weight: 500; margin: 0 10px; flex-grow: 1; }
.menu-btn {
    background: none; border: none; color: var(--text-secondary-light); font-size: 1.6em;
    cursor: pointer; padding: 8px; border-radius: var(--border-radius-main);
    display: none; transition: background-color 0.2s; z-index: 10;
}
.menu-btn:hover { background-color: var(--bg-secondary-dark); }

/* Стили для кастомного селектора бота */
.bot-selector-container { position: relative; }
.custom-select-trigger {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 12px; background-color: var(--bg-secondary-dark); color: var(--text-primary-light);
    border: 1px solid var(--border-color-dark); border-radius: var(--border-radius-main);
    cursor: pointer; min-width: 200px; font-size: 0.9em;
    transition: border-color 0.2s, box-shadow 0.2s;
    max-width: 100%; /* Гарантируем, что не выйдет за пределы контейнера */
}
.custom-select-trigger:hover,
.custom-select-trigger.active { border-color: var(--accent-color-modern); }
.custom-select-trigger:focus,
.custom-select-trigger.active {
    outline: none; border-color: var(--accent-color-modern);
    box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.3);
}

/* Стили для логотипа в закрытом селекторе */
.selected-model-logo {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
    font-size: 0.85em;
    font-weight: bold;
    color: var(--text-primary-light);
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: 0 0 4px rgba(16, 163, 127, 0.3);
}

.selected-model-logo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.custom-select-trigger .selected-value-container {
    display: flex;
    align-items: center;
    overflow: hidden;
    flex-grow: 1;
    margin-right: 8px;
}

.custom-select-trigger .selected-value-text { 
    white-space: nowrap; 
    overflow: hidden; 
    text-overflow: ellipsis;
    width: 100%;
    max-width: calc(100% - 10px); /* Ограничиваем ширину текста */
}

.custom-select-trigger .chevron-icon { 
    transition: transform 0.2s ease-in-out; 
    font-size: 0.8em; 
    color: var(--text-secondary-light);
    flex-shrink: 0;
}

.custom-select-trigger.active .chevron-icon { transform: rotate(180deg); }

.custom-select-options {
    position: absolute; top: calc(100% + 6px);
    background-color: var(--bg-secondary-dark); border: 1px solid var(--border-color-dark);
    border-radius: var(--border-radius-main); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 100; width: 400px; max-height: 450px; min-height: 450px; overflow-y: auto;
    padding: 8px; display: none;
}
.custom-select-options.open { display: block; }
.custom-select-options .options-title {
    font-size: 0.85em; color: var(--text-secondary-light); padding: 6px 12px;
    margin-bottom: 4px; font-weight: 500;
}

/* Стили для заголовков групп */
.option-group-header {
    padding: 8px 12px;
    margin-top: 4px;
    margin-bottom: 2px;
    font-size: 0.85em;
    font-weight: 600;
    color: var(--accent-color-modern);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-color-dark);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Базовые стили для групп */
.option-group-header {
    font-weight: 600;
    letter-spacing: 0.8px;
    border-radius: 6px;
    padding: 10px 12px;
    position: relative;
}

/* Стиль для группы "Платные" (первая группа) */
.option-group-header:first-of-type {
    color: #ef476f; /* Красноватый оттенок для платных */
    background-color: rgba(239, 71, 111, 0.1);
}

/* Стиль для группы "Бесплатные" (вторая группа) */
.option-group-header:nth-of-type(3) {
    color: var(--accent-color-modern);
    font-weight: 700;
    background-color: rgba(16, 163, 127, 0.1);
}


/* Изменяем стиль стрелки для группы "Бесплатные" */
.option-group-header:first-of-type:after {
    color: var(--accent-color-modern);
    transform: none !important; /* Предотвращаем трансформацию стрелки */
    content: "\F282" !important; /* Используем иконку "вниз" вместо "вправо" */
}

/* Добавляем стили для подгрупп внутри Бесплатные */
.option-group-header:first-of-type + .option-group-content .option-subgroup-header {
    padding-left: 25px;
    color: var(--text-secondary-light);
}

/* Добавляем иконку замка для индикации того, что группа "Бесплатные" всегда открыта */
.option-group-header:first-of-type:after {
    content: "\F47B" !important; /* Иконка замка из Bootstrap Icons */
    right: 15px;
    font-size: 0.9em;
}

/* Добавляем анимацию пульсации для иконки вопроса при открытии селектора */
.custom-select-options.open .info-icon {
    animation: pulse 2s infinite;
}

/* Останавливаем анимацию при наведении */
.info-icon:hover {
    animation: none;
}

.option-group-header:after {
    content: "\F282";
    font-family: "bootstrap-icons";
    font-size: 0.75em;
    transition: transform 0.2s;
    color: var(--text-secondary-light);
    margin-right: 2px;
}

.option-group-header.collapsed:after {
    content: "\F285"; /* Используем другую иконку для свернутого состояния - стрелка вправо */
    font-family: "bootstrap-icons";
}

/* Стиль при наведении */
.option-group-header:hover {
    background-color: rgba(45, 47, 58, 0.5);
}

.option-group-content {
    overflow: hidden;
    max-height: 1000px;
    transition: max-height 0.3s ease-in-out;
}

.option-group-content.collapsed {
    max-height: 0;
}

/* Стили для подзаголовков подгрупп (в секции "Бесплатные") */
.option-subgroup-header {
    padding: 10px 12px 10px 12px;
    margin: 4px 0;
    font-size: 0.85em;
    font-weight: 500;
    color: var(--text-secondary-light);
    background-color: rgb(56, 58, 77); /* Чуть темнее фона, как на изображении */
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Стиль для кружка с логотипом производителя */
.manufacturer-logo-circle {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
    font-size: 0.85em;
    font-weight: bold;
    color: var(--text-primary-light);
    overflow: hidden;
    flex-shrink: 0;
    /* Те же размеры, что и иконка вопроса и галочка */
    box-shadow: 0 0 4px rgba(16, 163, 127, 0.3);
}

/* При наведении на заголовок с логотипом */
.option-subgroup-header:hover .manufacturer-logo-circle {
    background-color: rgba(255, 255, 255, 0.3);
    box-shadow: 0 0 6px rgba(16, 163, 127, 0.5);
}

/* Стиль для изображения логотипа внутри кружка */
.logo-in-circle {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

/* Обновляем расположение элементов внутри заголовка подгруппы */
.option-subgroup-header {
    display: flex;
    align-items: center;
}

/* Стиль для текста названия производителя */
.option-subgroup-header span {
    flex-grow: 1;
}

.option-subgroup-header:after {
    content: "\F282";
    font-family: "bootstrap-icons";
    font-size: 0.8em;
    transition: transform 0.2s;
    color: var(--text-secondary-light);
    margin-right: 2px;
}

.option-subgroup-header.collapsed:after {
    content: "\F285"; /* Используем другую иконку для свернутого состояния - стрелка вправо */
    font-family: "bootstrap-icons";
}

/* Выделение для подгрупп при наведении */
.option-subgroup-header:hover {
    background-color: rgba(64, 65, 79, 0.9);
}

.option-subgroup-content {
    overflow: hidden;
    max-height: 500px;
    transition: max-height 0.3s ease-in-out, opacity 0.3s ease-in-out;
    margin-left: 10px; /* Отступ для вложенности */
    opacity: 1;
}

.option-subgroup-content.collapsed {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
    margin-bottom: 0;
}

.custom-option {
    display: flex; justify-content: space-between; align-items: center;
    padding: 6px 12px; cursor: pointer;
    border-radius: calc(var(--border-radius-main) - 2px); transition: background-color 0.2s;
    margin-left: 4px; /* Отступ для вложенности */
    margin-top: 2px;
    margin-bottom: 2px;
    position: relative; /* Для позиционирования иконки вопроса и подсказки */
}

/* Обеспечиваем правильную обработку кликов с иконкой */
.custom-option.has-info-icon {
    cursor: default; /* Убираем курсор указателя с самого элемента */
}

.custom-option.has-info-icon .option-content {
    cursor: pointer; /* Возвращаем курсор указателя для основного содержимого */
}

/* Стили для моделей в подгруппах */
.custom-option.free-model,
.custom-option.paid-model {
    padding-left: 28px; /* Отступ слева для элементов в подгруппе */
    margin-left: 8px;
    margin-right: 8px;
}

/* Компактный стиль для подгрупп бесплатных моделей */
.option-group-header + .option-group-content .option-subgroup-header {
    font-size: 0.8em;
    padding: 10px 12px 10px 24px;
    margin: 4px 4px;
    background-color: rgb(56, 58, 77); /* Цвет как на изображении */
    border-radius: 8px;
}

/* Стиль для групп, содержащих выбранную опцию */
.option-group-content:not(.collapsed) {
    padding-bottom: 6px;
}
.custom-option:hover { background-color: var(--bg-tertiary-dark); }
.custom-option.selected { 
    background-color: var(--accent-color-modern); 
    color: white; 
    position: relative;
    border-radius: 8px;
}
.custom-option.selected .option-description { color: rgba(255, 255, 255, 0.8); }

/* Добавляем галочку справа для выбранной опции, как на изображении */
.custom-option.selected:after {
    content: "\F26B"; /* Галочка из Bootstrap Icons */
    font-family: "bootstrap-icons";
    position: absolute;
    right: 45px; /* Оптимальное положение для десктопа */
    color: white;
    font-size: 1.1em;
}
.custom-option .option-content { 
    display: flex; 
    flex-direction: column; 
    flex-grow: 1; 
    padding-right: 50px; /* Увеличенный отступ для иконок */
}

/* Стили для иконок моделей удалены, теперь иконки только в закрытом селекторе */

.custom-option .option-content {
    display: flex;
    flex-direction: row;
    align-items: center;
    flex-grow: 1;
}

/* Специальный стиль для выбранной опции в меню */
.custom-option.selected {
    padding-right: 70px; /* Добавляем дополнительное пространство для иконок справа */
}

/* Дополнительно уменьшаем ширину контента в выбранной опции */
.custom-option.selected .option-content {
    width: calc(100% - 65px); /* Еще больше места для иконок в выбранной опции */
}

.custom-option .option-main-text { 
    font-size: 0.95em; 
    color: var(--text-primary-light); 
    font-weight: 500; 
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 350px;
}

/* Обеспечиваем правильное позиционирование контента и текста внутри опции */
.custom-option .option-content {
    width: calc(100% - 50px); /* Оставляем место для иконки справа */
    overflow: hidden; /* Для работы text-overflow внутри */
}

/* Стиль для иконки вопроса */
.info-icon {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background-color: white;
    color: var(--accent-color-modern);
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    z-index: 103; /* Повышаем, чтобы быть уверенным, что иконка поверх остальных элементов */
    box-shadow: 0 0 4px rgba(16, 163, 127, 0.5);
    user-select: none; /* Предотвращает выделение текста */
    pointer-events: all; /* Убеждаемся, что клики обрабатываются */
}

.info-icon:hover {
    background-color: white;
    color: var(--accent-color-modern);
    box-shadow: 0 0 8px rgba(16, 163, 127, 0.7);
    transform: translateY(-50%) scale(1.1);
}

/* Активная иконка (когда описание показано) */
.custom-option .model-description.show ~ .info-icon {
    background-color: white;
    color: var(--accent-color-modern);
    box-shadow: 0 0 8px rgba(16, 163, 127, 0.7);
}

/* Выбранная опция */
.custom-option.selected .info-icon {
    background-color: white;
    color: var(--accent-color-modern);
}

/* Анимация для плавного появления */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Анимация для заголовка при открытии */
@keyframes headerFadeIn {
    from { background-color: rgba(239, 71, 111, 0.05); }
    to { background-color: rgba(239, 71, 111, 0.1); }
}

@keyframes pulse {
    0% { transform: translateY(-50%) scale(1); box-shadow: 0 0 0 0 rgba(16, 163, 127, 0.4); }
    70% { transform: translateY(-50%) scale(1.1); box-shadow: 0 0 0 6px rgba(16, 163, 127, 0); }
    100% { transform: translateY(-50%) scale(1); box-shadow: 0 0 0 0 rgba(16, 163, 127, 0); }
}

/* Анимация пульсации для заголовка группы "Бесплатные" */
@keyframes headerPulse {
    0% { background-color: rgba(16, 163, 127, 0.1); }
    50% { background-color: rgba(16, 163, 127, 0.3); }
    100% { background-color: rgba(16, 163, 127, 0.1); }
}


/* Стиль для платных моделей */
.custom-option.paid-model {
    padding-left: 28px;
}


.pulse-animation {
    animation: headerPulse 0.5s ease-in-out;
}

/* Улучшенный тултип */
.tooltip {
    position: absolute;
    top: 50%;
    right: 40px; /* Отступ от иконки */
    transform: translateY(-50%);
    background-color: var(--bg-secondary-dark);
    color: var(--text-primary-light);
    padding: 10px 15px;
    border-radius: 6px;
    font-size: 0.9em;
    max-width: 300px;
    min-width: 250px;
    white-space: normal; /* Разрешаем перенос строк */
    overflow: hidden;
    line-height: 1.4;
    z-index: 104;
    border: 1px solid var(--accent-color-modern);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s, transform 0.2s;
}

.tooltip.show {
    opacity: 1;
    transform: translateY(-50%) scale(1);
}

/* Эффект появления тултипа */
@keyframes tooltipAppear {
    from { opacity: 0; transform: translateY(-50%) scale(0.9); }
    to { opacity: 1; transform: translateY(-50%) scale(1); }
}

.tooltip.show {
    animation: tooltipAppear 0.2s forwards;
}

/* Стрелка для тултипа */
.tooltip:after {
    content: "";
    position: absolute;
    top: 50%;
    right: -8px;
    transform: translateY(-50%);
    border-width: 8px 0 8px 8px;
    border-style: solid;
    border-color: transparent transparent transparent var(--accent-color-modern);
}

/* Стили для заголовка и содержимого тултипа */
.tooltip-title {
    font-weight: bold;
    color: var(--accent-color-modern);
    margin-bottom: 5px;
    font-size: 1em;
    border-bottom: 1px solid rgba(16, 163, 127, 0.3);
    padding-bottom: 3px;
}

.tooltip-content {
    max-height: 10px;
    padding-right: 5px;
    font-size: 0.8em;
    line-height: 0.6;
    color: var(--text-primary-light);
}

/* Тонкий скроллбар для длинных описаний */
.tooltip-content::-webkit-scrollbar {
    width: 3px;
}

.tooltip-content::-webkit-scrollbar-thumb {
    background-color: var(--accent-color-modern);
    border-radius: 2px;
}

/* Длинное описание (при клике) */
.full-description {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--bg-secondary-dark);
    color: var(--text-primary-light);
    padding: 15px;
    border-radius: 8px;
    max-width: 80%;
    max-height: 80vh;
    width: 500px;
    overflow-y: auto;
    overflow-x: hidden; /* Предотвращаем горизонтальный скролл */
    z-index: 106; /* Повышенный z-index, чтобы быть выше селектора */
    border: 1px solid var(--accent-color-modern);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.8);
    display: none;
    box-sizing: border-box; /* Гарантируем, что внутренние отступы не увеличивают размер */
}

.full-description.show {
    display: block;
    animation: fadeIn 0.3s ease-in-out;
}

.full-description-title {
    font-weight: bold;
    font-size: 1.2em;
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 1px solid var(--accent-color-modern);
    color: var(--accent-color-modern);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: calc(100% - 30px); /* Оставляем место для крестика */
}

.full-description-content {
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
    overflow-x: hidden; /* Предотвращаем горизонтальный скролл */
}

.full-description-content p {
    margin-bottom: 10px;
    max-width: 100%; /* Гарантируем, что параграфы не выходят за границы контейнера */
}

.full-description-close {
    position: absolute;
    right: 15px;
    top: 15px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background-color: rgba(16, 163, 127, 0.3);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    box-shadow: 0 0 4px rgba(16, 163, 127, 0.5);
}

.full-description-close:hover {
    background-color: var(--accent-color-modern);
    color: white;
    box-shadow: 0 0 8px rgba(16, 163, 127, 0.7);
    transform: scale(1.1);
}

/* Фон для модального окна */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 105; /* Повышенный z-index, но чуть ниже самого модального окна */
    display: none;
}

.modal-overlay.show {
    display: block;
}

/* Для мобильных устройств показываем описание снизу */
@media (max-width: 768px) {
    .model-description {
        right: 0;
        top: 100%;
        width: 100%;
    }
}
.custom-option.selected .option-main-text { color: white; }
.custom-option .option-description { 
    display: none; /* Скрываем описание по умолчанию */
    font-size: 0.8em; 
    color: var(--text-secondary-light); 
    margin-top: 2px; 
}
.custom-option.show-description .option-description { 
    display: block; /* Показываем описание, когда добавлен класс show-description */
}
.custom-option .checkmark-icon { font-size: 1.2em; color: var(--text-primary-light); opacity: 0; margin-left: 10px; }
.custom-option.selected .checkmark-icon { color: white; opacity: 1; }
#bot-selector { /* Скрытие оригинального селекта */
    position: absolute; opacity: 0; pointer-events: none; width: 0; height: 0; left: -9999px;
}

/* --- Интерфейс чата --- */
.chat-interface {
    flex-grow: 1; 
    display: flex; 
    flex-direction: column; 
    overflow: hidden;
    /* Фиксированная высота для мобильных устройств */
    height: 100%;
    position: relative;
    width: 100%; /* Убедимся, что ширина всегда 100% */
}
.message-container {
    flex-grow: 1; 
    padding: 20px 15px 100px 15px; /* Увеличиваем нижний padding для места форме */
    overflow-y: auto;
    display: flex; 
    flex-direction: column; 
    gap: 12px;
    background-color: var(--bg-primary-dark);
    height: 100%; /* Гарантируем полную высоту */
    box-sizing: border-box; /* Включаем padding в высоту */
    width: 100%; /* Гарантируем полную ширину */
}
.message-container::-webkit-scrollbar { width: 8px; }
.message-container::-webkit-scrollbar-thumb { background-color: var(--bg-secondary-dark); border-radius: 4px; }
.message-container::-webkit-scrollbar-track { background-color: transparent; }

.message {
    max-width: 75%; padding: 12px 18px;
    border-radius: var(--border-radius-messages);
    line-height: 1.5; word-wrap: break-word;
}

/* Стили для отформатированного текста */
.message strong, .message b { font-weight: bold; }
.message em, .message i { font-style: italic; }
.message code {
    font-family: "Courier New", monospace;
    background-color: rgba(0, 0, 0, 0.2);
    padding: 2px 4px;
    border-radius: 3px;
    font-size: 0.95em;
}

/* Стили для блоков кода */
.message pre.code-block {
    background-color: rgba(0, 0, 0, 0.3);
    padding: 10px;
    border-radius: 5px;
    margin: 8px 0;
    overflow-x: auto;
    max-width: 100%;
    border-left: 3px solid var(--accent-color-modern);
}

.message pre.code-block code {
    background-color: transparent;
    padding: 0;
    font-family: "Courier New", monospace;
    font-size: 0.9em;
    line-height: 1.5;
    white-space: pre;
    display: block;
}
.message del { text-decoration: line-through; }
.message h1, .message h2, .message h3 {
    margin: 8px 0;
    line-height: 1.3;
    font-weight: bold;
}
.message h1 { font-size: 1.3em; }
.message h2 { font-size: 1.2em; }
.message h3 { font-size: 1.1em; }
.message ul, .message ol {
    margin: 8px 0;
    padding-left: 25px;
}
.message ul li, .message ol li {
    margin-bottom: 4px;
}
.message a {
    color: #10a37f;
    text-decoration: underline;
}
.message a:hover {
    text-decoration: none;
}

/* Улучшенные стили для списков */
.message ul {
    list-style-type: disc;
}

.message ol {
    list-style-type: decimal;
}

/* Избегаем слишком широких сообщений на мобильных */
@media (max-width: 768px) {
    .message {
        max-width: 90%;
    }
    
    .message pre.code-block {
        max-width: 100%;
        margin: 8px -5px;
    }
    
    .message ul, .message ol {
        padding-left: 20px;
    }
}

/* Плавные переходы для анимации сообщений */
.message-container .message {
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
.message.user { background-color: var(--user-msg-bg-dark); align-self: flex-end; color: var(--text-primary-light); }
.message.bot { background-color: var(--bot-msg-bg-dark); align-self: flex-start; color: var(--text-primary-light); }
.message .timestamp {
    font-size: 0.7em; color: var(--text-secondary-light); opacity: 0.7;
    display: block; margin-top: 6px; text-align: right;
}
.message.bot .timestamp { text-align: left; }
.message.system {
    align-self: center; background-color: transparent; color: var(--text-secondary-light);
    font-size: 0.85em; font-style: italic; padding: 5px 10px;
}

.message-form {
    display: flex; 
    align-items: center; 
    padding: 15px 20px;
    background-color: var(--bg-primary-dark);
    border-top: 1px solid var(--border-color-dark);
    gap: 10px;
    position: fixed; /* Фиксируем форму внизу экрана */
    bottom: 0;
    /* Не наезжаем на сайдбар */
    left: var(--sidebar-width); 
    right: 0;
    z-index: 1000; /* Высокий z-index, чтобы быть выше всех элементов */
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.2); /* Тень сверху для визуального отделения */
}

/* На мобильных устройствах форма должна занимать всю ширину экрана */
@media (max-width: 768px) {
    .message-form {
        left: 0; /* На мобильных сайдбар скрыт, поэтому форма занимает всю ширину */
    }
    
    /* Когда сайдбар открыт на мобильных */
    .chat-history-sidebar.open ~ .chat-area-wrapper .message-form {
        width: 100%;
        left: 0;
    }
}
#message-input {
    flex-grow: 1; padding: 12px 18px; border: 1px solid var(--border-color-dark);
    border-radius: var(--border-radius-main); resize: none; font-size: 1em;
    line-height: 1.4; max-height: 120px; overflow-y: auto;
    background-color: var(--bg-secondary-dark); color: var(--text-primary-light);
}
#message-input::placeholder { color: var(--text-secondary-light); opacity: 0.8; }
#message-input:focus {
    outline: none; border-color: var(--accent-color-modern);
    box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.3);
}
#message-input::-webkit-scrollbar { width: 6px; }
#message-input::-webkit-scrollbar-thumb { background-color: var(--bg-tertiary-dark); border-radius: 3px; }

#send-button {
    background-color: var(--accent-color-modern); color: white; border: none;
    border-radius: var(--border-radius-main); width: auto; padding: 0 15px;
    height: 46px; font-size: 1.2em; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; transition: background-color 0.2s;
}
#send-button:hover { background-color: #0d8c6f; }
#send-button:disabled { background-color: var(--bg-tertiary-dark); cursor: not-allowed; }

/* --- Адаптивность --- */
@media (max-width: 768px) {
    .chat-history-sidebar {
        position: fixed; left: 0; top: 0;
        transform: translateX(-100%);
        z-index: 110;
        box-shadow: 2px 0 10px rgba(0,0,0,0.3);
    }
    .chat-history-sidebar.open { transform: translateX(0); }
    .menu-btn { display: flex; }
    .app-header h1 { text-align: left; margin-left: 10px; }
    
    /* Сбрасываем стили формы для мобильных */
    .message-form {
        left: 0;
        bottom: env(safe-area-inset-bottom, 0); /* Учитываем safe area на iOS */
    }
    
    /* Сбрасываем стили chat-area-wrapper для мобильных */
    .chat-area-wrapper {
        width: 100%;
        margin-left: 0;
    }
    
    /* Полностью меняем формат селектора на мобильных */
    .bot-selector-container { 
        flex-grow: 1;
        display: flex;
        justify-content: flex-end;
        padding-right: 5px;
    }
    
    .app-container {
        display: flex;
        flex-direction: column;
        height: 100%;
        position: relative;
        overflow: hidden;
    }
    
    .chat-area-wrapper {
        flex: 1;
        height: auto;
        position: relative;
        display: flex;
        flex-direction: column;
    }
    
    .chat-interface {
        flex: 1;
        position: relative;
        overflow: hidden;
    }
    
    .message-container {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        padding-bottom: 120px; /* Больший отступ для формы и панели браузера */
        height: 100%;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch; /* Плавный скролл на iOS */
    }
    
    .message-form {
        position: fixed;
        bottom: env(safe-area-inset-bottom, 0);
        left: 0;
        right: 0;
        padding: 10px 15px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0));
        background-color: var(--bg-primary-dark);
        z-index: 1000;
    }
    
    .custom-select-trigger {
        min-width: auto;
        width: auto;
        max-width: 160px; /* Задаем максимальную ширину для мобильной версии */
        padding: 6px 8px 6px 6px;
        background-color: rgba(45, 47, 58, 0.5);
        border: none;
    }
    
    /* Мобильная версия селектора показывает логотип, текст и стрелку */
    .custom-select-trigger .selected-value-container {
        margin-right: 1px;
    }
    
    .custom-select-trigger .selected-value-text {
        display: block; /* Показываем текст */
        font-size: 0.85em;
        max-width: 145px; /* Ограничиваем ширину текста */
    }
    
    .custom-select-trigger .chevron-icon {
        margin-left: 0;
    }
    
    /* Изменяем размер логотипа */
    .selected-model-logo {
        margin-right: 0;
        width: 24px;
        height: 24px;
    }
    
    /* Основной контент */
    .message-form { padding: 10px 12px; }
    #message-input { padding: 10px 15px; }
    #send-button { height: 42px; padding: 0 12px; }
    .message { max-width: 85%; }
    
    /* Селектор моделей полноэкранный на мобильных */
    .custom-select-options {
        width: 100%;
        max-height: 90vh;
        top: 0;
        left: 0;
        right: 0;
        transform: none;
        border-radius: 0;
        z-index: 100;
        position: fixed;
        height: 100%;
    }
    
    /* Стилизация опций в мобильном меню */
    .custom-option .option-main-text {
        max-width: calc(100% - 20px);
    }
    
    /* Корректируем ширину контента для мобильных */
    .custom-option .option-content {
        width: calc(100% - 60px);
    }
    
    /* Еще больше места для выбранной опции на мобильных */
    .custom-option.selected .option-content {
        width: calc(100% - 75px);
    }
    
    .custom-option {
        padding: 12px 15px;
    }
    
    /* Специальное позиционирование галочки на мобильных устройствах */
    .custom-option.selected:after {
        right: 40px; /* Правильная позиция, чтобы не наезжать на вопросик */
    }
    
    /* Добавляем кнопку закрытия для мобильного селектора */
    .mobile-close-btn {
        position: absolute;
        top: 10px;
        right: 10px;
        background: none;
        border: none;
        color: var(--text-secondary-light);
        font-size: 1.5em;
        cursor: pointer;
        z-index: 101;
        display: block;
    }
    
    /* Заголовок для мобильного селектора */
    .options-title {
        font-size: 1em;
        padding: 15px;
        text-align: center;
        margin-top: 5px;
    }
    
    /* Заголовки групп в мобильном селекторе */
    .option-group-header {
        padding: 12px 15px;
        font-size: 1em;
    }
    
    /* Подгруппы для мобильного селектора */
    .option-subgroup-header {
        padding: 12px 15px 12px 15px;
    }
    
    /* Изменяем стиль тултипа и модального окна для мобильных */
    .tooltip,
    .full-description {
        position: fixed;
        top: auto;
        left: 10px !important;
        right: 10px !important;
        bottom: 20%;
        transform: none !important;
        max-width: none;
        width: calc(100% - 20px);
        z-index: 112;
        padding: 15px;
        margin: 0;
    }
    
    .tooltip:after { display: none; }
    
    .tooltip-title,
    .full-description-title {
        font-size: 1.1em;
        margin-bottom: 8px;
        max-width: calc(100% - 30px);
    }
    
    .tooltip-content,
    .full-description-content {
        font-size: 1em;
        max-height: 250px;
    }
    
    /* Увеличиваем кнопку закрытия на мобильных */
    .full-description-close {
        width: 30px;
        height: 30px;
        font-size: 1.2rem;
        right: 10px;
        top: 10px;
    }
}

@media (max-width: 480px) {
    /* Адаптация меню для очень маленьких экранов */
    .custom-select-options {
        padding-top: 10px;
    }
    
    /* Компактная версия селектора для iPhone SE и других маленьких устройств */
    .custom-select-trigger {
        max-width: 200px;
        width: 200px;
        padding: 4px 6px 4px 4px;
    }
    
    /* Уменьшаем текст для компактности и задаем фиксированную максимальную ширину */
    .custom-select-trigger .selected-value-text {
        font-size: 0.8em;
        max-width: 145px; /* Фиксированная ширина для текста на мобильных */
    }
    
    /* Увеличиваем размер логотипа для лучшей видимости */
    .selected-model-logo {
        width: 22px;
        height: 22px;
        margin-right: 5px;
    }
    
    /* Дополнительные стили для позиционирования иконок в мобильном выбранном элементе */
    .custom-option.selected .info-icon {
        right: 10px;
    }
    
    /* Делаем элементы селектора крупнее для удобства */
    .custom-option {
        padding: 14px 12px;
    }
    
    .option-group-header,
    .option-subgroup-header {
        padding: 14px 12px;
        font-size: 1.05em;
    }
    
    .manufacturer-logo-circle {
        width: 28px;
        height: 28px;
        margin-right: 10px;
    }
}

/* Стили для кнопки закрытия мобильного селектора */
.mobile-close-btn {
    display: none; /* По умолчанию скрыта, показывается только на мобильных */
}

@media (max-width: 360px) {
    .new-chat-button span { display: none; }
    .new-chat-button { padding: 6px 8px; }
    
    /* Еще более компактная версия для очень маленьких экранов */
    .custom-select-trigger {
        max-width: 200px;
        width: 200px;
        padding: 4px 4px;
    }
    
    .custom-select-trigger .selected-value-text {
        max-width: 60px; /* Ограниченная фиксированная ширина для маленьких экранов */
    }
    
    /* Уменьшаем отступ между логотипом и текстом */
    .selected-model-logo {
        margin-right: 4px;
    }
    
    /* Еще точнее настраиваем позиционирование иконок для iPhone SE */
    .custom-option.selected:after {
        right: 35px; /* Уменьшаем отступ для очень узких экранов */
    }
    
    .custom-option .info-icon {
        right: 8px; /* Приближаем вопросик к краю для очень маленьких экранов */
    }
    
    /* Еще больше уменьшаем ширину текста на маленьких экранах */
    .custom-option .option-content {
        width: calc(100% - 65px);
    }
    
    .custom-option.selected .option-content {
        width: calc(100% - 80px);
    }
}