/* css/text_chat.css */

/* =========================================
   1. ПЕРЕМЕННЫЕ
   ========================================= */
:root {
    --tc-primary: #FABF3C;
    --tc-primary-rgb: 250, 191, 60;
    --tc-surface: #1a1a1a;
    --tc-surface-2: #151515;
    --tc-border: rgba(255, 255, 255, 0.1);
    --tc-border-code: #30363d;
    --tc-bg-code: #0d1117;
    --tc-bg-code-header: #161b22;
    --tc-text-primary: #fff;
    --tc-text-secondary: #e0e0e0;
    --tc-text-muted: #8b8b8b;
    --tc-text-placeholder: #666;
    --tc-radius-sm: 8px;
    --tc-radius-md: 12px;
    --tc-radius-lg: 20px;
    --tc-font-mono: 'Fira Code', 'Courier New', monospace;
    --tc-transition: all 0.2s ease;
}

/* =========================================
   2. АНИМАЦИИ
   ========================================= */
@keyframes fadeInMessage {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

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

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

/* =========================================
   3. ШАПКА
   ========================================= */
.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(var(--tc-primary-rgb), 0.1);
    border-radius: var(--tc-radius-sm);
    color: var(--primary);
}

.btn-icon-ghost {
    background: transparent;
    border: none;
    color: #888;
    width: 34px;
    height: 34px;
    border-radius: var(--tc-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--tc-transition);
}
.btn-icon-ghost:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--tc-text-primary);
}

/* =========================================
   4. ЭКРАН ПРИВЕТСТВИЯ
   ========================================= */
.welcome-icon-glow {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(var(--tc-primary-rgb), 0.05);
    border: 1px solid rgba(var(--tc-primary-rgb), 0.2);
    border-radius: 50%;
    box-shadow: 0 0 30px rgba(var(--tc-primary-rgb), 0.15);
}

.suggestion-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--tc-border);
    color: #ccc;
    padding: 8px 16px;
    border-radius: var(--tc-radius-lg);
    font-size: 0.85rem;
    transition: var(--tc-transition);
}
.suggestion-btn:hover {
    background: rgba(var(--tc-primary-rgb), 0.1);
    border-color: rgba(var(--tc-primary-rgb), 0.5);
    color: var(--tc-primary);
    transform: translateY(-2px);
}

/* =========================================
   5. ПОЛЕ ВВОДА
   ========================================= */
.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: var(--tc-surface);
    border: 1px solid var(--tc-border);
    border-radius: var(--tc-radius-lg);
    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(var(--tc-primary-rgb), 0.4);
}

#text-chat-input {
    flex-grow: 1;
    background: transparent;
    border: none;
    color: var(--tc-text-primary);
    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;
}
#text-chat-input::placeholder {
    color: var(--tc-text-placeholder);
}

.chat-send-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--tc-radius-sm);
    border: none;
    background: var(--tc-primary);
    color: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--tc-transition);
    flex-shrink: 0;
    margin-bottom: 2px;
    outline: none;
}
.chat-send-btn:disabled {
    background: #333;
    color: var(--tc-text-placeholder);
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}
.chat-send-btn:not(:disabled):hover {
    transform: scale(1.05);
    box-shadow: 0 0 15px rgba(var(--tc-primary-rgb), 0.4);
}

/* =========================================
   6. СООБЩЕНИЯ (БАБЛЫ) — БАЗОВЫЕ СТИЛИ
   ========================================= */
.tc-message-wrapper {
    display: flex;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    animation: fadeInMessage 0.3s ease forwards;
    opacity: 0;
}

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

/* Бот */
.tc-message-wrapper.bot {
    justify-content: flex-start;
    gap: 24px;
}
.tc-message-wrapper.bot .tc-bubble {
    max-width: 85%;
    padding: 8px 0;
}

/* Общие стили для всех баблов */
.tc-bubble {
    color: var(--tc-text-secondary);
    font-size: 0.95rem;
    line-height: 1.6;
}

/* Аватар бота */
.tc-bot-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--tc-radius-sm);
    background: rgba(var(--tc-primary-rgb), 0.15);
    border: 1px solid rgba(var(--tc-primary-rgb), 0.3);
    color: var(--tc-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 4px;
}

/* Последнее сообщение */
.tc-message-wrapper:last-of-type {
    margin-bottom: 0;
}

/* =========================================
   7. ВЛОЖЕНИЯ В СООБЩЕНИЯХ
   ========================================= */
.tc-attached-image-box {
    margin-bottom: 8px;
}
.tc-attached-image-box img {
    max-width: 100%;
    max-height: 250px;
    border-radius: var(--tc-radius-md);
    border: 1px solid var(--tc-border);
    object-fit: cover;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    display: block;
}

.tc-bubble.only-image {
    background: transparent;
    border: none;
    padding: 0;
}

/* Бейдж стоимости */
.tc-message-cost {
    font-size: 0.65rem;
    color: var(--tc-text-muted);
    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: var(--tc-primary);
}

/* =========================================
   8. АНИМАЦИЯ "ПЕЧАТАЕТ..."
   ========================================= */
.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; }

/* =========================================
   9. MARKDOWN — ФОРМАТИРОВАНИЕ ОТВЕТА БОТА
   ========================================= */
.tc-markdown-body {
    width: 100%;
    color: var(--tc-text-secondary);
    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: var(--tc-text-primary);
    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: var(--tc-font-mono);
    background: rgba(var(--tc-primary-rgb), 0.15);
    color: var(--tc-primary);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-size: 0.85em;
}

/* Таблицы */
.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 var(--tc-border);
    padding: 8px 12px;
    text-align: left;
}
.tc-markdown-body th {
    background: rgba(255, 255, 255, 0.05);
    font-weight: 600;
    color: var(--tc-text-primary);
}
.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(--tc-primary);
    background: rgba(var(--tc-primary-rgb), 0.05);
    color: #b0b0b0;
    border-radius: 0 4px 4px 0;
}

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

/* Горизонтальные линии */
.tc-markdown-body hr {
    border: 0;
    height: 1px;
    background: var(--tc-border);
    margin: 1.5rem 0;
}

/* =========================================
   10. БЛОКИ КОДА (продолжение)
   ========================================= */
.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: var(--tc-transition);
}
.tc-code-copy:hover {
    color: #c9d1d9;
    background: rgba(255, 255, 255, 0.05);
}

.tc-code-wrapper pre {
    margin: 0;
    padding: 12px;
    overflow-x: auto;
}
.tc-code-wrapper pre code {
    font-family: var(--tc-font-mono);
    font-size: 0.85rem;
    background: transparent;
    padding: 0;
    color: #c9d1d9;
}

/* Обертка всего блока кода */
.tc-code-wrapper {
    background: var(--tc-bg-code);
    border: 1px solid var(--tc-border-code);
    border-radius: var(--tc-radius-md);
    margin: 12px 0;
    overflow: hidden; /* Чтобы скрыть острые углы внутренних элементов */
}

/* Шапка с названием языка и кнопкой копирования */
.tc-code-header {
    display: flex;
    justify-content: space-between; /* Расталкивает язык и кнопку по разным краям */
    align-items: center;
    padding: 8px 12px;
    background: var(--tc-bg-code-header);
    border-bottom: 1px solid var(--tc-border-code);
}

/* =========================================
   11. ПРЕВЬЮ ИЗОБРАЖЕНИЯ НАД ПОЛЕМ ВВОДА
   ========================================= */
#tc-image-preview-container {
    pointer-events: auto;
    border-color: #333;
    background: var(--tc-surface);
}

#tc-remove-image-btn {
    transition: var(--tc-transition);
    background: rgba(255, 77, 77, 0.9);
}
#tc-remove-image-btn:hover {
    transform: scale(1.15);
    background: #ff4d4d;
}

/* =========================================
   12. ОТСТУП СНИЗУ (СПЕЙСЕР)
   ========================================= */
#chat-bottom-spacer {
    flex-shrink: 0;
    width: 100%;
    min-height: 150px;
    pointer-events: none;
}

/* =========================================
   13. ИСТОРИЯ ЧАТОВ
   ========================================= */
.tc-history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: var(--tc-radius-md);
    margin-bottom: 8px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: var(--tc-transition);
}
.tc-history-item:hover {
    background: rgba(255, 255, 255, 0.08);
}
.tc-history-item.active {
    background: rgba(var(--tc-primary-rgb), 0.08);
    border-color: rgba(var(--tc-primary-rgb), 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(--tc-primary);
}

.tc-history-date {
    font-size: 0.75rem;
    color: var(--tc-text-muted);
    line-height: 1;
    display: flex;
    align-items: center;
    gap: 6px;
}

.tc-history-delete {
    background: transparent;
    border: none;
    color: var(--tc-text-placeholder);
    padding: 8px;
    border-radius: var(--tc-radius-sm);
    opacity: 0.6;
    transition: var(--tc-transition);
    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);
}

/* =========================================
   14. ШАПКА САЙДБАРА И КНОПКА "НОВЫЙ ЧАТ"
   ========================================= */
#text-chat-sidebar-view .chat-sidebar-header {
    font-family: 'Manrope', sans-serif;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--tc-text-muted);
    padding: 24px 16px 12px 16px;
    border-bottom: none;
    background: transparent;
}
#text-chat-sidebar-view .chat-sidebar-header span {
    font-weight: 700;
    opacity: 0.8;
}

#text-chat-sidebar-view .p-3.pb-0 {
    padding: 0 16px 16px 16px;
}

#tc-new-chat-btn {
    background: rgba(var(--tc-primary-rgb), 0.08);
    border: 1px solid rgba(var(--tc-primary-rgb), 0.2);
    color: var(--tc-primary);
    border-radius: var(--tc-radius-md);
    padding: 12px;
    font-weight: 600;
    font-size: 0.95rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: none;
}
#tc-new-chat-btn:hover {
    background: rgba(var(--tc-primary-rgb), 0.15);
    border-color: rgba(var(--tc-primary-rgb), 0.5);
    color: var(--tc-text-primary);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(var(--tc-primary-rgb), 0.15);
}

#tc-new-chat-btn svg {
    transition: transform 0.3s ease;
}
#tc-new-chat-btn:hover svg {
    transform: rotate(90deg);
}

/* =========================================
   15. МОБИЛЬНАЯ АДАПТАЦИЯ
   ========================================= */
@media (max-width: 991px) {

    /* --- Шапка --- */
    .text-chat-header {
        padding-left: 12px;
        padding-right: 12px;
    }
    .text-chat-header > div.d-flex {
        gap: 4px;
    }
    #dd-text-model {
        width: auto;
        min-width: 140px;
        flex-shrink: 1;
    }
    #dd-text-model .selected-text {
        font-size: 0.75rem;
        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;
    }

    /* --- Приветственный экран --- */
    .welcome-icon-glow {
        display: none;
    }
    #text-chat-welcome {
        transform: none;
        padding-top: 10px;
    }
    #text-chat-welcome h4 {
        font-size: 1.25rem;
    }

    /* --- Сайдбар (аккордеон) --- */
    #text-chat-sidebar-view {
        height: auto;
        background: var(--tc-surface-2);
        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;
        justify-content: space-between;
        align-items: center;
        padding: 4px 20px;
        transition: var(--tc-transition);
    }
    #text-chat-sidebar-view .chat-sidebar-header::after {
        content: '';
        display: block;
        width: 8px;
        height: 8px;
        border-bottom: 2px solid var(--tc-text-muted);
        border-right: 2px solid var(--tc-text-muted);
        transform: rotate(45deg);
        transition: transform 0.3s ease, border-color 0.3s ease;
    }

    /* Скрытое состояние */
    #text-chat-sidebar-view .p-3,
    #tc-history-list {
        display: none;
    }

    /* Открытое состояние */
    #text-chat-sidebar-view.mobile-open .chat-sidebar-header::after {
        transform: rotate(-135deg);
        border-color: var(--tc-primary);
    }
    #text-chat-sidebar-view.mobile-open .chat-sidebar-header span {
        color: var(--tc-primary);
    }
    #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;
    }
}