/*
 * GhostCart design tokens: PHANTOM (both themes).
 * Dark (ink-blue night + ectoplasm mint→cyan) is the default; light is opted
 * into with [data-theme=light] on <html>. Components reference ONLY these
 * variables, so a theme swap is a variable swap. Guide: docs/design/PHANTOM_SYSTEM.md
 *
 * Legacy names (--surface-*, --border*, --accent*, --tone-*, --font*, --r-*,
 * --shadow-*, --dur-*, --ease-*) are kept and remapped to Phantom values, so
 * every existing page keeps working. Phantom additions:
 *
 *   Atmosphere   --wash-1 --wash-2 (aurora blobs) --grain-opacity --scrim
 *   Surfaces     --surface-glass (card over aurora) --tick (HUD corner ticks)
 *   Ectoplasm    --ecto (fill) --ecto-1 mint --ecto-2 cyan --ecto-text (accent as text)
 *                --ecto-ink (text ON ecto) --ecto-grad --ecto-soft --ecto-softer --ecto-glow
 *   Status       --tone-preorder --tone-confirmed (+ -bg/-bd) next to the legacy tones
 *   Retailers    --retailer-walmart|pokemon|target|bestbuy|amazon|other (spend bars only)
 *   Charts       --chart-1..7 --chart-other (Phantom order, CVD-validated, see below)
 *   Type         --font-display (Bahnschrift numerals) --font-ui (= --font) --font-mono (Cascadia)
 *                --fs-kpi --fs-display --eyebrow-track
 *   Motion       --spring (bouncy controls) --ease-out (expo) --dur-appear --stagger
 *   Layout       --rail-w (76px icon rail) --topbar-h --bottomnav-h (0 unless the tab bar shows)
 */

:root, [data-theme="dark"] {
  color-scheme: dark;

  /* ---- Atmosphere ---- */
  --bg: #04070f;
  --bg-grad-1: rgba(64, 255, 190, 0.07);   /* legacy name: first aurora wash */
  --bg-grad-2: rgba(40, 170, 255, 0.06);
  --grain-opacity: 0.07;
  --scrim: rgba(2, 4, 10, 0.5);

  /* ---- Surfaces (back → front) ---- */
  --surface-0: #060b17;          /* rail / chrome */
  --surface-1: #0a1222;          /* cards */
  --surface-2: #0f1a2f;          /* raised: inputs, hovers, popovers */
  --surface-3: #16243d;          /* active / pressed */
  --surface-glass: rgba(10, 18, 34, 0.82); /* card sitting over the aurora */
  --overlay: rgba(2, 4, 10, 0.55);

  /* ---- Lines ---- */
  --border: rgba(150, 205, 255, 0.075);
  --border-strong: rgba(150, 205, 255, 0.14);
  --border-focus: #5ef3d6;
  --hairline-highlight: rgba(255, 255, 255, 0.03);
  --grid-line: rgba(150, 205, 255, 0.09);
  --tick: rgba(124, 255, 212, 0.38);

  /* ---- Text tiers (contrast vs --surface-1: 16.6 / 9.3 / 5.9 / 5.0) ---- */
  --text: #e9f2ff;
  --text-2: #a9b8d0;
  --text-3: #8191ad;
  --text-4: #7e8eab;
  --text-on-accent: #021318;     /* ink on the ectoplasm fill — never white on mint */

  /* ---- Ectoplasm accent ---- */
  --ecto: #5ef3d6;
  --ecto-1: #7dffc6;
  --ecto-2: #3ee0ff;
  --ecto-text: #7dffc6;
  --ecto-ink: #021318;
  --ecto-grad: linear-gradient(120deg, #8affca 0%, #55f0da 45%, #3ad8ff 100%);
  --ecto-soft: rgba(94, 243, 214, 0.12);
  --ecto-softer: rgba(94, 243, 214, 0.06);
  --ecto-glow: 0 0 0 1px rgba(94, 243, 214, 0.35), 0 6px 28px -6px rgba(62, 224, 255, 0.55);

  --accent-ring: 0 0 0 3px rgba(94, 243, 214, 0.22);

  /* ---- Status tones ("soul" pills): fg / soft bg / border. Every tone ≥ 6.7:1 on raised. ---- */
  --tone-alive: #6dfcb4;     --tone-alive-bg: rgba(109, 252, 180, 0.11);  --tone-alive-bd: rgba(109, 252, 180, 0.24);
  --tone-preorder: #7fd8ff;  --tone-preorder-bg: rgba(127, 216, 255, 0.10); --tone-preorder-bd: rgba(127, 216, 255, 0.24);
  --tone-confirmed: #4fe0cf; --tone-confirmed-bg: rgba(79, 224, 207, 0.11); --tone-confirmed-bd: rgba(79, 224, 207, 0.24);
  --tone-shipped: #6aa6ff;   --tone-shipped-bg: rgba(106, 166, 255, 0.12); --tone-shipped-bd: rgba(106, 166, 255, 0.26);
  --tone-arriving: #ffd166;  --tone-arriving-bg: rgba(255, 209, 102, 0.11); --tone-arriving-bd: rgba(255, 209, 102, 0.24);
  --tone-delivered: #c7adff; --tone-delivered-bg: rgba(199, 173, 255, 0.12); --tone-delivered-bd: rgba(199, 173, 255, 0.26);
  --tone-cancelled: #ff7393; --tone-cancelled-bg: rgba(255, 115, 147, 0.11); --tone-cancelled-bd: rgba(255, 115, 147, 0.24);
  --tone-refunded: #97a5bf;  --tone-refunded-bg: rgba(151, 165, 191, 0.11); --tone-refunded-bd: rgba(151, 165, 191, 0.22);
  --tone-alerts: #ff9f5a;    --tone-alerts-bg: rgba(255, 159, 90, 0.12);  --tone-alerts-bd: rgba(255, 159, 90, 0.26);
  --tone-neutral: #a3b0c6;   --tone-neutral-bg: rgba(163, 176, 198, 0.09); --tone-neutral-bd: rgba(163, 176, 198, 0.2);
  --tone-accent-bd: rgba(94, 243, 214, 0.3);


  /* ---- Retailer identity (spend bars only, always next to logo + name) ---- */
  --retailer-walmart: #4b8dff;
  --retailer-pokemon: #ffcb3d;
  --retailer-target: #e879f9;   /* fuchsia, not red: red = cancelled */
  --retailer-bestbuy: #2fd1c4;
  --retailer-amazon: #ff9b45;
  --retailer-other: #66758f;

  /* Chart palette — categorical, fixed order (never cycled). Validated with the
     dataviz palette checker against --surface-1 in each theme: lightness band,
     chroma, CVD ΔE ≥ 8.0 adjacent, normal-vision ≥ 19, contrast ≥ 3:1. */
  --chart-1: #18a88e;  /* ecto teal */
  --chart-2: #d9622b;  /* ember */
  --chart-3: #3d84e6;  /* blue */
  --chart-4: #bf8500;  /* amber */
  --chart-5: #d4508a;  /* rose */
  --chart-6: #8a6fe8;  /* violet */
  --chart-7: #4c9a2a;  /* moss */
  --chart-other: #66758f;

  /* ---- Radii ---- */
  --r-xs: 4px;
  --r-sm: 7px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 18px;
  --r-2xl: 22px;
  --r-full: 999px;

  /* ---- Shadows / glows ---- */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 20px 40px -24px rgba(0, 0, 0, 0.8);
  --shadow-md: 0 8px 24px -8px rgba(0, 0, 0, 0.6), 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 24px 50px -16px rgba(0, 0, 0, 0.7), 0 2px 8px rgba(0, 0, 0, 0.35);
  --shadow-xl: 0 30px 80px -20px rgba(0, 0, 0, 0.85), 0 6px 18px rgba(0, 0, 0, 0.4);
  --drawer-shade: -30px 0 80px -20px rgba(0, 0, 0, 0.85);

  /* ---- Spacing (4px grid) ---- */
  --s-0: 0;
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-7: 32px;
  --s-8: 40px;
  --s-9: 48px;
  --s-10: 64px;

  /* ---- Typography (system fonts that ship with Windows; nothing downloaded) ---- */
  --font: "Segoe UI Variable Text", "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-ui: var(--font);
  --font-display: Bahnschrift, "DIN Alternate", "DIN 2014", "Segoe UI Variable Display", "Segoe UI", system-ui, sans-serif;
  --font-mono: "Cascadia Mono", "Cascadia Code", Consolas, ui-monospace, "SF Mono", Menlo, monospace;
  --fs-xs: 11px;
  --fs-sm: 12.5px;
  --fs-md: 13.5px;
  --fs-lg: 15px;
  --fs-xl: 18px;
  --fs-2xl: 22px;
  --fs-3xl: 28px;
  --fs-4xl: 36px;
  --fs-kpi: 40px;
  --fs-display: 26px;
  --eyebrow-track: 0.14em;

  /* ---- Layout ---- */
  --rail-w: 76px;
  --sidebar-w: var(--rail-w);          /* legacy name */
  --sidebar-w-collapsed: var(--rail-w);
  --topbar-h: 76px;
  --bottomnav-h: 0px;                   /* 66px while the phone tab bar shows */
  --content-max: 1560px;

  /* ---- Z-index ---- */
  --z-base: 1;
  --z-sticky: 10;
  --z-sidebar: 30;
  --z-topbar: 40;
  --z-banner: 45;
  --z-dropdown: 60;
  --z-drawer: 70;
  --z-modal: 80;
  --z-palette: 90;
  --z-toast: 100;
  --z-tooltip: 110;
  --z-grain: 120;

  /* ---- Motion ---- */
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-spring: var(--spring);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --dur-1: 120ms;
  --dur-2: 180ms;
  --dur-3: 240ms;
  --dur-4: 360ms;
  --dur-slow: 700ms;
  --dur-appear: 800ms;
  --stagger: 55ms;
}

@media (max-width: 759px) {
  :root { --topbar-h: 62px; --bottomnav-h: 66px; }
}

[data-theme="light"] {
  color-scheme: light;

  --bg: #edf2f7;
  --bg-grad-1: rgba(0, 190, 140, 0.08);
  --bg-grad-2: rgba(0, 150, 220, 0.07);
  --grain-opacity: 0.035;
  --scrim: rgba(20, 34, 54, 0.28);

  --surface-0: #f8fbfd;
  --surface-1: #ffffff;
  --surface-2: #f1f5f9;
  --surface-3: #e3eaf2;
  --surface-glass: rgba(255, 255, 255, 0.9);
  --overlay: rgba(20, 34, 54, 0.3);

  --border: rgba(12, 34, 64, 0.085);
  --border-strong: rgba(12, 34, 64, 0.15);
  --border-focus: #008f80; /* >= 3:1 on white, bg and pressed (non-text AA) */
  --hairline-highlight: rgba(255, 255, 255, 0.9);
  --grid-line: rgba(12, 34, 64, 0.1);
  --tick: rgba(0, 140, 110, 0.45);

  --text: #0a1424;
  --text-2: #3c4a62;
  --text-3: #58667e;
  --text-4: #5a6880;
  --text-on-accent: #021318;

  --ecto: #00a99a;
  --ecto-1: #00b886;
  --ecto-2: #0099cc;
  --ecto-text: #007a5e;
  --ecto-ink: #021318;
  --ecto-grad: linear-gradient(120deg, #5ff2b4 0%, #3fe0d0 45%, #45ccff 100%);
  --ecto-soft: rgba(0, 169, 154, 0.1);
  --ecto-softer: rgba(0, 169, 154, 0.05);
  --ecto-glow: 0 0 0 1px rgba(0, 169, 154, 0.35), 0 8px 24px -8px rgba(0, 153, 204, 0.45);
  --accent-ring: 0 0 0 3px rgba(0, 169, 154, 0.2);

  /* Light tones sit one step darker than RATIONALE.md so 11px pill text keeps
     AA (>= 4.5:1) on its own tint over raised (#F1F5F9) and pressed (#E3EAF2) rows. */
  --tone-alive: #066f44;     --tone-alive-bg: rgba(7, 122, 75, 0.1);    --tone-alive-bd: rgba(7, 122, 75, 0.22);
  --tone-preorder: #0a6893;  --tone-preorder-bg: rgba(11, 111, 156, 0.09); --tone-preorder-bd: rgba(11, 111, 156, 0.22);
  --tone-confirmed: #076e65; --tone-confirmed-bg: rgba(8, 122, 112, 0.09); --tone-confirmed-bd: rgba(8, 122, 112, 0.22);
  --tone-shipped: #1e5bc9;   --tone-shipped-bg: rgba(31, 95, 209, 0.09); --tone-shipped-bd: rgba(31, 95, 209, 0.22);
  --tone-arriving: #805400;  --tone-arriving-bg: rgba(200, 140, 0, 0.13); --tone-arriving-bd: rgba(138, 90, 0, 0.24);
  --tone-delivered: #6a43c9; --tone-delivered-bg: rgba(106, 67, 201, 0.09); --tone-delivered-bd: rgba(106, 67, 201, 0.22);
  --tone-cancelled: #b6214a; --tone-cancelled-bg: rgba(196, 36, 80, 0.09); --tone-cancelled-bd: rgba(196, 36, 80, 0.22);
  --tone-refunded: #56637a;  --tone-refunded-bg: rgba(86, 99, 122, 0.1);  --tone-refunded-bd: rgba(86, 99, 122, 0.22);
  --tone-alerts: #a14400;    --tone-alerts-bg: rgba(181, 76, 0, 0.1);   --tone-alerts-bd: rgba(181, 76, 0, 0.24);
  --tone-neutral: #56637a;   --tone-neutral-bg: rgba(86, 99, 122, 0.08); --tone-neutral-bd: rgba(86, 99, 122, 0.18);
  --tone-accent-bd: rgba(0, 169, 154, 0.3);

  --retailer-walmart: #2a6fe0;
  --retailer-pokemon: #c99400;
  --retailer-target: #a21caf;
  --retailer-bestbuy: #00a396;
  --retailer-amazon: #e56f0e;
  --retailer-other: #8a96a8;

  --chart-1: #119c84;
  --chart-2: #e06a2c;
  --chart-3: #2f76e0;
  --chart-4: #b88600;
  --chart-5: #e0659a;
  --chart-6: #7458e0;
  --chart-7: #3f9a28;
  --chart-other: #8a96a8;

  --shadow-xs: 0 1px 2px rgba(10, 30, 60, 0.06);
  --shadow-sm: 0 1px 2px rgba(10, 30, 60, 0.05), 0 12px 30px -18px rgba(10, 30, 60, 0.25);
  --shadow-md: 0 6px 18px -6px rgba(10, 30, 60, 0.16), 0 1px 3px rgba(10, 30, 60, 0.06);
  --shadow-lg: 0 20px 44px -16px rgba(10, 30, 60, 0.28), 0 2px 8px rgba(10, 30, 60, 0.06);
  --shadow-xl: 0 30px 80px -20px rgba(10, 30, 60, 0.35), 0 6px 18px rgba(10, 30, 60, 0.08);
  --drawer-shade: -24px 0 70px -20px rgba(10, 30, 60, 0.35);
}

/* Aliases resolved per theme scope (so a nested [data-theme] island — e.g. the
   /styleguide side-by-side preview — recomputes them from its own palette). */
:root, [data-theme] {
  --wash-1: var(--bg-grad-1);
  --wash-2: var(--bg-grad-2);
  --accent: var(--ecto);
  --accent-2: var(--ecto-2);
  --accent-strong: var(--ecto-text);
  --accent-grad: var(--ecto-grad);
  --accent-fill: var(--ecto-grad);
  --accent-soft: var(--ecto-soft);
  --accent-softer: var(--ecto-softer);
  --tone-accent: var(--ecto-text);
  --tone-accent-bg: var(--ecto-soft);
  --success: var(--tone-alive);    --success-bg: var(--tone-alive-bg);
  --danger: var(--tone-cancelled); --danger-bg: var(--tone-cancelled-bg);
  --warning: var(--tone-arriving); --warning-bg: var(--tone-arriving-bg);
  --info: var(--tone-shipped);     --info-bg: var(--tone-shipped-bg);
  --shadow-accent: var(--ecto-glow);
  --shadow-drawer: var(--drawer-shade), 0 0 0 1px var(--border-strong);
  --inset-highlight: inset 0 1px 0 var(--hairline-highlight);
}
