/**
 * 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 - Deep Teal */
  --color-primary-50: rgba(13, 148, 136, 0.04);
  --color-primary-100: rgba(13, 148, 136, 0.08);
  --color-primary-200: rgba(13, 148, 136, 0.14);
  --color-primary-300: rgba(13, 148, 136, 0.22);
  --color-primary-400: #2dd4bf;
  --color-primary-500: #14b8a6;
  --color-primary-600: #0d9488;
  --color-primary-700: #0f766e;
  --color-primary-800: #115e59;
  --color-primary-900: #134e4a;

  /* Primary semantic colors */
  /* AA-safe brand teal: white-text-on-this passes AA (5:1) and this color
     passes AA on light surfaces. The brighter #0d9488 (now in --color-primary-bright)
     is reserved for decorative/icon use where contrast doesn't apply. */
  --color-primary: #0f766e;
  --color-primary-bright: #0d9488;
  --color-primary-hover: #115e59;
  --color-primary-active: #134e4a;
  --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 (tertiary slightly darkened to pass AA on white) */
  --color-text-primary: #1a1816;
  --color-text-secondary: #5c5650;
  --color-text-tertiary: #5e5852;
  --color-text-disabled: #908a83;
  --color-text-inverse: #ffffff;

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

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

  /* darker amber so foreground use passes AA on white/warning-bg */
  --color-warning: #b45309;
  --color-warning-bg: #fffbeb;
  --color-warning-border: #fde68a;

  /* darker red: white-text-on-this is 4.83:1 (AA). #ef4444 was only 3.76. */
  --color-error: #dc2626;
  --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: #047857;
  --color-error-text: #dc2626;

  /* Text on primary — white when primary is dark, dark when primary is bright */
  --color-text-on-primary: #ffffff;

  /* Input idle background - faint warm tint for unfocused inputs */
  --color-input-bg: #fafbfc;

  /* Tint tokens - very faint background tints for stat/metric cards */
  --color-tint-teal: rgba(13, 148, 136, 0.04);
  --color-tint-green: rgba(16, 185, 129, 0.04);
  --color-tint-amber: rgba(245, 158, 11, 0.04);
  --color-tint-blue: rgba(59, 130, 246, 0.04);

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

  /* Letter Spacing — Tighter headings, open small text */
  --tracking-tighter: -0.025em;  /* Large display text */
  --tracking-tight: -0.015em;    /* Page titles, headings */
  --tracking-normal: -0.011em;   /* Body text (Apple standard) */
  --tracking-wide: 0.01em;       /* Captions, labels */
  --tracking-wider: 0.025em;     /* Badges, small UI text */
  --tracking-caps: 0.06em;       /* Uppercase section headers */

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

  /* ================================
   * Motion — Unified easing & duration language
   *
   * Easing curves describe the *feel* of a transition. Use them for any
   * property change. Pair with a duration that matches the size of the move:
   *   - micro (color, opacity)        → --duration-fast (140ms) + ease-out
   *   - hover/state                   → --duration-base (200ms) + ease-standard
   *   - panel slide / scale-in        → --duration-emphasized (320ms) + ease-emphasized
   *   - large overlay / page          → --duration-slow (480ms) + ease-emphasized
   * ================================ */

  /* Easing — cohesive curve family. All are "natural" feeling. */
  /* Standard: smooth in/out — for color/state changes that move both ways. */
  --ease-standard: cubic-bezier(0.4, 0, 0.2, 1);
  /* Out: decelerate to rest — for elements entering view/state. */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  /* In: accelerate away — for elements leaving. */
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  /* Emphasized: heavier deceleration, subtle overshoot feel — for hero
     moments (modals, page transitions). iOS-inspired. */
  --ease-emphasized: cubic-bezier(0.32, 0.72, 0, 1);
  /* Spring: gentle bounce-back — for press feedback, toggles. */
  --ease-spring: cubic-bezier(0.34, 1.4, 0.64, 1);

  /* Duration scale.
     Steps map roughly to motion *scale*, not just speed:
       instant  — 80ms   tiny prop changes (icon color)
       fast     — 140ms  buttons, links, micro-states
       base     — 200ms  hover/focus, dropdowns
       medium   — 240ms  panels, popovers, drawers
       emphasized — 320ms  page content, modal scale
       slow     — 480ms  large overlays, hero transitions */
  --duration-instant: 80ms;
  --duration-fast: 140ms;
  --duration-base: 200ms;
  --duration-medium: 240ms;
  --duration-emphasized: 320ms;
  --duration-slow: 480ms;

  /* Composed transition tokens (back-compat + ergonomics) */
  --transition-instant: var(--duration-instant) var(--ease-standard);
  --transition-fast: var(--duration-fast) var(--ease-standard);
  --transition-base: var(--duration-base) var(--ease-standard);
  --transition-medium: var(--duration-medium) var(--ease-out);
  --transition-slow: var(--duration-slow) var(--ease-emphasized);
  --transition-spring: var(--duration-base) var(--ease-spring);

  /* 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(13, 148, 136, 0.14);
  --focus-ring-shadow-strong: 0 0 0 4px rgba(13, 148, 136, 0.2);

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

  /* Smooth scroll */
  scroll-behavior: smooth;
}

/* ================================
 * 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 (improved contrast) */
  --color-text-primary: #f5f2ed;
  --color-text-secondary: #a8a29e;
  --color-text-tertiary: #a3a09b;
  --color-text-disabled: #52504e;
  --color-text-inverse: #0e0d0c;

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

  /* Primary - Lighter teal for dark backgrounds */
  --color-primary: #2dd4bf;
  --color-primary-hover: #14b8a6;
  --color-primary-active: #5eead4;
  --color-primary-50: rgba(45, 212, 191, 0.06);
  --color-primary-100: rgba(45, 212, 191, 0.12);
  --color-primary-200: rgba(45, 212, 191, 0.18);
  --color-primary-300: rgba(45, 212, 191, 0.28);
  --color-primary-400: #5eead4;
  --color-primary-bg: rgba(45, 212, 191, 0.12);

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

  /* Text on primary — dark text for bright teal primary */
  --color-text-on-primary: #0e0d0c;

  /* Input idle background */
  --color-input-bg: #1a1816;

  /* Tint tokens */
  --color-tint-teal: rgba(45, 212, 191, 0.06);
  --color-tint-green: rgba(52, 211, 153, 0.06);
  --color-tint-amber: rgba(251, 191, 36, 0.06);
  --color-tint-blue: rgba(96, 165, 250, 0.06);
}

/* ================================
 * 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: #2dd4bf;

    /* Primary - Lighter teal for dark backgrounds */
    --color-primary: #2dd4bf;
    --color-primary-hover: #14b8a6;
    --color-primary-active: #5eead4;
    --color-primary-50: rgba(45, 212, 191, 0.05);
    --color-primary-100: rgba(45, 212, 191, 0.1);
    --color-primary-200: rgba(45, 212, 191, 0.16);
    --color-primary-300: rgba(45, 212, 191, 0.24);
    --color-primary-400: #5eead4;
    --color-primary-bg: rgba(45, 212, 191, 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);

    /* Text on primary — dark text for bright teal primary */
    --color-text-on-primary: #0e0d0c;

    /* Input idle background */
    --color-input-bg: #1a1816;

    /* Tint tokens */
    --color-tint-teal: rgba(45, 212, 191, 0.06);
    --color-tint-green: rgba(52, 211, 153, 0.06);
    --color-tint-amber: rgba(251, 191, 36, 0.06);
    --color-tint-blue: rgba(96, 165, 250, 0.06);
  }
}

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

@media (prefers-reduced-motion: reduce) {
  :root {
    --duration-instant: 0ms;
    --duration-fast: 0ms;
    --duration-base: 0ms;
    --duration-medium: 0ms;
    --duration-emphasized: 0ms;
    --duration-slow: 0ms;
    --transition-instant: 0ms linear;
    --transition-fast: 0ms linear;
    --transition-base: 0ms linear;
    --transition-medium: 0ms linear;
    --transition-slow: 0ms linear;
    --transition-spring: 0ms linear;
  }
  /* Disable animation as well, not just transition */
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0ms !important;
    scroll-behavior: auto !important;
  }
}
