/* ============================================================================
   @briefcase/ui: design tokens, the single source of truth. System: DATUM (v2).
   ----------------------------------------------------------------------------
   Every surface inherits from here: the outfra.ai site, the workbench, admin,
   the agent chat, and (through mirrors) the auth emails and the iOS shell.
   Datum replaced "Instrument" on 2026-10-07. The plan and the reasons live in
   .cursor/plans/active/platform/design-system-datum.plan.md.

   TWO PALETTES, SAME TOKEN NAMES
   - Paper (the base :root): light pages everywhere. Warm white paper, graphite
     ink, white surfaces. Pages do not follow the OS theme.
   - Night: warm graphite. Applied to a whole page with data-theme="dark" on
     <html>, or to one region with class="night" (product bands) or
     class="screen" (instrument insets, the ticker, live readouts).
     The CAD viewport keeps its own near-black backdrop in both palettes.

   ONE ACCENT RULE
   - Chrome is monochrome: the accent alias is the ink colour, so primary
     buttons, links, focus rings and selection read as ink.
   - Signal is the logo's orange (the Carry cells). It marks emphasis and live
     state only: an accent line, a running LED, a progress cell. Never a fill
     behind body text. On paper it is graphic only (3.5:1); small orange text
     uses the amber token, which is the deep Carry cell.
   - Physics colours are data, never chrome: cyan airflow, amber heat and
     power, green in budget, red fault, warn caution.

   Colours are raw RGB triplets so they compose with alpha:
       background: rgb(var(--cyan) / 0.12);
       color:      rgb(var(--ink));

   THE ONE RULE: surfaces reference these tokens, never raw hex or rgba,
   off-scale radii, or ad-hoc durations. lint-tokens.mjs reports drift.
   Do not write a declaration pattern inside a comment in this file: the token
   exporter and the contrast gates parse it with regexes.
   ========================================================================== */

:root {
  color-scheme: light;

  /* --- typography: one family, two voices --------------------------------- */
  /* IBM Plex Sans for words (display and UI), IBM Plex Mono for numbers,
     labels and code. Self-hosted through fonts.css; the site CSP blocks
     third-party fonts. The display alias is kept so existing rules resolve. */
  --font-display: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-ui:      "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono:    "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --fs-xs:   0.75rem;    /* 12: labels, eyebrows, captions */
  --fs-sm:   0.875rem;   /* 14: secondary copy, table cells */
  --fs-base: 1rem;       /* 16: body and UI */
  --fs-md:   1.1875rem;  /* 19: lead paragraph */
  --fs-lg:   1.5rem;     /* 24: card titles */
  --fs-xl:   2.5rem;     /* 40: section headlines */
  --fs-2xl:  3.5rem;     /* 56: page headlines */
  --fs-3xl:  4.75rem;    /* 76: the hero */

  --fw-regular:  400;
  --fw-medium:   500;
  --fw-semibold: 600;
  --fw-bold:     700;
  --fw-black:    700;    /* Plex Sans tops out at 700; kept for older rules */

  --tracking-eyebrow:  0.08em;   /* uppercase mono labels */
  --tracking-wide:     0.06em;   /* mono chips, tabs */
  --tracking-tight:   -0.03em;   /* headlines */
  --tracking-tighter: -0.035em;  /* hero and wordmark */
  --leading-tight:    1.04;
  --leading-snug:     1.2;
  --leading-body:     1.6;

  --text-eyebrow-size: var(--fs-xs);
  --text-body-size:    var(--fs-base);
  --text-lead-size:    var(--fs-md);

  /* --- spacing: strict 4px baseline --------------------------------------- */
  --space-1: 0.25rem;  --space-2: 0.5rem;   --space-3: 0.75rem;
  --space-4: 1rem;     --space-5: 1.5rem;   --space-6: 2rem;
  --space-8: 3rem;     --space-10: 4rem;    --space-12: 6rem;
  --space-16: 8rem;

  /* --- radius: machined, square-shouldered -------------------------------- */
  --radius-xs: 4px;      /* chips, tags, small insets */
  --radius-sm: 6px;      /* controls: buttons, inputs, segmented */
  --radius:    10px;     /* cards, panels, rows */
  --radius-lg: 14px;     /* sheets, large frames */
  --radius-pill: 999px;  /* LED dots, toggles, progress tracks only */

  /* --- motion: quick, damped, decisive ------------------------------------ */
  --dur-micro:  80ms;    /* press, focus, check draw */
  --dur-fast:   120ms;   /* hover, chip toggle, tooltip */
  --dur-base:   220ms;   /* menus, toasts, state change */
  --dur-medium: 320ms;   /* dialogs and sheets entering, page transitions */
  --dur-slow:   480ms;   /* meters, delta pops, reveals */
  --dur-scene:  720ms;   /* 3D explode and camera moves; never longer than 900ms */
  --ease:       cubic-bezier(0.2, 0.8, 0.2, 1);    /* resolve and settle (default) */
  --ease-out:   cubic-bezier(0.16, 1, 0.3, 1);     /* entrances, assembly snap */
  --ease-exit:  cubic-bezier(0.4, 0, 1, 1);        /* leaving: accelerate away */
  --ease-inout: cubic-bezier(0.65, 0, 0.35, 1);    /* camera and tour moves */
  --ease-spring: linear(0, 0.078, 0.242, 0.423, 0.588, 0.721, 0.822, 0.894, 0.942, 0.973, 0.991, 1, 1.005, 1.006, 1.006, 1.005, 1.004, 1.003, 1);
  --stagger:    40ms;    /* per item; at most six items in one reveal */

  /* --- layout ------------------------------------------------------------- */
  --maxw: 1280px;
  --measure: 40rem;      /* readable text column */
  --gutter: clamp(1.25rem, 4vw, 2.5rem);

  /* --- brand cells: the Carry mark's three bars (theme-invariant) ---------- */
  --carry-1: 153 60 29;    /* #993c1d  deep cell */
  --carry-2: 216 90 48;    /* #d85a30  middle cell */
  --carry-3: 240 153 123;  /* #f0997b  light cell */

  /* --- instrument screen and CAD viewport (theme-invariant) --------------- */
  /* Dark in both palettes. These mirror the night palette so a screen inset
     on a paper page reads exactly like a night band. */
  --viewport-bg:  18 17 16;    /* #121110  CAD viewport backdrop */
  --screen:       28 27 25;    /* #1c1b19 */
  --screen-edge:  58 55 51;    /* #3a3733 */
  --screen-ink:   236 235 229; /* #ecebe5 */
  --screen-dim:   180 176 167; /* #b4b0a7  6.6:1 on the screen */
  --screen-amber: 255 138 76;  /* #ff8a4c  7.4:1 */
  --screen-cyan:  126 168 255; /* #7ea8ff  7.2:1 */

  /* ====================================================================== */
  /* PALETTE: PAPER (the base)                                               */
  /* ====================================================================== */
  --canvas:   246 245 242;  /* #f6f5f2  page */
  --surface:  255 255 255;  /* #ffffff  cards, panels, inputs */
  --elevated: 238 236 231;  /* #eeece7  wells, segmented tracks, hover fills */
  --hairline: 223 220 213;  /* #dfdcd5  every border; never text */
  --hairline-strong: 207 203 194; /* #cfcbc2  control borders */
  --paper-hi: 246 245 242;  /* text on ink fills */

  --ink:      34 32 29;     /* #22201d  primary text and chrome */
  --ink-dim:  85 81 74;     /* #55514a  secondary text: 7.2 canvas, 6.7 elevated */
  --ink-mute: 110 106 98;   /* #6e6a62  labels, captions: 4.9 canvas, 4.6 elevated, the AA floor */

  --white: 255 255 255;
  --black: 0 0 0;

  --signal: 216 90 48;      /* #d85a30  the Carry cell: graphic and large text only on paper */

  --cyan:  36 86 184;       /* #2456b8  airflow, cool, data */
  --amber: 153 60 29;       /* #993c1d  heat, power, battery; small orange text */
  --green: 17 101 60;       /* #11653c  checked, in budget, charged */
  --red:   164 37 32;       /* #a42520  over limit, fault */
  --warn:  128 76 4;        /* #804c04  caution, never a call to action */

  --shadow-card:   0 0 0 0 transparent;
  --shadow-lifted: 0 1px 2px rgb(34 32 29 / 0.06), 0 12px 32px rgb(34 32 29 / 0.12);
  --action-surface: linear-gradient(to bottom, color-mix(in srgb, rgb(var(--ink)) 75%, rgb(var(--ink-dim))), rgb(var(--ink))); /* @kind color */
  --action-surface-hover: linear-gradient(to bottom, color-mix(in srgb, rgb(var(--ink)) 45%, rgb(var(--ink-dim))), rgb(var(--ink))); /* @kind color */
  --elev-action-rest: inset 0 1px 0 rgb(var(--paper-hi) / 0.12), inset 0 -1px 0 rgb(var(--ink) / 0.2), 0 1px 1px rgb(var(--ink) / 0.12); /* @kind shadow */
  --elev-action-press: inset 0 2px 4px rgb(var(--ink) / 0.25); /* @kind shadow */

  /* --- touch and density -------------------------------------------------- */
  --touch-min:   44px;
  --touch-comfy: 48px;

  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);

  --sheet-max-h:   80svh;
  --sheet-radius:  var(--radius-lg);
  --sheet-grabber: 36px;
}

/* ============================================================================
   PALETTE: NIGHT. A whole page (data-theme="dark" on html), a product band
   (.night) or an instrument inset (.screen). Ratios are on canvas / elevated.
   ========================================================================== */
:root[data-theme="dark"],
.night,
.screen {
  --canvas:   28 27 25;     /* #1c1b19 */
  --surface:  36 35 32;     /* #242320 */
  --elevated: 44 42 39;     /* #2c2a27 */
  --hairline: 58 55 51;     /* #3a3733 */
  --hairline-strong: 74 70 64; /* #4a4640 */
  --paper-hi: 28 27 25;     /* text on bone fills */

  --ink:      236 235 229;  /* #ecebe5  15.0 / 12.9 */
  --ink-dim:  180 176 167;  /* #b4b0a7  8.0 / 6.6 */
  --ink-mute: 154 150 142;  /* #9a968e  5.8 / 4.9 */

  --signal: 255 138 76;     /* #ff8a4c  7.4 / 6.2, text-safe on night */

  --cyan:  126 168 255;     /* #7ea8ff */
  --amber: 255 138 76;      /* #ff8a4c */
  --green: 96 205 150;      /* #60cd96 */
  --red:   255 122 107;     /* #ff7a6b */
  --warn:  255 184 108;     /* #ffb86c */

  --shadow-card:   0 0 0 0 transparent;
  --shadow-lifted: 0 16px 48px rgb(0 0 0 / 0.45);
  --action-surface: linear-gradient(to bottom, color-mix(in srgb, rgb(var(--ink)) 70%, rgb(246 245 242)), rgb(var(--ink))); /* @kind color */
  --action-surface-hover: linear-gradient(to bottom, rgb(246 245 242), rgb(var(--ink))); /* @kind color */
  --elev-action-rest: inset 0 1px 0 rgb(var(--ink) / 0.18), inset 0 -1px 0 rgb(var(--paper-hi) / 0.18), 0 1px 1px rgb(var(--paper-hi) / 0.12); /* @kind shadow */
  --elev-action-press: inset 0 2px 4px rgb(var(--paper-hi) / 0.25); /* @kind shadow */
}

:root[data-theme="dark"] {
  color-scheme: dark;
}

.night,
.screen {
  color-scheme: dark;
  background: rgb(var(--canvas));
  color: rgb(var(--ink));
}

/* ============================================================================
   DERIVED. Declared on every palette scope so they recompute with it: an alias
   computed on :root would otherwise carry paper values into a night band.
   ========================================================================== */
:root,
.night,
.screen {
  --accent: var(--ink);
  --action-primary: var(--ink);
  --action-hover: var(--ink-dim);
  --action-active: var(--ink-mute);
  --action-focus-ring: var(--focus-ring);
  --data:   var(--cyan);

  --signal-soft: rgb(var(--signal) / 0.12);
  --cyan-soft:   rgb(var(--cyan)   / 0.12);
  --amber-soft:  rgb(var(--amber)  / 0.12);
  --green-soft:  rgb(var(--green)  / 0.12);
  --red-soft:    rgb(var(--red)    / 0.12);
  --warn-soft:   rgb(var(--warn)   / 0.12);

  --glow-cyan: 0 0 0 1px rgb(var(--cyan) / 0.4), 0 0 24px rgb(var(--cyan) / 0.18);
  --ring-data: 0 0 0 3px rgb(var(--cyan) / 0.22);
  --ring-signal: 0 0 0 4px rgb(var(--signal) / 0.16);

  --glass-bg:   rgb(var(--canvas) / 0.86);
  --glass-blur: blur(12px);

  --text-strong:    rgb(var(--ink));
  --text-body:      rgb(var(--ink-dim));
  --text-muted:     rgb(var(--ink-mute));
  --text-accent:    rgb(var(--accent));
  --text-on-accent: rgb(var(--paper-hi));
  --surface-page:   rgb(var(--canvas));
  --surface-card:   rgb(var(--surface));
  --surface-inset:  rgb(var(--elevated));
  --border-hairline: rgb(var(--hairline));

  --focus-ring:   0 0 0 2px rgb(var(--canvas)), 0 0 0 4px rgb(var(--accent) / 0.9);
  --focus-offset: 2px;
}

/* ----------------------------------------------------------------------------
   Density. Pointer defaults first; the explicit touch opt-in comes after at
   equal specificity so it wins. Do not reorder.
   -------------------------------------------------------------------------- */
:root {
  --control-h: 40px;
  --row-gap:   var(--space-2);
  --tap-pad:   var(--space-2);
}
[data-density="touch"] {
  --control-h: var(--touch-comfy);
  --row-gap:   var(--space-3);
  --tap-pad:   var(--space-3);
}
@media (hover: none) and (pointer: coarse) {
  :root:not([data-density="pointer"]) {
    --control-h: var(--touch-comfy);
    --row-gap:   var(--space-3);
    --tap-pad:   var(--space-3);
  }
}

/* ----------------------------------------------------------------------------
   Accessibility fallbacks.
   -------------------------------------------------------------------------- */
@media (prefers-reduced-transparency: reduce) {
  :root,
  .night,
  .screen {
    --glass-bg:   rgb(var(--canvas));
    --glass-blur: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --dur-micro:  0.001ms;
    --dur-fast:   0.001ms;
    --dur-base:   0.001ms;
    --dur-medium: 0.001ms;
    --dur-slow:   0.001ms;
    --dur-scene:  0.001ms;
    --stagger:    0ms;
  }
}
