/* ============================================
   COOKIEJAR DESIGN SYSTEM v3.0
   Abstract, Cinematic, Research Terminal
   ============================================ */

/* ============================================
   CSS CUSTOM PROPERTIES - LIGHT MODE
   ============================================ */
:root {
    /* Color Palette - Light Mode (Research Lab Aesthetic) */
    --color-bg-primary: #f5f4f1;
    --color-bg-secondary: #eceae6;
    --color-bg-tertiary: #e4e2dd;
    --color-bg-elevated: #ffffff;

    /* Surface colors with subtle violet undertone */
    --color-surface: #faf9f7;
    --color-surface-hover: #f0efec;
    --color-surface-active: #e8e6e2;

    /* Text colors - neutral, calm */
    --color-text-primary: #1a1a1a;
    --color-text-secondary: #555555;
    --color-text-tertiary: #888888;
    --color-text-muted: #aaaaaa;

    /* Accent colors - cold, professional */
    --color-accent-primary: #4a6fa5;
    --color-accent-secondary: #6b8cbe;
    --color-accent-tertiary: #8fa8d0;
    --color-accent-glow: rgba(74, 111, 165, 0.15);

    /* State colors */
    --color-success: #4a9b7f;
    --color-warning: #c4923a;
    --color-error: #c45c5c;
    --color-info: #5a8ac4;

    /* Borders and dividers */
    --color-border: rgba(0, 0, 0, 0.08);
    --color-border-subtle: rgba(0, 0, 0, 0.04);
    --color-border-focus: var(--color-accent-primary);

    /* Shadows - soft, diffused */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.05), 0 2px 4px rgba(0, 0, 0, 0.03);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.06), 0 4px 8px rgba(0, 0, 0, 0.04);
    --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.08), 0 8px 16px rgba(0, 0, 0, 0.05);
    --shadow-glow: 0 0 20px var(--color-accent-glow);

    /* Gradients */
    --gradient-bg: linear-gradient(135deg, #f5f4f1 0%, #eae8e4 100%);
    --gradient-surface: linear-gradient(180deg, rgba(255,255,255,0.8) 0%, rgba(250,249,247,0.6) 100%);
    --gradient-accent: linear-gradient(135deg, var(--color-accent-primary) 0%, var(--color-accent-secondary) 100%);

    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --font-heading: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;

    /* Font sizes */
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-3xl: 1.875rem;
    --text-4xl: 2.25rem;
    --text-5xl: 3rem;

    /* Font weights */
    --font-normal: 400;
    --font-medium: 500;
    --font-semibold: 600;
    --font-bold: 700;

    /* Line heights */
    --leading-tight: 1.25;
    --leading-snug: 1.375;
    --leading-normal: 1.5;
    --leading-relaxed: 1.625;

    /* Spacing */
    --space-0: 0;
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;
    --space-16: 4rem;
    --space-20: 5rem;
    --space-24: 6rem;

    /* Border radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-2xl: 24px;
    --radius-full: 9999px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 200ms ease;
    --transition-slow: 300ms ease;
    --transition-slower: 500ms ease;

    /* Z-index scale */
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-fixed: 300;
    --z-modal-backdrop: 400;
    --z-modal: 500;
    --z-popover: 600;
    --z-tooltip: 700;

    /* Layout */
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 72px;
    --topbar-height: 64px;
    --content-max-width: 1200px;
}

/* ============================================
   DARK MODE - Atmospheric Research Terminal
   ============================================ */
[data-theme="dark"] {
    /* Background - deep, layered darkness with subtle color */
    --color-bg-primary: #0d0f14;
    --color-bg-secondary: #12151c;
    --color-bg-tertiary: #181c26;
    --color-bg-elevated: #1e222e;

    /* Surface colors - soft dark with depth */
    --color-surface: #1a1e28;
    --color-surface-hover: #22273a;
    --color-surface-active: #2a3044;

    /* Text colors - soft, not harsh white */
    --color-text-primary: #e8e9ed;
    --color-text-secondary: #a0a4b0;
    --color-text-tertiary: #6b7080;
    --color-text-muted: #4a4f5c;

    /* Accent colors - cold cyan, electric purple, icy blue */
    --color-accent-primary: #64b5f6;
    --color-accent-secondary: #90caf9;
    --color-accent-tertiary: #bbdefb;
    --color-accent-glow: rgba(100, 181, 246, 0.2);

    /* State colors - adjusted for dark mode */
    --color-success: #66bb6a;
    --color-warning: #ffa726;
    --color-error: #ef5350;
    --color-info: #42a5f5;

    /* Borders - subtle luminosity */
    --color-border: rgba(255, 255, 255, 0.08);
    --color-border-subtle: rgba(255, 255, 255, 0.04);
    --color-border-focus: var(--color-accent-primary);

    /* Shadows - deeper, more dramatic */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4), 0 2px 4px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5), 0 4px 8px rgba(0, 0, 0, 0.4);
    --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.6), 0 8px 16px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 30px var(--color-accent-glow), 0 0 60px rgba(100, 181, 246, 0.1);

    /* Gradients - atmospheric depth */
    --gradient-bg: linear-gradient(180deg, #0d0f14 0%, #0a0c10 100%);
    --gradient-surface: linear-gradient(180deg, rgba(30, 34, 46, 0.8) 0%, rgba(26, 30, 40, 0.6) 100%);
    --gradient-accent: linear-gradient(135deg, #64b5f6 0%, #42a5f5 100%);
}

/* ============================================
   BASE RESET & GLOBAL STYLES
   ============================================ */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body {
    font-family: var(--font-sans);
    font-size: var(--text-base);
    font-weight: var(--font-normal);
    line-height: var(--leading-normal);
    color: var(--color-text-primary);
    background: var(--gradient-bg);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================
   CUSTOM CURSOR SYSTEM (High-Tech HTML Element)
   Desktop only - smooth trailing movement
   ============================================ */

/* Hide native cursor on desktop when custom cursor is active */
.custom-cursor-active {
    cursor: none !important;
}

.custom-cursor-active *,
.custom-cursor-active *::before,
.custom-cursor-active *::after {
    cursor: none !important;
}

/* Custom cursor element */
.custom-cursor {
    --cursor-size: 24px;
    --cursor-dot-size: 4px;
    --cursor-color: #64b5f6;
    --cursor-glow: rgba(100, 181, 246, 0.4);
    --cursor-glow-strong: rgba(100, 181, 246, 0.6);

    position: fixed;
    top: 0;
    left: 0;
    width: var(--cursor-size);
    height: var(--cursor-size);
    pointer-events: none;
    z-index: 99999;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 0.3s ease;
    mix-blend-mode: screen;
}

.custom-cursor.visible {
    opacity: 1;
}

/* Cursor ring (outer circle) */
.custom-cursor-ring {
    position: absolute;
    inset: 0;
    border: 1.5px solid var(--cursor-color);
    border-radius: 50%;
    opacity: 0.9;
    box-shadow:
        0 0 8px var(--cursor-glow),
        0 0 16px var(--cursor-glow),
        inset 0 0 4px var(--cursor-glow);
    transition:
        transform 0.15s cubic-bezier(0.25, 0.1, 0.25, 1),
        border-color 0.2s ease,
        box-shadow 0.2s ease,
        opacity 0.2s ease;
}

/* Cursor dot (center) */
.custom-cursor-dot {
    position: absolute;
    top: 50%;
    left: 50%;
    width: var(--cursor-dot-size);
    height: var(--cursor-dot-size);
    background: var(--cursor-color);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 6px var(--cursor-glow);
    transition:
        transform 0.15s cubic-bezier(0.25, 0.1, 0.25, 1),
        background-color 0.2s ease,
        box-shadow 0.2s ease,
        width 0.15s ease,
        height 0.15s ease;
}

/* I-beam element for text cursor */
.custom-cursor-ibeam {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 2px;
    height: 18px;
    background: var(--cursor-color);
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 0.15s ease;
    box-shadow: 0 0 4px var(--cursor-glow);
}

.custom-cursor-ibeam::before,
.custom-cursor-ibeam::after {
    content: '';
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 8px;
    height: 2px;
    background: var(--cursor-color);
}

.custom-cursor-ibeam::before {
    top: 0;
}

.custom-cursor-ibeam::after {
    bottom: 0;
}

/* Drag grip dots */
.custom-cursor-grip {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    gap: 3px;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.custom-cursor-grip::before,
.custom-cursor-grip::after {
    content: '';
    width: 3px;
    height: 3px;
    background: var(--cursor-color);
    border-radius: 50%;
    box-shadow: 0 0 4px var(--cursor-glow);
}

/* Resize arrows */
.custom-cursor-arrows {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 0.15s ease;
}

.custom-cursor-arrows svg {
    width: 16px;
    height: 16px;
    fill: var(--cursor-color);
    filter: drop-shadow(0 0 4px var(--cursor-glow));
}

/* Forbidden slash */
.custom-cursor-forbidden {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 2px;
    background: var(--cursor-color);
    transform: translate(-50%, -50%) rotate(-45deg);
    opacity: 0;
    transition: opacity 0.15s ease;
}

/* Busy spinner segment */
.custom-cursor-spinner {
    position: absolute;
    inset: -2px;
    border: 2px solid transparent;
    border-top-color: var(--cursor-color);
    border-radius: 50%;
    opacity: 0;
    animation: cursor-spin 0.8s linear infinite;
    animation-play-state: paused;
}

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

/* ============================================
   CURSOR STATES
   ============================================ */

/* DEFAULT STATE */
.custom-cursor[data-state="default"] .custom-cursor-ring {
    transform: scale(1);
}

.custom-cursor[data-state="default"] .custom-cursor-dot {
    transform: translate(-50%, -50%) scale(1);
}

/* POINTER STATE (buttons, links, clickables) */
.custom-cursor[data-state="pointer"] {
    --cursor-size: 32px;
}

.custom-cursor[data-state="pointer"] .custom-cursor-ring {
    transform: scale(1.3);
    box-shadow:
        0 0 12px var(--cursor-glow-strong),
        0 0 24px var(--cursor-glow),
        inset 0 0 8px var(--cursor-glow);
}

.custom-cursor[data-state="pointer"] .custom-cursor-dot {
    transform: translate(-50%, -50%) scale(1.2);
    box-shadow: 0 0 10px var(--cursor-glow-strong);
}

/* TEXT STATE (inputs, textareas) */
.custom-cursor[data-state="text"] {
    --cursor-size: 20px;
}

.custom-cursor[data-state="text"] .custom-cursor-ring {
    transform: scale(0.7);
    opacity: 0.5;
}

.custom-cursor[data-state="text"] .custom-cursor-dot {
    opacity: 0;
}

.custom-cursor[data-state="text"] .custom-cursor-ibeam {
    opacity: 1;
}

/* DRAG STATE */
.custom-cursor[data-state="drag"] {
    --cursor-size: 28px;
}

.custom-cursor[data-state="drag"] .custom-cursor-ring {
    transform: scaleX(1.2) scaleY(0.9);
    animation: cursor-wobble 0.3s ease-in-out infinite;
}

.custom-cursor[data-state="drag"] .custom-cursor-dot {
    opacity: 0;
}

.custom-cursor[data-state="drag"] .custom-cursor-grip {
    opacity: 1;
}

@keyframes cursor-wobble {
    0%, 100% { transform: scaleX(1.2) scaleY(0.9) rotate(-2deg); }
    50% { transform: scaleX(1.2) scaleY(0.9) rotate(2deg); }
}

/* RESIZE STATES */
.custom-cursor[data-state="resize-x"],
.custom-cursor[data-state="resize-y"],
.custom-cursor[data-state="resize-diag"] {
    --cursor-size: 28px;
}

.custom-cursor[data-state="resize-x"] .custom-cursor-arrows,
.custom-cursor[data-state="resize-y"] .custom-cursor-arrows,
.custom-cursor[data-state="resize-diag"] .custom-cursor-arrows {
    opacity: 1;
}

.custom-cursor[data-state="resize-x"] .custom-cursor-dot,
.custom-cursor[data-state="resize-y"] .custom-cursor-dot,
.custom-cursor[data-state="resize-diag"] .custom-cursor-dot {
    opacity: 0;
}

.custom-cursor[data-state="resize-y"] .custom-cursor-arrows {
    transform: translate(-50%, -50%) rotate(90deg);
}

.custom-cursor[data-state="resize-diag"] .custom-cursor-arrows {
    transform: translate(-50%, -50%) rotate(45deg);
}

/* FORBIDDEN STATE */
.custom-cursor[data-state="forbidden"] {
    --cursor-color: #ef5350;
    --cursor-glow: rgba(239, 83, 80, 0.4);
}

.custom-cursor[data-state="forbidden"] .custom-cursor-ring {
    animation: cursor-pulse-red 1s ease-in-out infinite;
}

.custom-cursor[data-state="forbidden"] .custom-cursor-forbidden {
    opacity: 1;
}

.custom-cursor[data-state="forbidden"] .custom-cursor-dot {
    opacity: 0;
}

@keyframes cursor-pulse-red {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 8px var(--cursor-glow), 0 0 16px var(--cursor-glow);
    }
    50% {
        transform: scale(1.1);
        box-shadow: 0 0 12px var(--cursor-glow), 0 0 24px var(--cursor-glow);
    }
}

/* BUSY STATE */
.custom-cursor[data-state="busy"] .custom-cursor-spinner {
    opacity: 1;
    animation-play-state: running;
}

.custom-cursor[data-state="busy"] .custom-cursor-dot {
    animation: cursor-pulse-dot 1.5s ease-in-out infinite;
}

@keyframes cursor-pulse-dot {
    0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 0.8; }
    50% { transform: translate(-50%, -50%) scale(1.3); opacity: 1; }
}

/* Light mode adjustments */
[data-theme="light"] .custom-cursor {
    --cursor-color: #4a6fa5;
    --cursor-glow: rgba(74, 111, 165, 0.4);
    --cursor-glow-strong: rgba(74, 111, 165, 0.6);
    mix-blend-mode: multiply;
}

/* Touch device - hide cursor completely */
@media (pointer: coarse), (hover: none) {
    .custom-cursor {
        display: none !important;
    }

    .custom-cursor-active {
        cursor: auto !important;
    }

    .custom-cursor-active *,
    .custom-cursor-active *::before,
    .custom-cursor-active *::after {
        cursor: auto !important;
    }
}

/* ============================================
   CUSTOM SCROLLBAR (High-Tech Neon Aesthetic)
   Desktop only - thin, dark glass track, neon blue thumb
   ============================================ */
@media (min-width: 768px) {
    /* Webkit scrollbar (Chrome, Safari, Edge) */
    ::-webkit-scrollbar {
        width: 6px;
        height: 6px;
    }

    ::-webkit-scrollbar-track {
        background: rgba(0, 0, 0, 0.2);
        border-radius: 10px;
        backdrop-filter: blur(4px);
    }

    ::-webkit-scrollbar-thumb {
        background: linear-gradient(180deg, #64b5f6 0%, #42a5f5 50%, #1e88e5 100%);
        border-radius: 10px;
        box-shadow:
            0 0 6px rgba(100, 181, 246, 0.4),
            inset 0 0 2px rgba(255, 255, 255, 0.3);
    }

    ::-webkit-scrollbar-thumb:hover {
        background: linear-gradient(180deg, #90caf9 0%, #64b5f6 50%, #42a5f5 100%);
        box-shadow:
            0 0 12px rgba(100, 181, 246, 0.6),
            0 0 20px rgba(100, 181, 246, 0.3),
            inset 0 0 4px rgba(255, 255, 255, 0.4);
    }

    ::-webkit-scrollbar-thumb:active {
        background: linear-gradient(180deg, #bbdefb 0%, #90caf9 50%, #64b5f6 100%);
    }

    ::-webkit-scrollbar-corner {
        background: rgba(0, 0, 0, 0.2);
    }

    /* Firefox scrollbar */
    html {
        scrollbar-width: thin;
        scrollbar-color: #64b5f6 rgba(0, 0, 0, 0.2);
    }

    /* Dark mode scrollbar enhancement */
    [data-theme="dark"] ::-webkit-scrollbar-track {
        background: rgba(0, 0, 0, 0.4);
    }

    [data-theme="dark"] ::-webkit-scrollbar-thumb {
        background: linear-gradient(180deg, #64b5f6 0%, #42a5f5 50%, #1e88e5 100%);
        box-shadow:
            0 0 8px rgba(100, 181, 246, 0.5),
            0 0 16px rgba(100, 181, 246, 0.2),
            inset 0 0 2px rgba(255, 255, 255, 0.2);
    }

    [data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
        box-shadow:
            0 0 14px rgba(100, 181, 246, 0.7),
            0 0 28px rgba(100, 181, 246, 0.4),
            inset 0 0 4px rgba(255, 255, 255, 0.3);
    }

    /* Light mode scrollbar */
    [data-theme="light"] ::-webkit-scrollbar-track {
        background: rgba(0, 0, 0, 0.08);
    }

    [data-theme="light"] ::-webkit-scrollbar-thumb {
        background: linear-gradient(180deg, #4a6fa5 0%, #5a8ac4 50%, #6b9bd1 100%);
        box-shadow:
            0 0 4px rgba(74, 111, 165, 0.3),
            inset 0 0 2px rgba(255, 255, 255, 0.4);
    }

    [data-theme="light"] ::-webkit-scrollbar-thumb:hover {
        box-shadow:
            0 0 10px rgba(74, 111, 165, 0.5),
            0 0 20px rgba(74, 111, 165, 0.2);
    }

    [data-theme="light"] html {
        scrollbar-color: #4a6fa5 rgba(0, 0, 0, 0.08);
    }
}

/* Fallback for browsers without custom scrollbar support (Firefox uses scrollbar-width/color) */
@supports not selector(::-webkit-scrollbar) {
    html {
        overflow-y: scroll;
        scrollbar-width: thin;
        scrollbar-color: #64b5f6 rgba(0, 0, 0, 0.2);
    }
}

/* ============================================
   TYPOGRAPHY
   ============================================ */
h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    font-weight: var(--font-semibold);
    line-height: var(--leading-tight);
    color: var(--color-text-primary);
    letter-spacing: -0.02em;
}

h1 { font-size: var(--text-4xl); font-weight: var(--font-bold); }
h2 { font-size: var(--text-3xl); }
h3 { font-size: var(--text-2xl); }
h4 { font-size: var(--text-xl); }
h5 { font-size: var(--text-lg); }
h6 { font-size: var(--text-base); }

p {
    color: var(--color-text-secondary);
    line-height: var(--leading-relaxed);
}

a {
    color: var(--color-accent-primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--color-accent-secondary);
}

/* ============================================
   FOCUS STYLES (Accessibility)
   ============================================ */
:focus {
    outline: none;
}

:focus-visible {
    outline: 2px solid var(--color-accent-primary);
    outline-offset: 2px;
}

/* ============================================
   SKIP LINK (Accessibility)
   ============================================ */
.skip-link {
    position: absolute;
    top: -100%;
    left: var(--space-4);
    z-index: var(--z-tooltip);
    padding: var(--space-3) var(--space-4);
    background: var(--color-accent-primary);
    color: white;
    font-weight: var(--font-semibold);
    border-radius: var(--radius-md);
    transition: top var(--transition-fast);
}

.skip-link:focus {
    top: var(--space-4);
}

/* ============================================
   APP SHELL LAYOUT
   ============================================ */
.app-shell {
    display: flex;
    min-height: 100vh;
}

/* Top Bar */
.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-height);
    background: var(--color-bg-elevated);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-6);
    z-index: var(--z-fixed);
    backdrop-filter: blur(12px);
}

[data-theme="dark"] .topbar {
    background: rgba(30, 34, 46, 0.85);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.topbar-center {
    flex: 1;
    display: flex;
    justify-content: center;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

/* Logo */
.logo {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-size: var(--text-xl);
    font-weight: var(--font-bold);
    color: var(--color-text-primary);
    text-decoration: none;
}

.logo-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    background: var(--gradient-accent);
    border-radius: var(--radius-md);
    color: white;
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--color-bg-secondary);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    z-index: var(--z-sticky);
    transition: transform var(--transition-slow), width var(--transition-slow);
}

[data-theme="dark"] .sidebar {
    background: var(--color-bg-secondary);
}

.sidebar-nav {
    flex: 1;
    padding: var(--space-4);
    overflow-y: auto;
}

.sidebar-footer {
    padding: var(--space-4);
    border-top: 1px solid var(--color-border);
}

/* Navigation items */
.nav-section {
    margin-bottom: var(--space-6);
}

.nav-section-title {
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    color: var(--color-text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: var(--space-2) var(--space-3);
    margin-bottom: var(--space-2);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-lg);
    color: var(--color-text-secondary);
    font-weight: var(--font-medium);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
}

.nav-item:hover {
    background: var(--color-surface-hover);
    color: var(--color-text-primary);
}

.nav-item.active {
    background: var(--color-accent-glow);
    color: var(--color-accent-primary);
}

.nav-item-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.nav-item-label {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-item-badge {
    padding: var(--space-1) var(--space-2);
    background: var(--color-accent-primary);
    color: white;
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    border-radius: var(--radius-full);
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    margin-top: var(--topbar-height);
    min-height: calc(100vh - var(--topbar-height));
    padding: var(--space-8);
}

.content-container {
    max-width: var(--content-max-width);
    margin: 0 auto;
}

/* Mobile sidebar */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: calc(var(--z-sticky) - 1);
        opacity: 0;
        visibility: hidden;
        transition: all var(--transition-slow);
    }

    .sidebar-overlay.visible {
        opacity: 1;
        visibility: visible;
    }
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    line-height: 1;
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Primary button */
.btn-primary {
    background: var(--gradient-accent);
    color: white;
    box-shadow: var(--shadow-sm), 0 0 0 0 var(--color-accent-glow);
}

.btn-primary:hover:not(:disabled) {
    box-shadow: var(--shadow-md), var(--shadow-glow);
    transform: translateY(-1px);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

/* Secondary button */
.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text-primary);
    border: 1px solid var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--color-surface-hover);
    border-color: var(--color-border-focus);
}

/* Ghost button */
.btn-ghost {
    background: transparent;
    color: var(--color-text-secondary);
}

.btn-ghost:hover:not(:disabled) {
    background: var(--color-surface-hover);
    color: var(--color-text-primary);
}

/* Button sizes */
.btn-sm {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-xs);
}

.btn-lg {
    padding: var(--space-4) var(--space-6);
    font-size: var(--text-base);
}

.btn-xl {
    padding: var(--space-5) var(--space-8);
    font-size: var(--text-lg);
}

/* Icon button */
.btn-icon {
    padding: var(--space-2);
    border-radius: var(--radius-md);
}

.btn-icon.btn-lg {
    padding: var(--space-3);
}

/* ============================================
   FORM ELEMENTS
   ============================================ */
.form-group {
    margin-bottom: var(--space-5);
}

.form-label {
    display: block;
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--color-text-primary);
    margin-bottom: var(--space-2);
}

.form-input,
.form-textarea,
.form-select {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    font-family: var(--font-sans);
    font-size: var(--text-base);
    color: var(--color-text-primary);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    transition: all var(--transition-fast);
}

.form-input::placeholder,
.form-textarea::placeholder {
    color: var(--color-text-muted);
}

.form-input:hover,
.form-textarea:hover,
.form-select:hover {
    border-color: var(--color-text-tertiary);
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
    outline: none;
    border-color: var(--color-accent-primary);
    box-shadow: 0 0 0 3px var(--color-accent-glow);
}

.form-textarea {
    min-height: 120px;
    resize: vertical;
}

/* Large input for search/research questions */
.form-input-lg {
    padding: var(--space-4) var(--space-5);
    font-size: var(--text-lg);
}

.form-textarea-lg {
    padding: var(--space-5);
    font-size: var(--text-lg);
    min-height: 160px;
}

/* ============================================
   CARDS
   ============================================ */
.card {
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    padding: var(--space-6);
    transition: all var(--transition-base);
}

.card-hover:hover {
    border-color: var(--color-border-focus);
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--color-border-subtle);
}

.card-title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    color: var(--color-text-primary);
}

.card-body {
    color: var(--color-text-secondary);
}

.card-footer {
    margin-top: var(--space-4);
    padding-top: var(--space-4);
    border-top: 1px solid var(--color-border-subtle);
}

/* Floating card effect */
.card-floating {
    background: var(--gradient-surface);
    backdrop-filter: blur(8px);
    border: 1px solid var(--color-border-subtle);
    box-shadow: var(--shadow-lg);
}

/* ============================================
   RESEARCH RESULT SECTIONS
   ============================================ */
.research-section {
    margin-bottom: var(--space-8);
}

.research-section-header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.research-section-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-accent-glow);
    color: var(--color-accent-primary);
    border-radius: var(--radius-md);
    font-size: var(--text-lg);
}

.research-section-title {
    font-size: var(--text-xl);
    font-weight: var(--font-semibold);
}

.research-section-content {
    padding-left: var(--space-10);
}

/* Source cards */
.source-card {
    display: flex;
    gap: var(--space-4);
    padding: var(--space-4);
    background: var(--color-surface);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-3);
    transition: all var(--transition-fast);
}

.source-card:hover {
    border-color: var(--color-accent-primary);
    box-shadow: var(--shadow-sm);
}

.source-card-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg-tertiary);
    border-radius: var(--radius-md);
    flex-shrink: 0;
}

.source-card-content {
    flex: 1;
    min-width: 0;
}

.source-card-title {
    font-weight: var(--font-semibold);
    color: var(--color-text-primary);
    margin-bottom: var(--space-1);
}

.source-card-meta {
    font-size: var(--text-sm);
    color: var(--color-text-tertiary);
    margin-bottom: var(--space-2);
}

.source-card-snippet {
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
    line-height: var(--leading-relaxed);
}

.source-card-link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--color-accent-primary);
    margin-top: var(--space-2);
}

/* ============================================
   LOADING STATES
   ============================================ */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--color-surface) 25%,
        var(--color-surface-hover) 50%,
        var(--color-surface) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-md);
}

@keyframes skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-text {
    height: 1em;
    margin-bottom: var(--space-2);
}

.skeleton-title {
    height: 1.5em;
    width: 60%;
    margin-bottom: var(--space-3);
}

.skeleton-card {
    height: 120px;
}

/* Spinner */
.spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--color-border);
    border-top-color: var(--color-accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner-lg {
    width: 48px;
    height: 48px;
    border-width: 3px;
}

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

/* Loading overlay */
.loading-overlay {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-4);
    padding: var(--space-12);
    text-align: center;
}

.loading-text {
    font-size: var(--text-lg);
    color: var(--color-text-secondary);
}

.loading-progress {
    width: 100%;
    max-width: 400px;
    height: 4px;
    background: var(--color-surface);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.loading-progress-bar {
    height: 100%;
    background: var(--gradient-accent);
    border-radius: var(--radius-full);
    transition: width var(--transition-slow);
    box-shadow: var(--shadow-glow);
}

/* ============================================
   EMPTY STATES
   ============================================ */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-16);
    text-align: center;
}

.empty-state-icon {
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-surface);
    border-radius: var(--radius-2xl);
    font-size: 2.5rem;
    margin-bottom: var(--space-6);
}

.empty-state-title {
    font-size: var(--text-xl);
    font-weight: var(--font-semibold);
    color: var(--color-text-primary);
    margin-bottom: var(--space-2);
}

.empty-state-description {
    font-size: var(--text-base);
    color: var(--color-text-secondary);
    max-width: 400px;
    margin-bottom: var(--space-6);
}

/* ============================================
   ERROR STATES
   ============================================ */
.error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-12);
    text-align: center;
    background: rgba(196, 92, 92, 0.05);
    border: 1px solid rgba(196, 92, 92, 0.2);
    border-radius: var(--radius-xl);
}

.error-state-icon {
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(196, 92, 92, 0.1);
    color: var(--color-error);
    border-radius: var(--radius-xl);
    font-size: 2rem;
    margin-bottom: var(--space-4);
}

.error-state-title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    color: var(--color-error);
    margin-bottom: var(--space-2);
}

.error-state-message {
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
    margin-bottom: var(--space-4);
}

/* ============================================
   TOASTS / NOTIFICATIONS
   ============================================ */
.toast-container {
    position: fixed;
    bottom: var(--space-6);
    right: var(--space-6);
    z-index: var(--z-tooltip);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    animation: toast-in 0.3s ease;
}

.toast-success {
    border-left: 4px solid var(--color-success);
}

.toast-error {
    border-left: 4px solid var(--color-error);
}

.toast-warning {
    border-left: 4px solid var(--color-warning);
}

.toast-info {
    border-left: 4px solid var(--color-info);
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ============================================
   MODAL
   ============================================ */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: var(--z-modal-backdrop);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    animation: fade-in 0.2s ease;
}

.modal {
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 560px;
    max-height: calc(100vh - var(--space-8));
    overflow: hidden;
    animation: modal-in 0.3s ease;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-5) var(--space-6);
    border-bottom: 1px solid var(--color-border);
}

.modal-title {
    font-size: var(--text-xl);
    font-weight: var(--font-semibold);
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--color-text-tertiary);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--color-surface-hover);
    color: var(--color-text-primary);
}

.modal-body {
    padding: var(--space-6);
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
    padding: var(--space-5) var(--space-6);
    border-top: 1px solid var(--color-border);
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modal-in {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* ============================================
   THEME TOGGLE
   ============================================ */
.theme-toggle {
    position: relative;
    width: 48px;
    height: 28px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

.theme-toggle-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    background: var(--color-accent-primary);
    border-radius: 50%;
    transition: transform var(--transition-base);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: white;
}

[data-theme="dark"] .theme-toggle-thumb {
    transform: translateX(20px);
}

/* ============================================
   USER MENU
   ============================================ */
.user-menu {
    position: relative;
}

.user-menu-trigger {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.user-menu-trigger:hover {
    background: var(--color-surface-hover);
    border-color: var(--color-border);
}

.user-avatar {
    width: 32px;
    height: 32px;
    background: var(--gradient-accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: var(--font-semibold);
    font-size: var(--text-sm);
}

.user-info {
    text-align: left;
}

.user-name {
    font-weight: var(--font-medium);
    font-size: var(--text-sm);
    color: var(--color-text-primary);
}

.user-tier {
    font-size: var(--text-xs);
    color: var(--color-text-tertiary);
}

.user-menu-dropdown {
    position: absolute;
    top: calc(100% + var(--space-2));
    right: 0;
    min-width: 200px;
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    z-index: var(--z-dropdown);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all var(--transition-fast);
}

.user-menu.open .user-menu-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.user-menu-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.user-menu-item:hover {
    background: var(--color-surface-hover);
    color: var(--color-text-primary);
}

.user-menu-item:first-child {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.user-menu-item:last-child {
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.user-menu-divider {
    height: 1px;
    background: var(--color-border);
    margin: var(--space-2) 0;
}

/* ============================================
   CREDITS / USAGE DISPLAY
   ============================================ */
.credits-display {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    font-size: var(--text-sm);
}

.credits-value {
    font-weight: var(--font-semibold);
    color: var(--color-accent-primary);
}

.credits-label {
    color: var(--color-text-tertiary);
}

/* ============================================
   BADGE / TAG
   ============================================ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: var(--space-1) var(--space-2);
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    border-radius: var(--radius-sm);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-primary {
    background: var(--color-accent-glow);
    color: var(--color-accent-primary);
}

.badge-success {
    background: rgba(74, 155, 127, 0.15);
    color: var(--color-success);
}

.badge-warning {
    background: rgba(196, 146, 58, 0.15);
    color: var(--color-warning);
}

.badge-error {
    background: rgba(196, 92, 92, 0.15);
    color: var(--color-error);
}

/* ============================================
   TABS
   ============================================ */
.tabs {
    display: flex;
    gap: var(--space-1);
    border-bottom: 1px solid var(--color-border);
    margin-bottom: var(--space-6);
}

.tab {
    padding: var(--space-3) var(--space-4);
    font-weight: var(--font-medium);
    color: var(--color-text-tertiary);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
    margin-bottom: -1px;
}

.tab:hover {
    color: var(--color-text-primary);
}

.tab.active {
    color: var(--color-accent-primary);
    border-bottom-color: var(--color-accent-primary);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ============================================
   ABSTRACT BACKGROUND EFFECTS
   ============================================ */
.bg-gradient-subtle {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: -1;
}

[data-theme="dark"] .bg-gradient-subtle::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(
        ellipse at 30% 20%,
        rgba(100, 181, 246, 0.08) 0%,
        transparent 50%
    ),
    radial-gradient(
        ellipse at 70% 80%,
        rgba(126, 87, 194, 0.06) 0%,
        transparent 50%
    );
}

/* Subtle noise texture */
.bg-noise {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: -1;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
}

/* ============================================
   RESPONSIVE UTILITIES
   ============================================ */
@media (max-width: 768px) {
    :root {
        --space-8: 1.5rem;
        --space-10: 2rem;
        --space-12: 2.5rem;
    }

    .main-content {
        padding: var(--space-4);
    }

    .card {
        padding: var(--space-4);
    }

    h1 { font-size: var(--text-3xl); }
    h2 { font-size: var(--text-2xl); }
    h3 { font-size: var(--text-xl); }
}

/* Hide on mobile */
@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
}

/* Hide on desktop */
@media (min-width: 769px) {
    .hide-desktop {
        display: none !important;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    .sidebar,
    .topbar,
    .btn,
    .theme-toggle {
        display: none !important;
    }

    .main-content {
        margin: 0;
        padding: 0;
    }

    body {
        background: white;
        color: black;
    }
}
