/* CRM surface tokens. Hand-written, and it holds no colour literal: every
   value is a house token from the vendored tokens.css (iLivin Design
   Contract, Token Reference) or a color-mix of house tokens. Three jobs:
   1. short aliases, so app.css reads cleanly;
   2. the few tokens the contract does not have, each listed in DESIGN.md
      under "What this supplement adds" or "Departures";
   3. the contract's on-tray remap, for every surface drawn on the tray fill. */

:root {
  /* Aliases onto the contract */
  --canvas: var(--primary-background-color);
  --card: var(--card-background-color);
  --recess: var(--ilivin-tray-bg);
  --ink: var(--primary-text-color);
  --muted: var(--secondary-text-color);
  --border: var(--divider-color);
  --line: var(--ilivin-tray-line);
  --accent: var(--primary-color);
  --on-solid: var(--ilivin-stamp-ink);
  --shadow-soft: var(--ilivin-glass-shadow);

  --font-display: var(--ilivin-font-display);
  --font-body: var(--ilivin-font-interface);
  --font-mono: var(--ilivin-font-mono);

  /* Contract → Numeric Scales: font sizes 9 10 11 12 14 18 22 32 40, title 15 */
  --text-2xs: 9px;
  --text-xs: var(--ilivin-micro-size);
  --text-sm: 12px;
  --text-md: 14px;
  --text-base: 14px;
  --text-title: var(--ilivin-title-size);
  --text-lg: var(--ilivin-hero-number-md);
  --text-xl: var(--ilivin-hero-number-lg);
  --text-2xl: var(--ilivin-hero-number-lg);
  --text-3xl: var(--ilivin-hero-number-lg);
  --text-4xl: var(--ilivin-hero-number-xl);

  /* Contract → Numeric Scales: spacing 0 2 4 6 8 12 16 20 24. Nothing larger. */
  --space-1: var(--ilivin-space-1);
  --space-2: var(--ilivin-space-2);
  --space-3: var(--ilivin-space-3);
  --space-4: var(--ilivin-space-4);
  --space-5: var(--ilivin-space-5);
  --space-6: var(--ilivin-space-6);
  --space-8: var(--ilivin-space-6);
  --space-10: var(--ilivin-space-6);
  --space-12: var(--ilivin-space-6);

  /* Contract → Token Reference: radii */
  --radius-stamp: var(--ilivin-radius-stamp);
  --radius-xs: var(--ilivin-radius-xs);
  --radius-key: var(--ilivin-radius-sm);
  --radius-control: var(--ilivin-control-radius);
  --radius-tray: var(--ilivin-radius-tray);
  --radius-card: var(--ilivin-radius-tile);
  --radius-dialog: var(--ilivin-radius-dialog);
  --radius-pill: 999px;

  /* Contract → Motion: three durations, one curve */
  --motion-fast: var(--ilivin-motion-fast);
  --motion-base: var(--ilivin-motion-base);
  --motion-slow: var(--ilivin-motion-slow);
  --ease: var(--ilivin-ease);

  /* Contract → Buttons: the keycap recipe */
  --key: color-mix(in srgb, var(--primary-text-color) 5%, var(--card-background-color));
  --key-hover: color-mix(in srgb, var(--primary-text-color) 9%, var(--card-background-color));
  --key-line: color-mix(in srgb, var(--primary-text-color) 16%, transparent);
  --key-line-hover: color-mix(in srgb, var(--primary-text-color) 24%, transparent);
  --key-edge: color-mix(in srgb, var(--primary-text-color) 34%, transparent);
  --action: color-mix(in srgb, var(--ilivin-clay) 86%, var(--ilivin-ink));
  --action-hover: color-mix(in srgb, var(--ilivin-clay) 76%, var(--ilivin-ink));
  --action-edge: color-mix(in srgb, var(--ilivin-clay) 58%, var(--ilivin-ink));
  --on-action: var(--ilivin-linen);

  /* Contract → Chips: the capsule's hairline (22%) and its hover (40%) */
  --capsule-line: color-mix(in srgb, var(--primary-text-color) 22%, transparent);
  --capsule-line-hover: color-mix(in srgb, var(--primary-text-color) 40%, transparent);

  /* Contract → Progress indicators: the one bar track (ink 7%, ring 6%) */
  --track: color-mix(in srgb, var(--primary-text-color) 7%, transparent);
  --track-ring: color-mix(in srgb, var(--primary-text-color) 6%, transparent);

  /* Contract → Dialog and popup anatomy */
  --scrim: color-mix(in srgb, var(--ilivin-ink) 62%, transparent);
  --dialog-foot: color-mix(in srgb, var(--primary-text-color) 2%, transparent);
  --dialog-close: color-mix(in srgb, var(--primary-text-color) 4%, transparent);
  --dialog-close-hover: color-mix(in srgb, var(--primary-text-color) 8%, transparent);
  --shadow: var(--ilivin-glass-shadow), 0 24px 56px color-mix(in srgb, var(--ilivin-ink) 32%, transparent);

  /* Contract → Inputs: the warm 94% field fill. Over a card it is the card
     colour; over the canvas or a tray it reads a step brighter. */
  --field: color-mix(in srgb, var(--card-background-color) 94%, transparent);

  /* ---- Added by this surface (DESIGN.md, "What this supplement adds") ---- */

  /* Departure 11. The contract's divider edge is 1.26:1 on the card and its
     55% Clay focus ring 2.19:1. A field edge and a focus ring must reach
     3:1 (WCAG 1.4.11), so the edge is ink at 50% (3.08:1 or better on the
     card, the canvas and the tray, both modes) and the ring is solid Clay
     (3.83:1 or better) outside a card-coloured gap, so it also shows round
     the filled Clay key. */
  --field-border: color-mix(in srgb, var(--primary-text-color) 50%, transparent);
  --focus-shadow: 0 0 0 2px var(--card-background-color), 0 0 0 4px var(--primary-color);
  --focus-shadow-field: 0 0 0 2px var(--primary-color);

  --border-strong: color-mix(in srgb, var(--primary-text-color) 22%, var(--card-background-color));
  --nav-active: var(--ilivin-tray-bg);

  /* Layout */
  --side-width: 232px;
  --content-width: 1180px;
  --gutter: var(--ilivin-space-6);

  /* Reading text on the client pages and in documents (Departure 4) */
  --text-read: 16px;
}

/* Tone tokens. Declared on the root and again on every tray surface, because
   a custom property is computed where it is declared: without the second
   declaration a tray would keep the card-surface hue (Contract → Token
   Reference, Tray surface: "the aliases must be restated there"). */
:root,
.tray,
.entry,
.offer,
.doc-parties,
.sign-preview,
.dropzone {
  /* Contract → Status Values. The CRM reads the house tones like this. */
  --ok: var(--ilivin-ok);
  --warn: var(--ilivin-warn);
  --danger: var(--ilivin-danger);
  --info: var(--ilivin-timer);
  --ok-soft: var(--ilivin-ok-soft);
  --warn-soft: var(--ilivin-warn-soft);
  --danger-soft: var(--ilivin-danger-soft);
  --info-soft: var(--ilivin-timer-soft);

  /* Contract → Chips: a solid mark mixes its tone 80% into the text colour */
  --warn-solid: color-mix(in srgb, var(--ilivin-warn) 80%, var(--primary-text-color));
  --danger-solid: color-mix(in srgb, var(--ilivin-danger) 80%, var(--primary-text-color));
  --ok-solid: color-mix(in srgb, var(--ilivin-ok) 80%, var(--primary-text-color));

  /* Departure 14. Tone as small text ("13 days late", an outlined stamp, a
     tone key's label): the solid-mark mix used as ink. The raw tones are
     3.77:1 (danger) and 3.95:1 (teal) on the dark card; the mix holds 4.5:1
     on the card, the canvas and the tray in both modes. */
  --ok-text: var(--ok-solid);
  --warn-text: var(--warn-solid);
  --danger-text: var(--danger-solid);
  --info-text: color-mix(in srgb, var(--ilivin-timer) 80%, var(--primary-text-color));
  /* A tone key's label sits on the keycap surface, a step off the card, so
     it takes more of the text colour: 65%, where the contract's 86% is
     3.99:1 on the dark keycap. */
  --danger-key: color-mix(in srgb, var(--ilivin-danger) 65%, var(--primary-text-color));
  --link: color-mix(in srgb, var(--primary-color) 86%, var(--primary-text-color));

  /* Aged-debt ramp: one hue (danger) stepped into the card, light to dark */
  --age-0: var(--border-strong);
  --age-1: color-mix(in srgb, var(--ilivin-danger) 30%, var(--card-background-color));
  --age-2: color-mix(in srgb, var(--ilivin-danger) 52%, var(--card-background-color));
  --age-3: color-mix(in srgb, var(--ilivin-danger) 76%, var(--card-background-color));
  --age-4: var(--ilivin-danger);
}

/* Contract → Trays → Container: the on-tray remap, all ten, on every surface
   drawn on the tray fill. The tone tokens above then resolve to the hue that
   reads on the tray. */
.tray,
.entry,
.offer,
.doc-parties,
.sign-preview,
.dropzone {
  --ilivin-ok: var(--ilivin-ok-on-tray);
  --ilivin-warn: var(--ilivin-warn-on-tray);
  --ilivin-danger: var(--ilivin-danger-on-tray);
  --ilivin-charging: var(--ilivin-charging-on-tray);
  --ilivin-auto: var(--ilivin-auto-on-tray);
  --ilivin-standby: var(--ilivin-standby-on-tray);
  --ilivin-manual: var(--ilivin-manual-on-tray);
  --ilivin-process: var(--ilivin-process-on-tray);
  --ilivin-cool: var(--ilivin-cool-on-tray);
  --ilivin-sleep: var(--ilivin-sleep-on-tray);
}
