/*
 * Telegram AI Client - Modern Stylesheet
 * 2024 Redesign
 */

/* --- 1. CSS Variables & Theming --- */
:root {
    /* Light Theme (Default) */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

    /* Colors */
    --color-bg-primary: #f8f9fa;       /* Main background, very light grey */
    --color-bg-secondary: #ffffff;   /* Cards, modals, sidebars */
    --color-bg-tertiary: #f1f3f5;    /* Hover states, input backgrounds */
    --color-bg-accent: #e9ecef;       /* Subtle accents, borders */
    --color-bg-overlay: rgba(33, 37, 41, 0.5); /* Modal overlay */
    --color-bg-user-message: #3b82f6; /* Blue 500 */
    --color-bg-interlocutor-message: #e5e7eb; /* Cool Gray 200 */

    --color-text-primary: #212529;    /* Main text, almost black */
    --color-text-secondary: #495057;  /* Muted text */
    --color-text-tertiary: #adb5bd;   /* Borders, placeholders */
    --color-text-accent: #3b82f6;      /* Primary accent color (links, etc.) */
    --color-text-on-accent: #ffffff; /* Text on accent background (e.g., buttons) */
    --color-text-user-message: #ffffff;
    --color-text-interlocutor-message: #1f2937; /* Cool Gray 800 */
    --accent-color-hover: #3b82f6;
    --text-color: #212529;
    --text-color-light: #495057;
    --background-color: #e9ecef;
    /* Action Colors */
    --color-success: #16a34a; /* Green 600 */
    --color-danger: #dc2626;  /* Red 600 */
    --color-warning: #f59e0b; /* Amber 500 */
    --color-info: #0ea5e9;    /* Sky 500 */

    /* UI Elements */
    --border-color: #dee2e6;
    --border-radius-sm: 4px;
    --border-radius-md: 8px;
    --border-radius-lg: 16px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    --focus-ring: 0 0 0 3px rgba(59, 130, 246, 0.3);

    /* Transitions */
    --transition-fast: all 0.15s ease-in-out;
    --transition-slow: all 0.3s ease-in-out;
}

body[data-theme="dark"] {
    /* Dark Theme */
    --color-bg-primary: #111827;     /* Gray 900 */
    --color-bg-secondary: #1f2937;   /* Gray 800 */
    --color-bg-tertiary: #374151;    /* Gray 700 */
    --color-bg-accent: #4b5563;       /* Gray 600 */
    --color-bg-overlay: rgba(0, 0, 0, 0.7);
    --color-bg-user-message: #3b82f6; /* Blue 500 - stays the same */
    --color-bg-interlocutor-message: #374151; /* Gray 700 */

    --color-text-primary: #f9fafb;    /* Gray 50 */
    --color-text-secondary: #d1d5db;  /* Gray 300 */
    --color-text-tertiary: #6b7280;   /* Gray 500 */
    --color-text-accent: #60a5fa;      /* Blue 400 - slightly lighter */
    --color-text-on-accent: #ffffff;
    --color-text-user-message: #ffffff;
    --color-text-interlocutor-message: #f3f4f6; /* Gray 100 */

    --border-color: #4b5563;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.15);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.2), 0 2px 4px -2px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.25), 0 4px 6px -4px rgba(0, 0, 0, 0.25);
    --focus-ring: 0 0 0 3px rgba(96, 165, 250, 0.4);
}


/* --- 2. Base & Reset Styles --- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    margin: 0;
    padding: 0;
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.6;
    background-color: var(--color-bg-primary);
    color: var(--color-text-primary);
    transition: background-color var(--transition-slow), color var(--transition-slow);

    /* ЗМІНИТИ ТУТ: */
    height: 100vh; /* Фіксуємо висоту, щоб працювали внутрішні скроли */
    width: 100vw;  /* Фіксуємо ширину */
    overflow: hidden; /* Ховаємо зовнішній скрол */
}
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--color-bg-tertiary); }
::-webkit-scrollbar-thumb { background: var(--color-bg-accent); border-radius: var(--border-radius-lg); }
::-webkit-scrollbar-thumb:hover { background: var(--color-text-tertiary); }
a { color: var(--color-text-accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: 600; }
ul { list-style: none; padding: 0; margin: 0; }

/* --- 3. Utility Classes & Base Components --- */
/* Buttons */
.button-primary, .button-secondary, .button-success, .button-danger, .button-light {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    font-weight: 500;
    border-radius: var(--border-radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: var(--transition-fast);
}
.button-primary { background-color: var(--color-text-accent); color: var(--color-text-on-accent); }
.button-primary:hover { filter: brightness(1.1); }
.button-secondary { background-color: var(--color-bg-tertiary); color: var(--color-text-primary); border-color: var(--border-color); }
.button-secondary:hover { background-color: var(--color-bg-accent); }
.button-success { background-color: var(--color-success); color: #fff; }
.button-success:hover { filter: brightness(1.1); }
.button-danger { background-color: var(--color-danger); color: #fff; }
.button-danger:hover { filter: brightness(1.1); }
.button-light { background-color: var(--color-bg-secondary); color: var(--color-text-primary); border-color: var(--border-color); }
.button-light:hover { background-color: var(--color-bg-tertiary); }
.icon-button {
    background: none;
    border: none;
    color: var(--color-text-secondary);
    font-size: 1.1em;
    padding: 5px;
    cursor: pointer;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    transition: var(--transition-fast);
}
.icon-button:hover { background-color: var(--color-bg-tertiary); color: var(--color-text-accent); }

/* Inputs & Forms */
input[type="text"], input[type="password"], textarea, select {
    width: 100%;
    padding: 10px 12px;
    font-family: var(--font-sans);
    font-size: 1em;
    background-color: var(--color-bg-secondary);
    color: var(--color-text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    transition: var(--transition-fast);
}
input[type="text"]:focus, input[type="password"]:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--color-text-accent);
    box-shadow: var(--focus-ring);
}
textarea { resize: vertical; min-height: 100px; }

/* --- 4. Page Layout & Main Blocks --- */
/* Theme Switcher */
.theme-switcher {
    position: fixed;
    top: 15px;
    right: 20px;
    z-index: 1000;
}
#theme-toggle-button {
    background: var(--color-bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--color-text-secondary);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: var(--transition-fast);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
#theme-toggle-button:hover { color: var(--color-text-accent); box-shadow: var(--shadow-md); }
#theme-toggle-button .fa-sun { display: none; }
#theme-toggle-button .fa-moon { display: block; }
body[data-theme="dark"] #theme-toggle-button .fa-sun { display: block; }
body[data-theme="dark"] #theme-toggle-button .fa-moon { display: none; }

/* Main Page (Login) */
.main-page {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100vh;
}
.main-page-content {
    background-color: var(--color-bg-secondary);
    padding: 40px;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    text-align: center;
    max-width: 450px;
    animation: fadeIn 0.5s ease-out;
}
.main-page h1 { font-size: 2em; font-weight: 700; color: var(--color-text-primary); margin-bottom: 8px; display: flex; align-items: center; justify-content: center; gap: 12px; }
.main-page-subtitle { color: var(--color-text-secondary); margin-top: 0; margin-bottom: 30px; }
.main-page .links { display: flex; flex-direction: column; gap: 12px; margin-bottom: 30px; }
.main-page .links a { width: 100%; }
.global-settings { display: flex; align-items: center; gap: 15px; background: var(--color-bg-primary); padding: 12px; border-radius: var(--border-radius-md); }
.global-ai-text { text-align: left; }
.global-ai-text span { font-weight: 600; }
.global-ai-text p { font-size: 0.85em; color: var(--color-text-secondary); margin: 2px 0 0; }
.switch { position: relative; display: inline-block; width: 50px; height: 28px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--color-bg-accent); transition: .4s; }
.slider:before { position: absolute; content: ""; height: 20px; width: 20px; left: 4px; bottom: 4px; background-color: white; transition: .4s; }
input:checked + .slider { background-color: var(--color-success); }
input:checked + .slider:before { transform: translateX(22px); }
.slider.round { border-radius: 34px; }
.slider.round:before { border-radius: 50%; }

/* Telegram Client */
.telegram-client {
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--color-bg-primary);
}
/* Головна картка: Обгортка для сайдбару та форми */
.login-wrapper {
    display: flex;
    width: 900px;           /* Фіксована ширина для десктопу */
    max-width: 95%;         /* Щоб не вилазило на малих екранах */
    height: 600px;          /* Фіксована висота */
    background: var(--color-bg-secondary);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;       /* Щоб кути не обрізались */
}

/* ЛІВА ЧАСТИНА: Сайдбар сесій */
.sessions-sidebar {
    width: 320px;           /* Фіксована ширина колонки */
    background-color: var(--color-bg-tertiary); /* Трохи темніший фон */
    border-right: 1px solid var(--border-color);
    padding: 30px;
    display: flex;
    flex-direction: column;
    overflow-y: auto;       /* Скрол, якщо сесій багато */
}

.sessions-sidebar h3 {
    margin-bottom: 20px;
    font-size: 1.1em;
    color: var(--color-text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ПРАВА ЧАСТИНА: Контейнер форми */
.login-main {
    flex: 1;                /* Займає весь залишковий простір */
    padding: 40px;
    display: flex;
    flex-direction: column;
    justify-content: center; /* Вертикальне центрування форми */
    align-items: center;
    overflow-y: auto;
}
.container { width: 100%; height: 100%; display: flex; flex-direction: column; }
.login-form {
    width: 100%;
    max-width: 380px;       /* Обмежуємо ширину форми, щоб поля не були гігантськими */
    margin: 0 auto;         /* Центруємо форму горизонтально */
    display: flex;
    flex-direction: column;
    gap: 15px;              /* Відступи між інпутами */
}

/* Гарантуємо, що інпути не вилазять за межі */
.login-form input,
.login-form button {
    width: 100%;            /* Розтягуємо на всю ширину батька (.login-form) */
    box-sizing: border-box; /* Важливо! Враховує padding у ширину */
}

.login-form h2 {
    text-align: center;
    margin-bottom: 25px;
}
.main-content {
    display: grid;
    grid-template-columns: 280px 1fr 320px;
    width: 100%;
    height: 100vh; /* Примусово на весь екран */
    overflow: hidden;
}
.sessions-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.session-card {
    background: var(--color-bg-secondary);
    border: 1px solid var(--border-color);
    padding: 12px 14px;
    border-radius: var(--border-radius-md);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    transition: var(--transition-fast);
}

.session-card:hover {
    border-color: var(--color-text-accent);
    transform: translateX(4px);
    box-shadow: var(--shadow-md);
}

.session-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.session-name {
    font-weight: 600;
    font-size: 0.95em;
    color: var(--color-text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.session-phone {
    font-size: 0.85em;
    color: var(--color-text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.session-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
    flex-wrap: wrap;
}

.session-status {
    font-size: 0.78em;
    display: flex;
    align-items: center;
    gap: 4px;
}

.session-ai-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.76em;
    padding: 2px 7px;
    border-radius: 10px;
    background: var(--color-bg-primary);
    color: var(--color-text-tertiary);
    border: 1px solid var(--border-color);
    font-weight: 500;
    transition: var(--transition-fast);
    line-height: 1.2;
}

.session-ai-badge i {
    font-size: 0.9em;
}

.session-ai-badge.active {
    background: rgba(59, 130, 246, 0.12);
    color: var(--color-text-accent);
    border-color: rgba(59, 130, 246, 0.3);
    font-weight: 600;
}

body[data-theme="dark"] .session-ai-badge.active {
    background: rgba(96, 165, 250, 0.16);
    color: #60a5fa;
    border-color: rgba(96, 165, 250, 0.35);
}

.session-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.session-action-btn {
    width: 30px;
    height: 30px;
    border-radius: var(--border-radius-sm);
    font-size: 0.85em;
    color: var(--color-text-secondary);
    background: transparent;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
}

.session-action-btn:hover {
    background-color: var(--color-bg-tertiary);
    color: var(--color-text-accent);
}

.session-delete-btn:hover {
    background-color: rgba(220, 38, 38, 0.15) !important;
    color: var(--color-danger) !important;
}

.session-arrow {
    color: var(--color-text-tertiary);
    font-size: 0.85em;
    margin-left: 2px;
    display: flex;
    align-items: center;
}
/* Sidebar (Left) */
.sidebar {
    background: var(--color-bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex; /* <-- Вмикаємо Flexbox */
    flex-direction: column; /* <-- Встановлюємо вертикальний напрямок */
    overflow: hidden; /* <-- Важливо, щоб дочірні елементи не виходили за межі */
}

.sidebar-header, .photo-requests {
    flex-shrink: 0; /* <-- Забороняємо цим блокам стискатись */
}

.chat-list {
    flex-grow: 1; /* <-- КЛЮЧОВА ЗМІНА: Дозволяємо блоку рости і займати весь вільний простір */
    overflow-y: auto; /* <-- КЛЮЧОВА ЗМІНА: Вмикаємо скролінг, якщо контент не влазить */
}
.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.sidebar-header h3 { font-size: 1.1em; color: var(--color-text-primary); }
/* Chat Search Bar */
.chat-search-bar {
    padding: 10px 14px;
    background-color: var(--color-bg-primary);
    border-bottom: 1px solid var(--border-color);
    position: relative;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}
.chat-search-bar input {
    width: 100%;
    padding: 8px 30px 8px 34px;
    border-radius: var(--border-radius-md);
    border: 1px solid var(--border-color);
    background-color: var(--color-bg-secondary);
    color: var(--color-text-primary);
    font-size: 0.88em;
    outline: none;
    transition: var(--transition-fast);
    box-sizing: border-box;
}
.chat-search-bar input:focus {
    border-color: var(--color-text-accent);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}
.chat-search-icon {
    position: absolute;
    left: 24px;
    color: var(--color-text-tertiary);
    font-size: 0.85em;
    pointer-events: none;
}
.chat-search-clear {
    position: absolute;
    right: 20px;
    width: 22px;
    height: 22px;
    font-size: 14px;
    border: none;
    background: transparent;
    color: var(--color-text-tertiary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chat-search-clear:hover {
    color: var(--color-text-primary);
}

.chat-list { flex-grow: 1; overflow-y: auto; }
.chat-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    cursor: pointer;
    transition: background-color var(--transition-fast), border-color var(--transition-fast);
    border-bottom: 1px solid var(--border-color);
    gap: 10px;
}
.chat-list li:hover { background-color: var(--color-bg-tertiary); }
.chat-list li.selected {
    background-color: rgba(59, 130, 246, 0.12);
    border-left: 4px solid var(--color-text-accent);
}
.chat-list li.selected .chat-title {
    color: var(--color-text-accent);
    font-weight: 600;
}
.chat-item-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--color-bg-tertiary);
    color: var(--color-text-secondary);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85em;
    font-weight: 600;
    flex-shrink: 0;
    text-transform: uppercase;
}
.chat-item-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.chat-title { font-weight: 500; font-size: 0.94em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-badges {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
}
.chat-ai-badge {
    font-size: 0.74em;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 10px;
    background: rgba(22, 163, 74, 0.12);
    color: var(--color-success);
    border: 1px solid rgba(22, 163, 74, 0.3);
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.chat-tag {
    font-size: 0.74em;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    color: #fff;
    white-space: nowrap;
}

/* Chat Window (Center) */
.chat-window {
    display: flex;
    flex-direction: column;
    background: var(--color-bg-primary);
    overflow: hidden;
}
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 18px;
    background: var(--color-bg-secondary);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    position: relative;
    z-index: 5;
    min-height: 60px;
    box-sizing: border-box;
}
.chat-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex: 1;
}
.chat-header-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #3b82f6);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9em;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
    text-transform: uppercase;
}
.chat-header-titles {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.chat-header-titles h3 {
    margin: 0;
    font-size: 1.05em;
    font-weight: 600;
    color: var(--color-text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-subtitle {
    font-size: 0.78em;
    color: var(--color-text-tertiary);
    margin-top: 1px;
}
.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.quick-ai-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.82em;
    font-weight: 600;
    border: 1px solid var(--border-color);
    background: var(--color-bg-primary);
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: var(--transition-fast);
    box-shadow: var(--shadow-sm);
    user-select: none;
}
.quick-ai-btn:hover {
    border-color: var(--color-text-accent);
}
.quick-ai-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--color-text-tertiary);
    transition: var(--transition-fast);
}
.quick-ai-btn.active {
    background: rgba(22, 163, 74, 0.1);
    border-color: rgba(22, 163, 74, 0.4);
    color: var(--color-success);
}
.quick-ai-btn.active .quick-ai-dot {
    background-color: var(--color-success);
    box-shadow: 0 0 6px var(--color-success);
    animation: ai-pulse 2s infinite;
}
@keyframes ai-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(1.15); }
}
.messages-container {
    flex-grow: 1; /* <-- КЛЮЧОВА ЗМІНА: Блок росте, щоб зайняти простір між хедером і полем вводу */
    overflow-y: auto; /* <-- КЛЮЧОВА ЗМІНА: Вмикаємо скролінг для повідомлень */
    padding: 20px;
    display: flex;
    flex-direction: column-reverse; /* Це залишаємо, це правильно для чату */
}

#messages { display: flex; flex-direction: column; gap: 12px; }
.message {
    max-width: 75%;
    padding: 10px 15px;
    border-radius: var(--border-radius-lg);
    line-height: 1.5;
    word-wrap: break-word;
}
.message.user {
    background-color: var(--color-bg-user-message);
    color: var(--color-text-user-message);
    align-self: flex-end;
    border-bottom-right-radius: var(--border-radius-sm);
}
.message.interlocutor {
    background-color: var(--color-bg-interlocutor-message);
    color: var(--color-text-interlocutor-message);
    align-self: flex-start;
    border-bottom-left-radius: var(--border-radius-sm);
}
.message-time { font-size: 0.75em; opacity: 0.7; margin-top: 5px; text-align: right; }
.message-media { max-width: 100%; border-radius: var(--border-radius-md); margin-bottom: 8px; }
.message audio { width: 100%; max-width: 300px; display: block; }
.message-text { white-space: pre-wrap; }

/* Message Input */
.message-input {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    background: var(--color-bg-secondary);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0; /* <-- Забороняємо цьому блоку стискатись */
}
.input-wrapper { flex-grow: 1; position: relative; }
#messageInput { border-radius: 20px; padding: 10px 16px; background-color: var(--color-bg-tertiary); border-color: transparent; }
#messageInput:focus { background-color: var(--color-bg-secondary); border-color: var(--color-text-accent); }
.send-button { background-color: var(--color-text-accent); color: var(--color-text-on-accent); }
.send-button:hover { background-color: var(--color-text-accent); filter: brightness(1.1); }
#fileIndicator { position: absolute; bottom: 6px; left: 10px; display: flex; align-items: center; background: var(--color-bg-accent); padding: 2px 8px; border-radius: 10px; font-size: 0.8em; }
#fileName { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#clearFile { background: none; border: none; font-size: 1.2em; cursor: pointer; margin-left: 5px; color: var(--color-text-secondary); }

/* Info Panel (Right) */
.info-panel { background: var(--color-bg-secondary); border-left: 1px solid var(--border-color); display: flex; flex-direction: column; overflow: hidden; }
.info-panel-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border-color); flex-shrink: 0; }
.info-panel h3 { font-size: 1.1em; display: flex; align-items: center; gap: 8px; }
.auto-update-toggle { font-size: 0.9em; color: var(--color-text-secondary); cursor: pointer; display: flex; align-items: center; gap: 6px; }
.info-panel-body { flex-grow: 1; overflow-y: auto; padding: 20px; line-height: 1.7; }
.info-panel-body p { margin-bottom: 1em; color: var(--color-text-secondary); }
.info-panel-body strong { color: var(--color-text-primary); }
.info-panel-footer { display: flex; flex-direction: column; gap: 10px; padding: 16px; border-top: 1px solid var(--border-color); background: var(--color-bg-primary); }
.info-panel-footer button { width: 100%; }

/* --- 5. Modals & Notifications --- */
/* Modals */
.modal {
    display: none; /* <-- Початково приховано JS */
    position: fixed;
    z-index: 1050;
    inset: 0; /* Аналог top:0, right:0, bottom:0, left:0 */
    overflow-y: auto; /* Дозволяє скролити всю сторінку, якщо модалка не влазить */
    background-color: var(--color-bg-overlay);

    /* Flexbox для центрування діалогового вікна */
    display: flex;
    justify-content: center;
    align-items: flex-start; /* Вирівнюємо по верху, padding дасть відступ */
    padding: 50px 20px; /* 50px зверху/знизу, 20px з боків */
}
.modal-dialog {
    width: 100%;
    max-width: 650px; /* Стандартна максимальна ширина */
    margin: auto; /* Додаткове центрування */
    display: flex; /* Flex, щоб контент міг рости */
    flex-direction: column;
    max-height: calc(100vh - 100px); /* Максимальна висота = висота екрану мінус паддінги */
}

.modal-dialog.large {
    max-width: 1000px; /* Ширина для великих модалок, як Розклад */
}

.modal-content {
    background-color: var(--color-bg-secondary);
    border-radius: var(--border-radius-lg);
    position: relative;
    box-shadow: var(--shadow-lg);
    animation: modal-scale-in 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);

    display: flex; /* Flex для розділення хедера, тіла і футера */
    flex-direction: column;
    overflow: hidden; /* Ховаємо все, що виходить за межі радіусу */

    /* Важливо: .modal-content більше не має max-width, ним керує .modal-dialog */
}
.modal-header {
    padding: 20px 30px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0; /* Не стискати хедер */
}

.modal-body {
    padding: 25px 30px;
    overflow-y: auto; /* ТІЛЬКИ ЦЯ ЧАСТИНА БУДЕ СКРОЛИТИСЬ */
    flex-grow: 1; /* Займає весь вільний простір */
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 20px 30px;
    border-top: 1px solid var(--border-color);
    background-color: var(--color-bg-primary);
    flex-shrink: 0; /* Не стискати футер */
}

.modal-header h2 { margin: 0; }
.close-button { color: var(--color-text-tertiary); position: absolute; top: 15px; right: 20px; font-size: 28px; font-weight: bold; cursor: pointer; }
.close-button:hover { color: var(--color-text-primary); }

.modal-content.large { max-width: 950px; }

/* AI Settings Modal Dialog */
.modal-dialog.ai-settings-dialog {
    width: 95vw;
    max-width: 1180px;
    height: 88vh;
    max-height: 860px;
}

#ai-settings-modal .modal-content {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#ai-settings-modal .modal-body.ai-settings-body {
    padding: 0 !important;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* AI Settings 2-Pane Layout (Vertical Tabs on Left) */
.ai-settings-layout {
    display: grid;
    grid-template-columns: 230px 1fr;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* Left Sidebar */
.ai-settings-sidebar {
    background-color: var(--color-bg-primary);
    border-right: 1px solid var(--border-color);
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    height: 100%;
    box-sizing: border-box;
    overflow-y: auto;
}

.ai-settings-tabs.vertical {
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-bottom: none;
    margin-bottom: 0;
    width: 100%;
}

.ai-settings-tabs.vertical .ai-settings-tab {
    width: 100%;
    padding: 12px 14px;
    border-radius: 8px;
    border: 1px solid transparent;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 12px;
    background: transparent;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--color-text-secondary);
    box-sizing: border-box;
    margin-bottom: 0;
}

.ai-settings-tabs.vertical .ai-settings-tab:hover {
    background-color: var(--color-bg-secondary);
    color: var(--color-text-primary);
    transform: translateX(2px);
}

.ai-settings-tabs.vertical .ai-settings-tab.active {
    background-color: rgba(59, 130, 246, 0.1);
    border-color: rgba(59, 130, 246, 0.25);
    color: var(--color-text-accent);
}

.tab-icon-box {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: var(--color-bg-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    color: var(--color-text-secondary);
    transition: all 0.2s;
}

.ai-settings-tab.active .tab-icon-box {
    background: var(--color-text-accent);
    color: #fff;
    box-shadow: 0 2px 6px rgba(59, 130, 246, 0.3);
}

.tab-text-box {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.tab-main-title {
    font-weight: 600;
    font-size: 0.95em;
    line-height: 1.3;
}

.tab-sub-title {
    font-size: 0.76em;
    color: var(--color-text-tertiary);
    line-height: 1.3;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-settings-tab.active .tab-sub-title {
    color: rgba(59, 130, 246, 0.8);
}

/* Right Main Content */
.ai-settings-main-content {
    background-color: var(--color-bg-secondary);
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    height: 100%;
    box-sizing: border-box;
    overflow: hidden;
    min-width: 0;
}

.ai-settings-tab-content-container {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ai-settings-tab-content {
    display: none;
    height: 100%;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.ai-settings-tab-content.active {
    display: flex;
}

#tab-panel-command {
    height: 100%;
    display: none;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

#tab-panel-command.active {
    display: flex;
}

.tab-fill-textarea {
    flex: 1;
    width: 100%;
    min-height: 320px;
    padding: 14px 16px;
    font-family: inherit;
    font-size: 0.95em;
    line-height: 1.6;
    background-color: var(--color-bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--color-text-primary);
    box-sizing: border-box;
    resize: none;
}

.tab-fill-textarea:focus {
    border-color: var(--color-text-accent);
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

/* AI Settings Footer */
.modal-footer.ai-settings-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 24px;
    background-color: var(--color-bg-primary);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.ai-footer-options {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.setting-checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.92em;
    user-select: none;
    color: var(--color-text-primary);
}

.setting-checkbox-label input[type="checkbox"] {
    width: 17px;
    height: 17px;
    cursor: pointer;
    accent-color: var(--color-text-accent);
}

.ai-footer-buttons {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

/* Schedule Modal */
.schedule-entries-header, .schedule-entry { display: grid; grid-template-columns: 90px 90px 1fr 140px 160px 60px 40px; gap: 10px; align-items: center; padding: 8px; }
.schedule-entries-header { font-weight: 600; color: var(--color-text-secondary); border-bottom: 2px solid var(--border-color); }
#schedule-entries-container { max-height: 45vh; overflow-y: auto; }
.schedule-entry { border-bottom: 1px solid var(--border-color); }
.schedule-entry input, .schedule-entry select, .schedule-entry textarea { padding: 6px 8px; font-size: 0.9em; }
.schedule-entry textarea { min-height: 40px; }
.delete-schedule-entry { color: var(--color-danger); }
.add-entry-button { margin-top: 15px; }

/* Notifications (Toasts) */
.notification-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1060;
    width: 350px;
    background: var(--color-bg-secondary);
    color: var(--color-text-primary);
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow-lg);
    transform: translateX(120%);
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    border-left: 4px solid var(--color-info);
}
.notification-container.show { transform: translateX(0); }
.notification-content { padding: 15px 20px; }
.notification-title { font-weight: 700; margin-bottom: 5px; }
.notification-message { font-size: 0.95em; color: var(--color-text-secondary); margin: 0; }
.notification-success { border-left-color: var(--color-success); }
.notification-error { border-left-color: var(--color-danger); }
.notification-warning { border-left-color: var(--color-warning); }

.chat-list li {
    /* Додамо плавний перехід для кольору */
    transition: background-color 0.2s ease, border-color 0.2s ease;
    /* За замовчуванням прозора лінія */
    border-left: 4px solid transparent;
}

/* --- СТИЛІ ДЛЯ СВІТЛОЇ ТЕМИ --- */

/* Приватні чати (користувачі) */
body[data-theme="light"] .chat-list li[data-chat-type="user"] {
    border-left-color: #4CAF50; /* Зелений колір */
}
body[data-theme="light"] .chat-list li[data-chat-type="user"]:hover {
    background-color: #f1f8e9; /* Дуже світло-зелений при наведенні */
}

/* Групи та канали */
body[data-theme="light"] .chat-list li[data-chat-type="group"],
body[data-theme="light"] .chat-list li[data-chat-type="channel"] {
    border-left-color: #2196F3; /* Синій колір */
}
body[data-theme="light"] .chat-list li[data-chat-type="group"]:hover,
body[data-theme="light"] .chat-list li[data-chat-type="channel"]:hover {
    background-color: #e3f2fd; /* Дуже світло-синій при наведенні */
}


/* --- СТИЛІ ДЛЯ ТЕМНОЇ ТЕМИ --- */

/* Приватні чати (користувачі) */
body[data-theme="dark"] .chat-list li[data-chat-type="user"] {
    border-left-color: #66bb6a; /* Світліший зелений */
}
body[data-theme="dark"] .chat-list li[data-chat-type="user"]:hover {
    background-color: rgba(102, 187, 106, 0.15); /* Прозорий зелений при наведенні */
}

/* Групи та канали */
body[data-theme="dark"] .chat-list li[data-chat-type="group"],
body[data-theme="dark"] .chat-list li[data-chat-type="channel"] {
    border-left-color: #42a5f5; /* Світліший синій */
}
body[data-theme="dark"] .chat-list li[data-chat-type="group"]:hover,
body[data-theme="dark"] .chat-list li[data-chat-type="channel"]:hover {
    background-color: rgba(66, 165, 245, 0.15); /* Прозорий синій при наведенні */
}


/* Стиль для вибраного чату має бути пріоритетнішим */
.chat-list li.selected {
    /* Цей стиль перезапише колір фону при наведенні, але залишить кольорову лінію */
    background-color: var(--accent-color-hover) !important;
}

/* Стилі для тегів у списку чатів */
.chat-tag {
    display: inline-block;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 500;
    border-radius: 12px;
    margin-left: 0;
    color: #fff; /* Білий текст для кращого контрасту */
    background-color: #888; /* Колір за замовчуванням */
    max-width: 100px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
}

/* Контейнер бейджів чату */
.chat-badges {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    margin-left: 8px;
}

/* Бейдж увімкненого ШІ для діалогу */
.chat-ai-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 7px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 12px;
    background-color: rgba(22, 163, 74, 0.14);
    color: var(--color-success, #16a34a);
    border: 1px solid rgba(22, 163, 74, 0.35);
    line-height: 1.2;
    letter-spacing: 0.2px;
    white-space: nowrap;
    transition: var(--transition-fast);
}

.chat-ai-badge i {
    font-size: 0.95em;
}

body[data-theme="dark"] .chat-ai-badge {
    background-color: rgba(34, 197, 94, 0.18);
    color: #4ade80;
    border-color: rgba(74, 222, 128, 0.35);
}

.chat-list li.selected .chat-ai-badge {
    background-color: rgba(255, 255, 255, 0.25) !important;
    color: #ffffff !important;
    border-color: rgba(255, 255, 255, 0.5) !important;
}

/* Стилі для модального вікна налаштувань чату */
.modal-content.small {
    max-width: 400px; /* Менша ширина */
}
.form-group {
    margin-bottom: 15px;
}
.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: var(--text-color-light);
}
.form-group input[type="text"],
.form-group input[type="color"] {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border-color);
    background-color: var(--background-color);
    color: var(--text-color);
    border-radius: 4px;
    box-sizing: border-box; /* Важливо для правильної ширини */
}
.form-group input[type="color"] {
    padding: 4px; /* Кольоровий інпут має свій стиль */
    height: 40px;
}

/* Покращення для правого кліку */
.chat-list li {
    position: relative;
}

/* --- 6. Other Components --- */
/* Loading Indicator */
.loading-indicator {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--color-bg-overlay);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1070;
}
.spinner {
    border: 4px solid var(--color-bg-accent);
    border-top-color: var(--color-text-accent);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Photo Requests */
.photo-requests {
    padding: 12px 16px;
    background-color: rgba(var(--color-warning), 0.1);
    border-bottom: 1px solid rgba(var(--color-warning), 0.3);
    flex-shrink: 0;
}
.photo-requests h3 { font-size: 1em; color: var(--color-warning); margin-bottom: 10px; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* --- 7. Responsive Design (Mobile & Tablet) --- */

.mobile-only {
    display: none !important;
}

@media (max-width: 992px) {
    .main-content {
        display: flex !important;
        width: 100vw;
        height: 100vh;
        overflow: hidden;
        position: relative;
    }

    /* By default on tablet/mobile: sidebar covers full screen for selecting chat */
    .sidebar {
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        width: 100vw;
        z-index: 20;
        transform: translateX(0);
        transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
        border-right: none;
    }

    /* When a chat is active, sidebar slides left */
    .main-content.chat-active .sidebar,
    .sidebar.is-hidden {
        transform: translateX(-100%);
        pointer-events: none;
    }

    .chat-window {
        width: 100vw;
        height: 100vh;
        flex: 1;
    }

    .mobile-only {
        display: inline-flex !important;
    }

    /* Info panel as a sliding drawer on right */
    .info-panel {
        position: fixed;
        right: 0;
        top: 0;
        bottom: 0;
        width: 88vw;
        max-width: 380px;
        transform: translateX(100%);
        transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
        z-index: 100;
        border-left: 1px solid var(--border-color);
        box-shadow: -6px 0 24px rgba(0, 0, 0, 0.25);
    }

    .info-panel.is-open {
        transform: translateX(0);
    }

    .drawer-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.45);
        backdrop-filter: blur(2px);
        z-index: 90;
        transition: opacity 0.2s ease;
    }
}

@media (max-width: 768px) {
    body { font-size: 14px; }

    /* Login & Session screen on Mobile */
    .telegram-client {
        align-items: stretch;
        padding: 0;
    }

    .login-wrapper {
        width: 100% !important;
        max-width: 100% !important;
        height: 100vh !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        flex-direction: column !important;
        overflow-y: auto !important;
    }

    .login-mobile-tabs {
        display: flex !important;
        border-bottom: 1px solid var(--border-color);
        background: var(--color-bg-secondary);
        position: sticky;
        top: 0;
        z-index: 10;
        flex-shrink: 0;
    }

    .login-mobile-tab {
        flex: 1;
        padding: 12px 16px;
        font-weight: 600;
        font-size: 0.9em;
        background: transparent;
        border: none;
        border-bottom: 3px solid transparent;
        color: var(--color-text-secondary);
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        transition: var(--transition-fast);
    }

    .login-mobile-tab.active {
        color: var(--color-text-accent);
        border-bottom-color: var(--color-text-accent);
    }

    .login-wrapper.tab-sessions .login-main {
        display: none !important;
    }

    .login-wrapper.tab-new .sessions-sidebar {
        display: none !important;
    }

    .sessions-sidebar {
        width: 100% !important;
        padding: 16px !important;
        border-right: none !important;
        border-bottom: 1px solid var(--border-color);
        height: auto !important;
        flex: 1 !important;
    }

    .login-main {
        width: 100% !important;
        padding: 20px 16px !important;
        flex: 1 !important;
    }

    /* Chat header on small screens */
    .chat-header {
        padding: 8px 12px !important;
        min-height: 54px !important;
    }
    
    .chat-header-avatar {
        width: 34px !important;
        height: 34px !important;
        font-size: 0.85em !important;
    }

    .chat-header-titles h3 {
        font-size: 0.96em !important;
    }

    .quick-ai-btn {
        padding: 4px 8px !important;
        font-size: 0.76em !important;
    }

    /* Message Input on Mobile */
    .message-input {
        padding: 8px 10px !important;
        gap: 6px !important;
        position: sticky;
        bottom: 0;
        background: var(--color-bg-secondary);
        border-top: 1px solid var(--border-color);
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }

    .message {
        max-width: 86% !important;
        padding: 9px 13px !important;
        font-size: 0.95em !important;
    }

    /* AI Settings Modal on Mobile (Full Screen & Horizontal Tabs) */
    .modal-dialog.ai-settings-dialog {
        width: 100vw !important;
        max-width: 100vw !important;
        height: 100vh !important;
        max-height: 100vh !important;
        margin: 0 !important;
        border-radius: 0 !important;
    }

    .ai-settings-layout {
        display: flex !important;
        flex-direction: column !important;
        height: 100% !important;
    }

    .ai-settings-sidebar {
        width: 100% !important;
        height: auto !important;
        border-right: none !important;
        border-bottom: 1px solid var(--border-color) !important;
        padding: 8px 10px !important;
        overflow-x: auto !important;
        flex-shrink: 0 !important;
    }

    .ai-settings-tabs.vertical {
        flex-direction: row !important;
        gap: 6px !important;
        overflow-x: auto !important;
        width: 100% !important;
    }

    .ai-settings-tabs.vertical .ai-settings-tab {
        width: auto !important;
        padding: 7px 11px !important;
        flex-shrink: 0 !important;
    }

    .ai-settings-tabs.vertical .tab-sub-title {
        display: none !important;
    }

    .ai-settings-tabs.vertical .tab-icon-box {
        width: 26px !important;
        height: 26px !important;
        font-size: 11px !important;
    }

    .ai-settings-main-content {
        padding: 12px 10px !important;
        flex: 1 !important;
        min-height: 0 !important;
    }

    .instruction-toolbar {
        flex-direction: column !important;
        align-items: stretch !important;
        padding: 10px !important;
        gap: 8px !important;
    }

    .template-selector-box, .template-actions-box {
        width: 100% !important;
        max-width: 100% !important;
        flex-wrap: wrap !important;
    }

    .modal-footer.ai-settings-footer {
        flex-direction: column !important;
        padding: 12px !important;
        gap: 10px !important;
    }

    .ai-footer-options {
        flex-direction: column !important;
        gap: 6px !important;
        width: 100% !important;
    }

    .ai-footer-buttons {
        width: 100% !important;
        display: flex !important;
        gap: 8px !important;
    }

    .ai-footer-buttons button {
        flex: 1 !important;
        justify-content: center !important;
    }
}

.divider {
    text-align: center;
    margin: 15px 0;
    color: #888;
    font-size: 0.85em;
    position: relative;
}
.divider::before, .divider::after {
    content: "";
    display: inline-block;
    width: 30%;
    height: 1px;
    background: #ccc;
    vertical-align: middle;
    margin: 0 10px;
}

/* ==========================================================================
   Instruction Templates & Section Editor Styles (Spacious & Modern)
   ========================================================================== */
.modal-dialog.extra-large {
    width: 96vw;
    max-width: 1360px;
    height: 88vh;
    max-height: 920px;
}

#instruction-templates-modal .modal-content {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

#instruction-templates-modal .modal-header {
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--color-bg-primary);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.modal-header-info {
    display: flex;
    align-items: center;
    gap: 14px;
}

.modal-icon-badge {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: rgba(59, 130, 246, 0.12);
    color: var(--color-text-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3em;
    flex-shrink: 0;
}

#instruction-templates-modal .modal-body.template-manager-body {
    padding: 0 !important;
    flex: 1;
    overflow: hidden;
    display: flex;
    min-height: 0; /* Важливо для внутрішнього flex-скролу */
}

.btn-sm {
    padding: 6px 14px !important;
    font-size: 0.85em !important;
    font-weight: 500;
}

/* Chat Instruction Toolbar */
.instruction-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    background-color: var(--color-bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    margin-bottom: 14px;
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
}

.template-selector-box {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    max-width: 580px;
}

.template-selector-box label {
    font-size: 0.9em;
    font-weight: 600;
    color: var(--color-text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.template-selector-box select {
    padding: 7px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    background-color: var(--color-bg-secondary);
    color: var(--color-text-primary);
    font-size: 0.92em;
    flex: 1;
    min-width: 180px;
    transition: border-color 0.2s;
}

.template-selector-box select:focus {
    border-color: var(--color-text-accent);
    outline: none;
}

.template-actions-box {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.instruction-sections-header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.sections-title {
    font-weight: 600;
    font-size: 1em;
    color: var(--color-text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.sections-hint {
    font-size: 0.85em;
    color: var(--color-text-tertiary);
}

/* Sections Container */
.instruction-sections-container {
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow-y: auto;
    padding-right: 8px;
    margin-bottom: 12px;
    min-height: 100px;
}

#tab-panel-command .instruction-sections-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    max-height: none;
    margin-bottom: 0;
}

.instruction-sections-container::-webkit-scrollbar {
    width: 6px;
}
.instruction-sections-container::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 4px;
}

/* Section Card (Spacious & Clean) */
.instruction-section-card {
    background-color: var(--color-bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 16px 18px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
}

.instruction-section-card:hover {
    border-color: rgba(59, 130, 246, 0.4);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.instruction-section-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    flex-shrink: 0;
}

.section-index-badge {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(59, 130, 246, 0.12);
    color: var(--color-text-accent);
    font-weight: 700;
    font-size: 0.85em;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.section-title-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
}

.section-title-input {
    width: 100%;
    font-weight: 600;
    font-size: 0.98em;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: var(--color-bg-secondary);
    color: var(--color-text-primary);
    transition: all 0.2s;
    box-sizing: border-box;
}

.section-title-input:focus {
    border-color: var(--color-text-accent);
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

.section-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.section-action-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.85em;
}

.section-action-btn:hover:not(:disabled) {
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    border-color: var(--color-text-accent);
}

.section-action-btn.delete-btn:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.12);
    border-color: #ef4444;
}

.section-content-wrapper {
    position: relative;
}

.section-content-textarea {
    width: 100%;
    height: 200px;
    min-height: 140px;
    padding: 12px 14px;
    font-family: inherit;
    font-size: 0.95em;
    line-height: 1.6;
    background-color: var(--color-bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--color-text-primary);
    resize: vertical;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
}

/* Specific comfortable height for chat instruction textarea */
#chat-instruction-sections-container .section-content-textarea {
    height: 260px;
    min-height: 180px;
}

.section-content-textarea:focus {
    border-color: var(--color-text-accent);
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

@keyframes section-pulse-highlight {
    0% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.5); border-color: var(--color-text-accent); }
    50% { box-shadow: 0 0 0 6px rgba(59, 130, 246, 0.25); border-color: var(--color-text-accent); }
    100% { box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04); }
}

.instruction-section-card.section-highlight {
    animation: section-pulse-highlight 1.2s ease;
}

/* Dashed Add Section Button */
.add-section-dashed-btn {
    width: 100%;
    padding: 12px;
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    background: transparent;
    color: var(--color-text-secondary);
    font-weight: 500;
    font-size: 0.92em;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 16px;
    flex-shrink: 0;
}

.add-section-dashed-btn:hover {
    border-color: var(--color-text-accent);
    color: var(--color-text-accent);
    background: rgba(59, 130, 246, 0.05);
}

.instruction-sections-bottom-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding-top: 4px;
}

.instruction-preview-box textarea {
    width: 100%;
    min-height: 110px;
    padding: 12px;
    font-family: monospace;
    font-size: 0.88em;
    line-height: 1.5;
    background-color: var(--color-bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    color: var(--color-text-primary);
    box-sizing: border-box;
}

/* ==========================================================================
   Template Manager 3-Column Layout
   ========================================================================== */
.template-manager-layout.three-columns {
    display: grid;
    grid-template-columns: 270px 1fr 320px;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* Column 1: Left Sidebar */
.template-manager-sidebar {
    background-color: var(--color-bg-primary);
    border-right: 1px solid var(--border-color);
    padding: 18px 16px;
    display: flex;
    flex-direction: column;
    height: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

.template-sidebar-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    flex-shrink: 0;
}

.template-count-badge {
    background: var(--color-bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--color-text-secondary);
    font-size: 0.78em;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 12px;
}

.template-search-box {
    position: relative;
    margin-bottom: 14px;
    flex-shrink: 0;
}

.template-search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-text-tertiary);
    font-size: 0.88em;
    pointer-events: none;
}

.template-search-input {
    width: 100%;
    padding: 8px 12px 8px 34px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--color-bg-secondary);
    color: var(--color-text-primary);
    font-size: 0.9em;
    box-sizing: border-box;
    transition: border-color 0.2s;
}

.template-search-input:focus {
    border-color: var(--color-text-accent);
    outline: none;
}

.template-manager-list {
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-right: 4px;
    min-height: 0;
}

.template-item-card {
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background-color: var(--color-bg-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    border-left: 4px solid transparent;
}

.template-item-card:hover {
    border-color: var(--color-text-accent);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.template-item-card.active {
    border-color: var(--color-text-accent);
    border-left-color: var(--color-text-accent);
    background-color: rgba(59, 130, 246, 0.08);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.template-item-title {
    font-weight: 600;
    font-size: 0.95em;
    color: var(--color-text-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 5px;
}

.template-item-badge {
    font-size: 0.72em;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 12px;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: #ffffff;
    white-space: nowrap;
}

.template-item-badge.sample-badge {
    background: rgba(245, 158, 11, 0.16);
    color: #f59e0b;
    border: 1px solid rgba(245, 158, 11, 0.35);
}

.template-sample-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    margin-bottom: 14px;
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.32);
    border-radius: 8px;
    color: #fbbf24;
    font-size: 0.88em;
    line-height: 1.45;
    flex-shrink: 0;
}

.template-sample-banner i {
    font-size: 1.4em;
    color: #f59e0b;
    flex-shrink: 0;
}

.template-sample-banner strong {
    color: #fde68a;
}

.template-item-desc {
    font-size: 0.83em;
    color: var(--color-text-secondary);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 6px;
}

.template-item-sections-count {
    font-size: 0.78em;
    color: var(--color-text-tertiary);
    display: flex;
    align-items: center;
    gap: 5px;
    font-weight: 500;
}

/* Empty State (spans Col 2 and Col 3) */
.template-editor-empty {
    grid-column: 2 / 4;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--color-text-tertiary);
    text-align: center;
    padding: 40px;
    box-sizing: border-box;
}

.empty-icon-circle {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: rgba(59, 130, 246, 0.08);
    color: var(--color-text-accent);
    font-size: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

/* Column 2: Sections Editor */
.template-sections-column {
    background-color: var(--color-bg-secondary);
    border-right: 1px solid var(--border-color);
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    height: 100%;
    box-sizing: border-box;
    overflow: hidden;
    min-width: 0;
}

.template-sections-column .instruction-sections-container {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-right: 8px;
    margin-bottom: 12px;
    min-height: 0;
}

.template-sections-header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

/* Column 3: Template Info & Structure */
.template-info-column {
    background-color: var(--color-bg-primary);
    padding: 20px 18px;
    display: flex;
    flex-direction: column;
    height: 100%;
    box-sizing: border-box;
    overflow: hidden;
    min-width: 0;
}

.template-info-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.template-info-header {
    margin-bottom: 14px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.template-name-input {
    width: 100%;
    font-size: 1.02em;
    font-weight: 600;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--color-bg-secondary);
    color: var(--color-text-primary);
    box-sizing: border-box;
    transition: border-color 0.2s;
}

.template-desc-textarea {
    width: 100%;
    min-height: 75px;
    max-height: 140px;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--color-bg-secondary);
    color: var(--color-text-primary);
    font-size: 0.9em;
    line-height: 1.4;
    resize: vertical;
    box-sizing: border-box;
    transition: border-color 0.2s;
    font-family: inherit;
}

.template-name-input:focus, .template-desc-textarea:focus {
    border-color: var(--color-text-accent);
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

/* Structure Card in Column 3 */
.template-structure-card {
    background: var(--color-bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    margin-bottom: 16px;
    min-height: 130px;
}

.structure-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.structure-stats-badge {
    font-size: 0.78em;
    color: var(--color-text-tertiary);
    font-weight: 600;
}

.template-structure-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-right: 2px;
    min-height: 0;
}

.structure-outline-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border-radius: 6px;
    border: 1px solid transparent;
    background: var(--color-bg-primary);
    font-size: 0.85em;
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;
}

.structure-outline-item:hover {
    border-color: var(--color-text-accent);
    background: rgba(59, 130, 246, 0.08);
    transform: translateX(2px);
}

.structure-item-index {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(59, 130, 246, 0.12);
    color: var(--color-text-accent);
    font-weight: 700;
    font-size: 0.8em;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.structure-item-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
    color: var(--color-text-primary);
}

.structure-item-chars {
    font-size: 0.8em;
    color: var(--color-text-tertiary);
    flex-shrink: 0;
}

/* Actions Footer in Column 3 */
.template-info-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.template-actions-row {
    display: flex;
    gap: 8px;
    width: 100%;
}

.btn-block {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.flex-1 {
    flex: 1;
}

/* Responsive */
@media (max-width: 1080px) {
    .template-manager-layout.three-columns {
        grid-template-columns: 240px 1fr 280px;
    }
}

@media (max-width: 900px) {
    .modal-dialog.extra-large {
        width: 98vw;
        height: 94vh;
    }
    .template-manager-layout.three-columns {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
    }
    .template-editor-empty {
        grid-column: 1;
    }
    .template-manager-sidebar {
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        max-height: 180px;
        padding: 12px;
    }
    .template-sections-column {
        border-right: none;
        padding: 14px;
    }
    .template-info-column {
        border-top: 1px solid var(--border-color);
        max-height: 240px;
        padding: 12px;
    }
    .instruction-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    .template-selector-box, .template-actions-box {
        width: 100%;
    }
    .template-selector-box select {
        flex: 1;
        min-width: 0;
    }
}

/* ==========================================================================
   Isolated Dialog Q&A Modal Styles
   ========================================================================== */
.modal-dialog.dialog-qna-dialog {
    width: 94vw;
    max-width: 860px;
    height: 84vh;
    max-height: 780px;
}

#dialog-qna-modal .modal-content {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

#dialog-qna-modal .modal-header.dialog-qna-header {
    padding: 16px 22px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    background-color: var(--color-bg-primary);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.dialog-qna-title-wrap {
    min-width: 0;
}

.dialog-qna-title-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.dialog-qna-chat-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.78em;
    font-weight: 600;
    background: rgba(59, 130, 246, 0.12);
    color: var(--color-text-accent);
    border: 1px solid rgba(59, 130, 246, 0.28);
    max-width: 240px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dialog-qna-subtitle {
    margin: 4px 0 0;
    font-size: 0.82em;
    color: var(--color-text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.dialog-qna-subtitle i {
    color: var(--color-success);
}

.dialog-qna-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.dialog-qna-header .close-button {
    position: static;
    font-size: 26px;
    line-height: 1;
    margin-left: 4px;
    padding: 2px 6px;
    border-radius: 6px;
    transition: var(--transition-fast);
}

.dialog-qna-header .close-button:hover {
    background-color: var(--color-bg-tertiary);
}

#dialog-qna-modal .modal-body.dialog-qna-body {
    padding: 0;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: var(--color-bg-primary);
}

.dialog-qna-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.dialog-qna-empty {
    margin: auto;
    max-width: 560px;
    text-align: center;
    padding: 24px 16px;
}

.dialog-qna-empty-icon {
    width: 60px;
    height: 60px;
    margin: 0 auto 14px;
    border-radius: 16px;
    background: rgba(59, 130, 246, 0.12);
    color: var(--color-text-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6em;
}

.dialog-qna-empty h3 {
    font-size: 1.12em;
    color: var(--color-text-primary);
    margin-bottom: 8px;
}

.dialog-qna-empty p {
    font-size: 0.9em;
    color: var(--color-text-secondary);
    margin: 0 0 18px;
    line-height: 1.5;
}

.dialog-qna-suggestions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}

.dialog-qna-chip {
    background-color: var(--color-bg-secondary);
    color: var(--color-text-primary);
    border: 1px solid var(--border-color);
    border-radius: 18px;
    padding: 7px 14px;
    font-size: 0.85em;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-fast);
    text-align: left;
    line-height: 1.35;
}

.dialog-qna-chip:hover {
    border-color: var(--color-text-accent);
    color: var(--color-text-accent);
    background-color: rgba(59, 130, 246, 0.08);
    transform: translateY(-1px);
}

.dialog-qna-msg {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: fadeIn 0.2s ease-out;
}

.dialog-qna-msg.user {
    align-self: flex-end;
    align-items: flex-end;
}

.dialog-qna-msg.assistant {
    align-self: flex-start;
    align-items: flex-start;
}

.dialog-qna-msg-bubble {
    padding: 12px 16px;
    border-radius: 14px;
    font-size: 0.94em;
    line-height: 1.55;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.dialog-qna-msg.user .dialog-qna-msg-bubble {
    background-color: var(--color-bg-user-message);
    color: var(--color-text-user-message);
    border-bottom-right-radius: 4px;
    white-space: pre-wrap;
}

.dialog-qna-msg.assistant .dialog-qna-msg-bubble {
    background-color: var(--color-bg-secondary);
    color: var(--color-text-primary);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-sm);
}

.dialog-qna-msg.assistant.is-error .dialog-qna-msg-bubble {
    border-color: rgba(220, 38, 38, 0.45);
    background-color: rgba(220, 38, 38, 0.08);
    color: var(--color-danger);
}

.dialog-qna-markdown > *:first-child {
    margin-top: 0;
}

.dialog-qna-markdown > *:last-child {
    margin-bottom: 0;
}

.dialog-qna-markdown p {
    margin: 0 0 8px;
}

.dialog-qna-markdown ul,
.dialog-qna-markdown ol {
    margin: 6px 0 8px;
    padding-left: 20px;
    list-style: revert;
}

.dialog-qna-markdown li {
    margin-bottom: 4px;
}

.dialog-qna-markdown strong {
    font-weight: 600;
}

.dialog-qna-markdown code {
    font-family: monospace;
    font-size: 0.9em;
    padding: 1px 5px;
    border-radius: 4px;
    background-color: var(--color-bg-tertiary);
}

.dialog-qna-markdown pre {
    padding: 10px 12px;
    border-radius: 8px;
    background-color: var(--color-bg-tertiary);
    overflow-x: auto;
    margin: 8px 0;
}

.dialog-qna-markdown table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 0.9em;
}

.dialog-qna-markdown th,
.dialog-qna-markdown td {
    border: 1px solid var(--border-color);
    padding: 6px 8px;
    text-align: left;
}

.dialog-qna-markdown blockquote {
    margin: 8px 0;
    padding: 4px 12px;
    border-left: 3px solid var(--color-text-accent);
    color: var(--color-text-secondary);
}

.dialog-qna-msg-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 5px;
    font-size: 0.76em;
    color: var(--color-text-tertiary);
    padding: 0 4px;
}

.dialog-qna-copy-btn {
    background: transparent;
    border: 1px solid transparent;
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: 2px 7px;
    border-radius: 6px;
    font-size: 0.95em;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: var(--transition-fast);
}

.dialog-qna-copy-btn:hover {
    background-color: var(--color-bg-tertiary);
    border-color: var(--border-color);
    color: var(--color-text-accent);
}

.dialog-qna-thinking {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    background-color: var(--color-bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--color-text-secondary);
    font-size: 0.9em;
    align-self: flex-start;
}

.dialog-qna-dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.dialog-qna-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--color-text-accent);
    animation: dialogQnaBounce 1.2s infinite ease-in-out;
}

.dialog-qna-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.dialog-qna-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes dialogQnaBounce {
    0%, 80%, 100% {
        opacity: 0.3;
        transform: scale(0.8);
    }
    40% {
        opacity: 1;
        transform: scale(1.15);
    }
}

#dialog-qna-modal .modal-footer.dialog-qna-footer {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 14px 20px;
    background-color: var(--color-bg-secondary);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.dialog-qna-input-wrap {
    flex: 1;
    min-width: 0;
}

#dialog-qna-input {
    width: 100%;
    min-height: 44px;
    max-height: 140px;
    padding: 10px 14px;
    resize: none;
    overflow-y: auto;
    line-height: 1.45;
    border-radius: 12px;
    background-color: var(--color-bg-primary);
    color: var(--color-text-primary);
    border: 1px solid var(--border-color);
    font-family: var(--font-sans);
    font-size: 0.95em;
    box-sizing: border-box;
}

#dialog-qna-input:focus {
    border-color: var(--color-text-accent);
    box-shadow: var(--focus-ring);
    outline: none;
}

.dialog-qna-send-btn {
    height: 44px;
    padding: 0 18px;
    border-radius: 12px;
    flex-shrink: 0;
    white-space: nowrap;
}

.dialog-qna-send-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

@media (max-width: 768px) {
    #dialog-qna-modal {
        padding: 0 !important;
    }

    .modal-dialog.dialog-qna-dialog {
        width: 100vw !important;
        max-width: 100vw !important;
        height: 100vh !important;
        max-height: 100vh !important;
        margin: 0 !important;
    }

    #dialog-qna-modal .modal-content {
        border-radius: 0 !important;
        border: none !important;
    }

    #dialog-qna-modal .modal-header.dialog-qna-header {
        padding: 12px 14px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .dialog-qna-header-actions {
        margin-left: auto;
    }

    .dialog-qna-header-actions .btn-sm span {
        display: none;
    }

    .dialog-qna-messages {
        padding: 14px 12px;
    }

    .dialog-qna-msg {
        max-width: 94%;
    }

    #dialog-qna-modal .modal-footer.dialog-qna-footer {
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    .dialog-qna-send-btn span {
        display: none;
    }
}
