/* ============================================================
   EmCee - tokens.css
   Global design tokens. Loaded BEFORE main.css.

   1. Scale tokens (theme-independent): spacing, radius, motion, type.
   2. Per-theme palettes: semantic layers, text tiers, lines, status,
      and each theme's DEFAULT accent set.
   3. Legacy aliases: the old names (--bg, --surface, --border, --text...)
      now point at the new layers, so existing pages keep working.

   Rules (see CLAUDE.md "Design tokens"):
   - Spacing: 8px structural, 4px half-step. Use --sp-*, not raw px.
   - Higher elevation = lighter surface. Shadows only on --layer-3.
   - Text never goes below --text-3. --text-disabled is decoration only.
   - Accent: see src/utils/accent.js. Text may only use --accent-text;
     status colors (--ok/--warn/--err/--info) are never user-themable.
   ============================================================ */

:root {
  /* Spacing: 4px half-step, 8px structural */
  --u:    8px;
  --sp-0: 0;
  --sp-1: calc(var(--u) * 0.5);  /*  4 */
  --sp-2: var(--u);              /*  8 */
  --sp-3: calc(var(--u) * 1.5);  /* 12 */
  --sp-4: calc(var(--u) * 2);    /* 16 */
  --sp-5: calc(var(--u) * 3);    /* 24 */
  --sp-6: calc(var(--u) * 4);    /* 32 */
  --sp-7: calc(var(--u) * 6);    /* 48 */
  --sp-8: calc(var(--u) * 8);    /* 64 */
  --gutter: var(--sp-4);

  /* Control heights */
  --ctl-h-dense: 32px;
  --ctl-h:       40px;
  --ctl-h-touch: 48px;

  /* Radius and motion */
  --r-1:    4px;
  --r-2:    8px;
  --r-3:    12px;
  --r-4:    16px;
  --r-pill: 999px;
  --ease:   cubic-bezier(0.2, 0.8, 0.2, 1);
  --dur-1:  120ms;
  --dur-2:  200ms;

  /* Type scale (rem, so the user's font-size preset still scales it) */
  --fs-title:    1.75rem;    --lh-title:    2rem;
  --fs-h1:       1.5rem;     --lh-h1:       2rem;
  --fs-h2:       1.25rem;    --lh-h2:       1.75rem;
  --fs-section:  1.125rem;   --lh-section:  1.5rem;
  --fs-lead:     1rem;       --lh-lead:     1.5rem;
  --fs-body:     0.875rem;   --lh-body:     1.25rem;
  --fs-small:    0.8125rem;  --lh-small:    1rem;
  --fs-caption:  0.75rem;    --lh-caption:  1rem;
  --fs-overline: 0.6875rem;  --lh-overline: 1rem;
  --ls-overline: 0.08em;
  --fs-input:    16px;       /* iOS Safari zooms the page on focus below this */
  --fw-regular: 400;
  --fw-medium:  500;
  --fw-strong:  600;

  /* Status: fixed meaning, never overridden by the user accent */
  --warn: #f59e0b;
  --info: #5aa3ff;

  /* Accent tints: derived from --accent, so they follow a user override */
  --accent-soft:  color-mix(in srgb, var(--accent) 14%, transparent);
  --accent-ring:  color-mix(in srgb, var(--accent) 55%, transparent);
  --accent-glow:  color-mix(in srgb, var(--accent) 18%, transparent);
  --accent-muted: color-mix(in srgb, var(--accent) 18%, transparent);
}

/* ── Dark (default) ─────────────────────────────────────── */
:root, [data-theme="dark"] {
  color-scheme: dark;
  --layer-0: #0d1015;   /* app background */
  --layer-1: #131720;   /* card / surface */
  --layer-2: #1a1f2a;   /* raised: inputs, nested panels, table head */
  --layer-3: #222836;   /* floating: menus, drawer, sheet */
  --line:        #232a36;
  --line-strong: #333c4b;
  --text-1: #e6eaf2;
  --text-2: #98a3b6;
  --text-3: #7a869b;
  --text-disabled: #4b576b;
  --nav-idle: #a3aec2;
  --ok:  #3ecf8e;
  --err: #f85149;
  --accent:          #4e9eff;
  --accent-text:     #4e9eff;
  --accent-contrast: #0d1015;
  --shadow-float: 0 8px 24px rgb(0 0 0 / 0.45), 0 0 0 1px var(--line);
}

/* ── Light ──────────────────────────────────────────────── */
[data-theme="light"] {
  color-scheme: light;
  --layer-0: #f3f5f9;
  --layer-1: #ffffff;
  --layer-2: #eceff5;
  --layer-3: #ffffff;
  --line:        #dfe4ec;
  --line-strong: #c3cbd8;
  --text-1: #161c2b;
  --text-2: #536078;
  --text-3: #5f6b83;
  --text-disabled: #a3adbf;
  --nav-idle: #46536b;
  --ok:  #1a9e6a;
  --err: #d93025;
  --accent:          #1f6fd1;
  --accent-text:     #1f6fd1;
  --accent-contrast: #ffffff;
  --shadow-float: 0 8px 24px rgb(20 30 50 / 0.14), 0 0 0 1px var(--line);
}

/* ── Gray: mid-tone, kept close to its original palette ─── */
[data-theme="gray"] {
  color-scheme: dark;
  --layer-0: #3a3f47;
  --layer-1: #454b54;
  --layer-2: #4f565f;
  --layer-3: #59616c;
  --line:        #5c6570;
  --line-strong: #717b87;
  --text-1: #f0f2f5;
  --text-2: #cbd2db;
  --text-3: #bac3ce;
  --text-disabled: #8b95a3;
  --nav-idle: #c5cdd6;
  --ok:  #4ad999;
  --err: #ff6259;
  --accent:          #5aa3ff;
  --accent-text:     #88bdff;
  --accent-contrast: #0d1015;
  --shadow-float: 0 8px 24px rgb(0 0 0 / 0.4), 0 0 0 1px var(--line);
}

/* ── High contrast: unchanged in spirit; ignores user accent ─ */
[data-theme="high-contrast"] {
  color-scheme: dark;
  --layer-0: #000000;
  --layer-1: #0a0a0a;
  --layer-2: #161616;
  --layer-3: #222222;
  --line:        #f5f5f5;
  --line-strong: #ffffff;
  --text-1: #ffffff;
  --text-2: #d4d4d4;
  --text-3: #a0a0a0;
  --text-disabled: #6e6e6e;
  --nav-idle: #e8e8e8;
  --ok:  #3dff8a;
  --err: #ff3b30;
  --accent:          #ffd60a;
  --accent-text:     #ffd60a;
  --accent-contrast: #0d1015;
  --accent-glow:  color-mix(in srgb, var(--accent) 25%, transparent);
  --accent-muted: color-mix(in srgb, var(--accent) 25%, transparent);
  --shadow-float: 0 0 0 2px var(--line);
}

/* ── Interaction overlays + legacy aliases ──────────────────
   Applied on any themed element so a nested [data-theme] works. */
:root, [data-theme] {
  --hover:    color-mix(in srgb, var(--text-1) 5%, transparent);
  --pressed:  color-mix(in srgb, var(--text-1) 9%, transparent);
  --selected: var(--accent-soft);

  --bg:         var(--layer-0);
  --surface:    var(--layer-1);
  --surface-2:  var(--layer-2);
  --border:     var(--line);
  --border-hi:  var(--line-strong);
  --text:       var(--text-1);
  --text-muted: var(--text-2);
  --text-dim:   var(--text-3);
}

/* One consistent, always-visible keyboard focus ring (accent-derived) */
:focus-visible {
  outline: 2px solid var(--accent-ring);
  outline-offset: 2px;
}
