/* static/css/tokens.css
 * Single source of truth for the visual language.
 *
 * The values here implement display.md. Read that first — it explains the
 * reasoning; this file only records the numbers.
 *
 * SIZES and SPACING are tuned for the fixed 1024x600 touch panel, not copied
 * from any desktop reference.
 */

/* ---------------------------------------------------------------------------
 * FONTS
 * display.md names Inter as the intended face — the closest open, metric-similar
 * stand-in for SF Pro. It is NOT bundled yet: static/fonts/ holds Calibri only,
 * so --font-ui falls back to Calibri and the app renders as it did before.
 * Dropping inter-*.ttf in static/fonts/ and adding @font-face blocks alongside
 * the Calibri ones below is the whole migration.
 *
 * Calibri is a Microsoft font and does not ship with Linux, so the Orange Pi has
 * no way to render it and no runtime internet access to fetch it. The real TTFs
 * are bundled and served from disk instead. Declaring the family as "Calibri"
 * means the bundled files win even on a Windows machine that has Calibri
 * installed — so the device and a desktop preview render identically.
 *
 * NOTE ON WEIGHT: display.md asks for 600 (semibold). Calibri ships 400 and 700
 * only, so --fw-semibold resolves to the 700 face until Inter lands. Intended —
 * the hierarchy is correct either way, it is just heavier than final.
 * ------------------------------------------------------------------------ */

@font-face {
  font-family: "Calibri";
  src: url("/static/fonts/calibri-regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: block;
}

@font-face {
  font-family: "Calibri";
  src: url("/static/fonts/calibri-bold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: block;
}

@font-face {
  font-family: "Calibri";
  src: url("/static/fonts/calibri-italic.ttf") format("truetype");
  font-weight: 400;
  font-style: italic;
  font-display: block;
}

@font-face {
  font-family: "Calibri";
  src: url("/static/fonts/calibri-bold-italic.ttf") format("truetype");
  font-weight: 700;
  font-style: italic;
  font-display: block;
}

/* Just the full stop, from a system sans: the bundled Calibri reserves the
   "." but doesn't paint it at the app's sizes ("v0.1.35" showed as
   "v0 1 35"). unicode-range limits this face to U+002E, so in
   --font-ui-dots every other character is still Calibri. local() only: the
   device has DejaVu Sans and Nimbus Sans (checked on 192.168.8.117,
   2026-10-14); with none of these it doesn't apply, no worse than before. */
@font-face {
  font-family: "CalibriDot";
  src: local("Liberation Sans"), local("Nimbus Sans"), local("Arial"), local("DejaVu Sans");
  font-weight: 100 900;
  unicode-range: U+002E;
}

:root {
  /* =====================================================================
   * COLOR — BRAND
   * ONDA's blue (ondacorp.com). The only accent in the app; there is no
   * secondary palette. #0087ca and #0085ca also appear on that site and are
   * within a hair of --c-brand — deliberately not separate tokens.
   * ===================================================================== */
  --c-brand:          #0285ca;   /* accent: primary action, selection, focus */
  --c-brand-press:    #0270ad;   /* :active fill only */
  --c-brand-deep:     #204f8f;   /* navy companion; 2nd chart series */
  --c-brand-tint:     #eaf5fb;   /* selected row, tinted button. Never text. */
  --c-brand-tint-strong: #d3e9f6;   /* tinted button in a table with selectable rows (2026-10-27) */
  --c-brand-contrast: #ffffff;

  /* =====================================================================
   * COLOR — NEUTRALS
   * Cool grays. Never #000 for text: it reads harsh on this panel.
   * ===================================================================== */
  --c-ink:       #1d1d1f;   /* primary text, headings */
  --c-ink-2:     #6e6e73;   /* labels, secondary text */
  --c-ink-3:     #86868b;   /* placeholders, disabled, axis ticks */
  --c-hairline:  #d2d2d7;   /* every separator and control border, always 1px */
  --c-surface:   #ffffff;   /* cards, fields */
  --c-surface-2: #ececee;   /* page canvas behind the cards; inset fills */
  --c-danger:    #d70015;   /* error borders and messages only */
  /* Battery icon fills (components.html battery()), iPhone-style: green
     while charging, red when low. Used by the battery icon only. */
  --c-battery-charging: #34c759;
  --c-battery-low:      #ff3b30;
  --c-scrim:     rgba(0, 0, 0, 0.32);  /* dims the page behind a modal (keypad) */

  /* =====================================================================
   * COLOR — CHART SERIES
   * For a chart with more series than --c-brand / --c-brand-deep can carry
   * (the WF results histograms: P0, Ps, Pt, Ptot on one chart, 2026-11-01).
   * The first four slots of a validated categorical palette, in its fixed
   * order (adjacent pairs pass colour-blind separation on white). A series
   * keeps its slot when others are hidden. Lines and swatches only, never
   * text: 3 and 4 are under 3:1 on white, so every series also has a
   * legend name and a direct label in ink.
   * ===================================================================== */
  --c-series-1: #2a78d6;   /* blue    — P0 */
  --c-series-2: #eb6834;   /* orange  — Ps */
  --c-series-3: #1baf7a;   /* aqua    — Pt */
  --c-series-4: #eda100;   /* yellow  — Ptot */

  /* =====================================================================
   * TYPOGRAPHY
   * ===================================================================== */

  /* DO NOT add a family here that is not bundled in static/fonts/. On Linux,
     fontconfig fuzzy-matches an unknown family instead of failing through to
     the next entry — asking for "Inter" returns Noto Sans — and Chrome then
     measures and paints the run inconsistently, which visibly corrupts
     right-aligned text (it dropped the "x" from "File Index" and painted the
     label ~30px left of its box). Add the @font-face first, then the family. */
  --font-ui:   Calibri, sans-serif;
  --font-mono: Consolas, ui-monospace, monospace;   /* tabular data only */
  /* Calibri with a "." that paints (CalibriDot above): for numbers that
     need a decimal point but should look like the rest of the UI (the app
     version, the results view's Summary values). */
  --font-ui-dots: "CalibriDot", Calibri, sans-serif;

  /* Two weights only. 700 is heavier than this UI ever goes — hierarchy comes
     from size and weight, never from color or uppercase. */
  --fw-regular:  400;
  --fw-semibold: 600;

  /* Unified size: every role below 3xl renders at the same 17px (the size
     the Measure screen's Mask Sensor Array/Base cards introduced first —
     see display.md). --fs-3xl is the one deliberate exception, kept at its
     original size for Measure's five big sensor readouts (S1-S4, T) only.
     The names/roles stay distinct in case that ever needs to un-collapse,
     but every one of them is 17px right now: xs = chart ticks · sm =
     secondary labels · base = field labels and values · lg = sub-headings ·
     xl = section titles and tab labels · 2xl = large headings. */
  /* !! The bundled Calibri TTFs are unreliable in Chromium on Linux. !!
     At certain (glyph, pixel-size) pairs a glyph gets a corrupt advance: it is
     measured far wider than it paints, so text truncates mid-word and any
     right-aligned or shrink-to-fit box lands in the wrong place. Observed:
         regular 15px — "File Index" painted as "File Inde", ~30px off
         bold    16px — "Xfer" painted as "ifer"
         regular 13px — ":" painted as "·" with a huge advance ("09:04")
     This is the device's own browser, so it happens on the Orange Pi too.
     Ruled out: our CSS, the grid/max-content sizing, font-display, preload,
     and TrueType hinting (stripping fpgm/prep/cvt/gasp renders pixel-identical).
     The fault is in the font files, size-dependent.

     REGULAR WEIGHT (400) IS MUCH WORSE AT 17PX+ THAN AT THE OLD 14PX BASE —
     measured directly (a 22-char clock string, appendChild + getBoundingClientRect),
     not just eyeballed:
         regular:  14px→132px  15px→145px  16px→151px  17px→757px(!)  18px→391px  20px→441px
         semibold: 14px→135px  15px→145px  16px→155px  17px→167px     20px→193px  22px→210px
     Regular jumps ~5x at 17px and stays bad through 24px; semibold stays
     linear/correct all the way to 22px. This is why the tab bar clock
     (app.css .tabbar__clock) is pinned to --fw-semibold rather than
     inheriting the page default --fw-regular — at 17px, regular isn't just
     "some dropped characters" (tolerable, seen throughout this app already),
     it can blow a flex/auto-width element out to 4-5x its real width and
     break layout. Any new element that measures its own text (auto-width,
     shrink-to-fit, right-aligned against a moving edge) should use
     --fw-semibold at this size until the font files are replaced.
     THE REAL FIX is to replace the font files (Carlito is the metric-compatible
     libre drop-in for Calibri). Verify any size you add against both weights. */
  --fs-xs:   17px;
  --fs-sm:   17px;
  --fs-base: 17px;
  --fs-lg:   17px;
  --fs-xl:   17px;
  --fs-2xl:  17px;
  --fs-3xl:  48px;
  /* Second deliberate exception to the unified 17px size, alongside 3xl —
     the Log Viewer's monospace text is explicitly smaller than the rest of
     the app, not bound by the Calibri corrupt-glyph bug above since it
     renders in --font-mono (Consolas/ui-monospace), a completely different
     font stack the bug was never observed in. */
  --fs-log:  13px;
  /* Third exception: the on-screen keypad's key labels. 17px digits look
     lost on a --keypad-key square. Always semibold, per the font-bug note
     above; checked for correct glyph widths at this size. */
  --fs-keypad: 28px;
  /* Fourth exception: Measure's S1–S6 / T1–T6 labels, half the --fs-3xl
     values beside them. Semibold only: regular-weight "6" is corrupt at
     this size (see the font-bug note above); semibold measured correct for
     every S/T label from 20px to 48px. */
  --fs-reading-label: 24px;

  --lh-tight:  1.2;
  --lh-normal: 1.4;

  /* Tracking tightens as text grows; small text is never tracked out. */
  --track-tight: -0.02em;   /* --fs-2xl and up */
  --track-snug:  -0.01em;   /* --fs-lg / --fs-xl */

  /* =====================================================================
   * SPACING — 8px base grid.
   * Vertical room is scarce; expect to live in sp-2 through sp-4.
   * ===================================================================== */
  --sp-1:  4px;
  --sp-2:  8px;
  --sp-3:  12px;
  --sp-4:  16px;
  --sp-6:  24px;
  --sp-8:  32px;

  /* =====================================================================
   * SHAPE
   * Nested corners: inner radius = outer minus the padding between them, which
   * is why control and card sit 4px apart. Keep that if you add a third.
   * ===================================================================== */
  --radius-control: 10px;   /* buttons, fields, segmented, tags, tabs */
  --radius-card:    14px;   /* cards, panels, sections, dialogs */
  --radius-pill:    980px;  /* pills and toggle knobs only */

  /* Borders are hairlines, always 1px. The old 2px outer frame is gone — the
     tab bar and the content region are separated by tone, not by a heavy rule. */
  --border-w-inner: 1px;

  /* Focus is always drawn explicitly: a ring, never a removed outline. */
  --focus-w:      2px;
  --focus-offset: 2px;

  /* =====================================================================
   * ELEVATION — two steps, both cheap to composite.
   * Nothing else gets a shadow. Fields, rows and tabs are hairline only.
   * ===================================================================== */
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.06), 0 0 0 1px rgba(0, 0, 0, 0.04);
  --shadow-2: 0 4px 12px rgba(0, 0, 0, 0.10);

  /* =====================================================================
   * MOTION
   * State-change transitions only, on transform / opacity / color. Never on
   * width, height, top or box-shadow, and never looping, with one exception:
   * the tab bar's busy ring (app.css .tabbar__busy, 2026-11-04) turns while
   * a job runs: a 22px SVG, transform only.
   * ===================================================================== */
  --dur-fast: 120ms;
  --dur-base: 200ms;
  --dur-spin: 1s;         /* one turn of the busy ring */
  --ease:     cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out: cubic-bezier(0.32, 0.72, 0, 1);

  /* =====================================================================
   * LAYOUT — fixed 1024x600 kiosk display
   * ===================================================================== */
  --screen-w:  1024px;
  --screen-h:  600px;
  --tabbar-h:  56px;
  /* Every tab is this wide whatever its label, so the row reads as one strip of
     equal keys. Sized to the longest current label, "FILE MANAGER" — shorter
     than the old "Process Settings" (now "ANALYSIS"), so this was compressed
     down from 180px to free up room in the tab bar for the clock. */
  --tab-w:     150px;
  --content-h: calc(var(--screen-h) - var(--tabbar-h));  /* 544px */
  --gutter:    var(--sp-4);
  --tap-min:   44px;
  --tap-lg:    56px;      /* a screen's one standout action */

  --chart-h:   200px;     /* height budget for one chart in a section */
  /* Compact chart, for a screen stacking several plot groups. Four plots plus
     three groups of controls cannot all have --chart-h on a 544px canvas. */
  --chart-h-sm: 96px;
  /* One wide plot filling a card (Analysis's RMS CH4): what's left of 544px
     under the Index Selection table, the card's title and its status line.
     264px until 2026-10-14, when the index dropdown became a table. */
  --chart-h-lg: 229px;
  /* The results view's per-file card (values, 2D map, chosen plot). 460px
     (2026-10-14; it was 290px) so the 2D map, which takes the widest
     column, is limited less by height: the card fills one screen once the
     results view is scrolled to it. */
  --results-detail-h: 460px;
  --detail-col1-w: 200px;   /* that card's Summary column: fits its widest values */
  --detail-col3-w: 300px;   /* that card's third column (1D profile / spectra / waveform) */
  /* WF results view (2026-11-01): the Statistics card's width (a label
     column and four 4-significant-digit values), and the row's height
     (Statistics beside the histogram chart): what's left of 544px under the
     header and Comments, so the view fits without scrolling. */
  --wf-stats-w: 380px;
  --wf-stats-row-h: 36px;   /* its table rows: read-only, so under --tap-min */
  --wf-results-h: 308px;
  --icon:      20px;      /* glyph size inside a --tap-min icon button */
  --battery-w: 36px;      /* battery icon width; height follows its 27:13 viewBox */
  --net-icon:  28px;      /* tab bar's Ethernet indicator */
  --busy-icon: 22px;      /* tab bar's busy ring */
  --busy-stroke: 3px;     /* its ring's line width */

  /* Log Viewer's own scroll box (app.css .log-viewer) — capped so the pane,
     and so Device Settings as a whole, still fits the 544px budget without
     the *page* needing to scroll. This is a deliberate, explicit exception
     to "one scroll container per page" (display.md §1) for this one box. */
  --log-viewer-h: 380px;

  /* Stacking. A sticky header row only has to sit above its own table's
     rows; a full-content overlay (the Analysis results view) above all of
     that. Without the overlay layer, the index table's sticky header showed
     through the results view. */
  --z-sticky:  1;
  --z-overlay: 10;

  /* Analysis tab's index table columns (Index takes what's left). Status
     fits "Processing WF 17 of 18…" (175px + padding); Actions fits RMS
     results, WF results and Run processing (359px + gaps + padding). Both
     measured 2026-10-27, when WF results joined the row (they were 220 and
     330). Since 2026-11-30 Actions is 300px (two buttons since 2026-11-03:
     Results and Run processing / Remove from queue), which made room for
     RPM and Arm period (s). */
  --col-check:    56px;
  --col-files:    80px;
  --col-rpm:      72px;
  --col-arm:      136px;
  --col-status:   200px;
  --col-actions:  300px;
  /* Index table box: the header and up to 5 rows, then it scrolls. An
     estimate (header ~36px + 5 × ~53px rows) for no-JS; process_settings.js
     sets the exact height of the 5th row's bottom. */
  --index-list-h: 301px;

  --sidenav-w: 180px;     /* Maintenance side nav; the pane takes the rest */

  /* A primary action that must not stretch to its container (Overview's
     Record) — a deliberate width instead of --tap-min's minimum. */
  --btn-w-fixed: 220px;

  /* A text field that holds a short value and shouldn't stretch to fill its
     column (Settings tab's Mode group) — a deliberate width instead of the
     default flex stretch. */
  --field-w-sm: 200px;

  /* On-screen number keypad (_partials/keypad.html). Square keys, well over
     --tap-min, sized so display + 4 rows of keys + the Cancel/OK row fit the
     600px screen with room to spare. */
  --keypad-key: 64px;
  /* On-screen text keyboard (_partials/keyboard.html): 11 keys across, each
     at least --tap-min tall; the typed text shows in a box about 4 lines
     high that scrolls. */
  --kbd-key-w:   56px;
  --kbd-key-h:   48px;
  --kbd-value-h: 96px;
  --info-dialog-w: 480px;  /* info dialog card width */

  /* A checkbox's visible box (the tap target around it is --tap-min). */
  --checkbox-size: 24px;

  /* Optical centring for button labels: the UI face reserves descender space a
     label like "Record" never uses, so a flex-centred label sits ~2px high in a
     --tap-min control. Applied as padding-top, which shifts by half its value.
     Centres the cap-height box, so labels with and without descenders agree. */
  --btn-label-nudge: 4px;
}

@media (prefers-reduced-motion: reduce) {
  :root { --dur-fast: 0ms; --dur-base: 0ms; }
}
