/**
 * WhenBRRR Enterprise Design System
 * McKinsey-Grade Variables & Tokens
 * 
 * SINGLE SOURCE OF TRUTH - Import this file FIRST in all templates
 * 
 * Design Principles:
 * - 8px grid system
 * - 1.25 type scale ratio (Major Third)
 * - 5-level elevation system
 * - Semantic color naming
 * - Accessible contrast ratios (WCAG AA minimum)
 * 
 * @version 2.0.0
 * @updated October 2025
 */

/* ============================================================================
   COLOR SYSTEM - Semantic Naming
   ============================================================================ */

:root {
    /* Primary Brand Colors */
    --color-brand-50: #eff6ff;
    --color-brand-100: #dbeafe;
    --color-brand-200: #bfdbfe;
    --color-brand-300: #93c5fd;
    --color-brand-400: #60a5fa;
    --color-brand-500: #3b82f6;
    --color-brand-600: #2563eb;
    --color-brand-700: #1d4ed8;
    --color-brand-800: #1e40af;
    --color-brand-900: #1e3a8a;
    --color-brand-950: #172554;
    
    /* Accent Purple (Secondary Brand) */
    --color-accent-50: #faf5ff;
    --color-accent-100: #f3e8ff;
    --color-accent-200: #e9d5ff;
    --color-accent-300: #d8b4fe;
    --color-accent-400: #c084fc;
    --color-accent-500: #a855f7;
    --color-accent-600: #9333ea;
    --color-accent-700: #7e22ce;
    --color-accent-800: #6b21a8;
    --color-accent-900: #581c87;
    
    /* Semantic Status Colors */
    --color-success-50: #ecfdf5;
    --color-success-100: #d1fae5;
    --color-success-500: #10b981;
    --color-success-600: #059669;
    --color-success-700: #047857;
    
    --color-warning-50: #fffbeb;
    --color-warning-100: #fef3c7;
    --color-warning-500: #f59e0b;
    --color-warning-600: #d97706;
    --color-warning-700: #b45309;
    
    --color-danger-50: #fef2f2;
    --color-danger-100: #fee2e2;
    --color-danger-500: #ef4444;
    --color-danger-600: #dc2626;
    --color-danger-700: #b91c1c;
    
    --color-info-50: #eff6ff;
    --color-info-100: #dbeafe;
    --color-info-500: #3b82f6;
    --color-info-600: #2563eb;
    
    /* Neutral Grayscale */
    --color-gray-50: #f9fafb;
    --color-gray-100: #f3f4f6;
    --color-gray-200: #e5e7eb;
    --color-gray-300: #d1d5db;
    --color-gray-400: #9ca3af;
    --color-gray-500: #6b7280;
    --color-gray-600: #4b5563;
    --color-gray-700: #374151;
    --color-gray-800: #1f2937;
    --color-gray-900: #111827;
    --color-gray-950: #030712;
    
    /* Semantic Surface Colors - Light Mode */
    --surface-primary: #ffffff;
    --surface-secondary: #f9fafb;
    --surface-tertiary: #f3f4f6;
    --surface-elevated: #ffffff;
    --surface-overlay: rgba(0, 0, 0, 0.5);
    
    /* Semantic Text Colors - Light Mode */
    --text-primary: #111827;
    --text-secondary: #4b5563;
    --text-tertiary: #6b7280;
    --text-muted: #9ca3af;
    --text-inverse: #ffffff;
    --text-brand: #2563eb;
    
    /* Semantic Border Colors - Light Mode */
    --border-light: #e5e7eb;
    --border-medium: #d1d5db;
    --border-heavy: #9ca3af;
    --border-focus: #3b82f6;
    
    /* Regime-Specific Colors */
    --regime-high-tide: #059669;
    --regime-high-tide-bg: rgba(5, 150, 105, 0.1);
    --regime-tailwind: #3b82f6;
    --regime-tailwind-bg: rgba(59, 130, 246, 0.1);
    --regime-neutral: #6b7280;
    --regime-neutral-bg: rgba(107, 114, 128, 0.1);
    --regime-low-tide: #f59e0b;
    --regime-low-tide-bg: rgba(245, 158, 11, 0.1);
}

/* ============================================================================
   DARK MODE - Semantic Overrides
   ============================================================================ */

[data-theme="dark"] {
    /* Surfaces */
    --surface-primary: #0f172a;
    --surface-secondary: #1e293b;
    --surface-tertiary: #334155;
    --surface-elevated: #1e293b;
    --surface-overlay: rgba(0, 0, 0, 0.75);
    
    /* Text */
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-tertiary: #94a3b8;
    --text-muted: #64748b;
    --text-inverse: #0f172a;
    --text-brand: #60a5fa;
    
    /* Borders */
    --border-light: #334155;
    --border-medium: #475569;
    --border-heavy: #64748b;
    
    /* Regime colors stay the same, slightly boosted for visibility */
    --regime-high-tide: #34d399;
    --regime-tailwind: #60a5fa;
    --regime-neutral: #94a3b8;
    --regime-low-tide: #fbbf24;
}

/* ============================================================================
   TYPOGRAPHY SYSTEM - 1.25 Major Third Scale
   ============================================================================ */

:root {
    /* Font Families */
    --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", monospace;
    
    /* Type Scale - 1.25 ratio (Major Third) */
    --text-xs: 0.75rem;      /* 12px */
    --text-sm: 0.875rem;     /* 14px */
    --text-base: 1rem;       /* 16px - body text */
    --text-lg: 1.125rem;     /* 18px */
    --text-xl: 1.25rem;      /* 20px */
    --text-2xl: 1.5rem;      /* 24px */
    --text-3xl: 1.875rem;    /* 30px */
    --text-4xl: 2.25rem;     /* 36px */
    --text-5xl: 3rem;        /* 48px */
    --text-6xl: 3.75rem;     /* 60px */
    --text-7xl: 4.5rem;      /* 72px - hero metrics */
    
    /* Responsive Type Scale (fluid typography) */
    --text-display: clamp(2.25rem, 5vw, 4.5rem);
    --text-headline: clamp(1.875rem, 4vw, 3rem);
    --text-title: clamp(1.5rem, 3vw, 2.25rem);
    
    /* Font Weights */
    --font-normal: 400;
    --font-medium: 500;
    --font-semibold: 600;
    --font-bold: 700;
    --font-extrabold: 800;
    
    /* Line Heights */
    --leading-none: 1;
    --leading-tight: 1.25;
    --leading-snug: 1.375;
    --leading-normal: 1.5;
    --leading-relaxed: 1.625;
    --leading-loose: 2;
    
    /* Letter Spacing */
    --tracking-tighter: -0.05em;
    --tracking-tight: -0.025em;
    --tracking-normal: 0;
    --tracking-wide: 0.025em;
    --tracking-wider: 0.05em;
    --tracking-widest: 0.1em;
}

/* ============================================================================
   SPACING SYSTEM - 8px Grid
   ============================================================================ */

:root {
    /* Base 8px scale */
    --space-0: 0;
    --space-px: 1px;
    --space-0-5: 0.125rem;   /* 2px */
    --space-1: 0.25rem;      /* 4px */
    --space-1-5: 0.375rem;   /* 6px */
    --space-2: 0.5rem;       /* 8px - base unit */
    --space-2-5: 0.625rem;   /* 10px */
    --space-3: 0.75rem;      /* 12px */
    --space-3-5: 0.875rem;   /* 14px */
    --space-4: 1rem;         /* 16px */
    --space-5: 1.25rem;      /* 20px */
    --space-6: 1.5rem;       /* 24px */
    --space-7: 1.75rem;      /* 28px */
    --space-8: 2rem;         /* 32px */
    --space-9: 2.25rem;      /* 36px */
    --space-10: 2.5rem;      /* 40px */
    --space-11: 2.75rem;     /* 44px */
    --space-12: 3rem;        /* 48px */
    --space-14: 3.5rem;      /* 56px */
    --space-16: 4rem;        /* 64px */
    --space-20: 5rem;        /* 80px */
    --space-24: 6rem;        /* 96px */
    --space-28: 7rem;        /* 112px */
    --space-32: 8rem;        /* 128px */
    
    /* Semantic Spacing */
    --gap-card: var(--space-6);
    --gap-section: var(--space-12);
    --gap-page: var(--space-16);
    --padding-card: var(--space-6);
    --padding-button: var(--space-3) var(--space-5);
    --padding-input: var(--space-3) var(--space-4);
}

/* ============================================================================
   ELEVATION SYSTEM - 5 Levels
   ============================================================================ */

:root {
    /* Light Mode Shadows */
    --elevation-0: none;
    --elevation-1: 0 1px 2px rgba(0, 0, 0, 0.05);
    --elevation-2: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
    --elevation-3: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --elevation-4: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    --elevation-5: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    
    /* Special Shadows */
    --elevation-inner: inset 0 2px 4px rgba(0, 0, 0, 0.05);
    --elevation-ring: 0 0 0 3px rgba(59, 130, 246, 0.15);
    --elevation-glow-brand: 0 0 20px rgba(59, 130, 246, 0.3);
    --elevation-glow-success: 0 0 20px rgba(16, 185, 129, 0.3);
}

[data-theme="dark"] {
    --elevation-1: 0 1px 2px rgba(0, 0, 0, 0.25);
    --elevation-2: 0 1px 3px rgba(0, 0, 0, 0.35), 0 1px 2px -1px rgba(0, 0, 0, 0.3);
    --elevation-3: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -2px rgba(0, 0, 0, 0.35);
    --elevation-4: 0 10px 15px -3px rgba(0, 0, 0, 0.45), 0 4px 6px -4px rgba(0, 0, 0, 0.4);
    --elevation-5: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.45);
    --elevation-inner: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* ============================================================================
   BORDER RADIUS - Consistent Rounding
   ============================================================================ */

:root {
    --radius-none: 0;
    --radius-sm: 0.25rem;    /* 4px */
    --radius-md: 0.5rem;     /* 8px */
    --radius-lg: 0.75rem;    /* 12px */
    --radius-xl: 1rem;       /* 16px */
    --radius-2xl: 1.5rem;    /* 24px */
    --radius-full: 9999px;
}

/* ============================================================================
   TRANSITIONS & ANIMATIONS
   ============================================================================ */

:root {
    /* Durations */
    --duration-instant: 50ms;
    --duration-fast: 100ms;
    --duration-normal: 200ms;
    --duration-slow: 300ms;
    --duration-slower: 500ms;
    
    /* Easing Curves */
    --ease-linear: linear;
    --ease-in: cubic-bezier(0.4, 0, 1, 1);
    --ease-out: cubic-bezier(0, 0, 0.2, 1);
    --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
    --ease-spring: cubic-bezier(0.16, 1, 0.3, 1);
    
    /* Preset Transitions */
    --transition-colors: color var(--duration-normal) var(--ease-in-out),
                         background-color var(--duration-normal) var(--ease-in-out),
                         border-color var(--duration-normal) var(--ease-in-out);
    --transition-shadow: box-shadow var(--duration-normal) var(--ease-out);
    --transition-transform: transform var(--duration-normal) var(--ease-out);
    --transition-all: all var(--duration-normal) var(--ease-out);
}

/* ============================================================================
   Z-INDEX SCALE - Stacking Context
   ============================================================================ */

:root {
    --z-negative: -1;
    --z-0: 0;
    --z-10: 10;
    --z-20: 20;
    --z-30: 30;
    --z-40: 40;
    --z-50: 50;
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-fixed: 300;
    --z-modal-backdrop: 400;
    --z-modal: 500;
    --z-popover: 600;
    --z-tooltip: 700;
    --z-toast: 800;
    --z-max: 9999;
}

/* ============================================================================
   LAYOUT DIMENSIONS
   ============================================================================ */

:root {
    /* Container Widths */
    --container-xs: 20rem;   /* 320px */
    --container-sm: 24rem;   /* 384px */
    --container-md: 28rem;   /* 448px */
    --container-lg: 32rem;   /* 512px */
    --container-xl: 36rem;   /* 576px */
    --container-2xl: 42rem;  /* 672px */
    --container-3xl: 48rem;  /* 768px */
    --container-4xl: 56rem;  /* 896px */
    --container-5xl: 64rem;  /* 1024px */
    --container-6xl: 72rem;  /* 1152px */
    --container-7xl: 80rem;  /* 1280px */
    --container-max: 90rem;  /* 1440px */
    
    /* Component Sizes */
    --size-icon-xs: 0.75rem;  /* 12px */
    --size-icon-sm: 1rem;     /* 16px */
    --size-icon-md: 1.25rem;  /* 20px */
    --size-icon-lg: 1.5rem;   /* 24px */
    --size-icon-xl: 2rem;     /* 32px */
    
    --size-avatar-xs: 1.5rem; /* 24px */
    --size-avatar-sm: 2rem;   /* 32px */
    --size-avatar-md: 2.5rem; /* 40px */
    --size-avatar-lg: 3rem;   /* 48px */
    --size-avatar-xl: 4rem;   /* 64px */
    
    /* Navigation */
    --size-nav-height: 4rem;       /* 64px */
    --size-nav-height-sm: 3.5rem;  /* 56px */
    --size-sidebar-width: 16rem;   /* 256px */
    --size-sidebar-collapsed: 4rem; /* 64px */
    
    /* Touch Targets (accessibility) */
    --size-touch-min: 2.75rem; /* 44px - minimum tap target */
    --size-touch-comfortable: 3rem; /* 48px - comfortable tap target */
}

/* ============================================================================
   BREAKPOINTS - Media Query Reference
   ============================================================================ */

:root {
    /* 
     * Mobile-first breakpoints:
     * - sm: 640px  (small tablets, large phones)
     * - md: 768px  (tablets)
     * - lg: 1024px (small laptops)
     * - xl: 1280px (desktops)
     * - 2xl: 1536px (large screens)
     * 
     * Usage: @media (min-width: 768px) { }
     */
    --breakpoint-sm: 640px;
    --breakpoint-md: 768px;
    --breakpoint-lg: 1024px;
    --breakpoint-xl: 1280px;
    --breakpoint-2xl: 1536px;
}

/* ============================================================================
   GRADIENTS - Brand & Utility
   ============================================================================ */

:root {
    /* Brand Gradients */
    --gradient-brand: linear-gradient(135deg, var(--color-brand-500), var(--color-brand-700));
    --gradient-brand-vivid: linear-gradient(135deg, var(--color-brand-400), var(--color-brand-600));
    --gradient-accent: linear-gradient(135deg, var(--color-accent-500), var(--color-accent-700));
    --gradient-dark: linear-gradient(135deg, #1e3a5f, #0f172a);
    
    /* Status Gradients */
    --gradient-success: linear-gradient(135deg, var(--color-success-500), var(--color-success-600));
    --gradient-warning: linear-gradient(135deg, var(--color-warning-500), var(--color-warning-600));
    --gradient-danger: linear-gradient(135deg, var(--color-danger-500), var(--color-danger-600));
    
    /* Regime Gradients */
    --gradient-high-tide: linear-gradient(135deg, #10b981, #059669);
    --gradient-tailwind: linear-gradient(135deg, #3b82f6, #2563eb);
    --gradient-neutral: linear-gradient(135deg, #6b7280, #4b5563);
    --gradient-low-tide: linear-gradient(135deg, #f59e0b, #d97706);
    
    /* Surface Gradients */
    --gradient-surface: linear-gradient(180deg, var(--surface-primary), var(--surface-secondary));
    --gradient-glow: radial-gradient(circle at center, rgba(59, 130, 246, 0.15), transparent 70%);
}

/* ============================================================================
   FOCUS STYLES - Accessibility
   ============================================================================ */

:root {
    --focus-ring-width: 2px;
    --focus-ring-offset: 2px;
    --focus-ring-color: var(--color-brand-500);
    --focus-ring-style: solid;
}

/* Global focus visible styles */
:focus-visible {
    outline: var(--focus-ring-width) var(--focus-ring-style) var(--focus-ring-color);
    outline-offset: var(--focus-ring-offset);
}

/* Remove default focus for mouse users */
:focus:not(:focus-visible) {
    outline: none;
}

/* ============================================================================
   PROSE SETTINGS - Long-form Content
   ============================================================================ */

:root {
    --prose-width: 65ch;
    --prose-line-height: 1.75;
    --prose-spacing: 1.25em;
}

/* ============================================================================
   PRINT STYLES
   ============================================================================ */

@media print {
    :root {
        --surface-primary: white;
        --surface-secondary: white;
        --text-primary: black;
        --text-secondary: #333;
        --elevation-1: none;
        --elevation-2: none;
        --elevation-3: none;
        --elevation-4: none;
        --elevation-5: none;
    }
}

/* ============================================================================
   REDUCED MOTION - Accessibility
   ============================================================================ */

@media (prefers-reduced-motion: reduce) {
    :root {
        --duration-instant: 0ms;
        --duration-fast: 0ms;
        --duration-normal: 0ms;
        --duration-slow: 0ms;
        --duration-slower: 0ms;
    }
}
