/* ============================================
   qwri Design System
   Linear-Inspired Multi-Theme System
   ============================================ */

/* ============================================
   Base Design Tokens (Shared Across Themes)
   ============================================ */

:root {
    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', Consolas, monospace;

    /* Type Scale */
    --text-xs: 0.6875rem;    /* 11px */
    --text-sm: 0.75rem;      /* 12px */
    --text-base: 0.875rem;   /* 14px */
    --text-md: 0.9375rem;    /* 15px */
    --text-lg: 1rem;         /* 16px */
    --text-xl: 1.125rem;     /* 18px */
    --text-2xl: 1.375rem;    /* 22px */
    --text-3xl: 1.75rem;     /* 28px */
    --text-4xl: 2.25rem;     /* 36px */
    --text-5xl: 3rem;        /* 48px */
    --text-6xl: 3.75rem;     /* 60px */

    /* Font Weights */
    --font-normal: 400;
    --font-medium: 500;
    --font-semibold: 600;
    --font-bold: 700;

    /* Line Heights */
    --leading-none: 1;
    --leading-tight: 1.2;
    --leading-snug: 1.3;
    --leading-normal: 1.5;
    --leading-relaxed: 1.6;

    /* Letter Spacing */
    --tracking-tight: -0.02em;
    --tracking-normal: 0;
    --tracking-wide: 0.02em;

    /* Spacing Scale (4px base) */
    --space-0: 0;
    --space-1: 0.25rem;      /* 4px */
    --space-2: 0.5rem;       /* 8px */
    --space-3: 0.75rem;      /* 12px */
    --space-4: 1rem;         /* 16px */
    --space-5: 1.25rem;      /* 20px */
    --space-6: 1.5rem;       /* 24px */
    --space-8: 2rem;         /* 32px */
    --space-10: 2.5rem;      /* 40px */
    --space-12: 3rem;        /* 48px */
    --space-16: 4rem;        /* 64px */
    --space-20: 5rem;        /* 80px */

    /* Border Radius */
    --radius-none: 0;
    --radius-xs: 2px;
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
    --radius-xl: 12px;
    --radius-2xl: 16px;
    --radius-full: 9999px;

    /* Animation Timing */
    --duration-instant: 50ms;
    --duration-fast: 100ms;
    --duration-normal: 150ms;
    --duration-slow: 250ms;
    --duration-slower: 350ms;
    --ease-out: cubic-bezier(0.25, 0.1, 0.25, 1);
    --ease-in: cubic-bezier(0.42, 0, 1, 1);
    --ease-in-out: cubic-bezier(0.42, 0, 0.58, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

    /* Legacy Transitions (for compatibility) */
    --transition-fast: 100ms var(--ease-out);
    --transition-base: 150ms var(--ease-out);
    --transition-slow: 250ms var(--ease-out);
}

/* ============================================
   Theme: Midnight (Default Dark)
   Deep navy/charcoal with indigo accents
   ============================================ */

[data-theme="midnight"], :root {
    /* Backgrounds */
    --bg-body: #0a0a0f;
    --bg-primary: #12121a;
    --bg-secondary: #1a1a24;
    --bg-tertiary: #22222e;
    --bg-elevated: #2a2a38;
    --bg-sunken: #08080c;

    /* Text */
    --text-primary: #f0f0f5;
    --text-secondary: #a0a0b0;
    --text-tertiary: #707085;
    --text-muted: #505065;
    --text-inverse: #0a0a0f;

    /* Borders */
    --border-light: #1f1f2e;
    --border-primary: #2a2a3d;
    --border-secondary: #3a3a50;
    --border-focus: #6366f1;

    /* Accent (Indigo) */
    --accent-primary: #6366f1;
    --accent-hover: #818cf8;
    --accent-subtle: rgba(99, 102, 241, 0.15);
    --accent-light: rgba(99, 102, 241, 0.25);
    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    --accent-gradient-hover: linear-gradient(135deg, #818cf8 0%, #6366f1 100%);

    /* Semantic Colors */
    --success: #10b981;
    --success-subtle: rgba(16, 185, 129, 0.15);
    --warning: #f59e0b;
    --warning-subtle: rgba(245, 158, 11, 0.15);
    --error: #ef4444;
    --error-subtle: rgba(239, 68, 68, 0.15);

    /* Shadows */
    --shadow-color: rgba(0, 0, 0, 0.5);
    --shadow-xs: 0 1px 2px var(--shadow-color);
    --shadow-sm: 0 2px 4px var(--shadow-color);
    --shadow-md: 0 4px 8px var(--shadow-color);
    --shadow-lg: 0 8px 16px var(--shadow-color);
    --shadow-xl: 0 12px 24px var(--shadow-color);
    --shadow-2xl: 0 20px 40px var(--shadow-color);
    --shadow-focus: 0 0 0 3px var(--accent-subtle);

    /* Chat Specific */
    --chat-user-bg: #6366f1;
    --chat-user-text: #ffffff;
    --chat-sophia-bg: #1a1a24;
    --chat-sophia-text: #f0f0f5;
    --chat-sophia-border: #2a2a3d;

    /* Thinking Indicator */
    --thinking-primary: #6366f1;
    --thinking-secondary: #a78bfa;

    /* Code Blocks */
    --code-bg: #08080c;
    --code-text: #e0e0ea;
    --code-border: #1f1f2e;

    /* Scrollbar */
    --scrollbar-thumb: #3a3a50;
    --scrollbar-thumb-hover: #505065;
}

/* ============================================
   Theme: Snow (Default Light)
   Clean whites with indigo accents
   ============================================ */

[data-theme="snow"] {
    /* Backgrounds */
    --bg-body: #fafafa;
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f7;
    --bg-tertiary: #ebebef;
    --bg-elevated: #ffffff;
    --bg-sunken: #f0f0f4;

    /* Text */
    --text-primary: #1a1a2e;
    --text-secondary: #4a4a5e;
    --text-tertiary: #6a6a7e;
    --text-muted: #9a9aae;
    --text-inverse: #ffffff;

    /* Borders */
    --border-light: #f0f0f4;
    --border-primary: #e5e5eb;
    --border-secondary: #d5d5de;
    --border-focus: #5855eb;

    /* Accent (Indigo) */
    --accent-primary: #5855eb;
    --accent-hover: #4f46e5;
    --accent-subtle: rgba(88, 85, 235, 0.08);
    --accent-light: rgba(88, 85, 235, 0.15);
    --accent-gradient: linear-gradient(135deg, #5855eb 0%, #4f46e5 100%);
    --accent-gradient-hover: linear-gradient(135deg, #4f46e5 0%, #4338ca 100%);

    /* Semantic Colors */
    --success: #059669;
    --success-subtle: rgba(5, 150, 105, 0.1);
    --warning: #d97706;
    --warning-subtle: rgba(217, 119, 6, 0.1);
    --error: #dc2626;
    --error-subtle: rgba(220, 38, 38, 0.1);

    /* Shadows */
    --shadow-color: rgba(0, 0, 0, 0.08);
    --shadow-xs: 0 1px 2px var(--shadow-color);
    --shadow-sm: 0 2px 4px var(--shadow-color);
    --shadow-md: 0 4px 8px var(--shadow-color);
    --shadow-lg: 0 8px 16px var(--shadow-color);
    --shadow-xl: 0 12px 24px var(--shadow-color);
    --shadow-2xl: 0 20px 40px var(--shadow-color);
    --shadow-focus: 0 0 0 3px var(--accent-subtle);

    /* Chat Specific */
    --chat-user-bg: #5855eb;
    --chat-user-text: #ffffff;
    --chat-sophia-bg: #f5f5f7;
    --chat-sophia-text: #1a1a2e;
    --chat-sophia-border: #e5e5eb;

    /* Thinking Indicator */
    --thinking-primary: #5855eb;
    --thinking-secondary: #818cf8;

    /* Code Blocks */
    --code-bg: #1a1a2e;
    --code-text: #e0e0ea;
    --code-border: #2a2a3d;

    /* Scrollbar */
    --scrollbar-thumb: #d5d5de;
    --scrollbar-thumb-hover: #c5c5ce;
}

/* ============================================
   Theme: Dusk (Warm Dark)
   Purple/plum undertones with amber accents
   ============================================ */

[data-theme="dusk"] {
    /* Backgrounds */
    --bg-body: #0f0a14;
    --bg-primary: #1a1320;
    --bg-secondary: #241a2e;
    --bg-tertiary: #2e2238;
    --bg-elevated: #382a44;
    --bg-sunken: #0a070e;

    /* Text */
    --text-primary: #f5f0fa;
    --text-secondary: #b8a8c8;
    --text-tertiary: #8878a0;
    --text-muted: #5a4a70;
    --text-inverse: #0f0a14;

    /* Borders */
    --border-light: #241a2e;
    --border-primary: #342840;
    --border-secondary: #443858;
    --border-focus: #f59e0b;

    /* Accent (Amber) */
    --accent-primary: #f59e0b;
    --accent-hover: #fbbf24;
    --accent-subtle: rgba(245, 158, 11, 0.15);
    --accent-light: rgba(245, 158, 11, 0.25);
    --accent-gradient: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    --accent-gradient-hover: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);

    /* Semantic Colors */
    --success: #10b981;
    --success-subtle: rgba(16, 185, 129, 0.15);
    --warning: #fbbf24;
    --warning-subtle: rgba(251, 191, 36, 0.15);
    --error: #f87171;
    --error-subtle: rgba(248, 113, 113, 0.15);

    /* Shadows */
    --shadow-color: rgba(0, 0, 0, 0.5);
    --shadow-xs: 0 1px 2px var(--shadow-color);
    --shadow-sm: 0 2px 4px var(--shadow-color);
    --shadow-md: 0 4px 8px var(--shadow-color);
    --shadow-lg: 0 8px 16px var(--shadow-color);
    --shadow-xl: 0 12px 24px var(--shadow-color);
    --shadow-2xl: 0 20px 40px var(--shadow-color);
    --shadow-focus: 0 0 0 3px var(--accent-subtle);

    /* Chat Specific */
    --chat-user-bg: #f59e0b;
    --chat-user-text: #1a1320;
    --chat-sophia-bg: #241a2e;
    --chat-sophia-text: #f5f0fa;
    --chat-sophia-border: #342840;

    /* Thinking Indicator */
    --thinking-primary: #f59e0b;
    --thinking-secondary: #c084fc;

    /* Code Blocks */
    --code-bg: #0a070e;
    --code-text: #e8d8f0;
    --code-border: #241a2e;

    /* Scrollbar */
    --scrollbar-thumb: #443858;
    --scrollbar-thumb-hover: #5a4a70;
}

/* ============================================
   Theme: Aurora (Teal Dark)
   Dark theme with teal/emerald accents
   ============================================ */

[data-theme="aurora"] {
    /* Backgrounds */
    --bg-body: #080c0f;
    --bg-primary: #0f1418;
    --bg-secondary: #151c22;
    --bg-tertiary: #1c252e;
    --bg-elevated: #232e38;
    --bg-sunken: #060a0d;

    /* Text */
    --text-primary: #e8f4f0;
    --text-secondary: #98b8b0;
    --text-tertiary: #688880;
    --text-muted: #486860;
    --text-inverse: #080c0f;

    /* Borders */
    --border-light: #151c22;
    --border-primary: #1e2830;
    --border-secondary: #283540;
    --border-focus: #14b8a6;

    /* Accent (Teal) */
    --accent-primary: #14b8a6;
    --accent-hover: #2dd4bf;
    --accent-subtle: rgba(20, 184, 166, 0.15);
    --accent-light: rgba(20, 184, 166, 0.25);
    --accent-gradient: linear-gradient(135deg, #14b8a6 0%, #0d9488 100%);
    --accent-gradient-hover: linear-gradient(135deg, #2dd4bf 0%, #14b8a6 100%);

    /* Semantic Colors */
    --success: #2dd4bf;
    --success-subtle: rgba(45, 212, 191, 0.15);
    --warning: #fbbf24;
    --warning-subtle: rgba(251, 191, 36, 0.15);
    --error: #f87171;
    --error-subtle: rgba(248, 113, 113, 0.15);

    /* Shadows */
    --shadow-color: rgba(0, 0, 0, 0.5);
    --shadow-xs: 0 1px 2px var(--shadow-color);
    --shadow-sm: 0 2px 4px var(--shadow-color);
    --shadow-md: 0 4px 8px var(--shadow-color);
    --shadow-lg: 0 8px 16px var(--shadow-color);
    --shadow-xl: 0 12px 24px var(--shadow-color);
    --shadow-2xl: 0 20px 40px var(--shadow-color);
    --shadow-focus: 0 0 0 3px var(--accent-subtle);

    /* Chat Specific */
    --chat-user-bg: #14b8a6;
    --chat-user-text: #ffffff;
    --chat-sophia-bg: #151c22;
    --chat-sophia-text: #e8f4f0;
    --chat-sophia-border: #1e2830;

    /* Thinking Indicator */
    --thinking-primary: #14b8a6;
    --thinking-secondary: #34d399;

    /* Code Blocks */
    --code-bg: #060a0d;
    --code-text: #d0e8e0;
    --code-border: #151c22;

    /* Scrollbar */
    --scrollbar-thumb: #283540;
    --scrollbar-thumb-hover: #384858;
}

/* ============================================
   Theme: Sandstone (Warm Light)
   Cream/tan with earthy brown accents
   ============================================ */

[data-theme="sandstone"] {
    /* Backgrounds */
    --bg-body: #faf8f5;
    --bg-primary: #fffcf8;
    --bg-secondary: #f5f2ed;
    --bg-tertiary: #ebe8e2;
    --bg-elevated: #fffcf8;
    --bg-sunken: #f0ede7;

    /* Text */
    --text-primary: #2a2520;
    --text-secondary: #5a5248;
    --text-tertiary: #7a7268;
    --text-muted: #a8a090;
    --text-inverse: #fffcf8;

    /* Borders */
    --border-light: #f0ede7;
    --border-primary: #e0dcd5;
    --border-secondary: #d0ccc5;
    --border-focus: #92400e;

    /* Accent (Brown) */
    --accent-primary: #92400e;
    --accent-hover: #a3510f;
    --accent-subtle: rgba(146, 64, 14, 0.08);
    --accent-light: rgba(146, 64, 14, 0.15);
    --accent-gradient: linear-gradient(135deg, #92400e 0%, #78350f 100%);
    --accent-gradient-hover: linear-gradient(135deg, #a3510f 0%, #92400e 100%);

    /* Semantic Colors */
    --success: #059669;
    --success-subtle: rgba(5, 150, 105, 0.1);
    --warning: #b45309;
    --warning-subtle: rgba(180, 83, 9, 0.1);
    --error: #b91c1c;
    --error-subtle: rgba(185, 28, 28, 0.1);

    /* Shadows */
    --shadow-color: rgba(42, 37, 32, 0.1);
    --shadow-xs: 0 1px 2px var(--shadow-color);
    --shadow-sm: 0 2px 4px var(--shadow-color);
    --shadow-md: 0 4px 8px var(--shadow-color);
    --shadow-lg: 0 8px 16px var(--shadow-color);
    --shadow-xl: 0 12px 24px var(--shadow-color);
    --shadow-2xl: 0 20px 40px var(--shadow-color);
    --shadow-focus: 0 0 0 3px var(--accent-subtle);

    /* Chat Specific */
    --chat-user-bg: #92400e;
    --chat-user-text: #ffffff;
    --chat-sophia-bg: #f5f2ed;
    --chat-sophia-text: #2a2520;
    --chat-sophia-border: #e0dcd5;

    /* Thinking Indicator */
    --thinking-primary: #92400e;
    --thinking-secondary: #d97706;

    /* Code Blocks */
    --code-bg: #2a2520;
    --code-text: #f0ede7;
    --code-border: #3a3530;

    /* Scrollbar */
    --scrollbar-thumb: #d0ccc5;
    --scrollbar-thumb-hover: #c0bcb5;
}

/* ============================================
   System Preference Fallback (Midnight for dark, Snow for light)
   ============================================ */

@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        /* Midnight theme as default dark */
        --bg-body: #0a0a0f;
        --bg-primary: #12121a;
        --bg-secondary: #1a1a24;
        --bg-tertiary: #22222e;
        --bg-elevated: #2a2a38;
        --bg-sunken: #08080c;
        --text-primary: #f0f0f5;
        --text-secondary: #a0a0b0;
        --text-tertiary: #707085;
        --text-muted: #505065;
        --text-inverse: #0a0a0f;
        --border-light: #1f1f2e;
        --border-primary: #2a2a3d;
        --border-secondary: #3a3a50;
        --border-focus: #6366f1;
        --accent-primary: #6366f1;
        --accent-hover: #818cf8;
        --accent-subtle: rgba(99, 102, 241, 0.15);
        --accent-light: rgba(99, 102, 241, 0.25);
        --accent-gradient: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
        --accent-gradient-hover: linear-gradient(135deg, #818cf8 0%, #6366f1 100%);
        --success: #10b981;
        --success-subtle: rgba(16, 185, 129, 0.15);
        --warning: #f59e0b;
        --warning-subtle: rgba(245, 158, 11, 0.15);
        --error: #ef4444;
        --error-subtle: rgba(239, 68, 68, 0.15);
        --shadow-color: rgba(0, 0, 0, 0.5);
        --chat-user-bg: #6366f1;
        --chat-user-text: #ffffff;
        --chat-sophia-bg: #1a1a24;
        --chat-sophia-text: #f0f0f5;
        --chat-sophia-border: #2a2a3d;
        --thinking-primary: #6366f1;
        --thinking-secondary: #a78bfa;
        --code-bg: #08080c;
        --code-text: #e0e0ea;
        --code-border: #1f1f2e;
        --scrollbar-thumb: #3a3a50;
        --scrollbar-thumb-hover: #505065;
    }
}

@media (prefers-color-scheme: light) {
    :root:not([data-theme]) {
        /* Snow theme as default light */
        --bg-body: #fafafa;
        --bg-primary: #ffffff;
        --bg-secondary: #f5f5f7;
        --bg-tertiary: #ebebef;
        --bg-elevated: #ffffff;
        --bg-sunken: #f0f0f4;
        --text-primary: #1a1a2e;
        --text-secondary: #4a4a5e;
        --text-tertiary: #6a6a7e;
        --text-muted: #9a9aae;
        --text-inverse: #ffffff;
        --border-light: #f0f0f4;
        --border-primary: #e5e5eb;
        --border-secondary: #d5d5de;
        --border-focus: #5855eb;
        --accent-primary: #5855eb;
        --accent-hover: #4f46e5;
        --accent-subtle: rgba(88, 85, 235, 0.08);
        --accent-light: rgba(88, 85, 235, 0.15);
        --accent-gradient: linear-gradient(135deg, #5855eb 0%, #4f46e5 100%);
        --accent-gradient-hover: linear-gradient(135deg, #4f46e5 0%, #4338ca 100%);
        --success: #059669;
        --success-subtle: rgba(5, 150, 105, 0.1);
        --warning: #d97706;
        --warning-subtle: rgba(217, 119, 6, 0.1);
        --error: #dc2626;
        --error-subtle: rgba(220, 38, 38, 0.1);
        --shadow-color: rgba(0, 0, 0, 0.08);
        --chat-user-bg: #5855eb;
        --chat-user-text: #ffffff;
        --chat-sophia-bg: #f5f5f7;
        --chat-sophia-text: #1a1a2e;
        --chat-sophia-border: #e5e5eb;
        --thinking-primary: #5855eb;
        --thinking-secondary: #818cf8;
        --code-bg: #1a1a2e;
        --code-text: #e0e0ea;
        --code-border: #2a2a3d;
        --scrollbar-thumb: #d5d5de;
        --scrollbar-thumb-hover: #c5c5ce;
    }
}

/* ============================================
   Theme Transition
   Smooth color transitions when switching themes
   ============================================ */

html {
    transition: background-color var(--duration-slow) var(--ease-out),
                color var(--duration-slow) var(--ease-out);
}

html.theme-transitioning,
html.theme-transitioning *,
html.theme-transitioning *::before,
html.theme-transitioning *::after {
    transition: background-color var(--duration-slow) var(--ease-out),
                color var(--duration-slow) var(--ease-out),
                border-color var(--duration-slow) var(--ease-out),
                box-shadow var(--duration-slow) var(--ease-out) !important;
}

/* ============================================
   Base Reset & Styles
   ============================================ */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body {
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    color: var(--text-primary);
    background-color: var(--bg-body);
}

/* ============================================
   Typography
   ============================================ */

h1, h2, h3, h4, h5, h6 {
    font-weight: var(--font-semibold);
    line-height: var(--leading-tight);
    color: var(--text-primary);
    letter-spacing: var(--tracking-tight);
}

h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
h5 { font-size: var(--text-md); }
h6 { font-size: var(--text-base); }

p {
    line-height: var(--leading-relaxed);
}

a {
    color: var(--accent-primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--accent-hover);
}

strong, b {
    font-weight: var(--font-semibold);
}

small {
    font-size: var(--text-sm);
}

/* ============================================
   Form Elements
   ============================================ */

input, textarea, select, button {
    font-family: inherit;
    font-size: inherit;
}

.form-control,
.form-input {
    width: 100%;
    height: 36px;
    padding: 0 var(--space-3);
    font-size: var(--text-base);
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-control:focus,
.form-input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: var(--shadow-focus);
}

.form-control::placeholder,
.form-input::placeholder {
    color: var(--text-muted);
}

textarea.form-control,
textarea.form-input {
    height: auto;
    min-height: 80px;
    padding: var(--space-3);
    resize: vertical;
}

select.form-control,
select.form-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right var(--space-2) center;
    background-repeat: no-repeat;
    background-size: 1.25em 1.25em;
    padding-right: var(--space-8);
}

.form-check-input:focus {
    border-color: var(--border-focus);
    box-shadow: var(--shadow-focus);
    outline: none;
}

.valid.modified:not([type=checkbox]) {
    border-color: var(--success);
}

.invalid {
    border-color: var(--error);
}

.validation-message {
    color: var(--error);
    font-size: var(--text-xs);
    margin-top: var(--space-1);
}

/* Form Groups */
.form-group {
    margin-bottom: var(--space-4);
}

.form-group label {
    display: block;
    font-weight: var(--font-medium);
    color: var(--text-primary);
    margin-bottom: var(--space-2);
    font-size: var(--text-sm);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    cursor: pointer;
    color: var(--text-primary);
    font-size: var(--text-sm);
}

.checkbox-label input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    cursor: pointer;
    accent-color: var(--accent-primary);
}

/* ============================================
   Button System
   ============================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    height: 32px;
    padding: 0 var(--space-4);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    line-height: 1;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
}

.btn-primary {
    background: var(--accent-primary);
    color: #ffffff;
    border-color: transparent;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-primary:active:not(:disabled) {
    transform: scale(0.98);
}

.btn-secondary {
    background: var(--bg-primary);
    color: var(--text-primary);
    border-color: var(--border-primary);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-tertiary);
    border-color: var(--border-secondary);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: transparent;
}

.btn-ghost:hover:not(:disabled) {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-danger {
    background: var(--error);
    color: #ffffff;
    border-color: transparent;
}

.btn-danger:hover:not(:disabled) {
    background: var(--error);
    opacity: 0.9;
}

.btn-sm {
    height: 28px;
    padding: 0 var(--space-3);
    font-size: var(--text-xs);
}

.btn-lg {
    height: 40px;
    padding: 0 var(--space-6);
    font-size: var(--text-base);
}

/* Icon Button */
.btn-icon {
    width: 32px;
    padding: 0;
}

.btn-icon.btn-sm {
    width: 28px;
}

/* ============================================
   Card System
   ============================================ */

.card {
    background: var(--bg-primary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
}

.card-elevated {
    box-shadow: var(--shadow-md);
}

.card-header {
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-light);
}

.card-body {
    padding: var(--space-4);
}

.card-footer {
    padding: var(--space-4);
    border-top: 1px solid var(--border-light);
}

/* ============================================
   Badge System
   ============================================ */

.badge {
    display: inline-flex;
    align-items: center;
    height: 20px;
    padding: 0 var(--space-2);
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
    border-radius: var(--radius-full);
    white-space: nowrap;
}

.badge-default {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.badge-primary {
    background: var(--accent-subtle);
    color: var(--accent-primary);
}

.badge-success {
    background: var(--success-subtle);
    color: var(--success);
}

.badge-warning {
    background: var(--warning-subtle);
    color: var(--warning);
}

.badge-error {
    background: var(--error-subtle);
    color: var(--error);
}

/* ============================================
   Table System
   ============================================ */

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th {
    padding: var(--space-3) var(--space-4);
    text-align: left;
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
    border-bottom: 1px solid var(--border-primary);
    background: var(--bg-secondary);
}

.table td {
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-base);
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}

.table tbody tr {
    transition: background-color var(--transition-fast);
}

.table tbody tr:hover {
    background: var(--bg-secondary);
}

.table tbody tr:last-child td {
    border-bottom: none;
}

/* ============================================
   Modal System
   ============================================ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: var(--space-4);
    animation: fadeIn var(--duration-normal) var(--ease-out);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal {
    background: var(--bg-elevated);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 480px;
    max-height: calc(100vh - var(--space-8));
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--border-light);
    animation: slideUp var(--duration-slow) var(--ease-spring);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(16px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal.modal-small {
    max-width: 400px;
}

.modal.modal-large {
    max-width: 640px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border-light);
}

.modal-header h3 {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
}

.modal-body {
    padding: var(--space-5);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--border-light);
    background: var(--bg-secondary);
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

.modal .close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--text-muted);
    transition: all var(--transition-fast);
}

.modal .close-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* ============================================
   Alert/Banner System
   ============================================ */

.alert {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-lg);
    font-size: var(--text-sm);
    margin-bottom: var(--space-4);
}

.alert-success {
    background: var(--success-subtle);
    color: var(--success);
    border: 1px solid currentColor;
}

.alert-warning {
    background: var(--warning-subtle);
    color: var(--warning);
    border: 1px solid currentColor;
}

.alert-error {
    background: var(--error-subtle);
    color: var(--error);
    border: 1px solid currentColor;
}

.alert-info {
    background: var(--accent-subtle);
    color: var(--accent-primary);
    border: 1px solid currentColor;
}

/* ============================================
   Empty State
   ============================================ */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-12);
    text-align: center;
}

.empty-state-icon {
    width: 48px;
    height: 48px;
    margin-bottom: var(--space-4);
    color: var(--text-muted);
}

.empty-state-title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

.empty-state-description {
    font-size: var(--text-base);
    color: var(--text-tertiary);
    max-width: 320px;
}

/* ============================================
   Scrollbar Styling
   ============================================ */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) transparent;
}

/* ============================================
   Selection Color
   ============================================ */

::selection {
    background: var(--accent-light);
    color: var(--text-primary);
}

/* ============================================
   Focus Visible (Keyboard Navigation)
   ============================================ */

:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* Remove outline for mouse users */
:focus:not(:focus-visible) {
    outline: none;
}

/* ============================================
   Error Boundary
   ============================================ */

.blazor-error-boundary {
    background: var(--error);
    padding: var(--space-4);
    color: white;
    border-radius: var(--radius-lg);
    margin: var(--space-4);
}

.blazor-error-boundary::after {
    content: "An error has occurred. Please refresh the page.";
}

/* ============================================
   WASM Loading Screen
   ============================================ */

.loading-screen {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background: var(--bg-body, #0a0a0f);
}

.loading-content {
    text-align: center;
    color: var(--text-primary, #f0f0f5);
}

.loading-icon {
    font-size: 3rem;
    font-weight: var(--font-bold);
    margin-bottom: var(--space-4);
    color: var(--accent-primary, #6366f1);
}

.loading-logo {
    width: 240px;
    height: auto;
    margin-bottom: var(--space-4);
}

.loading-text {
    font-size: var(--text-lg);
    margin-bottom: var(--space-6);
    color: var(--text-secondary, #a0a0b0);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-primary, #2a2a3d);
    border-top-color: var(--accent-primary, #6366f1);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Blazor Error UI */
#blazor-error-ui {
    background: var(--error);
    color: white;
    bottom: 0;
    box-shadow: 0 -1px 4px rgba(0, 0, 0, 0.15);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: var(--space-3) var(--space-5);
    position: fixed;
    width: 100%;
    z-index: 1000;
    font-size: var(--text-sm);
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: var(--space-4);
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.8;
    transition: opacity var(--transition-fast);
}

#blazor-error-ui .dismiss:hover {
    opacity: 1;
}

#blazor-error-ui .reload {
    color: white;
    text-decoration: underline;
    margin-left: var(--space-2);
}

/* ============================================
   Utility Classes
   ============================================ */

.content {
    padding-top: var(--space-4);
}

h1:focus {
    outline: none;
}

/* Screen Reader Only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Text Utilities */
.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-error { color: var(--error); }

/* Background Utilities */
.bg-body { background-color: var(--bg-body); }
.bg-primary { background-color: var(--bg-primary); }
.bg-secondary { background-color: var(--bg-secondary); }
.bg-tertiary { background-color: var(--bg-tertiary); }

/* Flex Utilities */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }

/* Spacing Utilities */
.p-0 { padding: 0; }
.p-1 { padding: var(--space-1); }
.p-2 { padding: var(--space-2); }
.p-3 { padding: var(--space-3); }
.p-4 { padding: var(--space-4); }
.m-0 { margin: 0; }
.mt-4 { margin-top: var(--space-4); }
.mb-4 { margin-bottom: var(--space-4); }

/* Width Utilities */
.w-full { width: 100%; }

/* ============================================
   Micro-Interactions & Animation Utilities
   ============================================ */

/* Hover Lift Effect */
.hover-lift {
    transition: transform var(--duration-fast) var(--ease-out),
                box-shadow var(--duration-fast) var(--ease-out);
}

.hover-lift:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.hover-lift:active {
    transform: translateY(0);
    box-shadow: var(--shadow-sm);
}

/* Hover Scale Effect */
.hover-scale {
    transition: transform var(--duration-fast) var(--ease-spring);
}

.hover-scale:hover {
    transform: scale(1.02);
}

.hover-scale:active {
    transform: scale(0.98);
}

/* Press Effect - subtle depression on click */
.press-effect {
    transition: transform var(--duration-instant) var(--ease-out);
}

.press-effect:active {
    transform: scale(0.97);
}

/* Glow Effect on Focus */
.focus-glow:focus {
    box-shadow: 0 0 0 3px var(--accent-subtle),
                0 0 16px var(--accent-subtle);
}

/* Pulse Animation */
.pulse {
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.6;
    }
}

/* Shimmer Loading Effect */
.shimmer {
    background: linear-gradient(
        90deg,
        var(--bg-secondary) 0%,
        var(--bg-tertiary) 50%,
        var(--bg-secondary) 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s linear infinite;
}

@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* Skeleton Loading */
.skeleton {
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    animation: skeletonPulse 1.5s ease-in-out infinite;
}

.skeleton-text {
    height: 1em;
    margin-bottom: var(--space-2);
}

.skeleton-circle {
    border-radius: var(--radius-full);
}

@keyframes skeletonPulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* Staggered Fade In Animation (for lists) */
.fade-in-stagger > * {
    opacity: 0;
    animation: fadeInUp var(--duration-normal) var(--ease-out) forwards;
}

.fade-in-stagger > *:nth-child(1) { animation-delay: 0ms; }
.fade-in-stagger > *:nth-child(2) { animation-delay: 50ms; }
.fade-in-stagger > *:nth-child(3) { animation-delay: 100ms; }
.fade-in-stagger > *:nth-child(4) { animation-delay: 150ms; }
.fade-in-stagger > *:nth-child(5) { animation-delay: 200ms; }
.fade-in-stagger > *:nth-child(6) { animation-delay: 250ms; }
.fade-in-stagger > *:nth-child(7) { animation-delay: 300ms; }
.fade-in-stagger > *:nth-child(8) { animation-delay: 350ms; }
.fade-in-stagger > *:nth-child(n+9) { animation-delay: 400ms; }

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Slide Animations */
.slide-in-right {
    animation: slideInRight var(--duration-normal) var(--ease-out);
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(16px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.slide-in-left {
    animation: slideInLeft var(--duration-normal) var(--ease-out);
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-16px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.slide-in-up {
    animation: slideInUp var(--duration-normal) var(--ease-out);
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.slide-in-down {
    animation: slideInDown var(--duration-normal) var(--ease-out);
}

@keyframes slideInDown {
    from {
        opacity: 0;
        transform: translateY(-16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Scale In Animation */
.scale-in {
    animation: scaleIn var(--duration-normal) var(--ease-spring);
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Bounce Animation */
.bounce {
    animation: bounce 0.5s var(--ease-spring);
}

@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-8px);
    }
    60% {
        transform: translateY(-4px);
    }
}

/* Shake Animation (for errors) */
.shake {
    animation: shake 0.5s var(--ease-out);
}

@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translateX(-4px);
    }
    20%, 40%, 60%, 80% {
        transform: translateX(4px);
    }
}

/* Success Checkmark Animation */
.success-check {
    animation: successCheck 0.4s var(--ease-spring);
}

@keyframes successCheck {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Ripple Effect (for buttons) */
.ripple {
    position: relative;
    overflow: hidden;
}

.ripple::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.3) 0%, transparent 70%);
    opacity: 0;
    transform: scale(0);
    transition: opacity var(--duration-fast) var(--ease-out),
                transform var(--duration-slow) var(--ease-out);
}

.ripple:active::after {
    opacity: 1;
    transform: scale(2);
    transition: transform 0s;
}

/* Tooltip Styles */
.tooltip {
    position: relative;
}

.tooltip::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    padding: var(--space-1) var(--space-2);
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-size: var(--text-xs);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--duration-fast) var(--ease-out),
                transform var(--duration-fast) var(--ease-out),
                visibility var(--duration-fast);
    z-index: 1000;
    pointer-events: none;
}

.tooltip::after {
    content: '';
    position: absolute;
    bottom: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%);
    border: 4px solid transparent;
    border-top-color: var(--bg-elevated);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--duration-fast) var(--ease-out),
                visibility var(--duration-fast);
    z-index: 1000;
}

.tooltip:hover::before {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.tooltip:hover::after {
    opacity: 1;
    visibility: visible;
}

/* Progress Bar Animation */
.progress-bar {
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--accent-primary);
    border-radius: var(--radius-full);
    transition: width var(--duration-slow) var(--ease-out);
}

.progress-bar-indeterminate .progress-bar-fill {
    width: 40%;
    animation: progressIndeterminate 1.5s ease-in-out infinite;
}

@keyframes progressIndeterminate {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(350%);
    }
}

/* Floating Label Input */
.floating-label {
    position: relative;
}

.floating-label input {
    padding-top: var(--space-4);
}

.floating-label label {
    position: absolute;
    left: var(--space-3);
    top: 50%;
    transform: translateY(-50%);
    font-size: var(--text-base);
    color: var(--text-muted);
    pointer-events: none;
    transition: all var(--duration-fast) var(--ease-out);
}

.floating-label input:focus + label,
.floating-label input:not(:placeholder-shown) + label {
    top: var(--space-2);
    font-size: var(--text-xs);
    color: var(--accent-primary);
}

/* Notification Badge */
.notification-badge {
    position: relative;
}

.notification-badge::after {
    content: attr(data-count);
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    background: var(--error);
    color: white;
    font-size: 10px;
    font-weight: var(--font-bold);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: badgePop 0.3s var(--ease-spring);
}

@keyframes badgePop {
    0% {
        transform: scale(0);
    }
    70% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
    }
}

/* Status Dot Animation */
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    flex-shrink: 0;
}

.status-dot.online {
    background: var(--success);
    animation: statusPulse 2s ease-in-out infinite;
}

.status-dot.offline {
    background: var(--text-muted);
}

.status-dot.busy {
    background: var(--warning);
}

@keyframes statusPulse {
    0%, 100% {
        box-shadow: 0 0 0 0 var(--success-subtle);
    }
    50% {
        box-shadow: 0 0 0 4px var(--success-subtle);
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .pulse,
    .shimmer,
    .skeleton {
        animation: none;
    }
}

/* ============================================
   Dashboard Widget Overrides
   Global rules to beat Bootstrap specificity
   ============================================ */

/* SophiaWidget: no borders when inside a dashboard card */
.widget-card .sophia-widget {
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
}

/* Widget header: clean, borderless */
.widget-card .sophia-widget .widget-header {
    border: none !important;
    border-bottom: none !important;
}

/* Widget refresh button: ghost style */
.widget-card .sophia-widget .widget-refresh-btn {
    border: none !important;
    background: transparent;
    color: var(--text-tertiary);
}

.widget-card .sophia-widget .widget-refresh-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Markdown table fallback inside widgets — Bootstrap overrides */
.widget-card .widget-content table,
.widget-card .widget-content thead,
.widget-card .widget-content tbody,
.widget-card .widget-content tr,
.widget-card .widget-content td,
.widget-card .widget-content th {
    border-color: transparent !important;
    border-style: none !important;
    border-width: 0 !important;
    box-shadow: none !important;
}

.widget-card .widget-content table th {
    background: var(--bg-tertiary) !important;
    color: var(--text-tertiary) !important;
    border-bottom: 2px solid var(--border-primary) !important;
    border-style: solid !important;
}

.widget-card .widget-content table td {
    color: var(--text-primary) !important;
    border-bottom: 1px solid var(--border-light) !important;
    border-style: solid !important;
}

.widget-card .widget-content table tbody tr:nth-child(even) td {
    background: var(--bg-secondary) !important;
}
