/*
 * @chadon/ui-tokens: shared design tokens for Member Web and Admin Web.
 *
 * Layer 1 holds primitives (raw values); layer 2 holds semantic roles used by
 * components. Layer 3 holds Admin Web aliases for density, tables, sidebar and
 * controls, using existing tokens or plain dimensions, with no new colours.
 * The CJK stacks include 'Noto Sans CJK TC' / 'Noto Sans CJK SC' fallbacks.
 * No font is downloaded and nothing here makes a network request.
 * The Cashier App keeps apps/cashier/src/ui/theme.ts by value; a later follow-up
 * will check parity.
 * Design and rationale: docs/design/admin-web.md, "Tokens".
 */

:root {
  /* ---------- Layer 1: primitives ---------- */

  /*
   * Cha Don signboard palette, sampled from photos of the stores and menus
   * (navy lettering, orange sign, red ribbon, cream roundels). Replace with the
   * official brand values when the brand file arrives. Greens and teals are
   * deliberately absent: they read as a competitor's.
   */
  --navy-950: #0d1233;
  --navy-900: #141e4f;
  --navy-800: #18235a;
  --navy-700: #1e2c6e;
  --navy-600: #2f3f86;
  --navy-300: #9aa4d6;
  --navy-200: #c9cfee;
  --navy-100: #e6e9f7;

  --sign-700: #c9661c;
  --sign-600: #e9771f;
  --sign-500: #f39a3c;
  --sign-400: #f7b25a;
  --sign-300: #f9c47d;
  --sign-100: #fde7c6;

  --ribbon-800: #7f1820;
  --ribbon-700: #9e1f27;
  --ribbon-600: #c62b33;
  --ribbon-100: #f9dcdc;

  --cream-300: #f7e6c8;
  --cream-200: #fbebcf;
  --cream-100: #fdf5e6;
  --cream-50: #fbf5ea;

  /* Warm neutrals, so greys sit with the cream rather than against it. */
  --n-0: #ffffff;
  --n-25: #fffcf6;
  --n-50: #fbf5ea;
  --n-100: #f3ead8;
  --n-200: #e8dcc4;
  --n-300: #d3c4a6;
  --n-400: #a8997c;
  --n-500: #7d7262;
  --n-600: #5d5548;
  --n-700: #453f37;
  --n-800: #2e2a25;
  --n-850: #24211d;
  --n-900: #1c1a17;
  --n-950: #12110f;

  /* Status hues. Independent of the brand so a brand swap never breaks meaning. */
  --green-600: #1c7a45;
  --green-100: #dcf1e3;
  --amber-600: #9c5a00;
  --amber-100: #fbecd2;
  --red-600: #b42318;
  --red-100: #fbe0dd;
  --blue-600: #2456a5;
  --blue-100: #dde7f8;

  /* ---------- Layer 2: semantic roles (light) ---------- */

  --bg: var(--cream-50);
  --surface: var(--n-0);
  --surface-2: var(--n-25);
  --surface-sunken: var(--n-100);
  --line: var(--n-200);
  --line-strong: var(--n-300);
  --text: var(--navy-900);
  --text-2: var(--n-600);
  --text-3: var(--n-500);
  --text-inverse: var(--n-0);

  --brand: var(--navy-700);
  --brand-hover: var(--navy-800);
  --brand-strong: var(--navy-900);
  --brand-soft: var(--cream-200);
  --brand-softer: var(--cream-100);
  --on-brand: var(--n-0);

  /* The membership card is always a dark surface in both themes. */
  --card-bg: var(--sign-400);
  --card-bg-2: var(--sign-500);
  --card-text: var(--navy-900);
  --card-text-2: var(--navy-700);
  --card-line: rgba(20, 30, 79, 0.2);

  --points: var(--ribbon-600);
  --points-soft: var(--ribbon-100);
  --points-on-card: var(--navy-900);

  --success: var(--green-600);
  --success-soft: var(--green-100);
  --warning: var(--amber-600);
  --warning-soft: var(--amber-100);
  --danger: var(--red-600);
  --danger-soft: var(--red-100);
  --info: var(--blue-600);
  --info-soft: var(--blue-100);
  --focus: var(--navy-600);

  --scrim: rgba(15, 19, 17, 0.48);
  --camera: #050807;

  /* ---------- Typography ---------- */

  /*
   * Latin and digits come from Figtree; CJK falls through to Noto Sans TC or SC.
   * The :lang() rules below swap the CJK face so Simplified text never renders
   * with Traditional glyph forms.
   */
  --font-latin: 'Figtree', 'Segoe UI', system-ui, sans-serif;
  --font-cjk: 'Noto Sans TC', 'Noto Sans CJK TC', 'PingFang TC', 'Microsoft JhengHei', sans-serif;
  --font-cjk-display: 'Noto Serif TC', 'Songti TC', 'PMingLiU', serif;
  --font-sans: var(--font-latin), var(--font-cjk);
  --font-display: var(--font-cjk-display);
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', monospace;

  /* Type scale (rem at 16px). 12px is the floor: CJK strokes blur below it. */
  --fs-xs: 0.75rem; /* 12  captions, table meta */
  --fs-sm: 0.875rem; /* 14  secondary text */
  --fs-md: 1rem; /* 16  body, inputs */
  --fs-lg: 1.125rem; /* 18  emphasised body, list titles */
  --fs-xl: 1.375rem; /* 22  section titles */
  --fs-2xl: 1.75rem; /* 28  screen titles */
  --fs-3xl: 2.25rem; /* 36  points on card, admin KPIs */
  --fs-4xl: 3rem; /* 48  cashier amounts */
  --fs-5xl: 4rem; /* 64  cashier result */

  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;

  /* CJK needs more leading than Latin; the :lang() rules adjust these. */
  --lh-tight: 1.2;
  --lh-heading: 1.25;
  --lh-body: 1.5;
  --tracking-label: 0.06em;

  /* ---------- Spacing (4px grid) ---------- */

  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.25rem;
  --sp-6: 1.5rem;
  --sp-8: 2rem;
  --sp-10: 2.5rem;
  --sp-12: 3rem;
  --sp-16: 4rem;

  /* ---------- Radius ---------- */

  --r-xs: 4px; /* chips, table badges */
  --r-sm: 8px; /* inputs, small buttons */
  --r-md: 12px; /* buttons, list cards */
  --r-lg: 16px; /* panels, sheets */
  --r-xl: 24px; /* membership card */
  --r-pill: 999px;

  /* ---------- Elevation ---------- */

  --e-0: none;
  --e-1: 0 1px 2px rgba(15, 19, 17, 0.06), 0 1px 1px rgba(15, 19, 17, 0.04);
  --e-2: 0 4px 12px rgba(15, 19, 17, 0.08), 0 1px 3px rgba(15, 19, 17, 0.06);
  --e-3: 0 16px 40px rgba(15, 19, 17, 0.16), 0 4px 10px rgba(15, 19, 17, 0.08);

  /* ---------- Touch targets ---------- */

  --target-min: 44px; /* member and admin */
  --target-counter: 64px; /* cashier at a busy counter */

  --motion-fast: 120ms;
  --motion-med: 220ms;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

/* ---------- Dark theme ---------- */

/*
 * Light only for now. The register, sign-in, and other screens that predate
 * these tokens still use globals.css with hard-coded light colours, so an
 * automatic dark theme made their inputs navy on navy. Dark mode returns as an
 * explicit opt-in (data-theme='dark', below) once every screen uses these
 * semantic roles.
 */
:root:not([data-theme='dark']) {
  color-scheme: light;
}
:root[data-theme='dark'] {
  --bg: var(--navy-950);
  --surface: #151c45;
  --surface-2: #1a2252;
  --surface-sunken: #0a0e29;
  --line: #2a3366;
  --line-strong: #3a4580;
  --text: var(--cream-100);
  --text-2: #c9c3d9;
  --text-3: #a39dba;
  --text-inverse: var(--n-950);
  --brand: var(--sign-400);
  --brand-hover: var(--sign-300);
  --brand-strong: var(--sign-100);
  --brand-soft: #262f63;
  --brand-softer: #1a2252;
  --on-brand: var(--navy-950);
  --card-bg: var(--sign-400);
  --card-bg-2: var(--sign-500);
  --card-line: rgba(20, 30, 79, 0.2);
  --points: var(--sign-300);
  --points-soft: #3a2a12;
  --success: #6fcf97;
  --success-soft: #15291d;
  --warning: #f0b054;
  --warning-soft: #2f2210;
  --danger: #f2877d;
  --danger-soft: #331715;
  --info: #8fb2ee;
  --info-soft: #172338;
  --focus: var(--sign-300);
  --scrim: rgba(0, 0, 0, 0.62);
  --e-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --e-2: 0 4px 12px rgba(0, 0, 0, 0.45);
  --e-3: 0 16px 40px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

/* ---------- Locale-aware typography ---------- */

:lang(zh-Hans) {
  --font-cjk: 'Noto Sans SC', 'Noto Sans CJK SC', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --font-cjk-display: 'Noto Serif SC', 'Songti SC', 'SimSun', serif;
}
:lang(zh-Hant),
:lang(zh-Hans) {
  /* Re-resolve the composite stacks where the CJK face changes. */
  --font-sans: var(--font-latin), var(--font-cjk);
  --font-display: var(--font-cjk-display);
}
:lang(zh) {
  /* Chinese reads better with looser leading and no added tracking. */
  --lh-heading: 1.35;
  --lh-body: 1.7;
  --tracking-label: 0.02em;
}
:lang(en) {
  --font-sans: var(--font-latin), 'Noto Sans TC', sans-serif;
  --font-display: var(--font-latin);
}

/* ---------- Layer 3: Admin Web (aliases only, no new colours) ---------- */

/*
 * Admin Web is desktop-first and data-dense, so it adds density, table and
 * sidebar roles. Values alias existing tokens or use plain dimensions. Contrast ratios
 * for each pair are listed in docs/design/admin-web.md and checked by
 * docs/design/previews/admin-web/contrast.py.
 */
:root {
  /* Shell */
  --admin-sidebar-w: 248px;
  --admin-sidebar-w-compact: 216px; /* 1024 to 1279 px viewports */
  --admin-header-h: 64px;
  --admin-content-max: 1200px;
  --admin-gutter: var(--sp-8); /* 32px; 24px below 1280px */

  --admin-sidebar-bg: var(--navy-900);
  --admin-sidebar-text: var(--cream-100); /* 14.6 : 1 */
  --admin-sidebar-text-2: var(--navy-200); /* 10.3 : 1, group labels */
  --admin-sidebar-hover-bg: var(--navy-800);
  --admin-sidebar-active-bg: var(--navy-700);
  --admin-sidebar-active-text: var(--n-0); /* 12.8 : 1 */
  --admin-sidebar-indicator: var(--sign-400); /* 7.0 : 1 on active bg */
  --admin-sidebar-focus: var(--sign-300); /* light ring on the dark rail */

  --admin-header-bg: var(--surface);
  --admin-header-line: var(--line);

  /* Controls. Inputs need a 3 : 1 boundary (WCAG 1.4.11); --line is 1.4 : 1. */
  --admin-control-h: var(--target-min); /* 44px, kept from the shared token */
  --admin-control-h-sm: 32px; /* table row actions; above the 24px minimum */
  --admin-control-border: var(--n-500); /* 4.7 : 1 on white */
  --admin-control-border-hover: var(--n-600);
  --admin-control-bg: var(--surface);
  --admin-control-disabled-bg: var(--surface-sunken);

  /* Tables */
  --admin-row-h: 48px;
  --admin-row-h-compact: 40px;
  --admin-cell-px: var(--sp-4);
  --admin-table-header-bg: var(--surface-sunken);
  --admin-table-header-text: var(--text-2); /* 6.2 : 1 */
  --admin-table-line: var(--line);
  --admin-table-row-hover: var(--brand-softer);
  --admin-table-row-selected: var(--brand-soft);

  /* Text that may sit on --bg. --text-3 is 4.3 : 1 there, so admin meta text
     uses --text-2 off white surfaces and --text-3 only on --surface. */
  --admin-text-meta: var(--text-2);

  /* Panels and dialogs */
  --admin-panel-radius: var(--r-md);
  --admin-panel-pad: var(--sp-6);
  --admin-dialog-w: 520px;
  --admin-toast-w: 360px;

  /* Data */
  --admin-num-font: var(--font-latin); /* tabular figures set in CSS */
  --admin-kpi-size: var(--fs-3xl);
}

@media (max-width: 1279px) {
  :root {
    --admin-sidebar-w: var(--admin-sidebar-w-compact);
    --admin-gutter: var(--sp-6);
  }
}
