/* ========================================================
   BASE.CSS — Тема, шрифты, кнопки, утилиты, модалки
   ======================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ========== HTML / BODY ========== */
html {
    min-height: 100vh;
    background: #0b1222;
    background-image:
        radial-gradient(ellipse 90% 70% at 5% 15%, rgba(139, 92, 246, 0.28) 0%, transparent 55%),
        radial-gradient(ellipse 50% 40% at 0% 0%, rgba(167, 139, 250, 0.15) 0%, transparent 40%),
        radial-gradient(ellipse 60% 50% at 90% 10%, rgba(56, 139, 253, 0.12) 0%, transparent 50%),
        radial-gradient(ellipse 80% 60% at 95% 90%, rgba(56, 139, 253, 0.22) 0%, transparent 50%),
        radial-gradient(ellipse 50% 40% at 100% 100%, rgba(34, 211, 238, 0.12) 0%, transparent 40%),
        radial-gradient(ellipse 70% 40% at 50% 90%, rgba(125, 60, 200, 0.08) 0%, transparent 50%);
    background-attachment: fixed;
}

* { box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px 24px;
    background: transparent;
    color: #e6edf3;
    font-size: 14px;
    line-height: 1.5;
}

/* ========== GLASS UTILS ========== */
.glass {
    background: rgba(22, 27, 44, 0.55);
    backdrop-filter: blur(16px) saturate(1.4);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    border: 1px solid rgba(255, 255, 255, 0.06);
}
.glass-deep {
    background: rgba(13, 17, 30, 0.7);
    backdrop-filter: blur(20px) saturate(1.3);
    -webkit-backdrop-filter: blur(20px) saturate(1.3);
    border: 1px solid rgba(255, 255, 255, 0.04);
}

/* ========== ЗАГОЛОВОК СТРАНИЦЫ ========== */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    margin-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.page-header h1 {
    font-size: 20px;
    font-weight: 600;
    margin: 0;
    color: #f0f6fc;
    text-shadow: 0 0 20px rgba(139, 92, 246, 0.3);
    background: linear-gradient(135deg, #e6edf3, #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ========== КНОПКИ — БАЗА ========== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 16px;
    font-size: 14px;
    font-weight: 500;
    line-height: 20px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.25s ease;
    background: rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(8px);
    color: #e6edf3;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
}
.btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.15);
    box-shadow: 0 2px 12px rgba(139, 92, 246, 0.12);
}
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn:disabled:hover { background: rgba(255, 255, 255, 0.06); box-shadow: none; }
.btn::before {
    content: '';
    position: absolute;
    top: 0; left: -100%;
    width: 100%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.06), transparent);
    transition: left 0.5s;
}
.btn:hover::before { left: 100%; }

.btn-sm { padding: 3px 12px; font-size: 12px; border-radius: 8px; }
.btn-lg { padding: 9px 24px; font-size: 16px; font-weight: 600; }

/* ── Зелёные (Сохранить, Применить, Добавить, +) ── */
.btn-primary {
    background: rgba(46, 160, 67, 0.08) !important;
    border: 1px solid rgba(63, 185, 80, 0.25) !important;
    color: #3fb950 !important;
    box-shadow: none !important;
}
.btn-primary:hover {
    background: rgba(46, 160, 67, 0.15) !important;
    border-color: rgba(63, 185, 80, 0.4) !important;
    box-shadow: 0 0 12px rgba(63, 185, 80, 0.1) !important;
    transform: translateY(-1px) !important;
}
.btn-primary:disabled { opacity: 0.4; }
.btn-primary:active { transform: translateY(0); }

/* ── Синие (Редактировать) ── */
.btn-edit {
    background: rgba(56, 139, 253, 0.08) !important;
    border: 1px solid rgba(56, 139, 253, 0.25) !important;
    color: #58a6ff !important;
    box-shadow: none !important;
}
.btn-edit:hover {
    background: rgba(56, 139, 253, 0.15) !important;
    border-color: rgba(56, 139, 253, 0.4) !important;
    box-shadow: 0 0 12px rgba(56, 139, 253, 0.1) !important;
    transform: translateY(-1px) !important;
}

/* ── Синие маленькие (Применить шаблоны) ── */
.btn-blue {
    background: rgba(56, 139, 253, 0.08) !important;
    border: 1px solid rgba(56, 139, 253, 0.25) !important;
    color: #58a6ff !important;
    box-shadow: none !important;
}
.btn-blue:hover {
    background: rgba(56, 139, 253, 0.15) !important;
    border-color: rgba(56, 139, 253, 0.4) !important;
    box-shadow: 0 0 12px rgba(56, 139, 253, 0.1) !important;
    transform: translateY(-1px) !important;
}

/* ── Фиолетовые (Анализ ИИ) ── */
.btn-purple {
    background: rgba(139, 92, 246, 0.08) !important;
    border: 1px solid rgba(139, 92, 246, 0.25) !important;
    color: #a78bfa !important;
    box-shadow: none !important;
}
.btn-purple:hover {
    background: rgba(139, 92, 246, 0.15) !important;
    border-color: rgba(139, 92, 246, 0.4) !important;
    box-shadow: 0 0 12px rgba(139, 92, 246, 0.1) !important;
    transform: translateY(-1px) !important;
}

/* ── Красные (Удалить, Отменить) ── */
.btn-danger {
    background: rgba(248, 81, 73, 0.06) !important;
    border: 1px solid rgba(248, 81, 73, 0.2) !important;
    color: #f85149 !important;
    box-shadow: none !important;
}
.btn-danger:hover {
    background: rgba(248, 81, 73, 0.12) !important;
    border-color: rgba(248, 81, 73, 0.4) !important;
    box-shadow: 0 0 12px rgba(248, 81, 73, 0.1) !important;
    transform: translateY(-1px) !important;
}

/* ── Ghost кнопка ── */
.btn-ghost {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #8b949e;
}
.btn-ghost:hover {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.2);
    color: #e6edf3;
}

/* ── Нейтральные (Отмена, Скачать, обычные) ── */
.btn:not(.btn-primary):not(.btn-danger):not(.btn-purple):not(.btn-edit):not(.btn-blue):not(.btn-prompt-tpl):not(.chat-send-btn):not(.chat-stop-btn):not(.chat-rename-btn):not(.chat-attach-btn):not(.tab-btn):not(.ai-template-btn):not(.chat-item-menu-btn):not(.chat-msg-action-btn):not(.chat-msg-bottom-btn):not(.chat-msg-expand-btn) {
    background: rgba(255, 255, 255, 0.04) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    color: #c9d1d9 !important;
    box-shadow: none !important;
}
.btn:not(.btn-primary):not(.btn-danger):not(.btn-purple):not(.btn-edit):not(.btn-blue):not(.btn-prompt-tpl):not(.chat-send-btn):not(.chat-stop-btn):not(.chat-rename-btn):not(.chat-attach-btn):not(.tab-btn):not(.ai-template-btn):not(.chat-item-menu-btn):not(.chat-msg-action-btn):not(.chat-msg-bottom-btn):not(.chat-msg-expand-btn):hover {
    background: rgba(255, 255, 255, 0.08) !important;
    border-color: rgba(255, 255, 255, 0.18) !important;
    transform: translateY(-1px) !important;
}

/* Иконка внутри кнопки */
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}
.btn-icon svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
}

/* ========== КАРТОЧКИ ========== */
.box {
    background: rgba(22, 27, 44, 0.55);
    backdrop-filter: blur(16px) saturate(1.4);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
}
.box-header {
    padding: 6px 16px;
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid rgba(139, 92, 246, 0.08);
    font-weight: 600;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: #e6edf3;
    position: relative;
}
.box-header::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0;
    width: 100%;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(139, 92, 246, 0.15), transparent);
}
.box-header > span:first-child {
    background: linear-gradient(135deg, #e6edf3, #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 600;
    font-size: 15px;
}
.box-body {
    padding: 10px 16px;
    background: rgba(255, 255, 255, 0.01);
}

/* ========== TAB BAR ========== */
.tab-bar {
    display: flex;
    gap: 0;
    margin-bottom: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.tab-btn {
    padding: 10px 24px;
    font-size: 14px;
    font-weight: 600;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    color: #8b949e;
    cursor: pointer;
    transition: all 0.25s;
    display: flex;
    align-items: center;
    gap: 6px;
}
.tab-btn:hover { color: #e6edf3; }
.tab-btn.active {
    color: #f0f6fc;
    border-bottom-color: #a78bfa;
    text-shadow: 0 0 12px rgba(167, 139, 250, 0.4);
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ========== TOGGLE SWITCH ========== */
.toggle-item {
    display: flex; align-items: center; gap: 6px;
    font-size: 12px; color: #e6edf3;
    padding: 3px 8px; border-radius: 8px;
    cursor: pointer; user-select: none; transition: background 0.2s;
}
.toggle-item:hover { background: rgba(255, 255, 255, 0.04); }
.toggle-switch {
    position: relative; width: 34px; height: 18px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 9px;
    transition: background 0.3s; cursor: pointer; flex-shrink: 0;
}
.toggle-switch.active {
    background: linear-gradient(135deg, #6d28d9, #8b5cf6);
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.3);
}
.toggle-switch::after {
    content: ''; position: absolute; top: 2px; left: 2px;
    width: 14px; height: 14px; background: #fff;
    border-radius: 50%; transition: transform 0.3s ease;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}
.toggle-switch.active::after { transform: translateX(16px); }

/* ========== УНИВЕРСАЛЬНЫЕ ЧЕКБОКСЫ ========== */
input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 15px;
    height: 15px;
    border: 1.5px solid rgba(167, 139, 250, 0.35);
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.03);
    cursor: pointer;
    position: relative;
    transition: all 0.2s;
    margin: 0;
    flex-shrink: 0;
}
input[type="checkbox"]:hover {
    border-color: rgba(167, 139, 250, 0.6);
    background: rgba(139, 92, 246, 0.08);
}
input[type="checkbox"]:checked {
    background: linear-gradient(135deg, #7c3aed, #8b5cf6);
    border-color: #8b5cf6;
    box-shadow: 0 0 8px rgba(139, 92, 246, 0.3);
}
input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    top: 1px;
    left: 4px;
    width: 4px;
    height: 8px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* ========== CLEARABLE INPUT ========== */
.input-clearable {
    position: relative;
    display: block;
}
.input-clearable input {
    padding-right: 32px !important;
}
.input-clear-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #8b949e;
    cursor: pointer;
    font-size: 9px;
    line-height: 1;
    width: 18px;
    height: 18px;
    min-width: 18px;
    min-height: 18px;
    max-width: 18px;
    max-height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    opacity: 0.4;
    transition: all 0.15s;
    z-index: 2;
}
.input-clear-btn:hover {
    opacity: 1;
    background: rgba(248, 81, 73, 0.1);
    border-color: rgba(248, 81, 73, 0.3);
    color: #f85149;
}

/* ========== АВТОЗАПОЛНЕНИЕ БРАУЗЕРА ========== */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active,
textarea:-webkit-autofill,
textarea:-webkit-autofill:hover,
textarea:-webkit-autofill:focus,
textarea:-webkit-autofill:active {
    -webkit-box-shadow: 0 0 0 1000px rgba(13, 17, 30, 1) inset !important;
    -webkit-text-fill-color: #e6edf3 !important;
    caret-color: #e6edf3 !important;
    transition: background-color 5000s ease-in-out 0s !important;
}

/* ========== УВЕДОМЛЕНИЯ ========== */
.error {
    color: #f85149;
    background: rgba(248, 81, 73, 0.06);
    padding: 4px 12px;
    border-radius: 10px;
    border: 1px solid rgba(248, 81, 73, 0.15);
    margin: 0; font-size: 13px;
    backdrop-filter: blur(8px);
}
.success {
    color: #3fb950;
    background: rgba(63, 185, 80, 0.06);
    padding: 4px 12px;
    border-radius: 10px;
    border: 1px solid rgba(63, 185, 80, 0.15);
    margin: 0; font-size: 13px;
    backdrop-filter: blur(8px);
}
#message { margin: 0; display: block; }
label { cursor: pointer; }

/* ========== СПИННЕР ========== */
.spinner {
    width: 18px; height: 18px;
    border: 2px solid rgba(139, 92, 246, 0.2);
    border-top-color: #8b5cf6;
    border-radius: 50%; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ========== КАСТОМНЫЕ МОДАЛКИ ========== */
.custom-modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(5, 8, 18, 0.7);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 9999;
    align-items: center;
    justify-content: center;
}
.custom-modal-overlay.visible {
    display: flex;
    animation: modalOverlayIn 0.2s ease;
}
@keyframes modalOverlayIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.custom-modal {
    background:
        radial-gradient(ellipse 80% 60% at 10% 20%, rgba(139, 92, 246, 0.08) 0%, transparent 60%),
        radial-gradient(ellipse 60% 50% at 90% 80%, rgba(56, 139, 253, 0.05) 0%, transparent 50%),
        rgba(16, 20, 35, 0.75);
    backdrop-filter: blur(28px) saturate(1.5);
    -webkit-backdrop-filter: blur(28px) saturate(1.5);
    border: 1px solid rgba(139, 92, 246, 0.12);
    border-radius: 18px;
    padding: 0;
    max-width: 420px;
    width: 90%;
    box-shadow:
        0 16px 56px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(255, 255, 255, 0.03),
        inset 0 1px 0 rgba(255, 255, 255, 0.04);
    animation: modalSlideIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    overflow: hidden;
}
@keyframes modalSlideIn {
    from { opacity: 0; transform: scale(0.95) translateY(-10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.custom-modal-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 20px 0;
    margin: 0;
}
.custom-modal-icon {
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.custom-modal-icon svg {
    width: 22px;
    height: 22px;
    vertical-align: middle;
}
.custom-modal-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #f0f6fc;
}

.custom-modal-body {
    padding: 12px 20px 16px;
}
.custom-modal-body p {
    margin: 0;
    font-size: 14px;
    color: #c9d1d9;
    line-height: 1.6;
}

.custom-modal-input {
    width: 100%;
    margin-top: 12px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    color: #f0f6fc;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.custom-modal-input:focus {
    border-color: rgba(139, 92, 246, 0.5);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1);
}

.custom-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 0 20px 16px;
}

/* Типы модалок */
.custom-modal.modal-error .custom-modal-title { color: #f85149; }
.custom-modal.modal-error {
    border-color: rgba(248, 81, 73, 0.2);
    box-shadow: 0 16px 56px rgba(0, 0, 0, 0.5), 0 0 30px rgba(248, 81, 73, 0.06);
}
.custom-modal.modal-success .custom-modal-title { color: #3fb950; }
.custom-modal.modal-success {
    border-color: rgba(63, 185, 80, 0.2);
    box-shadow: 0 16px 56px rgba(0, 0, 0, 0.5), 0 0 30px rgba(63, 185, 80, 0.06);
}
.custom-modal.modal-warning .custom-modal-title { color: #d29922; }
.custom-modal.modal-warning {
    border-color: rgba(210, 153, 34, 0.2);
    box-shadow: 0 16px 56px rgba(0, 0, 0, 0.5), 0 0 30px rgba(210, 153, 34, 0.06);
}
.custom-modal.modal-info .custom-modal-title { color: #58a6ff; }
.custom-modal.modal-info {
    border-color: rgba(56, 139, 253, 0.2);
    box-shadow: 0 16px 56px rgba(0, 0, 0, 0.5), 0 0 30px rgba(56, 139, 253, 0.06);
}

/* ========== УНИФИКАЦИЯ ВСЕХ МОДАЛОК ========== */
#restoreModal > div,
#deleteTemplateModal > div > div,
#pickTemplateModal > div,
#renameChatModal > div,
#downloadFormatModal > div,
#aiModal .modal-content {
    background:
        radial-gradient(ellipse 80% 60% at 10% 20%, rgba(139, 92, 246, 0.1) 0%, transparent 60%),
        radial-gradient(ellipse 60% 50% at 90% 80%, rgba(56, 139, 253, 0.07) 0%, transparent 50%),
        rgba(16, 20, 35, 0.65) !important;
    backdrop-filter: blur(28px) saturate(1.5) !important;
    -webkit-backdrop-filter: blur(28px) saturate(1.5) !important;
    border: 1px solid rgba(139, 92, 246, 0.1) !important;
    border-radius: 18px !important;
    box-shadow:
        0 16px 56px rgba(0, 0, 0, 0.45),
        0 0 0 1px rgba(255, 255, 255, 0.03),
        inset 0 1px 0 rgba(255, 255, 255, 0.04) !important;
}

#restoreModal,
#deleteTemplateModal > div,
#pickTemplateModal,
#renameChatModal,
#downloadFormatModal {
    background: rgba(5, 8, 18, 0.6) !important;
    backdrop-filter: blur(6px) !important;
    -webkit-backdrop-filter: blur(6px) !important;
}

/* ========== ФИКС ОТСТУПОВ ========== */
.top-grid { margin-bottom: 0 !important; padding-bottom: 0 !important; }
.top-grid .box { margin-bottom: 0 !important; }
.box-body { padding-bottom: 2px !important; margin-bottom: 0 !important; }
#message:empty { display: none !important; padding: 0 !important; margin: 0 !important; height: 0 !important; }
.success, .error { padding: 3px 12px !important; margin: 0 !important; }
#cancelBtn:hover { background: #f85149 !important; color: #fff !important; }

input[type="file"] { display: none; }
/* ═══ Фикс кнопок в модалке выбора шаблона ═══ */
#pickTemplateList .btn {
    overflow: visible;
    transform: none !important;
}
#pickTemplateList .btn::before {
    display: none;
}
#pickTemplateList .btn:hover {
    transform: none !important;
    background: rgba(139, 92, 246, 0.1) !important;
    border-color: rgba(139, 92, 246, 0.3) !important;
}
/* Дебаг чата — раскомментировать при необходимости */
#streamDebug { display: none !important; }
/* ========== Единый стиль модалок ========== */
.modal-overlay-unified {
    background: rgba(5, 8, 18, 0.7) !important;
    backdrop-filter: blur(6px) !important;
    -webkit-backdrop-filter: blur(6px) !important;
}

.modal-box {
    background:
        radial-gradient(ellipse 80% 60% at 10% 20%, rgba(139, 92, 246, 0.08) 0%, transparent 60%),
        radial-gradient(ellipse 60% 50% at 90% 80%, rgba(56, 139, 253, 0.05) 0%, transparent 50%),
        rgba(16, 20, 35, 0.75);
    backdrop-filter: blur(28px) saturate(1.5);
    -webkit-backdrop-filter: blur(28px) saturate(1.5);
    border: 1px solid rgba(139, 92, 246, 0.12);
    border-radius: 18px;
    box-shadow:
        0 16px 56px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(255, 255, 255, 0.03),
        inset 0 1px 0 rgba(255, 255, 255, 0.04);
    animation: modalSlideIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Инпуты внутри единых модалок */
.modal-box input[type="text"],
.modal-box textarea {
    width: 100%;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    color: #f0f6fc;
    font-size: 14px;
    padding: 10px 12px;
    outline: none;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.modal-box .input-clearable input[type="text"] {
    padding-right: 32px;
}
.modal-box input[type="text"]:focus,
.modal-box textarea:focus {
    border-color: rgba(139, 92, 246, 0.4);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.1);
}