/**
 * Theme Variables - Centralized Design Tokens
 * Unified CSS variable system for consistent theming across the application
 */

/* Anti-FOUC - Prevent flash of unstyled content */
html:not(.theme-loaded) {
    visibility: hidden;
}

html.theme-loaded {
    visibility: visible;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ============================================
   LIGHT MODE (Default)
   ============================================ */
:root,
[data-theme="light"] {
    /* Primary Colors */
    --theme-primary: #4f46e5;
    --theme-primary-hover: #4338ca;
    --theme-primary-light: #e0e7ff;
    --theme-primary-dark: #3730a3;
    
    /* Secondary Colors */
    --theme-secondary: #10b981;
    --theme-secondary-hover: #059669;
    --theme-secondary-light: #d1fae5;
    
    /* Background Colors */
    --theme-bg-primary: #ffffff;
    --theme-bg-secondary: #f7f9fc;
    --theme-bg-tertiary: #f0f4f8;
    --theme-bg-card: #ffffff;
    --theme-bg-hover: #f5f7fa;
    --theme-bg-active: #eef1f5;
    --theme-bg-input: #ffffff;
    --theme-bg-modal: #ffffff;
    --theme-bg-overlay: rgba(0, 0, 0, 0.5);
    
    /* Text Colors */
    --theme-text-primary: #0f172a;
    --theme-text-secondary: #475569;
    --theme-text-tertiary: #94a3b8;
    --theme-text-muted: #64748b;
    --theme-text-inverse: #ffffff;
    
    /* Border Colors */
    --theme-border-primary: #e2e8f0;
    --theme-border-secondary: #cbd5e1;
    --theme-border-tertiary: #f1f5f9;
    --theme-border-focus: var(--theme-primary);
    --theme-border-error: #ef4444;
    --theme-border-success: #10b981;
    --theme-border-warning: #f59e0b;
    
    /* Semantic Colors */
    --theme-success: #10b981;
    --theme-success-light: #d1fae5;
    --theme-success-dark: #059669;
    
    --theme-warning: #f59e0b;
    --theme-warning-light: #fef3c7;
    --theme-warning-dark: #d97706;
    
    --theme-error: #ef4444;
    --theme-error-light: #fee2e2;
    --theme-error-dark: #dc2626;
    
    --theme-info: #3b82f6;
    --theme-info-light: #dbeafe;
    --theme-info-dark: #2563eb;
    
    /* Shadows */
    --theme-shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --theme-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --theme-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --theme-shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --theme-shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    
    /* Glassmorphism */
    --theme-glass-bg: rgba(255, 255, 255, 0.8);
    --theme-glass-border: rgba(255, 255, 255, 0.5);
    --theme-glass-blur: blur(20px);
    
    /* Unified Glass Header System */
    --theme-header-glass-bg: rgba(255, 255, 255, 0.75);
    --theme-header-glass-bg-scrolled: rgba(255, 255, 255, 0.88);
    --theme-header-glass-border: rgba(255, 255, 255, 0.5);
    --theme-header-glass-border-accent: rgba(79, 70, 229, 0.12);
    --theme-header-glass-blur: blur(20px) saturate(180%);
    --theme-header-glass-blur-scrolled: blur(24px) saturate(200%);
    --theme-header-shadow: 
        0 1px 0 rgba(255, 255, 255, 0.6) inset,
        0 4px 24px rgba(79, 70, 229, 0.07),
        0 1px 3px rgba(0, 0, 0, 0.04);
    --theme-header-shadow-scrolled:
        0 1px 0 rgba(255, 255, 255, 0.8) inset,
        0 8px 32px rgba(79, 70, 229, 0.11),
        0 2px 6px rgba(0, 0, 0, 0.06);
    --theme-header-height: 60px;
    --theme-header-z-index: 1000;
    
    /* Spacing */
    --theme-space-1: 0.25rem;
    --theme-space-2: 0.5rem;
    --theme-space-3: 0.75rem;
    --theme-space-4: 1rem;
    --theme-space-5: 1.25rem;
    --theme-space-6: 1.5rem;
    --theme-space-8: 2rem;
    --theme-space-10: 2.5rem;
    --theme-space-12: 3rem;
    
    /* Border Radius */
    --theme-radius-sm: 0.375rem;
    --theme-radius-md: 0.5rem;
    --theme-radius-lg: 0.75rem;
    --theme-radius-xl: 1rem;
    --theme-radius-2xl: 1.5rem;
    --theme-radius-full: 9999px;
    
    /* Typography */
    --theme-font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    --theme-font-mono: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', 'Source Code Pro', monospace;
    
    --theme-text-xs: 0.75rem;
    --theme-text-sm: 0.875rem;
    --theme-text-base: 1rem;
    --theme-text-lg: 1.125rem;
    --theme-text-xl: 1.25rem;
    --theme-text-2xl: 1.5rem;
    --theme-text-3xl: 1.875rem;
    --theme-text-4xl: 2.25rem;
    --theme-text-5xl: 3rem;
    
    --theme-font-light: 300;
    --theme-font-normal: 400;
    --theme-font-medium: 500;
    --theme-font-semibold: 600;
    --theme-font-bold: 700;
    
    /* Transitions */
    --theme-transition-fast: 150ms ease;
    --theme-transition-base: 200ms ease;
    --theme-transition-slow: 300ms ease;
    --theme-transition-slower: 500ms ease;
    
    /* Z-Index */
    --theme-z-dropdown: 1000;
    --theme-z-sticky: 1020;
    --theme-z-fixed: 1030;
    --theme-z-modal-backdrop: 1040;
    --theme-z-modal: 1050;
    --theme-z-popover: 1060;
    --theme-z-tooltip: 1070;
    
    /* Sidebar */
    --theme-sidebar-width-expanded: 280px;
    --theme-sidebar-width-collapsed: 72px;
    --theme-sidebar-transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --theme-sidebar-bg: #ffffff;
    --theme-sidebar-border-color: #e5e7eb;
    --theme-sidebar-hover-bg: #f3f4f6;
    --theme-sidebar-text-color: #374151;
    --theme-sidebar-text-muted: #6b7280;
    --theme-sidebar-active-bg: #f3f4f6;
}

/* ============================================
   DARK MODE
   ============================================ */
[data-theme="dark"] {
    /* Primary Colors */
    --theme-primary: #6366f1;
    --theme-primary-hover: #818cf8;
    --theme-primary-light: #312e81;
    --theme-primary-dark: #4338ca;
    
    /* Secondary Colors */
    --theme-secondary: #10b981;
    --theme-secondary-hover: #34d399;
    --theme-secondary-light: #065f46;
    
    /* Background Colors */
    --theme-bg-primary: #0f172a;
    --theme-bg-secondary: #1e293b;
    --theme-bg-tertiary: #334155;
    --theme-bg-card: #1e293b;
    --theme-bg-hover: #334155;
    --theme-bg-active: #475569;
    --theme-bg-input: #1e293b;
    --theme-bg-modal: #1e293b;
    --theme-bg-overlay: rgba(0, 0, 0, 0.7);
    
    /* Text Colors */
    --theme-text-primary: #f8fafc;
    --theme-text-secondary: #cbd5e1;
    --theme-text-tertiary: #94a3b8;
    --theme-text-muted: #64748b;
    --theme-text-inverse: #0f172a;
    
    /* Border Colors */
    --theme-border-primary: #334155;
    --theme-border-secondary: #475569;
    --theme-border-tertiary: #1e293b;
    --theme-border-focus: var(--theme-primary);
    --theme-border-error: #ef4444;
    --theme-border-success: #10b981;
    --theme-border-warning: #f59e0b;
    
    /* Semantic Colors (adjusted for dark mode) */
    --theme-success: #10b981;
    --theme-success-light: #064e3b;
    --theme-success-dark: #34d399;
    
    --theme-warning: #f59e0b;
    --theme-warning-light: #78350f;
    --theme-warning-dark: #fbbf24;
    
    --theme-error: #ef4444;
    --theme-error-light: #7f1d1d;
    --theme-error-dark: #f87171;
    
    --theme-info: #3b82f6;
    --theme-info-light: #1e3a8a;
    --theme-info-dark: #60a5fa;
    
    /* Shadows (darker for dark mode) */
    --theme-shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --theme-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
    --theme-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
    --theme-shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 10px 10px -5px rgba(0, 0, 0, 0.3);
    --theme-shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.6);
    
    /* Glassmorphism */
    --theme-glass-bg: rgba(30, 41, 59, 0.8);
    --theme-glass-border: rgba(51, 65, 85, 0.5);
    --theme-glass-blur: blur(20px);
    
    /* Unified Glass Header System (Dark Mode) */
    --theme-header-glass-bg: rgba(15, 23, 42, 0.75);
    --theme-header-glass-bg-scrolled: rgba(15, 23, 42, 0.88);
    --theme-header-glass-border: rgba(51, 65, 85, 0.5);
    --theme-header-glass-border-accent: rgba(99, 102, 241, 0.15);
    --theme-header-glass-blur: blur(20px) saturate(180%);
    --theme-header-glass-blur-scrolled: blur(24px) saturate(200%);
    --theme-header-shadow: 
        0 1px 0 rgba(255, 255, 255, 0.05) inset,
        0 4px 24px rgba(0, 0, 0, 0.3),
        0 1px 3px rgba(0, 0, 0, 0.2);
    --theme-header-shadow-scrolled:
        0 1px 0 rgba(255, 255, 255, 0.08) inset,
        0 8px 32px rgba(0, 0, 0, 0.4),
        0 2px 6px rgba(0, 0, 0, 0.3);
    --theme-header-height: 60px;
    --theme-header-z-index: 1000;
    
    /* Sidebar (dark mode) */
    --theme-sidebar-bg: #1e293b;
    --theme-sidebar-border-color: #334155;
    --theme-sidebar-hover-bg: #334155;
    --theme-sidebar-text-color: #e2e8f0;
    --theme-sidebar-text-muted: #94a3b8;
    --theme-sidebar-active-bg: #334155;
}

/* ============================================
   BACKWARD COMPATIBILITY ALIASES
   ============================================ */
:root,
[data-theme="light"] {
    /* Map old variable names to new system */
    --primary-color: var(--theme-primary);
    --primary-hover: var(--theme-primary-hover);
    --secondary-color: var(--theme-secondary);
    --bg-color: var(--theme-bg-secondary);
    --card-bg: var(--theme-bg-card);
    --text-inverse: var(--theme-text-inverse);
    --text-main: var(--theme-text-primary);
    --text-color: var(--theme-text-primary);
    --text-muted: var(--theme-text-muted);
    --hover-bg: var(--theme-bg-hover);
    --secondary-bg: var(--theme-bg-secondary);
    --border-color: var(--theme-border-primary);
    --danger: var(--theme-error);
    --success: var(--theme-success);
    --warning: var(--theme-warning);
    --shadow-sm: var(--theme-shadow-sm);
    --shadow-md: var(--theme-shadow-md);
    --shadow-lg: var(--theme-shadow-lg);
    --radius: var(--theme-radius-md);
    --container-width: 1200px;
}

[data-theme="dark"] {
    /* Map old variable names to new system (dark mode) */
    --primary-color: var(--theme-primary);
    --primary-hover: var(--theme-primary-hover);
    --secondary-color: var(--theme-secondary);
    --bg-color: var(--theme-bg-primary);
    --card-bg: var(--theme-bg-card);
    --text-inverse: var(--theme-text-inverse);
    --text-main: var(--theme-text-primary);
    --text-color: var(--theme-text-primary);
    --text-muted: var(--theme-text-muted);
    --hover-bg: var(--theme-bg-hover);
    --secondary-bg: var(--theme-bg-secondary);
    --border-color: var(--theme-border-primary);
    --danger: var(--theme-error);
    --success: var(--theme-success);
    --warning: var(--theme-warning);
    --shadow-sm: var(--theme-shadow-sm);
    --shadow-md: var(--theme-shadow-md);
    --shadow-lg: var(--theme-shadow-lg);
    --radius: var(--theme-radius-md);
}

/* ============================================
   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;
    }
    
    html.theme-loaded {
        transition: none;
    }
}

/* ============================================
   HIGH CONTRAST MODE SUPPORT
   ============================================ */
@media (prefers-contrast: high) {
    :root,
    [data-theme="light"] {
        --theme-border-primary: #000000;
        --theme-border-secondary: #000000;
        --theme-text-tertiary: #000000;
    }
    
    [data-theme="dark"] {
        --theme-border-primary: #ffffff;
        --theme-border-secondary: #ffffff;
        --theme-text-tertiary: #ffffff;
    }
}
