/* ===== CUSTOM PROPERTIES ===== */

:root[data-theme="dark"] {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-glass: rgba(17, 24, 39, 0.65);
    --bg-glass-hover: rgba(17, 24, 39, 0.8);
    --border-glass: rgba(255, 255, 255, 0.08);
    --border-glass-hover: rgba(255, 255, 255, 0.15);

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-glow: rgba(59, 130, 246, 0.25);
    --accent-subtle: rgba(59, 130, 246, 0.1);

    --success: #10b981;
    --error: #ef4444;
    --error-bg: rgba(239, 68, 68, 0.1);
    --warning: #f59e0b;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 8px 48px rgba(0, 0, 0, 0.6);
    --shadow-glow: 0 0 40px var(--accent-glow);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-full: 9999px;

    --scrollbar-track: transparent;
    --scrollbar-thumb: rgba(148, 163, 184, 0.38);
    --scrollbar-thumb-hover: rgba(148, 163, 184, 0.62);
}

/* Схемы каталога (parser): базовый filter + слой .parts-scheme__tint::after (mix-blend-mode: color) даёт синий подтон */
:root:is([data-theme="dark"], :not([data-theme])) {
    --parser-scheme-diagram-filter: invert(1) sepia(0.05) hue-rotate(210deg) saturate(0.68) brightness(0.93) contrast(0.88);
    /* Сила синего подтона поверх схемы (не серый — hue/sat от --accent) */
    --parser-scheme-undertone-opacity: 0.22;
}

:root[data-theme="light"] {
    --bg-primary: #f0f4f8;
    --bg-secondary: #ffffff;
    --bg-glass: rgba(255, 255, 255, 0.7);
    --bg-glass-hover: rgba(255, 255, 255, 0.85);
    --border-glass: rgba(0, 0, 0, 0.08);
    --border-glass-hover: rgba(0, 0, 0, 0.12);

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;

    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-glow: rgba(37, 99, 235, 0.2);
    --accent-subtle: rgba(37, 99, 235, 0.06);

    --success: #059669;
    --error: #dc2626;
    --error-bg: rgba(220, 38, 38, 0.06);
    --warning: #d97706;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 48px rgba(0, 0, 0, 0.12);
    --shadow-glow: 0 0 40px var(--accent-glow);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-full: 9999px;

    --scrollbar-track: rgba(0, 0, 0, 0.04);
    --scrollbar-thumb: rgba(100, 116, 139, 0.45);
    --scrollbar-thumb-hover: rgba(71, 85, 105, 0.65);

    --parser-scheme-diagram-filter: none;
    --parser-scheme-undertone-opacity: 0;
}

/* ===== RESET & BASE ===== */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    /* Reserve scrollbar space to prevent layout shift
       when results appear and page becomes scrollable. */
    scrollbar-gutter: stable;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
}

[data-theme="dark"] body {
    background-image:
        radial-gradient(ellipse 80% 50% at 50% -20%, rgba(59, 130, 246, 0.08), transparent),
        radial-gradient(ellipse 60% 40% at 80% 100%, rgba(139, 92, 246, 0.06), transparent);
}

/* ===== GLASS ===== */

.glass {
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.glass:hover {
    border-color: var(--border-glass-hover);
}

/* ===== HEADER ===== */

.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-glass);
}

.header__inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header__logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 700;
    font-size: 1.125rem;
}

.header__logo-icon {
    color: var(--accent);
    font-size: 1.4rem;
    position: relative;
    top: -1px;
}

.header__nav {
    display: flex;
    gap: 8px;
}

.header__link {
    padding: 6px 16px;
    border-radius: var(--radius-full);
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.header__link:hover {
    color: var(--text-primary);
    background: var(--accent-subtle);
}

.header__link--active {
    color: var(--accent);
    background: var(--accent-subtle);
}

.header__actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header__icon-btn {
    background: none;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-full);
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all 0.2s ease;
    color: var(--text-secondary);
    text-decoration: none;
    flex-shrink: 0;
}

.header__icon-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.header__icon-btn--active {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-subtle);
}

.theme-toggle {
    background: none;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-full);
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all 0.2s ease;
    color: var(--text-secondary);
}

.theme-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
}

[data-theme="dark"] .theme-toggle__icon--light { display: none; }
[data-theme="dark"] .theme-toggle__icon--dark  { display: inline; }
[data-theme="light"] .theme-toggle__icon--dark  { display: none; }
[data-theme="light"] .theme-toggle__icon--light { display: inline; }

/* ===== MAIN ===== */

.main {
    flex: 1;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 40px 24px;
}

/* ===== THEMED SCROLLBARS (все прокручиваемые области, в т.ч. модалки) ===== */

* {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

*::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

*::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
    border-radius: var(--radius-full);
}

*::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: var(--radius-full);
    border: 2px solid transparent;
    background-clip: padding-box;
}

*::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
    background-clip: padding-box;
}

*::-webkit-scrollbar-corner {
    background: transparent;
}

/* ===== SPINNER ===== */

.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== FOOTER ===== */

.footer {
    border-top: 1px solid var(--border-glass);
    margin-top: auto;
}

.footer__inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px 24px;
    text-align: center;
}

.footer__text {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ===== ANIMATIONS ===== */

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

/* ===== RESPONSIVE ===== */

@media (max-width: 640px) {
    .header__inner { padding: 0 16px; }
    .main { padding: 24px 16px; }
}
