/**
 * Design Token System
 * Unified design variables for consistent styling across the application
 * Supports light and dark mode theming
 */

:root {
  /* ================================
   * Color System - Light Mode
   * Modern, refined palette inspired by Linear/Vercel/Anthropic
   * ================================ */

  /* Primary Brand Colors - Vibrant Indigo */
  --color-primary-50: rgba(108, 99, 255, 0.04);
  --color-primary-100: rgba(108, 99, 255, 0.08);
  --color-primary-200: rgba(108, 99, 255, 0.14);
  --color-primary-300: rgba(108, 99, 255, 0.22);
  --color-primary-400: #8a82ff;
  --color-primary-500: #6c63ff;
  --color-primary-600: #5a50f0;
  --color-primary-700: #4a40d8;
  --color-primary-800: #3830a8;
  --color-primary-900: #282080;

  /* Primary semantic colors */
  --color-primary: #6c63ff;
  --color-primary-hover: #5a50f0;
  --color-primary-active: #4a40d8;
  --color-primary-bg: var(--color-primary-100);

  /* Background Colors - Warm stone neutrals */
  --color-background: #faf9f7;
  --color-background-secondary: #f2f0ed;
  --color-background-tertiary: #e8e5e1;
  --color-surface: #ffffff;
  --color-surface-hover: #f7f5f2;

  /* Text Colors - Warm neutrals */
  --color-text-primary: #1a1816;
  --color-text-secondary: #5c5650;
  --color-text-tertiary: #8e8880;
  --color-text-disabled: #c0bab4;
  --color-text-inverse: #ffffff;

  /* Border Colors - Warm, subtle */
  --color-border: #e5e1dc;
  --color-border-hover: #d0cbc5;
  --color-border-focus: #6c63ff;

  /* Semantic Status Colors */
  --color-success: #10b981;
  --color-success-bg: #ecfdf5;
  --color-success-border: #a7f3d0;

  --color-warning: #f59e0b;
  --color-warning-bg: #fffbeb;
  --color-warning-border: #fde68a;

  --color-error: #ef4444;
  --color-error-hover: #dc2626;
  --color-error-active: #b91c1c;
  --color-error-bg: #fef2f2;
  --color-error-border: #fecaca;

  --color-info: #3b82f6;
  --color-info-bg: #eff6ff;
  --color-info-border: #bfdbfe;

  /* Semantic text colors for status on light backgrounds */
  --color-success-text: #059669;
  --color-error-text: #dc2626;

  /* ================================
   * Typography
   * ================================ */

  /* Font Families */
  --font-family-sans: 'Sora', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-family-mono: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;

  /* Font Sizes - Optimized for readability */
  --font-size-xs: 0.6875rem;  /* 11px - Legal, timestamps */
  --font-size-sm: 0.8125rem;  /* 13px - Captions */
  --font-size-base: 0.9375rem;/* 15px - Body text (iOS standard) */
  --font-size-md: 1.0625rem;  /* 17px - Emphasized body */
  --font-size-lg: 1.25rem;    /* 20px - Subheadings */
  --font-size-xl: 1.5rem;     /* 24px - Section headers */
  --font-size-2xl: 1.75rem;   /* 28px - Page titles */
  --font-size-3xl: 2.125rem;  /* 34px - Large titles */
  --font-size-4xl: 3rem;      /* 48px - Hero text */

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

  /* Line Heights - Improved readability */
  --line-height-tight: 1.2;
  --line-height-snug: 1.375;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.625;

  /* ================================
   * Spacing Scale
   * ================================ */

  --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 */

  /* ================================
   * Shadows - Refined, layered elevation system
   * ================================ */

  --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.03);
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.04), 0 1px 3px 0 rgb(0 0 0 / 0.03);
  --shadow-md: 0 2px 4px -1px rgb(0 0 0 / 0.04), 0 4px 6px -1px rgb(0 0 0 / 0.03);
  --shadow-lg: 0 4px 6px -2px rgb(0 0 0 / 0.03), 0 10px 15px -3px rgb(0 0 0 / 0.05);
  --shadow-xl: 0 8px 10px -4px rgb(0 0 0 / 0.03), 0 20px 25px -5px rgb(0 0 0 / 0.05);
  --shadow-2xl: 0 25px 50px -12px rgb(0 0 0 / 0.12);

  /* Card shadows - Barely-there elevation */
  --shadow-card: 0 0 0 1px rgb(0 0 0 / 0.03), 0 1px 2px 0 rgb(0 0 0 / 0.04);
  --shadow-card-hover: 0 0 0 1px rgb(0 0 0 / 0.03), 0 3px 8px -2px rgb(0 0 0 / 0.06);

  /* ================================
   * Border Radius - Tighter, more refined
   * ================================ */

  --radius-xs: 0.25rem;   /* 4px - Chips, badges */
  --radius-sm: 0.5rem;    /* 8px - Buttons, inputs */
  --radius-md: 0.625rem;  /* 10px - Small cards */
  --radius-lg: 0.75rem;   /* 12px - Cards, modals */
  --radius-xl: 1rem;      /* 16px - Containers */
  --radius-2xl: 1.25rem;  /* 20px - Hero sections */
  --radius-3xl: 1.5rem;   /* 24px - Full-screen modals */
  --radius-full: 9999px;

  /* ================================
   * Z-Index Scale
   * ================================ */

  --z-base: 0;
  --z-dropdown: 1000;
  --z-sticky: 1020;
  --z-fixed: 1030;
  --z-modal-backdrop: 10040;
  --z-modal: 10050;
  --z-popover: 10060;
  --z-tooltip: 10070;
  --z-toast: 10100;

  /* ================================
   * Transitions
   * ================================ */

  --transition-instant: 100ms cubic-bezier(0.25, 0.1, 0.25, 1);
  --transition-fast: 150ms cubic-bezier(0.25, 0.1, 0.25, 1);
  --transition-base: 200ms cubic-bezier(0.25, 0.1, 0.25, 1);
  --transition-slow: 400ms cubic-bezier(0.25, 0.1, 0.25, 1);

  /* Focus ring styles */
  --focus-ring-color: var(--color-primary-500);
  --focus-ring-width: 2px;
  --focus-ring-offset: 2px;
  --focus-ring-shadow: 0 0 0 3px rgba(108, 99, 255, 0.08);

  /* ================================
   * Sizing
   * ================================ */

  --input-height-sm: 2rem;      /* 32px */
  --input-height-md: 2.25rem;   /* 36px */
  --input-height-lg: 2.75rem;   /* 44px */

  --button-height-sm: 1.75rem;  /* 28px */
  --button-height-md: 2.25rem;  /* 36px */
  --button-height-lg: 2.75rem;  /* 44px */

  /* Touch targets (mobile only) */
  --touch-target-min: 44px;
}

/* ================================
 * Dark Mode Theme Overrides
 * ================================ */

[data-theme="dark"] {
  /* Background Colors - Warm dark */
  --color-background: #0e0d0c;
  --color-background-secondary: #171514;
  --color-background-tertiary: #211f1d;
  --color-surface: #1c1a18;
  --color-surface-hover: #262422;

  /* Text Colors - Warm off-whites */
  --color-text-primary: #ede9e3;
  --color-text-secondary: #9c9590;
  --color-text-tertiary: #6e6862;
  --color-text-disabled: #4a4440;
  --color-text-inverse: #0e0d0c;

  /* Border Colors - Warm subtle */
  --color-border: #302c28;
  --color-border-hover: #423d38;
  --color-border-focus: #7b73ff;

  /* Primary - Slightly lighter indigo for dark backgrounds */
  --color-primary: #7b73ff;
  --color-primary-hover: #6c63ff;
  --color-primary-active: #8a82ff;
  --color-primary-50: rgba(123, 115, 255, 0.05);
  --color-primary-100: rgba(123, 115, 255, 0.1);
  --color-primary-200: rgba(123, 115, 255, 0.16);
  --color-primary-300: rgba(123, 115, 255, 0.24);
  --color-primary-400: #9590ff;
  --color-primary-bg: rgba(123, 115, 255, 0.1);

  /* Semantic Colors - Adjusted for dark mode */
  --color-success-bg: rgba(13, 150, 104, 0.1);
  --color-success-border: rgba(13, 150, 104, 0.2);
  --color-success-text: #34d399;

  --color-warning-bg: rgba(217, 119, 6, 0.1);
  --color-warning-border: rgba(217, 119, 6, 0.2);

  --color-error-hover: #dc2626;
  --color-error-active: #b91c1c;
  --color-error-bg: rgba(220, 38, 38, 0.1);
  --color-error-border: rgba(220, 38, 38, 0.2);
  --color-error-text: #f87171;

  --color-info-bg: rgba(37, 99, 235, 0.1);
  --color-info-border: rgba(37, 99, 235, 0.2);

  /* Shadows - Barely visible in dark mode (rely on borders) */
  --shadow-xs: 0 0 0 1px rgb(255 255 255 / 0.04);
  --shadow-sm: 0 0 0 1px rgb(255 255 255 / 0.04), 0 1px 2px 0 rgb(0 0 0 / 0.4);
  --shadow-md: 0 0 0 1px rgb(255 255 255 / 0.04), 0 2px 4px 0 rgb(0 0 0 / 0.4);
  --shadow-lg: 0 0 0 1px rgb(255 255 255 / 0.04), 0 8px 16px -4px rgb(0 0 0 / 0.5);
  --shadow-xl: 0 0 0 1px rgb(255 255 255 / 0.04), 0 16px 32px -8px rgb(0 0 0 / 0.5);
  --shadow-2xl: 0 0 0 1px rgb(255 255 255 / 0.04), 0 24px 48px -12px rgb(0 0 0 / 0.5);

  --shadow-card: 0 0 0 1px rgb(255 255 255 / 0.05);
  --shadow-card-hover: 0 0 0 1px rgb(255 255 255 / 0.08), 0 2px 8px -2px rgb(0 0 0 / 0.3);
}

/* ================================
 * System Preference Detection
 * Auto-apply dark mode based on system preference
 * ================================ */

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    /* Background Colors - Warm dark */
    --color-background: #0e0d0c;
    --color-background-secondary: #171514;
    --color-background-tertiary: #211f1d;
    --color-surface: #1c1a18;
    --color-surface-hover: #262422;

    /* Text Colors - Warm off-whites */
    --color-text-primary: #ede9e3;
    --color-text-secondary: #9c9590;
    --color-text-tertiary: #6e6862;
    --color-text-disabled: #4a4440;
    --color-text-inverse: #0e0d0c;

    /* Border Colors - Warm subtle */
    --color-border: #302c28;
    --color-border-hover: #423d38;
    --color-border-focus: #7b73ff;

    /* Primary - Indigo for dark backgrounds */
    --color-primary: #7b73ff;
    --color-primary-hover: #6c63ff;
    --color-primary-active: #8a82ff;
    --color-primary-50: rgba(123, 115, 255, 0.05);
    --color-primary-100: rgba(123, 115, 255, 0.1);
    --color-primary-200: rgba(123, 115, 255, 0.16);
    --color-primary-300: rgba(123, 115, 255, 0.24);
    --color-primary-400: #9590ff;
    --color-primary-bg: rgba(123, 115, 255, 0.1);

    /* Semantic Colors */
    --color-success-bg: rgba(13, 150, 104, 0.1);
    --color-success-border: rgba(13, 150, 104, 0.2);
    --color-success-text: #34d399;

    --color-warning-bg: rgba(217, 119, 6, 0.1);
    --color-warning-border: rgba(217, 119, 6, 0.2);

    --color-error-hover: #dc2626;
    --color-error-active: #b91c1c;
    --color-error-bg: rgba(220, 38, 38, 0.1);
    --color-error-border: rgba(220, 38, 38, 0.2);
    --color-error-text: #f87171;

    --color-info-bg: rgba(37, 99, 235, 0.1);
    --color-info-border: rgba(37, 99, 235, 0.2);

    /* Shadows */
    --shadow-xs: 0 0 0 1px rgb(255 255 255 / 0.04);
    --shadow-sm: 0 0 0 1px rgb(255 255 255 / 0.04), 0 1px 2px 0 rgb(0 0 0 / 0.4);
    --shadow-md: 0 0 0 1px rgb(255 255 255 / 0.04), 0 2px 4px 0 rgb(0 0 0 / 0.4);
    --shadow-lg: 0 0 0 1px rgb(255 255 255 / 0.04), 0 8px 16px -4px rgb(0 0 0 / 0.5);
    --shadow-xl: 0 0 0 1px rgb(255 255 255 / 0.04), 0 16px 32px -8px rgb(0 0 0 / 0.5);
    --shadow-2xl: 0 0 0 1px rgb(255 255 255 / 0.04), 0 24px 48px -12px rgb(0 0 0 / 0.5);

    --shadow-card: 0 0 0 1px rgb(255 255 255 / 0.05);
    --shadow-card-hover: 0 0 0 1px rgb(255 255 255 / 0.08), 0 2px 8px -2px rgb(0 0 0 / 0.3);
  }
}

/* ================================
 * Reduced Motion Support
 * ================================ */

@media (prefers-reduced-motion: reduce) {
  :root {
    --transition-fast: 0ms;
    --transition-base: 0ms;
    --transition-slow: 0ms;
  }
}
