/* css/text_chat.css */

/* --- Шапка --- */
.text-chat-header {
    background: rgba(16, 16, 16, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.chat-header-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: rgba(250, 191, 60, 0.1);
    border-radius: 8px;
    color: var(--primary);
}

.btn-icon-ghost {
    background: transparent;
    border: none;
    color: #888;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.btn-icon-ghost:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

/* --- Экран приветствия --- */
.welcome-icon-glow {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(250, 191, 60, 0.05);
    border: 1px solid rgba(250, 191, 60, 0.2);
    border-radius: 50%;
    box-shadow: 0 0 30px rgba(250, 191, 60, 0.15);
}

.suggestion-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #ccc;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    transition: all 0.2s ease;
}
.suggestion-btn:hover {
    background: rgba(250, 191, 60, 0.1);
    border-color: rgba(250, 191, 60, 0.5);
    color: var(--primary);
    transform: translateY(-2px);
}

/* --- Плавающее поле ввода --- */
.text-chat-input-wrapper {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0; 
    width: 100%;
    padding: 20px 40px;
    background: linear-gradient(0deg, rgba(16,16,16,1) 40%, rgba(16,16,16,0) 100%);
    pointer-events: none; 
    display: flex;
    flex-direction: column;
    align-items: center;
}

.chat-input-box {
    position: relative;
    width: 100%; 
    max-width: 800px;
    margin: 0 auto;
    background: #1a1a1a;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 8px 16px; /* Чуть изменили отступы контейнера */
    display: flex;
    align-items: flex-end; /* Кнопка прижимается к низу */
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    pointer-events: auto; 
    transition: border-color 0.3s;
}
.chat-input-box:focus-within {
    border-color: rgba(250, 191, 60, 0.4);
}

#text-chat-input {
    flex-grow: 1;
    background: transparent;
    border: none;
    color: #fff;
    resize: none;
    min-height: 40px; /* Базовая высота для одной строки */
    max-height: 200px;
    padding: 8px 12px 8px 0; /* Дали тексту "дышать" сверху и снизу */
    font-size: 0.95rem;
    line-height: 1.5;
    outline: none;
    box-shadow: none;
    overflow-y: hidden; /* Скролл скрыт по умолчанию, появится через JS */
}
#text-chat-input::placeholder { color: #666; }

.chat-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    border: none;
    background: var(--primary, #FABF3C);
    color: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    margin-bottom: 2px; /* Идеальное выравнивание по нижнему краю текста */
    outline: none;
}
.chat-send-btn:disabled {
    background: #333;
    color: #666;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}
.chat-send-btn:not(:disabled):hover {
    transform: scale(1.05);
    box-shadow: 0 0 15px rgba(250, 191, 60, 0.4);
}
/* --- Сообщения (Баблы) --- */
.tc-message-wrapper {
    display: flex;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    animation: fadeInMessage 0.3s ease forwards;
    opacity: 0;
}

@keyframes fadeInMessage {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Пользователь */
.tc-message-wrapper.user {
    justify-content: flex-end;
}
.tc-message-wrapper.user .tc-bubble {
    background: #2a2a2a;
    color: #fff;
    border-radius: 20px 20px 4px 20px;
    padding: 12px 18px;
    font-size: 0.95rem;
    line-height: 1.6;
    max-width: 80%;
    border: 1px solid rgba(255,255,255,0.05);
}

/* Бот */
.tc-message-wrapper.bot {
    justify-content: flex-start;
    gap: 12px;
}
.tc-bot-avatar {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: rgba(250, 191, 60, 0.15);
    border: 1px solid rgba(250, 191, 60, 0.3);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 4px;
}
.tc-message-wrapper.bot .tc-bubble {
    color: #e0e0e0;
    font-size: 0.95rem;
    line-height: 1.6;
    max-width: 85%;
    padding: 8px 0; /* У бота нет явного фона, выглядит как статья */
}

/* --- Форматирование внутри ответа бота (Markdown) --- */

.tc-markdown-body {
    width: 100%;
    color: #e0e0e0;
    line-height: 1.6;
    font-size: 0.95rem;
}

/* Отступы для абзацев */
.tc-markdown-body p {
    margin-bottom: 1rem;
}
.tc-markdown-body p:last-child {
    margin-bottom: 0;
}

/* Заголовки */
.tc-markdown-body h1, 
.tc-markdown-body h2, 
.tc-markdown-body h3, 
.tc-markdown-body h4 {
    color: #fff;
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    font-weight: 600;
}
.tc-markdown-body h1 { font-size: 1.5rem; }
.tc-markdown-body h2 { font-size: 1.3rem; }
.tc-markdown-body h3 { font-size: 1.15rem; }

/* Списки */
.tc-markdown-body ul, 
.tc-markdown-body ol {
    margin-bottom: 1rem;
    padding-left: 1.5rem;
}
.tc-markdown-body li {
    margin-bottom: 0.3rem;
}

/* Инлайн-код */
.tc-markdown-body code:not(.hljs) {
    font-family: 'Fira Code', 'Courier New', monospace;
    background: rgba(250, 191, 60, 0.15); /* Цвет в стиле вашего сайта */
    color: #FABF3C;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-size: 0.85em;
}

/* Блоки с кодом (Обертка) */
.tc-code-wrapper {
    background: #0d1117; /* Темный фон под код */
    border: 1px solid #30363d;
    border-radius: 8px;
    margin: 1.2rem 0;
    overflow: hidden;
}

/* Шапка блока с кодом */
.tc-code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #161b22;
    padding: 6px 12px;
    border-bottom: 1px solid #30363d;
}

.tc-code-lang {
    font-size: 0.75rem;
    color: #8b949e;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.tc-code-copy {
    background: transparent;
    border: none;
    color: #8b949e;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s;
}

.tc-code-copy:hover {
    color: #c9d1d9;
    background: rgba(255, 255, 255, 0.05);
}

/* Сам код (pre/code) */
.tc-code-wrapper pre {
    margin: 0;
    padding: 12px;
    overflow-x: auto;
}

.tc-code-wrapper pre code {
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: 0.85rem;
    background: transparent;
    padding: 0;
    color: #c9d1d9;
}

/* Таблицы */
.tc-markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.2rem 0;
    font-size: 0.9rem;
}
.tc-markdown-body th, 
.tc-markdown-body td {
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 8px 12px;
    text-align: left;
}
.tc-markdown-body th {
    background: rgba(255, 255, 255, 0.05);
    font-weight: 600;
    color: #fff;
}
.tc-markdown-body tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

/* Цитаты */
.tc-markdown-body blockquote {
    margin: 1rem 0;
    padding: 0.5rem 1rem;
    border-left: 4px solid var(--primary, #FABF3C);
    background: rgba(250, 191, 60, 0.05);
    color: #b0b0b0;
    border-radius: 0 4px 4px 0;
}

/* Ссылки */
.tc-markdown-body a {
    color: var(--primary, #FABF3C);
    text-decoration: none;
}
.tc-markdown-body a:hover {
    text-decoration: underline;
}

/* Горизонтальные линии */
.tc-markdown-body hr {
    border: 0;
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
    margin: 1.5rem 0;
}
/* Анимация "Печатает..." */
.tc-typing-indicator { display: flex; gap: 5px; align-items: center; height: 24px;}
.tc-dot { width: 6px; height: 6px; background: #888; border-radius: 50%; animation: tc-typing 1.4s infinite ease-in-out both; }
.tc-dot:nth-child(1) { animation-delay: -0.32s; }
.tc-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes tc-typing {
    0%, 80%, 100% { transform: scale(0); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; background: var(--primary); }
}

.tc-bubble pre {
    background: #282c34; /* Цвет под тему atom-one-dark */
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 10px 0;
}
.tc-bubble code {
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: 0.9em;
}
/* Инлайн-код */
.tc-bubble p > code, .tc-bubble li > code {
    background: rgba(255,255,255,0.1);
    padding: 2px 6px;
    border-radius: 4px;
    color: #fabf3c;
}
.tc-bubble table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
}
.tc-bubble th, .tc-bubble td {
    border: 1px solid rgba(255,255,255,0.2);
    padding: 8px;
}

/* --- Фикс отступа снизу --- */
#chat-bottom-spacer {
    flex-shrink: 0 !important; /* Запрещаем флексбоксу сжимать этот блок */
    width: 100%;
    min-height: 150px;         /* Базовый размер */
    pointer-events: none;
}

/* Гарантируем, что последнее сообщение пользователя выравнивается правильно */
.tc-message-wrapper:last-of-type {
    margin-bottom: 0 !important;
}

/* --- Фикс клика по превью над полем ввода --- */
#tc-image-preview-container {
    pointer-events: auto !important; /* Возвращаем кликабельность! */
    border-color: #333 !important;
    background: #1a1a1a !important;
}

#tc-remove-image-btn {
    transition: all 0.2s ease;
    background: rgba(255, 77, 77, 0.9) !important;
}
#tc-remove-image-btn:hover {
    transform: scale(1.15);
    background: #ff4d4d !important;
}

/* --- Красивая картинка внутри чата (сообщение пользователя) --- */
.tc-attached-image-box {
    margin-bottom: 8px; /* Отступ между картинкой и текстом */
}

.tc-attached-image-box img {
    max-width: 100%;
    max-height: 250px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    object-fit: cover;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    display: block;
}

/* Если пользователь отправил только картинку без текста */
.tc-bubble.only-image {
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
}

/* =========================================
   ИСТОРИЯ ЧАТОВ (КРАСИВЫЙ И ЧИТАЕМЫЙ UI)
   ========================================= */

.tc-history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px; /* Даем больше "воздуха" внутри блока */
    background: rgba(255, 255, 255, 0.04); /* Легкий светлый фон для контраста */
    border-radius: 12px;
    margin-bottom: 8px; /* Отступ между чатами */
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s ease;
}

.tc-history-item:hover {
    background: rgba(255, 255, 255, 0.08); /* Подсветка при наведении */
}

/* Активный (выбранный) чат */
.tc-history-item.active {
    background: rgba(250, 191, 60, 0.08);
    border-color: rgba(250, 191, 60, 0.3);
}

/* Фикс обрезания текста: убираем конфликты высоты */
.tc-history-item > div:first-child {
    overflow: hidden;
    flex-grow: 1;
    padding-right: 10px;
}

.tc-history-title {
    color: #f1f1f1; /* Яркий белый цвет для читаемости */
    font-size: 0.95rem;
    font-weight: 500;
    line-height: 1.4; /* ИСПРАВЛЕНИЕ ОБРЕЗАННЫХ БУКВ СНИЗУ И СВЕРХУ */
    margin-bottom: 4px; /* Отделяем текст от даты */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tc-history-item.active .tc-history-title {
    color: var(--primary, #FABF3C); /* Желтый заголовок у активного чата */
}

.tc-history-date {
    font-size: 0.75rem;
    color: #8b8b8b; /* Мягкий серый для второстепенной инфы */
    line-height: 1;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Иконка удаления */
.tc-history-delete {
    background: transparent;
    border: none;
    color: #666;
    padding: 8px;
    border-radius: 8px;
    opacity: 0.6; /* Слегка видно всегда */
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.tc-history-item:hover .tc-history-delete {
    opacity: 1;
    color: #ff4d4d;
    background: rgba(255, 77, 77, 0.15);
}

/* =========================================
   КРАСИВАЯ ШАПКА И КНОПКА "НОВЫЙ ЧАТ"
   ========================================= */

/* Делаем заголовок аккуратным, современным и не таким кричащим */
#text-chat-sidebar-view .chat-sidebar-header {
    font-family: 'Manrope', sans-serif !important; /* Убираем угловатый шрифт */
    font-size: 0.75rem !important;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: #8b8b8b !important;
    padding: 24px 16px 12px 16px !important;
    border-bottom: none !important;
    background: transparent !important;
}

#text-chat-sidebar-view .chat-sidebar-header span {
    font-weight: 700 !important;
    opacity: 0.8;
}

/* Корректируем отступы вокруг кнопки, чтобы было гармонично */
#text-chat-sidebar-view .p-3.pb-0 {
    padding: 0 16px 16px 16px !important;
}

/* Премиальная мягкая кнопка вместо стандартной обводки */
#tc-new-chat-btn {
    background: rgba(250, 191, 60, 0.08) !important; /* Мягкий желтый фон */
    border: 1px solid rgba(250, 191, 60, 0.2) !important; /* Легкая рамка */
    color: #FABF3C !important;
    border-radius: 12px !important;
    padding: 12px !important;
    font-weight: 600 !important;
    font-size: 0.95rem !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    box-shadow: none !important;
}

/* Эффект при наведении (кнопка загорается) */
#tc-new-chat-btn:hover {
    background: rgba(250, 191, 60, 0.15) !important;
    border-color: rgba(250, 191, 60, 0.5) !important;
    color: #fff !important; /* Текст становится белым */
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(250, 191, 60, 0.15) !important;
}

/* Красивая анимация плюсика внутри кнопки */
#tc-new-chat-btn svg {
    transition: transform 0.3s ease;
}
#tc-new-chat-btn:hover svg {
    transform: rotate(90deg); /* Плюсик красиво поворачивается */
}

/* =========================================
   МОБИЛЬНАЯ ВЫПАДАЮЩАЯ ИСТОРИЯ (АККОРДЕОН)
   ========================================= */
@media (max-width: 991px) {
    /* Превращаем левую панель в компактный блок */
    #text-chat-sidebar-view {
        height: auto !important;
        background: #151515; /* Темный фон */
        border-radius: 16px;
        border: 1px solid rgba(255, 255, 255, 0.05);
        flex-direction: column;
        overflow: hidden;
        flex-shrink: 0;
    }

    /* Заголовок теперь работает как кнопка открытия */
    #text-chat-sidebar-view .chat-sidebar-header {
        cursor: pointer;
        display: flex !important;
        justify-content: space-between;
        align-items: center;
        padding: 4px 20px !important;
        transition: all 0.2s ease;
    }

    /* Рисуем стрелочку вниз */
    #text-chat-sidebar-view .chat-sidebar-header::after {
        content: '';
        display: block;
        width: 8px;
        height: 8px;
        border-bottom: 2px solid #8b8b8b;
        border-right: 2px solid #8b8b8b;
        transform: rotate(45deg);
        transition: transform 0.3s ease, border-color 0.3s ease;
    }

    /* Прячем кнопку "Новый чат" и сам список по умолчанию */
    #text-chat-sidebar-view .p-3,
    #tc-history-list {
        display: none;
    }

    /* ===== ОТКРЫТОЕ СОСТОЯНИЕ (Класс mobile-open) ===== */
    
    #text-chat-sidebar-view.mobile-open .chat-sidebar-header::after {
        transform: rotate(-135deg); /* Стрелка смотрит вверх */
        border-color: #FABF3C;
    }
    
    #text-chat-sidebar-view.mobile-open .chat-sidebar-header span {
        color: #FABF3C !important; /* Текст становится желтым */
    }

    /* Показываем контент */
    #text-chat-sidebar-view.mobile-open .p-3,
    #text-chat-sidebar-view.mobile-open #tc-history-list {
        display: block;
        animation: fadeInDown 0.3s ease forwards;
    }

    /* Ограничиваем высоту списка, чтобы он не улетал за пределы экрана */
    #tc-history-list {
        max-height: 45vh;
        overflow-y: auto;
        padding-bottom: 15px !important;
    }
}

@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* =========================================
   АДАПТАЦИЯ ПРИВЕТСТВЕННОГО ЭКРАНА (МОБИЛЬНЫЕ)
   ========================================= */
@media (max-width: 991px) {
    /* Скрываем огромную желтую иконку */
    .welcome-icon-glow {
        display: none !important;
    }
    
    /* Убираем смещение вверх, чтобы текст не наезжал на шапку */
    #text-chat-welcome {
        transform: none !important;
        padding-top: 10px;
    }

    /* Делаем заголовок чуть компактнее */
    #text-chat-welcome h4 {
        font-size: 1.25rem;
    }
}

/* Бейдж стоимости ответа */
.tc-message-cost {
    font-size: 0.65rem;
    color: #8b8b8b;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    gap: 4px;
    opacity: 0.8;
}
.tc-message-cost svg {
    color: #FABF3C;
}

/* =========================================
   ИСПРАВЛЕНИЕ ШАПКИ НА МОБИЛЬНЫХ ЭКРАНАХ
   ========================================= */
@media (max-width: 991px) {
    /* Уменьшаем боковые отступы в самой шапке */
    .text-chat-header {
        padding-left: 12px !important;
        padding-right: 12px !important;
    }
    
    /* Сжимаем контейнеры с кнопками */
    .text-chat-header > div.d-flex {
        gap: 4px !important;
    }

    /* Делаем выпадающий список резиновым */
    #dd-text-model {
        width: auto !important;
        min-width: 140px;
        flex-shrink: 1; /* Позволяем ему сжиматься */
    }

    /* Обрезаем длинные названия моделей (например Claude Sonnet 4.6 -> Claude Son...) */
    #dd-text-model .selected-text {
        font-size: 0.75rem !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 115px; 
        display: inline-block;
        vertical-align: bottom;
    }

    /* Чуть сжимаем иконки справа (Инфо и Корзина) */
    #tc-pricing-btn, 
    #text-chat-clear-btn {
        width: 32px;
        height: 32px;
        padding: 0;
        margin: 0 !important;
    }
}