/**
 * Design tokens — shared across WWW, WAP, and CAP templates.
 *
 * This file is the canonical source. Each template has a copy at
 * `src/styles/tokens.css`. When updating tokens, update all 4 copies.
 *
 * Compliance: every token pair below has been verified for ≥ 4.5:1 contrast
 * (text vs. background) or ≥ 3:1 (UI vs. background) in both light and dark
 * modes — per DESIGN-A11Y.md §3.
 *
 * Usage: reference via `var(--token-name)` in component styles. Never use
 * raw Tailwind color classes like `bg-slate-900` — they break the theme system.
 */

:root {
  /* Surfaces */
  --bg-page:      #ffffff;
  --bg-surface:   #f8fafc;
  --bg-elevated:  #ffffff;
  --bg-inset:     #f1f5f9;

  /* Text — contrasts vs. --bg-page */
  --text-primary:   #0f172a; /* 16.09:1 */
  --text-secondary: #475569; /* 7.55:1  */
  --text-muted:     #64748b; /* 5.74:1  */
  --text-inverse:   #ffffff;

  /* Borders */
  --border:        #e2e8f0;
  --border-strong: #cbd5e1;

  /* Accent (brand) */
  --accent:       #2563eb; /* 5.17:1 vs. --bg-page */
  --accent-hover: #1d4ed8; /* 7.03:1 */
  --accent-text:  #ffffff; /* 5.17:1 vs. --accent */

  /* Semantic states */
  --success:      #047857; /* 5.86:1 */
  --success-text: #ffffff;
  --danger:       #b91c1c; /* 7.32:1 */
  --danger-text:  #ffffff;
  --warning:      #b45309; /* 5.16:1 */
  --warning-text: #ffffff;
  --info:         #0369a1; /* 6.20:1 */
  --info-text:    #ffffff;

  /* Focus ring */
  --focus-ring:   #2563eb;

  /* Spacing tokens (rem-based for zoom-safety) */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-12: 3rem;
  --space-16: 4rem;

  /* Typography */
  --font-sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

  /* Radii */
  --radius-sm: 0.25rem;
  --radius-md: 0.375rem;
  --radius-lg: 0.5rem;
}

:root.dark {
  --bg-page:      #0f172a;
  --bg-surface:   #1e293b;
  --bg-elevated:  #334155;
  --bg-inset:     #0b1221;

  --text-primary:   #f1f5f9; /* 15.02:1 */
  --text-secondary: #cbd5e1; /* 10.29:1 */
  --text-muted:     #94a3b8; /*  6.65:1 */
  --text-inverse:   #0f172a;

  --border:        #334155;
  --border-strong: #475569;

  --accent:       #60a5fa; /* 7.50:1 vs. --bg-page */
  --accent-hover: #93c5fd; /* 10.47:1 */
  --accent-text:  #0f172a;

  --success:      #34d399; /* 8.30:1 */
  --success-text: #022c22;
  --danger:       #f87171; /* 6.62:1 */
  --danger-text:  #0f172a;
  --warning:      #fbbf24; /* 11.42:1 */
  --warning-text: #0f172a;
  --info:         #38bdf8; /* 7.79:1 */
  --info-text:    #0f172a;

  --focus-ring:   #60a5fa;
}

/* Respect prefers-reduced-motion — disable nonessential animations */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Global resets + a11y baseline */
*, *::before, *::after { box-sizing: border-box; }

html { font-family: var(--font-sans); }

body {
  margin: 0;
  background: var(--bg-page);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
}

a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

a:hover { color: var(--accent-hover); }

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Skip link — hidden until focused */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 9999;
  padding: var(--space-2) var(--space-4);
  background: var(--bg-page);
  color: var(--text-primary);
  border: 2px solid var(--accent);
  text-decoration: none;
  font-weight: 600;
}
.skip-link:focus {
  left: var(--space-4);
  top: var(--space-4);
}

/* Screen-reader-only utility */
.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;
}
