/* ════════════════════════════════════════════════════════════════════
   OmniSolverCode — Theme System (Minimal • Classic • Cosmos)
   ────────────────────────────────────────────────────────────────────
   Всё через CSS-переменные на :root[data-theme]. Любой элемент
   использующий var(--bg), var(--bg-card), var(--text), var(--primary)
   и т.п. автоматически меняет вид.

   В Космосе:
     • body-фон = ОДИН слой с туманностями + статичным паттерном звёзд
       (background-attachment: fixed → один на всё окно, не «прыгает»)
     • Все --bg-* переменные = rgba(... , 0.6-0.75) → панели стеклянно
       пропускают фон. НЕТ нагромождений backdrop-filter.
     • Никаких injected div'ов и mix-blend-mode → просто, быстро.
   ════════════════════════════════════════════════════════════════════ */

/* ─── CLASSIC (default) ───────────────────────────────────────────── */
:root,
:root[data-theme="classic"] {
    --bg:             #06070c;
    --bg-card:        #0c0d17;
    --bg-secondary:   #111225;
    --bg-tertiary:    #161730;
    --bg-hover:       #13152a;
    --bg-input:       #090a13;
    --bg-elev:        #14162b;
    --bg-sidebar:     #08090f;

    --border:         #191b30;
    --border-light:   #262842;

    --text:           #e8e8f4;
    --text-secondary: #9294b8;
    --text-muted:     #585a82;

    --primary:        #6c5ce7;
    --primary-light:  #a29bfe;
    --primary-dark:   #5541d9;
    --primary-glow:   rgba(108, 92, 231, 0.25);

    --accent:         #00cec9;
    --accent-light:   #55efc4;
    --chip-accent:    rgba(108, 92, 231, 0.18);

    --gradient:       linear-gradient(135deg, #6c5ce7, #00cec9);
    --gradient-text:  linear-gradient(135deg, #a29bfe, #55efc4);

    --code-bg:        #080914;
    --code-border:    #191b30;

    --msg-user:       #0e0f1c;
    --msg-ai:         #0a0b16;

    --success:        #22c55e;
    --warning:        #fbbf24;
    --danger:         #ef4444;

    --shadow:         0 4px 24px rgba(0, 0, 0, 0.5);
    --transition:     0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    --radius:         14px;
    --radius-lg:      18px;
}

/* ─── MINIMAL (монохром) ──────────────────────────────────────────── */
:root[data-theme="minimal"] {
    --bg:             #050505;
    --bg-card:        #0a0a0a;
    --bg-secondary:   #0e0e0e;
    --bg-tertiary:    #141414;
    --bg-hover:       #161616;
    --bg-input:       #070707;
    --bg-elev:        #181818;
    --bg-sidebar:     #060606;

    --border:         #1e1e1e;
    --border-light:   #2a2a2a;

    --text:           #f0f0f0;
    --text-secondary: #a0a0a0;
    --text-muted:     #5a5a5a;

    --primary:        #e8e8e8;
    --primary-light:  #ffffff;
    --primary-dark:   #b0b0b0;
    --primary-glow:   rgba(255, 255, 255, 0.10);

    --accent:         #c0c0c0;
    --accent-light:   #e0e0e0;
    --chip-accent:    rgba(255, 255, 255, 0.06);

    --gradient:       linear-gradient(135deg, #ffffff, #888888);
    --gradient-text:  linear-gradient(135deg, #ffffff, #b0b0b0);

    --code-bg:        #050505;
    --code-border:    #1e1e1e;

    --msg-user:       #0c0c0c;
    --msg-ai:         #080808;

    --success:        #22c55e;
    --warning:        #fbbf24;
    --danger:         #ef4444;

    --shadow:         0 4px 24px rgba(0, 0, 0, 0.7);
}

/* ─── COSMOS — стеклянный поверх космического фона ────────────────── */
:root[data-theme="cosmos"] {
    --bg:             #04041a;
    --bg-card:        rgba(10, 12, 36, 0.72);
    --bg-secondary:   rgba(15, 17, 44, 0.72);
    --bg-tertiary:    rgba(22, 24, 56, 0.72);
    --bg-hover:       rgba(40, 44, 92, 0.45);
    --bg-input:       rgba(8, 10, 28, 0.70);
    --bg-elev:        rgba(20, 22, 56, 0.78);
    --bg-sidebar:     rgba(6, 8, 22, 0.78);

    --border:         rgba(99, 102, 241, 0.16);
    --border-light:   rgba(129, 140, 248, 0.28);

    --text:           #e8eafe;
    --text-secondary: #9aa3d4;
    --text-muted:     #5d6699;

    --primary:        #818cf8;
    --primary-light:  #a5b4fc;
    --primary-dark:   #6366f1;
    --primary-glow:   rgba(129, 140, 248, 0.35);

    --accent:         #06b6d4;
    --accent-light:   #67e8f9;
    --chip-accent:    rgba(129, 140, 248, 0.18);

    --gradient:       linear-gradient(135deg, #6366f1, #06b6d4);
    --gradient-text:  linear-gradient(135deg, #a5b4fc, #67e8f9);

    --code-bg:        rgba(4, 6, 22, 0.85);
    --code-border:    rgba(99, 102, 241, 0.22);

    --msg-user:       rgba(20, 24, 60, 0.55);
    --msg-ai:         rgba(8, 10, 30, 0.55);

    --success:        #34d399;
    --warning:        #fbbf24;
    --danger:         #f43f5e;

    --shadow:         0 8px 32px rgba(0, 0, 5, 0.5);
}

/* ════════════════════════════════════════════════════════════════════
   COSMOS — единый фон на body.
   Туманности: яркие radial-gradients (большие размытые пятна).
   Звёзды: редкий точечный паттерн.
   ──────────────────────────────────────────────────────────────────── */
:root[data-theme="cosmos"] body {
    background-color: #04041a !important;
    background-image:
        /* 5 редких звёзд (паттерн 480×480) */
        radial-gradient(1px 1px at 67px 113px,  rgba(255,255,255,0.40), transparent 60%),
        radial-gradient(1px 1px at 251px 67px,  rgba(220,230,255,0.30), transparent 60%),
        radial-gradient(1.2px 1.2px at 379px 311px, rgba(255,255,255,0.45), transparent 60%),
        radial-gradient(1px 1px at 137px 379px, rgba(190,210,255,0.30), transparent 60%),
        radial-gradient(1px 1px at 433px 191px, rgba(255,255,255,0.35), transparent 60%),
        /* Туманности — крупные, насыщенные, с мягким fade */
        radial-gradient(ellipse 65vw 50vh at 18% 22%, rgba(99,102,241,0.45) 0%, rgba(99,102,241,0.18) 35%, transparent 70%),
        radial-gradient(ellipse 60vw 45vh at 82% 78%, rgba(6,182,212,0.35) 0%, rgba(6,182,212,0.12) 40%, transparent 75%),
        radial-gradient(ellipse 50vw 35vh at 60% 30%, rgba(192,132,252,0.28) 0%, rgba(192,132,252,0.10) 40%, transparent 75%),
        radial-gradient(ellipse 45vw 32vh at 30% 80%, rgba(244,114,182,0.18) 0%, rgba(244,114,182,0.06) 45%, transparent 80%),
        /* Базовый dark gradient */
        linear-gradient(180deg, #04041a 0%, #08093a 50%, #050822 100%) !important;
    background-size:
        480px 480px, 480px 480px, 480px 480px, 480px 480px, 480px 480px,
        100% 100%, 100% 100%, 100% 100%, 100% 100%, 100% 100% !important;
    background-attachment: fixed !important;
    background-repeat: repeat, repeat, repeat, repeat, repeat,
                       no-repeat, no-repeat, no-repeat, no-repeat, no-repeat !important;
}

/* ════════════════════════════════════════════════════════════════════
   TOPBAR — отдельные правила, потому что в chat.css он hardcoded rgba.
   ──────────────────────────────────────────────────────────────────── */
:root[data-theme="classic"] .chat-topbar {
    background: rgba(7, 8, 14, 0.85) !important;
    border-bottom: 1px solid var(--border) !important;
}
:root[data-theme="minimal"] .chat-topbar {
    background: rgba(5, 5, 5, 0.90) !important;
    border-bottom: 1px solid var(--border) !important;
}
:root[data-theme="cosmos"] .chat-topbar {
    background: rgba(6, 8, 22, 0.55) !important;
    border-bottom: 1px solid var(--border) !important;
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
}

/* В iframe (split-view) тело прозрачное — фон рендерится в parent окне */
:root[data-theme="cosmos"] html {
    background-color: transparent;
}

/* ════════════════════════════════════════════════════════════════════
   Theme picker modal — фиксированные цвета, не зависят от темы юзера
   ──────────────────────────────────────────────────────────────────── */
.theme-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 5, 0.55);
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: theme-fade-in 0.2s ease;
}
@keyframes theme-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
.theme-modal {
    width: min(960px, 94vw);
    max-height: 86vh;
    overflow-y: auto;
    background: #0c0d17;
    border: 1px solid #262842;
    border-radius: 18px;
    padding: 24px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.6);
    color: #e8e8f4;
    animation: theme-slide-up 0.25s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}
@keyframes theme-slide-up {
    from { opacity: 0; transform: translateY(20px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0)   scale(1);     }
}
.theme-modal-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    color: #e8e8f4;
}
.theme-modal-title {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.02em;
}
.theme-modal-subtitle {
    font-size: 13px;
    color: #9294b8;
    margin-bottom: 18px;
}
.theme-modal-close {
    margin-left: auto;
    background: transparent;
    border: none;
    color: #585a82;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.18s ease;
}
.theme-modal-close:hover {
    background: rgba(239, 68, 68, 0.10);
    color: #ef4444;
}
.theme-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 14px;
}
@media (max-width: 760px) {
    .theme-grid { grid-template-columns: 1fr; }
}

/* Theme cards — единый прямоугольник, без рамок, monolithic */
.theme-card {
    border: none;
    outline: none;
    border-radius: 14px;
    padding: 0;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    background: #0c0d17;
    overflow: hidden;
    text-align: left;
    color: #e8e8f4;
    position: relative;
    min-height: 250px;
}
.theme-card:hover {
    transform: translateY(-3px);
}
.theme-card.active {
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18);
}
.theme-card.active::before {
    content: '✓';
    position: absolute;
    top: 10px;
    right: 12px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #ffffff;
    color: #0c0d17;
    font-size: 13px;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
    z-index: 3;
}
.theme-card-preview {
    position: absolute;
    inset: 0 0 auto 0;
    height: 130px;
    pointer-events: none;
    -webkit-mask-image: linear-gradient(to bottom, black 0%, black 50%, transparent 100%);
            mask-image: linear-gradient(to bottom, black 0%, black 50%, transparent 100%);
}
.theme-card-preview.classic {
    background:
        radial-gradient(ellipse 70% 60% at 25% 30%, rgba(108,92,231,0.40) 0%, transparent 70%),
        radial-gradient(ellipse 60% 50% at 75% 70%, rgba(0,206,201,0.25) 0%, transparent 70%);
}
.theme-card-preview.classic::before {
    content: '';
    position: absolute;
    top: 48px; left: 50%;
    width: 70%; height: 3px;
    background: linear-gradient(90deg, #6c5ce7, #a29bfe, #00cec9);
    transform: translateX(-50%);
    border-radius: 2px;
    box-shadow: 0 0 18px rgba(108, 92, 231, 0.55);
}
.theme-card-preview.minimal {
    background: linear-gradient(180deg, rgba(255,255,255,0.04), transparent);
}
.theme-card-preview.minimal::before {
    content: '';
    position: absolute;
    top: 48px; left: 50%;
    width: 70%; height: 3px;
    background: linear-gradient(90deg, #22c55e, #fbbf24, #ef4444);
    transform: translateX(-50%);
    border-radius: 2px;
    opacity: 0.65;
}
.theme-card-preview.cosmos {
    background:
        radial-gradient(ellipse 60% 80% at 20% 30%, rgba(99,102,241,0.42) 0%, transparent 70%),
        radial-gradient(ellipse 55% 75% at 80% 70%, rgba(6,182,212,0.30) 0%, transparent 75%),
        radial-gradient(circle 60% at 60% 30%, rgba(192,132,252,0.18), transparent 80%);
}
.theme-card-preview.cosmos::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(1.5px 1.5px at 12% 22%, rgba(255,255,255,0.9), transparent 70%),
        radial-gradient(1px 1px at 32% 58%, rgba(220,230,255,0.7), transparent 70%),
        radial-gradient(1.5px 1.5px at 52% 30%, rgba(255,255,255,0.85), transparent 70%),
        radial-gradient(2px 2px at 72% 48%, rgba(255,255,255,1), transparent 70%),
        radial-gradient(1px 1px at 88% 72%, rgba(190,210,255,0.7), transparent 70%),
        radial-gradient(1px 1px at 22% 70%, rgba(255,255,255,0.55), transparent 70%);
}
.theme-card-body {
    position: relative;
    padding: 110px 18px 18px;
    background: transparent;
}
.theme-card-name {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 4px;
    letter-spacing: -0.01em;
    color: #e8e8f4;
}
.theme-card-desc {
    font-size: 12px;
    color: #9294b8;
    line-height: 1.5;
    min-height: 36px;
}
.theme-card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 10px;
}
.theme-card-tag {
    font-size: 10px;
    padding: 3px 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    color: #9294b8;
    border: none;
    letter-spacing: 0.02em;
}

/* ════════════════════════════════════════════════════════════════════
   Theme switcher button (header)
   ──────────────────────────────────────────────────────────────────── */
.theme-btn svg {
    width: 18px;
    height: 18px;
    transition: transform 0.4s ease;
}
.theme-btn:hover svg {
    transform: rotate(35deg);
}

/* Smooth transition при смене темы */
.theme-transitioning,
.theme-transitioning * {
    transition: background-color 0.25s ease,
                background 0.25s ease,
                color 0.20s ease,
                border-color 0.20s ease,
                box-shadow 0.25s ease !important;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .theme-transitioning, .theme-transitioning * {
        transition: none !important;
    }
}

/* ════════════════════════════════════════════════════════════════════
   LIGHT THEME — единая светлая палитра для ВСЕХ оформлений.
   Тогл «Светлая тема» в сайдбаре → body.light-theme. Один и тот же набор
   CSS-vars применяется поверх любого data-theme (classic/minimal/cosmos),
   потому что body.light-theme имеет более высокую специфичность чем
   :root[data-theme=*]. Декоративные фишки оформлений (шрифты, анимации,
   border-radius, отдельные классы) сохраняются — меняется только палитра.
   ──────────────────────────────────────────────────────────────────── */
body.light-theme,
:root[data-theme="classic"] body.light-theme,
:root[data-theme="minimal"] body.light-theme,
:root[data-theme="cosmos"]  body.light-theme {
    --bg:             #f6f7fc;
    --bg-card:        #ffffff;
    --bg-secondary:   #f1f3f9;
    --bg-tertiary:    #e9ecf3;
    --bg-hover:       #eef0f7;
    --bg-input:       #ffffff;
    --bg-elev:        #ffffff;
    --bg-sidebar:     #f3f5fa;

    --border:         #dfe2ec;
    --border-light:   #c9cdda;

    --text:           #1a1d29;
    --text-secondary: #4a4f63;
    --text-muted:     #7a7f93;

    --primary:        #6c5ce7;
    --primary-light:  #a29bfe;
    --primary-dark:   #5541d9;
    --primary-glow:   rgba(108, 92, 231, 0.18);

    --accent:         #00cec9;
    --accent-light:   #55efc4;
    --chip-accent:    rgba(108, 92, 231, 0.10);

    --gradient:       linear-gradient(135deg, #6c5ce7, #00cec9);
    --gradient-text:  linear-gradient(135deg, #5541d9, #00a5a1);

    --code-bg:        #f4f5fa;
    --code-border:    #e1e4ed;
    --msg-user:       #eef1fb;
    --msg-ai:         #ffffff;

    --success:        #16a34a;
    --warning:        #d97706;
    --danger:         #dc2626;

    --shadow:         0 4px 18px rgba(15, 23, 42, 0.10);

    background: var(--bg);
    color: var(--text);
}

/* В cosmos светлая тема убирает тёмный космо-фон body — иначе фиолетовые
   туманности перебивают светлый layout. Декоративные эффекты cosmos
   (glow-shadow на карточках, glassmorphism через backdrop-filter, иконки
   и шрифты — всё что лежит в *других* классах) — остаются. */
:root[data-theme="cosmos"] body.light-theme {
    background-image: none !important;
    background-color: var(--bg) !important;
}

/* Topbar — светлый glass поверх единой палитры, в любой теме оформления */
body.light-theme .chat-topbar,
:root[data-theme="classic"] body.light-theme .chat-topbar,
:root[data-theme="minimal"] body.light-theme .chat-topbar,
:root[data-theme="cosmos"]  body.light-theme .chat-topbar {
    background: rgba(255, 255, 255, 0.92) !important;
    border-bottom: 1px solid var(--border) !important;
    color: var(--text) !important;
    backdrop-filter: blur(8px) !important;
    -webkit-backdrop-filter: blur(8px) !important;
}

/* Light: чат-сообщения, инпут, кнопки — выровнять по новым цветам */
body.light-theme .message,
body.light-theme .chat-input,
body.light-theme .chat-input-wrapper,
body.light-theme .sidebar,
body.light-theme .chat-screen,
body.light-theme .chat-main,
body.light-theme .chat-messages {
    color: var(--text);
}
body.light-theme .chat-input {
    background: var(--bg-input);
    border-color: var(--border);
}
body.light-theme .message.user .message-content,
body.light-theme .message.user {
    background: var(--msg-user);
    color: var(--text);
}
body.light-theme .message.assistant .message-content,
body.light-theme .message.assistant {
    background: var(--msg-ai);
    color: var(--text);
    border: 1px solid var(--border);
}
body.light-theme code,
body.light-theme pre,
body.light-theme .inline-diff {
    background: var(--code-bg) !important;
    border-color: var(--code-border) !important;
    color: #0f172a;
}
body.light-theme .fm-ctx-menu {
    background: rgba(252, 253, 255, 0.985) !important;
    color: var(--text);
}
body.light-theme .scroll-to-top-btn {
    border-color: rgba(99, 102, 241, 0.30);
    background: linear-gradient(135deg, rgba(99,102,241,0.10), rgba(6,182,212,0.08));
}
