/* ════════════════════════════════════════════════════════════════════════
   tokens.css — THE token home for Gestano (Theming System Phase 1).
   Layer 1 primitives + Layer 2 semantic roles live here; app.css and every
   component are pure consumers. Linked BEFORE app.css in base.html so the
   token :root paints first. The server injects an <style id="active-theme">
   AFTER this file to override role values per the company's active theme.
   NOTE (Gate 1): this is the VERBATIM :root block moved out of app.css —
   zero visual change. The 3-layer primitives/semantic/module restructure +
   dark mode land in later gates.
   ════════════════════════════════════════════════════════════════════════ */

:root {
  /* ════ V2 DESIGN TOKENS (canonical — from seed/Artifact-relation_V2 tokens/*.css).
     The named token system is the source of truth; the short app aliases below
     (--bg/--accent/--overdue/…) are kept and mapped onto it so existing rules
     don't regress. Update a value HERE, in the V2 token, and it flows through. ════ */

  /* ---- Colors (tokens/colors.css) ---- */
  /* Light-theme primitive values RECONCILED to the approved mockup (Gate 6): the always-on
     active-theme injection supplies these same values on authed pages via the role aliases, so
     the base here matches → login / pre-auth paint and any primitive-ref render are consistent. */
  /* Gestano rebrand (2026-08-20): --paper + --ink aligned to the exact brand sheet values
     (Paper #F2F3EF, Ink #1A1D1A) — was #EDF1EF/#182220 from the mockup, a near-identical hue.
     Kept in lockstep with the built-in "light" theme (themes_store._LIGHT + themes row) so the
     login/pre-auth paint matches the injected authed roles, and with the PWA background_color. */
  --paper:#F2F3EF; --surface:#FFFFFF; --surface-sunk:#FAFBF9;
  --field-tint:#F7F8F4;   /* same hue as --paper, a touch lighter — subtle field-entry hint */
  /* Redesign F1 (DSN-01/DSN-11): muted = the Dsn-Overview value; faint = the board's #6B756F nudged
     to #646E68 because #6B756F on Paper is 4.28:1 (WE MEASURED IT) — now AA on white AND Paper.
     Old values #657069 / #93A099 (the faint one was 2.6:1). */
  --ink:#1A1D1A; --ink-muted:#4F5A54; --ink-faint:#646E68;
  --line:rgba(20,40,32,.10); --line-soft:rgba(20,40,32,.06);
  --green:#15604A; --green-deep:#114F3D; --green-soft:#E1EBE6; --green-pop:#7FC9AC;
  --red:#B3261E; --red-soft:#F6E1DF;
  --amber:#9E6B12; --amber-soft:#EEE7D6;
  --blue:#2C5C82; --blue-soft:#E2EBF2;
  /* (the old sidebar tokens --side/--side-2/--side-ink/--side-faint were replaced by the redesign
     shell's --side-bg/--side-on/--side-text/--side-muted below — F3) */

  /* ---- Typography (tokens/typography.css) ---- */
  /* Redesign F1 (FND-09, DSN-02): Figtree body + tables + amounts (tabular figures — verified in
     scripts/verify_fonts_latin_ext.py), Familjen Grotesk headings + key amounts. Both latin-ext. */
  --font-display:'Familjen Grotesk','Figtree',system-ui,sans-serif;
  --font-body:'Figtree',system-ui,-apple-system,'Segoe UI',sans-serif;
  --font-num:'Figtree',system-ui,sans-serif;   /* amounts — always with tabular-nums */
  --font-mono:'IBM Plex Mono',ui-monospace,'SF Mono',monospace;   /* codes (IBAN, refs) only */
  /* THE TYPE SCALE (DSN-02): body 15 · dense work screens 14 · labels 13 (quieter colour). Density
     comes from spacing, never from smaller text (DSN-03) — nothing in a work screen goes below 13. */
  --text-body:15px; --text-dense:14px; --text-label:13px;
  --text-title:26px;      /* the one-line page title (page head, DSN-14 #1) */
  --text-key:28px;        /* a key amount on a card (Familjen Grotesk) */
  --text-h1:22px; --text-h2:18px; --text-h3:15px; --text-base:14px;
  --text-sm:13px; --text-xs:12px;
  --label-ink:var(--ink-muted);   /* labels: quieter than the value they name */
  --weight-regular:400; --weight-medium:500; --weight-semibold:600; --weight-bold:700;
  --leading-tight:1.25; --leading-normal:1.5;
  --tracking-label:.08em;

  /* ---- Spacing & sizing (tokens/spacing.css) ---- */
  /* PRIMITIVE step scale (Layer 1) — sizes, not meanings. Essentially unused: grep finds ONE
     consumer (`.gtable .gt-row`). The SEMANTIC rhythm scale below is what components consume. */
  --space-1:4px; --space-2:6px; --space-3:8px; --space-4:10px; --space-5:12px;
  --space-6:14px; --space-7:16px; --space-8:18px;

  /* ════ SPACING RHYTHM — the semantic scale (Layer 2). ════════════════════════════════
     Added 2026-08-03 (spacing foundation, pass 1). WHY it exists: no rule OWNED vertical
     rhythm, so every screen improvised its own margins — and any structural change silently
     removed whatever was accidentally holding a layout together. The Backups Run-history
     block sitting flush against the grid above it was that failure, not sloppiness.

     Names describe the RELATIONSHIP, never the size — the same doctrine as the colour role
     aliases above. Change the RELATIONSHIP here, once, and every archetype follows.

     PASS 2a (2026-08-03) RECONCILED RANKS 1 AND 2 — the two changes with a conservative
     default: every off-scale value collapsed onto the PLURALITY number, and the stacked-sibling
     gap was raised off its accidental zero. Both pass-2 marker tokens are gone. Ranks 3–6
     (the column gutter, the single section rule, component padding, the `rem` outliers) are
     TASTE CALLS with no safe default and remain Dick's — see docs/spacing-inventory.md. ════ */

  /* THE SCALE — the four relationships the layout is actually built out of. */
  --gap-field:8px;        /* inside a block, between one field and the next */
  --gap-block:16px;       /* between stacked blocks / cards in a column */
  --gap-section:24px;     /* between major sections / rows of blocks */
  --gutter-col:28px;      /* the gutter between side-by-side columns */

  /* Sub-relationships that are genuinely their own thing, not deviations from the scale. */
  --gap-inline:6px;       /* two controls sharing ONE line (Phone|Mobile, Postcode|Town) */
  --gap-card:12px;        /* between cards in a card GRID (a row of KPIs) — not a stacked block */
  --gap-head-ic:10px;     /* a block header's icon chip → its title */
  --gap-head-rule:10px;   /* a block header's content → its underline */
  /* ⚠ KEPT at 6px in pass 2a, deliberately. A block header sitting TIGHTER to its body than
     fields do to each other (8px) may be a real, wanted distinction rather than drift — that is
     Dick's call, not one to make on his behalf while he is away. */
  --gap-head-body:6px;    /* a block header's underline → the block's first field */

  /* ── The stacked-sibling gap. Pass 1 gave it an owner at its accidental value of 0 (a block
     FOLLOWING a sibling block owned no spacing anywhere in the app — Backups ▸ Run history sat
     flush against the grid above it). Pass 2a raises that one token to the plurality, and every
     stacked block in the app gains rhythm together. THIS single line is the whole fix. ── */
  --gap-stack:16px;
  /* sidebar width RECONCILED to the .app grid (was a dead+contradicted 212px; .app now var-ifies this) */
  --sidebar-w:256px; --content-pad:16px;   /* sidebar = the board's 256px (F3); content pad grows on wide screens below */
  /* persistent bottom status bar — height (excl. safe area) + the full reserve incl. mobile safe-area inset */
  /* the bottom status bar was replaced by toasts (redesign F4): the reserve now only keeps the safe area */
  --statusbar-reserve:env(safe-area-inset-bottom);
  /* the top / side safe area (an installed web app on an iPad or iPhone: the clock line, the notch in landscape).
     viewport-fit=cover lets the page run under them; app.css keeps room with these, NEVER env() directly
     (gate verify_safe_top.py). 0 in every desktop browser. */
  --safe-top:env(safe-area-inset-top, 0px); --safe-left:env(safe-area-inset-left, 0px); --safe-right:env(safe-area-inset-right, 0px);

  /* ---- Effects (tokens/effects.css) ---- */
  --radius-sm:7px;
  --radius-md:8px; --radius-xl:12px; --radius-pill:100px;
  --border-hairline:1px solid var(--line); --border-inner:1px solid var(--line-soft);
  --shadow-none:none;
  --shadow-pop:0 8px 24px rgba(0,0,0,.16);
  --shadow-soft:0 1px 2px rgba(0,0,0,.06);   /* subtle accent — the nav-bar strip */
  --shadow-field:0 1px 4px rgba(0,0,0,.10);  /* detail-card field "lift" — soft, both browse + edit (zero-shift) */
  /* accent focus-ring / thumb tokens (were hardcoded rgba(21,96,74,…) literals — value-identical) */
  --focus-ring:0 0 0 3px rgba(21,96,74,.13);   /* the standard field/summary focus ring */
  --shadow-thumb:rgba(21,96,74,.22);           /* primary photo-thumb ring colour */
  --grad-header:linear-gradient(180deg,#ECF2EE,#F4F8F5);
  /* Motion (DSN-10): 0.15–0.2 s, no bounce; app.css zeroes these under prefers-reduced-motion. */
  --ease-standard:cubic-bezier(.2,0,.2,1); --dur-fast:150ms; --dur-normal:200ms;

  /* ════ REDESIGN F1 — direction A "calm & airy" (DSN-00/01/03/08), values from board Dsn-Overview.
     NEW names only; the role aliases above stay the theming seam (the per-company accent arrives via
     the active-theme injection as --accent/--accent-d/--accent-soft/--on-accent). ════ */
  /* Surfaces + edges */
  --radius-card:20px; --radius-field:12px; --radius-btn:999px;
  --shadow-card:0 1px 2px rgba(26,29,26,.06), 0 4px 16px rgba(26,29,26,.05);
  /* THE SHELL (F3, DSN-00 / SHL-03): the desktop sidebar is Ink; sizes of the three presentations */
  --side-bg:var(--ink);
  --side-on:rgba(255,255,255,.07); --side-hover-strong:rgba(255,255,255,.12);
  --side-text:#E8EBE6; --side-muted:#A9B0AA;
  --rail-w:76px;          /* tablet landscape icon rail */
  --tabbar-h:64px;        /* phone bottom bar (above the safe area) */
  --dock-h:0px;           /* set by shell.js to the docked primary's height on phone forms (SHL-12) */
  --head-pad-top:28px;    /* space above the page head (title) */
  /* F2 building blocks (Dsn-Overview §1) */
  --line-field:#DCDFD8;          /* field + search border (1.5px) */
  --line-btn:#CDD2CC;            /* secondary button border, toggle off, dashed "+ Filter" */
  --danger-line:#E8B4AE;         /* danger button border */
  --smart-bg:#F4F8F6;            /* "filled in for you" field + smart note tint (DSN-07) */
  --attn:#C2571A;                /* count badge */
  --radius-chip:10px;            /* find chips (Find: … / Omit: …) */
  --scrim:rgba(26,29,26,.32);    /* behind a phone bottom sheet */
  --h-btn:46px; --h-field:48px; --h-chip:36px;   /* ≥ 44px touch targets on touch screens (DSN-11) */
  --h-btn-sm:36px;               /* small buttons — only with a fine pointer (mouse); 44px on touch */
  /* THE STATUS SET (DSN-08) — five names, five colours, every module maps onto them
     (mapping table: _wiki/projects/gestano/design-system.md § Status mapping). */
  --st-draft-bg:#EEF0EC;   --st-draft-ink:#4F5A54;
  --st-sent-bg:#E7EEF8;    --st-sent-ink:#24508F;
  --st-part-bg:#FBEED3;    --st-part-ink:#7A5200;
  --st-overdue-bg:#FBE3DA; --st-overdue-ink:#A3361A;
  --st-paid-bg:#DDF2E8;    --st-paid-ink:#145C3F;
  /* TWO DENSITIES, ONE STYLE (DSN-03): airy = overview screens (Home, record summaries); work =
     lists, document editor, bank, VAT. Only SPACING changes — never the text size below 14. A screen
     opts into work density with [data-density="work"] on its page wrapper. */
  --pad-card:22px; --pad-row:14px;

  /* ════ App aliases — mapped onto the V2 tokens so existing rules keep working ════ */
  --bg:var(--paper); --ink-on:var(--ink);
  --muted:var(--ink-muted); --faint:var(--ink-faint);
  --line2:var(--line-soft);
  /* ── Shared DATA-TABLE skin (2026-07-14) — the ONE skin both data-table substrates read:
     table.tbl (Relations, native sortable list) AND .gtable (the grid N-line data-table, /time/
     + future consumers). Values == the existing tokens, so routing both through these changes NO
     pixel — it just makes the skin ONE source, so a theme / per-user appearance change flows
     through both identically (R1: Relations stays a native <table>, skin-shared not restyled). */
  --dt-head-bg:var(--surface); --dt-head-line:var(--line); --dt-row-line:var(--line2);
  --dt-zebra:var(--row-alt); --dt-hover:var(--surface-sunk);
  --accent:var(--green); --accent-d:var(--green-deep); --accent-soft:var(--green-soft);
  --overdue:var(--red); --overdue-soft:var(--red-soft);
  --radius:var(--radius-md);   /* (--radius-lg retired in redesign F1: cards use --radius-card) */
  --radius-input:var(--radius-field);                        /* fields = 12px (Dsn-Overview) */
  --shadow:0 1px 2px rgba(20,40,32,.05), 0 8px 22px rgba(20,40,32,.06); /* reconciled to mockup (Gate 6) — matches the injected light --shadow */
  --shadow-lg:0 14px 40px rgba(0,0,0,.18); /* kept (no regression); V2 big elevation = --shadow-window */

  /* ── Legacy compat aliases (older component classes still reference these) ── */
  --text:var(--ink); --text-strong:#0d0f0d;
  --neutral-100:var(--line); --neutral-200:rgba(0,0,0,.12);
  --neutral-300:rgba(0,0,0,.20); --neutral-400:rgba(0,0,0,.26);
  --brand-brown:var(--accent); --brand-brown-dk:var(--accent-d); --brand-rust:var(--amber);
  --accent-bright:var(--accent-d); --accent-hover:var(--green-deep);
  --success:#2f7d52; --warning:var(--amber); --danger:var(--overdue);

  /* ── Theming Phase 1 — added semantic roles (LIGHT defaults; the injected
     active-theme <style> overrides these per the company's theme). These give
     login / pre-injection / sparse-theme fallbacks. ── */
  --on-accent:#ffffff;         /* text/icon on an accent fill — dark theme FLIPS to #0F1513 */
  --wall:none;                 /* dark-theme wallpaper url() (none in light) */
  --shadow-lift:0 2px 4px rgba(20,40,32,.06), 0 16px 34px rgba(20,40,32,.12);
  --amber-ink:#B0863E;         /* browner amber watermark */
  --slate:var(--blue); --slate-soft:var(--blue-soft);
  --purple:#4A3C82; --purple-soft:#E6E2F2;   /* SERVICE type badge (dark theme lightens it) */
  --accent-pop:var(--green-pop);

  /* ── STYLE RULES (staging-tuning 2026-07) — theme-aware, mode-keyed. These are NEW tokens the
     injected active-theme <style> does NOT set, so their light default (here) + dark override
     (app.css [data-theme-mode="dark"]) always win — working for Light, Dark AND user themes
     (every theme carries a mode). See docs/DESIGN-REFERENCE.md § "Style rules". ── */
  --field-bg:var(--field-tint);  /* A2 — the ONE form-field fill. Light = the subtle field-tint hint;
                                    dark raises it a bit lighter than the page = a clear "fill in here" cue. */
  --row-alt:rgba(20,40,32,.035); /* A5 — subtle zebra tint for alternate list rows (light = faint green-ink). */

  /* ── Step 11r-a / A1 + P4 (Dick 2026-11-23): "chosen" = soft pine on every device — chips, toggles, segmented
     choices, the chosen row in pickers and bottom sheets. Main actions stay solid in the company accent. ── */
  --chosen-bg:#E1EBE6; --chosen-ink:#15604A; --chosen-line:#B7D2C5;
  --tick-mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E");
  /* A count pill (S1/S2): green normally, red for what needs attention or is negative. */
  --pill-ok:#15604A; --pill-bad:#B3261E;
  --on-area:#FFFFFF;   /* the white icon / digits on a module square or a count pill — the same in dark mode */

  /* ── Step 11r-a / A6 + P3 (Dick 2026-11-23, "Module colours approved"): ONE colour per module, used ONLY as the
     rounded square behind the white module icon (sidebar, rail, bottom bar, More list, page head). Never a status
     colour (green / red / amber stay status-only). The key = shell_nav's area key; `[data-area]` below picks it. ── */
  --area-home:#4F5A54;      --area-home-soft:#EAEDEA;
  --area-relations:#36699E; --area-relations-soft:#E3ECF6;
  --area-sales:#5856A3;     --area-sales-soft:#EAE9F7;
  --area-purchases:#8A4F86; --area-purchases-soft:#F4E8F3;
  --area-products:#2C7A86;  --area-products-soft:#DFF0F2;
  --area-work:#9A4F6C;      --area-work-soft:#F6E7ED;
  --area-money:#2A4468;     --area-money-soft:#E2E7F0;
  --area-mail:#66748E;      --area-mail-soft:#E9ECF1;
  --area-settings:#4F5A54;  --area-settings-soft:#EAEDEA;

  /* ── Step 11r-d (H3, M2): chart colours. [DICK SAID IT, 2026-11-23] money in #15604A, out #BFC6C1, coming in
     #7FC9AC, profit green / loss red. Costs by category: the dataviz reference categorical order (validated with its
     validate_palette.js, light + dark: CVD + normal-vision PASS; light contrast WARN → every bar carries its name and
     amount as text). Green within the payment days, amber later (status colours, with words beside them). ── */
  --ch-in:#15604A; --ch-out:#BFC6C1; --ch-pop:#7FC9AC; --ch-neg:#B3261E; --ch-warn:#D08A16; --ch-band:rgba(21,96,74,.12);
  --ch-c0:#A3AAA6; --ch-c1:#2A78D6; --ch-c2:#EB6834; --ch-c3:#1BAF7A; --ch-c4:#EDA100; --ch-c5:#E87BA4; --ch-c6:#6250D6;
  /* step 11g (RB1), Part B / 0 (E1): a project's colour — 10 clearly different hues (orange, blue, purple as drawn,
     then green, pink, teal, olive, slate, magenta, sky); projects 11–20 take the same hues with stripes (.pl-pat).
     Every block carries its project's name as text too, so colour is never the only signal. */
  --pl-c0:#E3672A; --pl-c1:#2A6FD0; --pl-c2:#7A4FD6; --pl-c3:#17A06F; --pl-c4:#DB5B96;
  --pl-c5:#13808C; --pl-c6:#8C7A1A; --pl-c7:#56677C; --pl-c8:#A8329A; --pl-c9:#3BA3DB;
  /* 11r-e (A4): the paper viewer — grey ground [DICK SAID IT: #C9CDC8], the sheet stays white paper in every theme;
     the Settings mini page's dotted margin lines */
  --pp-ground:#C9CDC8; --pp-sheet:#FFFFFF; --pp-shadow:0 2px 6px rgba(20,28,24,.18), 0 12px 32px rgba(20,28,24,.16);
  --pp-guide:#2C7A86;
}
/* 11r-a / A1 in the dark theme: the same soft-pine idea, dark enough to sit on the dark page. [WE ASSUMED IT] */
[data-theme-mode="dark"] { --chosen-bg:#1F3A31; --chosen-ink:#BFE3D3; --chosen-line:#33604F;
  --ch-in:#3FA584; --ch-out:#5C6661; --ch-pop:#5FB596; --ch-neg:#E66767; --ch-warn:#C98500; --ch-band:rgba(63,165,132,.16);
  --ch-c0:#6F7772; --ch-c1:#3987E5; --ch-c2:#D95926; --ch-c3:#199E70; --ch-c4:#C98500; --ch-c5:#D55181; --ch-c6:#9085E9;
  --pl-c0:#F07A3E; --pl-c1:#4A8CEB; --pl-c2:#9A7AEE; --pl-c3:#2DBA86; --pl-c4:#E874A8;
  --pl-c5:#2AA3B0; --pl-c6:#B3A13A; --pl-c7:#8A9AAE; --pl-c8:#C956BA; --pl-c9:#5DBBEA;
  --pp-ground:#3A403C; --pp-guide:#5FB5C2; }
/* The module colour of an element: data-area="<shell_nav key>" sets --area / --area-soft (the ONE mapping). */
[data-area] { --area:var(--area-home); --area-soft:var(--area-home-soft); }
[data-area="relations"] { --area:var(--area-relations); --area-soft:var(--area-relations-soft); }
[data-area="sales"] { --area:var(--area-sales); --area-soft:var(--area-sales-soft); }
[data-area="purchases"] { --area:var(--area-purchases); --area-soft:var(--area-purchases-soft); }
[data-area="products"] { --area:var(--area-products); --area-soft:var(--area-products-soft); }
[data-area="work"] { --area:var(--area-work); --area-soft:var(--area-work-soft); }
[data-area="money"] { --area:var(--area-money); --area-soft:var(--area-money-soft); }
[data-area="mail"] { --area:var(--area-mail); --area-soft:var(--area-mail-soft); }
[data-area="settings"] { --area:var(--area-settings); --area-soft:var(--area-settings-soft); }

@media (min-width: 1024px) { :root { --content-pad:24px; } }
/* 11r-f / A2 (Dick 2026-11-23): mouse spacing — with a fine pointer a field, a button and a chip are 36px (touch keeps
   48 / 46 / 36 + the 44px floor) and the cards and gaps tighten, so a detail or edit screen fits 1366 × 768. Text never
   shrinks for this (the Viewport Rule: density from spacing). */
@media (pointer: fine) { :root { --h-field:36px; --h-btn:36px; --h-chip:32px; --pad-card:16px; --gap-block:12px; --gap-section:16px; --head-pad-top:14px; } }
@media (max-width: 1023px) { :root { --head-pad-top:16px; } }

/* Work density (DSN-03): the same pieces, tighter spacing — a whole invoice fits a 14" laptop. */
[data-density="work"] { --pad-card:14px; --pad-row:9px; }
