/* ===================================================================
   Dina design tokens — THE single source of truth for every Dina product.

   Reconciled from the two existing implementations:
     • DinaCode  apps/web/src/app/globals.css  (the `--acc-*` / `--ink-*` / `--paper-*` names)
     • DinaChat  apps/dashboard/src/styles/tokens.css (the `--grad` / `--dark-*` / `--bg` names)

   The VALUES were already ~98% identical; only the NAMES differed. DinaCode's names win
   because design.md (shipped here as DESIGN.md) specifies them in writing. DinaChat keeps
   working by importing `compat-dinachat.css`, which aliases its names onto these.

   Two values genuinely diverged and are settled here:
     --d-faint  #6a6a86  (DinaCode) — DinaChat had #6f6f8a on the same role
     --err-bg   #fdeceb  (DinaCode) — DinaChat had #fdf2f1
   Both are within a shade of each other; picking one is the point of this file.

   Import order in a consuming app's stylesheet:
     @import '@dinalabs/ui/tokens.css';
     @import '@dinalabs/ui/base.css';        (optional reset)
     @import '@dinalabs/ui/components.css';  (if you use the React primitives)
   =================================================================== */

:root {
  /* ── accent — the one constant across every surface and every product ──────
     The gradient is rationed on purpose. It belongs to the primary button, the logo
     mark, the active nav item, unread counters, progress fills, active toggles and
     gradient badges — and nothing else. Ink on top of it is ALWAYS --ink-on-grad. */
  --acc-1: #8b5cf6;
  --acc-2: #22d3ee;
  --acc-grad: linear-gradient(115deg, var(--acc-1), var(--acc-2));
  --acc-glow: color-mix(in oklch, var(--acc-1) 55%, var(--acc-2));
  /* 13% tint of the gradient, for badges that may not carry the full fill. */
  --acc-tint: linear-gradient(115deg, rgba(139, 92, 246, 0.13), rgba(34, 211, 238, 0.13));
  --acc-tint-soft: linear-gradient(115deg, rgba(139, 92, 246, 0.1), rgba(34, 211, 238, 0.1));
  /* Text on any gradient fill. Near-black, NEVER white — see DESIGN.md §3. */
  --ink-on-grad: #0a0a12;
  /* The accent as a flat colour, for a dot or an icon stroke that cannot take a gradient. */
  --violet: #8b5cf6;
  /* Focus ring — 3px of accent at 14%. */
  --ring: 0 0 0 3px rgba(139, 92, 246, 0.14);

  /* ── dark surfaces ───────────────────────────────────────────────────────── */
  --ink-0: #07070e; /* deepest — page bg, sidebar */
  --ink-1: #0c0c16; /* hero bg */
  --ink-2: #12121f; /* raised panel */
  --ink-3: #1a1a2b; /* card */
  --ink-line: rgba(255, 255, 255, 0.08);
  --ink-line-strong: rgba(255, 255, 255, 0.1);
  --ink-fill: rgba(255, 255, 255, 0.07);

  /* ── light surfaces ──────────────────────────────────────────────────────── */
  --paper-0: #f5f5fa; /* app bg */
  --paper-1: #ffffff; /* card */
  --paper-2: #ededf4; /* inset / track */
  --paper-3: #f9f9fd; /* field bg */
  --paper-line: #e6e6f0; /* border */
  /* A ramp of progressively softer hairlines, for table rows and nested dividers. */
  --paper-line-row: #eff0f6;
  --paper-line-soft: #f0f0f7;
  --paper-line-softer: #f3f3f9;
  --paper-track: #d8d8e4; /* scrollbar thumb, toggle track */

  /* ── text ────────────────────────────────────────────────────────────────── */
  --l-fg: #14141f; /* on light */
  --l-mut: #5b5b73;
  --l-faint: #8a8aa2;
  --d-fg: #ececf6; /* on dark */
  --d-mut: #9a9ab4;
  --d-faint: #6a6a86;

  /* ── status ──────────────────────────────────────────────────────────────── */
  --ok: #16915b;
  --ok-bg: #e6f9ee;
  --warn: #c5780a;
  --warn-bg: #fff2e0;
  --warn-bd: #f0d9ae;
  --warn-deep: #8a5405;
  --info: #2563c9;
  --info-bg: #e7f0ff;
  --err: #d6453f;
  --err-bg: #fdeceb;
  --err-bd: #f4d5d4;
  --err-deep: #a8322d;
  --err-fill: #fbe4e3;
  --gold: #f5b301;

  /* ── categorical scale — the ONLY palette for "colour means a category" ───
     Charts, legends, board cells, tokens in a diagram: anywhere a fill is a
     category rather than a status. Ordered and stable, so «رنگ سوم» is the same
     colour in every product and every chart.

     Derived by mixing the status/accent hues against `--c-ground` — the surface
     the series actually sits on — so one set of declarations covers a light card
     and a dark panel. A dark subtree redefines ONLY `--c-ground` (see base.css's
     `.dina-on-dark`) and the whole ramp follows. Promoted from DinaCode's MathLab
     (`--ml-c1..c6`), which proved the approach.

     Never pick a fresh hex for a series. Never use a status colour (--ok, --err)
     to mean a category: a green bar that means "third quarter" and a green bar
     that means "healthy" cannot both be true on one page.

     Hue alone fails a colour-blind reader, a greyscale print and forced-colours
     mode — so anywhere the category is load-bearing (not just decorative), draw
     the flat tone AND `tonePattern()` over it. See src/viz/tones.ts. */
  --c-ground: var(--paper-1);
  --c1: color-mix(in oklch, var(--acc-1) 74%, var(--c-ground));
  --c2: color-mix(in oklch, var(--acc-2) 74%, var(--c-ground));
  --c3: color-mix(in oklch, var(--ok) 74%, var(--c-ground));
  /* Gold mixed toward the ground goes muddy on white, so it leans on the ink instead.
     The one exception, and it earns it — a yellow series on paper is otherwise invisible. */
  --c4: color-mix(in oklch, var(--gold) 82%, var(--l-fg));
  --c5: color-mix(in oklch, var(--warn) 74%, var(--c-ground));
  --c6: color-mix(in oklch, var(--info) 74%, var(--c-ground));

  /* Accent-tinted "verified / special" row, used where the gradient itself is too loud. */
  --verified-fg: #5b21b6;
  --verified-bd: rgba(139, 92, 246, 0.32);
  --sel-bg: #f4f1ff;
  --fresh-bg: #fdfbff;

  /* ── syntax (dark code surfaces) ─────────────────────────────────────────── */
  --syn-key: #c79bff;
  --syn-fn: #62d6ff;
  --syn-str: #7ce8b0;
  --syn-num: #ffb86b;
  --syn-com: #6a6a86;
  --syn-punc: #b9b9d6;
  --syn-id: #ececf6;

  /* ── geometry ────────────────────────────────────────────────────────────── */
  --r-xs: 6px;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 28px;
  --r-pill: 100px;

  --shadow-card: 0 1px 2px rgba(20, 20, 40, 0.04), 0 12px 28px -20px rgba(40, 30, 80, 0.28);
  --shadow-pop: 0 20px 48px -24px rgba(40, 30, 80, 0.42);
  --shadow-glow: 0 10px 28px -12px var(--acc-glow);

  /* ── glass ───────────────────────────────────────────────────────────────── */
  /* The frosted surface the marketing sites layer over an accent wash: `.dina-glass`, the site
     nav, and any landing card that wants the same frosting. Light ground only — on the ink
     canvas a white film reads as grey haze, not glass. Without a vibrant wash behind it a glass
     card is just a pale card, so a page that uses these paints one. */
  --glass-bg: color-mix(in srgb, var(--paper-1) 58%, transparent);
  --glass-bg-strong: color-mix(in srgb, var(--paper-1) 78%, transparent);
  --glass-line: color-mix(in srgb, var(--paper-1) 80%, transparent);
  --glass-line-soft: color-mix(in srgb, var(--l-fg) 8%, transparent);
  --glass-blur: 18px;

  /* ── motion ──────────────────────────────────────────────────────────────── */
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --t-fast: 120ms;
  --t-slow: 200ms;

  /* ── type ────────────────────────────────────────────────────────────────── */
  /* `--font-estedad` / `--font-jetbrains` come from next/font/local on <html> — see
     @dinalabs/ui/fonts — which hashes the family name, so the variable is the only way
     to reach it.

     ⚠ EVERY `var()` HERE CARRIES A FALLBACK, and that is load-bearing, not tidiness.
     A `var()` naming an undefined property with NO fallback is invalid at
     computed-value time, and CSS drops the WHOLE declaration — not just that one entry.
     So in an app that self-hosts with plain `@font-face` instead of next/font (دینا چت
     does; its own fonts.css declares the families), `--ui` resolved to nothing at all
     and every page fell back to Times. The literal family names below are what such an
     app matches on, and they must stay.

     Estedad sits in the MONO stack on purpose (DinaChat's finding): JetBrains Mono
     carries no usable Persian glyphs, so Persian that turns up inside otherwise-Latin
     code — a `title` in a JSON tool result — would fall back to whatever the OS picked
     and stop matching the product. With Estedad next in line, Latin comes from the mono
     face and Persian always comes from Estedad. */
  --ui: var(--font-estedad, 'Estedad'), 'Vazirmatn', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  --mono: var(--font-jetbrains, 'JetBrains Mono'), var(--font-estedad, 'Estedad'), ui-monospace, 'SF Mono', Menlo, monospace;

  /* Fluid display scale (marketing surfaces). */
  --fz-hero: clamp(2.6rem, 6vw, 5rem);
  --fz-h2: clamp(2rem, 4vw, 3.25rem);
  --fz-h3: clamp(1.3rem, 2vw, 1.7rem);

  /* ── layout ──────────────────────────────────────────────────────────────── */
  --wrap: 1200px;
  --sb-w: 264px;
  --topbar-h: 62px;
  --bottom-tab-h: 60px;
  --mobile-topbar-h: 56px;
}

/* ===================================================================
   Dark theme (v0.21.0; دینا چت's panel first, owner 2026-11-15).

   `data-theme="dark"` on <html>, set by `themeScript()` before the first paint and by `useTheme()`
   after. It always holds the RESOLVED theme («خودکار» is decided in script from the device), so
   this is the only dark block: no copy inside a prefers-color-scheme query.

   What changes is the LIGHT half: the paper surfaces, their hairlines, the text on them, the status
   tints and the accent-tinted rows. The ink surfaces (a sidebar, a toast, a code block) were dark
   already and stay. Because every component and every compat alias reads these names, nothing else
   needs a rule, except the handful of literals components.css twins at its end.

   The ramp: the app's ground sits just above the sidebar's ink, cards a step above that, fields a
   step below the cards. Text keeps the ink side's own `--d-*` values, so a dark page and a sidebar
   read as one hand.
   =================================================================== */
:root[data-theme='dark'] {
  color-scheme: dark;

  --paper-0: #0d0d17; /* app bg */
  --paper-1: #151522; /* card */
  --paper-2: #1e1e2e; /* inset / track */
  --paper-3: #11111c; /* field bg */
  --paper-line: #2a2a3d;
  --paper-line-row: #222233;
  --paper-line-soft: #1f1f2f;
  --paper-line-softer: #1b1b2a;
  --paper-track: #34344a;

  --l-fg: #ececf6;
  --l-mut: #a3a3bd;
  --l-faint: #747490;

  /* Status: the hue lifted to read on dark, its tint a dark wash of the same hue. */
  --ok: #3ccf8e;
  --ok-bg: #11291f;
  --warn: #f0a63a;
  --warn-bg: #2c2112;
  --warn-bd: #4d3814;
  --warn-deep: #f5c26b;
  --info: #6ea2ff;
  --info-bg: #13213b;
  --err: #f2726c;
  --err-bg: #2e1618;
  --err-bd: #4d2326;
  --err-deep: #ff9a94;
  --err-fill: #3a1b1d;

  --verified-fg: #c4b5fd;
  --verified-bd: rgba(167, 139, 250, 0.4);
  --sel-bg: #221d3b;
  --fresh-bg: #17152b;

  --ring: 0 0 0 3px rgba(167, 139, 250, 0.3);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 28px -20px rgba(0, 0, 0, 0.7);
  --shadow-pop: 0 20px 48px -24px rgba(0, 0, 0, 0.8);
}
