/**
 * SignSafe Design Tokens - Unified Design System
 * Single source of truth for all web pages
 * Version: 1.0.0
 */

:root {
  /* === Brand Colors === */
  --primary: #0066ff;
  --primary-dark: #0052cc;
  --primary-light: #3b82f6;
  --primary-bg: rgba(0, 102, 255, 0.1);
  --primary-hover: rgba(0, 102, 255, 0.15);

  /* Brand Palette (Extended) */
  --brand-electric: #00d4ff;
  --brand-electric-glow: rgba(0, 212, 255, 0.15);
  --brand-violet: #8b5cf6;
  --brand-violet-glow: rgba(139, 92, 246, 0.15);

  /* Gradients */
  --gradient-cta: linear-gradient(
    135deg,
    var(--brand-electric) 0%,
    var(--brand-violet) 100%
  );

  /* === Semantic Colors === */
  --success: #00875a;
  --success-light: #e3fcef;
  --success-dark: #006644;
  --success-bg: rgba(0, 135, 90, 0.1);
  --success-glow: rgba(0, 135, 90, 0.15);

  --warning: #ff8b00;
  --warning-light: #fffae6;
  --warning-dark: #cc6d00;
  --warning-bg: rgba(255, 139, 0, 0.1);

  --error: #de350b;
  --error-light: #ffebe6;
  --error-dark: #bf2600;
  --danger: #de350b;
  --danger-bg: rgba(222, 53, 11, 0.1);
  --danger-glow: rgba(222, 53, 11, 0.15);

  --info: #0065ff;
  --info-light: #deebff;

  /* === Neutral Palette === */
  --gray-50: #fafbfc;
  --gray-100: #f4f5f7;
  --gray-200: #ebecf0;
  --gray-300: #dfe1e6;
  --gray-400: #c1c7d0;
  --gray-500: #a5adba;
  --gray-600: #6b778c;
  --gray-700: #505f79;
  --gray-800: #344563;
  --gray-900: #172b4d;
  --gray-950: #091e42;

  /* === Surface Colors (Light Mode) === */
  --bg: #fafbfc;
  --bg-alt: #f4f5f7;
  --card: #ffffff;
  --card-bg: #ffffff;
  --card-elevated: #ffffff;

  /* Dark Surfaces */
  --surface-void: #000000;
  --surface-obsidian: #0a0a0a;
  --surface-carbon: #0d1117;
  --surface-graphite: #161b22;
  --surface-slate: #1c2128;

  /* === Text Colors (WCAG 2.2 AA compliant with safety margins) === */
  --text: #172b4d; /* 12.6:1 on white - WCAG AAA ✅ */
  --text-primary: #172b4d; /* 12.6:1 on white - WCAG AAA ✅ */
  --text-secondary: #505f79; /* 7.6:1 on white - WCAG AAA ✅ */
  --text-muted: #5a6a85; /* 5.5:1 on white - WCAG AA ✅ (+1.0 safety margin) (was #6b778c - 4.64:1) */
  --text-tertiary: #505f79; /* 7.6:1 on white - WCAG AAA ✅ (use secondary for consistency) */
  --text-inverse: #ffffff; /* Maximum contrast */

  /* === Border Colors === */
  --border: #dfe1e6;
  --border-subtle: #30363d;
  --border-light: #ebecf0;
  --border-strong: #c1c7d0;

  /* === Typography === */
  --font-sans:
    "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-display: "Plus Jakarta Sans", var(--font-sans);
  --font-mono: "JetBrains Mono", "SF Mono", "Fira Code", monospace;

  /* Font Sizes */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;
  --text-4xl: 2.25rem;
  --text-5xl: 3rem;
  --text-display-md: 3.5rem;
  --text-display-lg: 4rem;

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

  /* === Spacing === */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4rem;
  --space-4xl: 6rem;

  /* Numeric Spacing Scale */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-16: 4rem;
  --space-24: 6rem;

  /* === Border Radius === */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-2xl: 24px;
  --radius-full: 9999px;

  /* === Shadows === */
  --shadow-xs: 0 1px 2px 0 rgba(23, 43, 77, 0.04);
  --shadow-sm:
    0 1px 3px 0 rgba(23, 43, 77, 0.06), 0 1px 2px -1px rgba(23, 43, 77, 0.06);
  --shadow:
    0 4px 6px -1px rgba(23, 43, 77, 0.08), 0 2px 4px -2px rgba(23, 43, 77, 0.06);
  --shadow-md:
    0 4px 6px -1px rgba(23, 43, 77, 0.08), 0 2px 4px -2px rgba(23, 43, 77, 0.06);
  --shadow-lg:
    0 10px 15px -3px rgba(23, 43, 77, 0.08),
    0 4px 6px -4px rgba(23, 43, 77, 0.04);
  --shadow-xl:
    0 20px 25px -5px rgba(23, 43, 77, 0.1),
    0 8px 10px -6px rgba(23, 43, 77, 0.06);
  --shadow-2xl: 0 25px 50px -12px rgba(23, 43, 77, 0.25);
  --shadow-primary: 0 4px 14px 0 rgba(0, 102, 255, 0.25);
  --shadow-glow-electric: 0 0 30px rgba(0, 212, 255, 0.3);

  /* === Transitions === */
  --transition-fast: 100ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 300ms ease;

  /* Duration Values */
  --duration-fast: 150ms;
  --duration-normal: 200ms;
  --duration-slow: 300ms;

  /* Easing Functions */
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Card Backgrounds */
  --card-solid: var(--bg-elevated);

  /* === Z-Index === */
  --z-dropdown: 1000;
  --z-sticky: 1100;
  --z-modal: 1400;
  --z-toast: 1700;
  --z-tooltip: 1800;

  /* === Layout === */
  --container-sm: 640px;
  --container-md: 768px;
  --container-lg: 1024px;
  --container-xl: 1280px;

  /* Component Tokens */
  --nav-height: 64px;
  --touch-target: 44px;

  /* Safe Areas (iOS notch support) */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

/* === Dark Mode === */
@media (prefers-color-scheme: dark) {
  :root {
    /* Brand - slightly lighter for dark mode */
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --primary-light: #60a5fa;
    --primary-bg: rgba(59, 130, 246, 0.15);
    --primary-hover: rgba(59, 130, 246, 0.25);

    /* Semantic - adjusted for dark backgrounds */
    --success: #36b37e;
    --success-light: rgba(0, 135, 90, 0.15);
    --warning: #ffab00;
    --warning-light: rgba(255, 139, 0, 0.15);
    --error: #ff5630;
    --error-light: rgba(222, 53, 11, 0.15);

    /* Surfaces */
    --bg: #0d1117;
    --bg-alt: #161b22;
    --card: #161b22;
    --card-bg: #161b22;
    --card-elevated: #21262d;

    /* Text (WCAG 2.2 AA compliant on dark bg) */
    --text: #f0f6fc;
    --text-primary: #f0f6fc;
    --text-secondary: #c9d1d9; /* 8.5:1 on #0d1117 - improved from #b1bac4 */
    --text-tertiary: #b1bac4; /* 6.3:1 on #0d1117 */
    --text-muted: #9ca3af; /* 4.6:1 on #0d1117 - was #6e7681 */
    --text-inverse: #172b4d;

    /* Borders */
    --border: #30363d;
    --border-light: #21262d;
    --border-strong: #484f58;

    /* Dark mode shadows */
    --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.4);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
  }
}

/* === Forced Dark Theme (add .dark-theme to body) === */
.dark-theme {
  /* Brand - slightly lighter for dark mode */
  --primary: #0066ff;
  --primary-dark: #0052cc;
  --primary-light: #3b82f6;
  --primary-bg: rgba(0, 102, 255, 0.15);
  --primary-hover: rgba(0, 102, 255, 0.25);

  /* Semantic - adjusted for dark backgrounds */
  --success: #36b37e;
  --success-light: rgba(0, 135, 90, 0.15);
  --warning: #ffab00;
  --warning-light: rgba(255, 139, 0, 0.15);
  --error: #ff5630;
  --error-light: rgba(222, 53, 11, 0.15);

  /* Surfaces */
  --bg: #0d1117;
  --bg-alt: #161b22;
  --card: #161b22;
  --card-bg: #161b22;
  --card-elevated: #21262d;

  /* Text (WCAG 2.2 AA compliant on dark bg) */
  --text: #f0f6fc;
  --text-primary: #f0f6fc;
  --text-secondary: #c9d1d9; /* 8.5:1 on #0d1117 - improved from #b1bac4 */
  --text-tertiary: #b1bac4; /* 6.3:1 on #0d1117 */
  --text-muted: #9ca3af; /* 4.6:1 on #0d1117 - was #6e7681 */
  --text-inverse: #172b4d;

  /* Borders */
  --border: #30363d;
  --border-light: #21262d;
  --border-strong: #484f58;

  /* Dark mode shadows */
  --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.4);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
}

/* === Reduced Motion === */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* === Base Reset === */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Focus styles for accessibility */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

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

/* ============================================================
   DARK SURFACE TEXT - WCAG 2.2 AA Compliant
   Use these on dark backgrounds for guaranteed readability
   ============================================================ */

/* Text colors for dark surfaces (guaranteed high contrast) */
.text-on-dark {
  color: #f0f6fc !important; /* 14.7:1 on #0d1117 */
}

.text-on-dark-secondary {
  color: #c9d1d9 !important; /* 8.5:1 on #0d1117 */
}

.text-on-dark-muted {
  color: #9ca3af !important; /* 4.6:1 on #0d1117 - WCAG AA minimum */
}

/* Auto-apply light text in dark surface containers */
.surface-dark,
.bg-dark,
[class*="surface-slate"],
[class*="surface-graphite"],
[class*="surface-carbon"],
[class*="surface-obsidian"],
[class*="surface-void"] {
  color: #f0f6fc;
}

.surface-dark *,
.bg-dark * {
  --text-primary: #f0f6fc;
  --text-secondary: #c9d1d9;
  --text-muted: #9ca3af;
}

/* Global placeholder styling for inputs/textareas */
input::placeholder,
textarea::placeholder {
  color: var(--text-muted, #9ca3af);
  opacity: 1; /* Firefox fix */
}

/* Dark theme placeholder colors */
.dark-theme input::placeholder,
.dark-theme textarea::placeholder {
  color: #9ca3af; /* 4.6:1 on dark backgrounds */
}

/* High contrast mode support */
@media (prefers-contrast: more) {
  :root {
    --text-primary: #000000;
    --text-secondary: #1a1a1a;
    --text-muted: #333333;
  }

  .dark-theme {
    --text-primary: #ffffff;
    --text-secondary: #f0f0f0;
    --text-muted: #cccccc;
  }
}
