/*
  tokens.css — THE design knobs for the whole site.

  This is the file to edit when you want to change how GammaLab looks
  globally: fonts, text sizes, colours, spacing, corner rounding, shadows,
  animation speed. Nothing else in here — no layout, no components.

  Every other stylesheet refers to these by name and never writes a raw
  value, so changing a number here changes it everywhere at once.

  MUST load FIRST, before base.css and styles.css, on every page.

  ── Rules for editing ──────────────────────────────────────────────────
  • Never rename an existing variable. public/js/*.js reads about twenty of
    them by string (getPropertyValue('--muted') and friends) — a rename
    silently blanks a chart rather than throwing.
  • Colour is written ONCE, not once per theme. A theme states its page
    colour, its ink and its tint; everything else is derived from those
    three in the shared block, so a neutral belongs there and not in a
    theme block. Only put a value in a theme block if the two themes
    genuinely disagree about it.
  • No colour value outside the source-colour block. A grey is the theme's
    ink at an alpha — rgb(from var(--ink) r g b / 0.65) — not #555. That is
    what makes a palette change filter through instead of stopping at the
    first hard-coded value.
  • Alphas step by 0.05 and are written to two decimals — 0.05, 0.10, 0.65,
    0.85. No 0.66, no 0.17. A value that lands between two steps picks one;
    it does not invent a step of its own.
  • Adding a size/space step is fine; adding a twentieth is how we got here.
*/

:root {

  /* ── Type ───────────────────────────────────────────────────────────
     Four sizes carry the whole site, plus one for the landing hero and
     one for chart text on the Flows page.
     --fs-md is the base: body text, and what 1em means everywhere.     */

  --font-sans: 'Instrument Sans', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, Menlo, monospace;

  --fs-xxs: 11px;  /* Flows page only: all chart text except the chart titles       */
  --fs-xs: 13px;   /* chart axis labels, dense table cells, fine print                 */
  --fs-sm: 14px;   /* most app chrome: buttons, table text, form labels, default 14px  */
  --fs-md: 16px;   /* body copy — the base size, default 16px                          */
  --fs-lg: 18px;   /* section headings (h2/h3)                                         */
  --fs-display: clamp(24px, 3.2vw, 32px);   /* landing hero / h1 only                  */

  --fw-normal: 400; /* regular weight */
  --fw-bold: 600; /* bold text */

  --lh-none: 1;      /* buttons, icons, single-line chrome */
  --lh-tight: 1.25;  /* headings, table rows              */
  --lh-normal: 1.5;  /* body copy — the base              */
  --lh-loose: 1.75;   /* long-form prose on public pages   */

  --tracking-wide: 0.04em;   /* letter spacing for all text, headings and body alike */

  /* Text strength, as an opacity of the theme's ink (0 to 1). Main text sits
     a touch under full strength for a smoother look; the dims are the
     secondary levels every grey text colour below is built from. */
  --text-opacity: 0.95;   /* main text */
  --text-dim: 0.85;       /* secondary text: captions, labels, dark-theme inputs */
  --text-soft: 0.75;      /* text under a headline, the ticker bar */
  --text-faint: 0.65;     /* dimmed until selected */
  --fade-near: 0.5;       /* prompt panel reel: the rows next to the one in focus */
  --fade-far: 0.25;       /* prompt panel reel: the rows further out */
  --busy-opacity: 0.6;    /* a button while it waits for the server (same value as the landing page's) */

  /* ── Space ──────────────────────────────────────────────────────────
     One ramp for padding, margin and gap alike. --sp-4 (10px) and
     --sp-5 (20px) are the site's backbone; --sp-6 is the page gutter.  */

  --sp-1: 2px;
  --sp-2: 4px;
  --sp-3: 6px;
  --sp-4: 10px;
  --sp-5: 20px;
  --sp-6: 40px;
  --sp-7: 120px;   /* reserved gutter behind a fixed bottom bar (Prompt tab) */
  --sp-row: 5px;   /* top and bottom padding of a row in a dense list (admin Stats) */

  --page-top: var(--sp-6);      /* distance from the tab bar to content  */
  --content-max: 1200px;        /* width of the centred content column   */
  --content-max-wide: 1400px;   /* wider standalone pages, e.g. pca.html */
  --panel-node-w: 150px;        /* prompt panel: one step box of the graphic */
  --panel-reel-w: 340px;        /* prompt panel: the tool reel, until prompt-panel.js measures its widest text */
  --link-gap: 5px;              /* prompt panel: space between an arrow and its boxes */
  --reel-gap: 5px;              /* prompt panel: space between two tool boxes */
  --modal-max: 800px;           /* centred pop-ups, e.g. the feed's sources */
  --field-h: 25px;              /* admin panel: every one-line field and dropdown */
  --admin-label-w: 100px;       /* admin panel: the label beside a full-width field (Tour steps) */
  --tour-box-w: 600px;          /* the guided tour's step box (css/tour.css) */
  --tour-box-top: 60px;         /* its distance from the top of the screen */
  --flows-summary-h: 195px;     /* Flows page: the summary row's height: the
                                   tallest card (5 lines), so the space under
                                   it matches the space over a chart title */
  --admin-chart-h: 200px;       /* a chart inside an admin sub-foldout   */
  --memory-chart-h: 400px;      /* Website Health → Memory (CEO, 2026-11-18) */
  --flows-plot-top: 40px;      /* Flows page: every chart's plot starts this
                                   far under its title                      */
  --flows-page-bottom: 31px;   /* Flows page: last chart's canvas to the
                                   ticker stream, so its x labels end 40px
                                   over the stream (CEO, 2026-11-13; the
                                   labels' ink ends 9px above the canvas
                                   bottom, measured)                        */
  --flows-plot-bottom: 30px;   /* Flows page: and ends this far above the
                                   chart's bottom, the x-axis labels' row   */
  --flows-chart-h: 350px;       /* Flows page: every chart, one height; set by
                                   the ladder charts, whose rows need about
                                   15px each to be read                     */

  /* ── Corners ────────────────────────────────────────────────────────  */

  --r-sm: 2px;      /* inputs, small buttons, chips  */
  --r-btn: 4px;    /* the tour's buttons: the landing page's button corner (landing.css --r-sm) */
  --r-md: 8px;     /* cards, folds, panels          */
  --r-lg: 12px;     /* chat bubbles, large surfaces  */
  --r-pill: 999px;  /* fully rounded pill buttons    */

  /* ── Shadows ────────────────────────────────────────────────────────
     --border-sh is theme-coloured and defined with the palette below.  */

  --shadow-sm: 0 6px 18px var(--border-sh);
  --shadow-md: 0 10px 20px var(--border-sh);
  --shadow-lg: 8px 8px 20px var(--border-sh);
  --shadow-up: 0 -10px 20px var(--border-sh);   /* bars docked to the bottom */
  /* Floating menus, which need a real drop shadow rather than a page-coloured
     halo — the only shadow that is not built off --border-sh. */
  --shadow-menu: 0 8px 24px rgb(from var(--c-black) r g b / 0.30);

  /* ── Motion ─────────────────────────────────────────────────────────  */

  --t-fast: 0.15s ease;   /* hovers, colour swaps          */
  --t-med: 0.25s ease;    /* folds opening, small reveals  */
  --t-slow: 0.6s ease;    /* panels, page-level moves      */
  --t-fade: 1s ease;      /* slow content fade-ins         */
  --t-feed: 0.5s ease;    /* a news item sliding into the feed, then its time row */

  /* ── Stacking layers ────────────────────────────────────────────────
     Named so a new overlay doesn't have to guess a number. The values
     preserve the ordering the site already had.                        */

  --z-base: 1;
  --z-raised: 2;
  --z-sticky: 10;
  --z-header: 41;
  --z-overlay: 100;
  --z-menu: 201;
  --z-modal: 502;
  --z-popover: 720;
  --z-splash: 999;
  --z-top: 10000;
}

/* ════════════════════════════════════════════════════════════════════════
   COLOUR

   Three layers, in this order:

     1. SOURCE COLOURS — the only place in the site a colour is written as
        a value. Eight hex codes.
     2. THE TWO THEMES — each says what its page colour, its ink and its
        tint are, plus the handful of values the themes truly disagree on.
        Nothing else belongs here.
     3. EVERYTHING ELSE — written once as ink or page at some alpha, using
        relative colour syntax — rgb(from var(--ink) r g b / 0.65) — and
        shared by both themes.

   So changing a source colour, or a theme's ink, filters through the whole
   site: greys, borders, dividers, hovers, chart grids and canvas ink all
   follow, because none of them is a colour of its own.
   ════════════════════════════════════════════════════════════════════════ */

/* ── 1. Source colours ───────────────────────────────────────────────── */

:root {
  --c-black: #000000;      /* default: #000000 */
  --c-white: #ffffff;      /* default: #ffffff */
  --c-shell: #141616;      /* default: #0c0b0d - the near-black chrome: the dark page, and light's bar + fields */
  --c-grey: #808080;       /* the one grey that must read the same on white and on black */
  --c-lavender: #ddccff;   /* dark theme's tint on buttons, menus and inputs */

  --c-primary: #39b3b0;      /* default: #4db3a2 - teal — the brand colour */
  --c-secondary: #323040;
  --c-tertiary: #ff4f89;     /* IV surface ramp, high — the ramp's low end is
                                --primary-dark, calculated from the teal above */

  /* The landing page's own palette (public/css/landing.css keeps its copy),
     worn by the login page so the way in reads as one page. */
  --c-landing-ink: #111113;     /* text */
  --c-landing-muted: #5c5c60;   /* softer grey text */
  --c-landing-link: #17807d;    /* teal used for text */

}

/* ── 2. The two themes ───────────────────────────────────────────────── */

:root,
:root[data-theme="light"] {
  color-scheme: light;

  --bg: var(--c-white);      /* the page   */
  --ink: var(--c-black);     /* everything drawn on it */
  --tint: var(--c-black);    /* wash on buttons, menus, inputs */

  --fg: var(--ink-text);
  --input-fg: var(--ink-text);    /* also the text drawn ON the teal chart chips */
  --tint-1: rgb(from var(--tint) r g b / 0.15);   /* the tinted surface itself */
  --tint-2: rgb(from var(--tint) r g b / 0.20);    /* and its hover             */
  --tint-admin-1: rgb(from var(--tint) r g b / 0.35);  /* admin-only foldouts, same in both themes (CEO, 2026-11-16) */
  --tint-admin-2: rgb(from var(--tint) r g b / 0.40);  /* and their hover             */

  /* Fields and top bar, light theme only. The boxy text inputs/textareas and
     the app's top menu bar deliberately sit on the dark chrome colour in light
     mode. Kept as their own names, NOT folded into --input-bg/--input-fg:
     those two are also worn by the teal chip inputs in the chart headers and
     by the chat bubbles, none of which change. */
  --field-bg: var(--c-shell);
  --bar-bg: var(--c-shell);           /* .tabs + #dash-menu */
  --bar-line: var(--primary);         /* the menu's underline on that bar */
  /* Hover lift: white at 20% laid OVER the field, not instead of it. A plain
     alpha here would let the white page show through and the light text on the
     field would vanish, so it is mixed into --field-bg up front. */
  --field-ho: color-mix(in srgb, var(--c-white) 20%, var(--field-bg));

  --error: #b00020;
  --success: #006400;
  --highlight: #db49fc;

  --chart-sg-prior: rgb(from var(--ink) r g b / 0.30);
  /* Light only, on purpose: dark has never defined a reference line, so the
     chart code's own fallback draws it there. Adding one would silently
     restyle every dark reference line. */
  --chart-ref-line: rgb(from var(--ink) r g b / 0.15);
}

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

  --bg: var(--c-shell);
  --ink: var(--c-white);
  --tint: var(--c-lavender);

  --fg: var(--ink-text);
  --input-fg: rgb(from var(--ink) r g b / var(--text-dim));
  --tint-1: rgb(from var(--tint) r g b / 0.07);
  --tint-2: rgb(from var(--tint) r g b / 0.12);
  --tint-admin-1: rgb(from var(--tint) r g b / 0.35);
  --tint-admin-2: rgb(from var(--tint) r g b / 0.40);

  /* Dark already looked the way light is being pushed towards: the fields are
     just the ordinary tinted surface, and the bar stays teal. */
  --field-bg: var(--tint-1);
  --bar-bg: var(--primary);
  --bar-line: var(--on-primary);      /* teal on a teal bar would vanish */
  --field-ho: var(--field-bg);   /* dark never had a hover here, and is not gaining one */

  --error: #ff6b6b;
  --success: #7cfc7c;
  --highlight: var(--tint-2);

  --chart-sg-prior: rgb(from var(--ink) r g b / 0.75);
}

/* ── 3. Everything else, derived ─────────────────────────────────────── */

:root {

  /* Surfaces */
  --bg2: color-mix(in srgb, var(--ink) 5%, var(--bg));  /* one step off the page */
  --shell: var(--c-shell);      /* dark chrome — the same colour in both themes */
  /* A wash laid over the page to lift one card off the feed without tinting it
     a colour. Ink, so each theme washes with its own opposite — white over a
     white page would be nothing at all. */
  --surface-wash: rgb(from var(--ink) r g b / 0.05);
  --surface-wash-2: rgb(from var(--ink) r g b / 0.10);   /* its hover / selected step */
  --scrim: rgb(from var(--bg) r g b / 0.50);   /* the page colour at half strength, over content */
  /* Opaque, not an alpha: the ticker bar is fixed over the page, so any
     transparency let the feed scroll visibly through it. */
  --ticker-bg: var(--bg2);

  /* Ink */
  --ink-text: rgb(from var(--ink) r g b / var(--text-opacity));   /* main text */
  --text: var(--fg);
  --muted: rgb(from var(--ink) r g b / var(--text-dim));
  --ink-dim: rgb(from var(--ink) r g b / var(--text-faint));   /* dimmed until selected, on the page */
  --ink-soft: rgb(from var(--ink) r g b / var(--text-soft));  /* secondary reading text under a headline */
  --accent: var(--ink);
  --border: rgb(from var(--ink) r g b / 0.10);
  --border-feed: rgb(from var(--ink) r g b / 0.20);   /* divider between news items */
  --page-rule: rgb(from var(--ink) r g b / 0.15);     /* divider between charts on the Flows page, Raydn's --page-rule */
  --border-sh: var(--bg);
  --ticker-fg: rgb(from var(--ink) r g b / var(--text-soft));

  /* Brand. The IV surface ramp runs --primary-dark → --primary → --tertiary. */
  --primary: var(--c-primary);
  /* The low end of the IV surface ramp. Not a colour of its own — it is the
     brand teal at 55%, which is exactly what the hand-written #2a6259 was, so
     changing --c-primary now carries the whole ramp with it instead of leaving
     this end behind. */
  --primary-dark: color-mix(in srgb, var(--c-primary) 55%, var(--c-black));
  --primary-wash: rgb(from var(--c-primary) r g b / 0.25);   /* the highlighted news item's card */
  --tertiary: var(--c-tertiary);
  --secondary: var(--c-secondary);

  /* Drawn ON the teal bars and buttons, or on the dark chrome — so white in
     both themes, because the surface underneath is never --bg. */
  --on-primary: var(--c-white);
  --on-primary-soft: rgb(from var(--c-white) r g b / 0.85);   /* secondary text there */
  --on-primary-dim: rgb(from var(--c-white) r g b / 0.50);     /* dimmed until selected */
  --on-primary-faint: rgb(from var(--c-white) r g b / 0.25);  /* landing footer fine print */
  --on-primary-wash: rgb(from var(--c-white) r g b / 0.10);   /* hover over teal  */
  --on-primary-line: rgb(from var(--c-white) r g b / 0.20);    /* divider over teal */

  /* Fields and controls. --field-* always sit on a dark surface — the chrome in
     light, the tinted surface in dark — so their ink is white either way. */
  --field-fg: rgb(from var(--c-white) r g b / 0.80);
  --field-ph: rgb(from var(--c-white) r g b / 0.65);   /* placeholder */
  --input-bg: var(--tint-1);
  --menu-bg: var(--tint-1);
  --button-bg: var(--tint-1);
  --button-fg: var(--input-fg);
  --button-ho: var(--tint-2);
  --hover: var(--button-ho);
}

/* ── Chart colours ──────────────────────────────────────────────────────
   Read at render time by public/js/*.js via getPropertyValue(). Renaming
   one of these does not error — the chart just draws in the wrong colour
   or not at all. Both themes shared the same alphas already, so these are
   stated once; the two that differ live in the theme blocks above. */

:root {
  --chart-bar: rgb(from var(--primary) r g b / 0.85);
  --chart-border: var(--primary);

  --chart-neg-bar: rgb(from var(--ink) r g b / 0.85);
  --chart-neg-border: rgb(from var(--ink) r g b / 0.85);

  --chart-prior-bar: rgb(from var(--primary) r g b / 0.65);      /* prior GEX/options bars — positive */
  --chart-prior-neg-bar: rgb(from var(--ink) r g b / 0.65);      /* prior bars — negative             */

  --chart-grid: rgb(from var(--ink) r g b / 0.10);
  /* One step up from --chart-grid, for a baseline that has to read as a
     baseline: the PCA live chart hangs bars below zero to show direction, so
     the 0% line is the whole reading and can't look like every other rule. */
  --chart-zero-line: rgb(from var(--ink) r g b / 0.30);
  --chart-tick: var(--muted);
  --chart-line: rgb(from var(--ink) r g b / 0.75);
  --chart-sg-today: var(--primary);   /* spot vs gamma chart */

  /* Flows overview (public/js/flows-charts.js): one colour per flow, the
     same on the summary, the ladder and the price map. The three systematic
     funds share the teal family, with leveraged ETFs in ink so the three
     tell apart; dealers, who trade against them, take the second hue. */
  --chart-flow-cta: var(--primary);
  --chart-flow-vc: rgb(from var(--primary) r g b / 0.55);
  --chart-flow-letf: rgb(from var(--ink) r g b / 0.45);
  --chart-flow-dealer: var(--tertiary);
  --chart-flow-dealer-fill: rgb(from var(--tertiary) r g b / 0.25);
  --chart-flow-net: var(--ink);

  /* Memory chart in Website Health (public/js/app.js, renderMemory): server
     RAM stacked as agents, sites and other, under the server's limit. The
     brand's two chart hues for GammaLab's own parts, ink for everything else
     on the box, and the error colour for the limit it must stay under. */
  --chart-mem-agents: var(--primary);
  --chart-mem-agents-fill: rgb(from var(--primary) r g b / 0.25);
  --chart-mem-sites: var(--tertiary);
  --chart-mem-sites-fill: rgb(from var(--tertiary) r g b / 0.25);
  --chart-mem-other: rgb(from var(--ink) r g b / 0.45);
  --chart-mem-other-fill: rgb(from var(--ink) r g b / 0.10);
  --chart-mem-limit: var(--error);
  --chart-mem-plan: var(--c-grey);     /* the 4 GB DreamHost's plan names */
}

/* ── Price Chart canvas ink ─────────────────────────────────────────────
   The session/day-change verticals, the gamma-flip and current-price lines,
   the crosshair, the implied-move dashes, the provisional-candle overlay and
   every label drawn beside them are painted onto a canvas, where no
   stylesheet can reach them — public/js/app.js and public/js/chart-popup.js
   read these at draw time instead (pmInk / pmLineStyleFromToken). Built off
   --ink like everything above, so a theme says nothing about them at all
   and no alpha, width or dash pattern is written twice.

   This is the ONLY place those five line styles live (2026-08-21). They were
   ten admin-config keys, one per line per theme — which put a style value in
   a per-server runtime file, so a change made on one server was invisible on
   the other, and left the light ones set to white, i.e. invisible. The
   `--chart-line-*` values keep that config's own shorthand
   ("<width>px solid|dashed|dotted <colour>"), because the JS parser for it is
   the thing that turns a dash keyword into Canvas2D's dash array.

   --chart-extended-fill is deliberately NOT ink: the muted band over the
   still-forming candle reads the same grey on white and on black, and
   tying it to the ink would turn it into a black block in light theme. */

:root {
  --chart-vlabel: var(--ink);
  --chart-extended-border: rgb(from var(--ink) r g b / 0.35);
  --chart-extended-fill: rgb(from var(--c-grey) r g b / 0.25);

  /* The dashed reference edges drawn around a PCA time-series line (that
     portfolio's average-day share), at the same 50% as the day-boundary line
     it shares a chart with. */
  --chart-band: rgb(from var(--ink) r g b / 0.50);

  /* The "basket unstable" rule on the PCA time series — the day a portfolio
     stopped being the same portfolio. A plain colour rather than one of the
     `--chart-line-*` shorthands below, because public/js/pca.js is a
     standalone page that does not load app.js and has no parser for that
     shorthand. One step up the ramp from the band it shares a chart with — it
     is an annotation the reader is meant to notice, not structure. */
  --chart-basket-break: rgb(from var(--ink) r g b / 0.80);

  /* Cyber incidents (Context → Cyber incidents): one colour per way an
     incident is first reported, stacked in one bar per month. Item 1.05 is
     the brand bar; other 8-Ks are ink, one step lighter so the teal reads
     first; 6-Ks (foreign companies) take the second hue. The two rule-change
     dates are annotations, drawn like the PCA basket break. */
  --chart-cyber-105: var(--chart-bar);
  --chart-cyber-other: rgb(from var(--ink) r g b / 0.45);
  --chart-cyber-6k: rgb(from var(--tertiary) r g b / 0.70);
  --chart-cyber-rule: var(--chart-basket-break);
  /* The reported-cost line on the right axis: the house line colour, so the
     bars keep the three hues and the line reads by its shape. */
  --chart-cyber-cost: var(--chart-line);

  /* PCA theme map: one colour per portfolio, for its dots and its two end
     names — so a stock reads as belonging to the across theme or the up
     theme at a glance, rather than every dot being the same teal. The
     brand's two chart hues, plain (not relative) colours so Chart.js can
     parse them on hover. */
  --chart-map-across: var(--primary);
  --chart-map-up: var(--tertiary);

  --chart-line-session: 1px dashed rgb(from var(--ink) r g b / 0.50);
  --chart-line-day-boundary: 1px solid rgb(from var(--ink) r g b / 0.50);
  --chart-line-gamma-flip: 1px solid var(--primary);
  --chart-line-current-price: 1px dotted rgb(from var(--ink) r g b / 0.50);
  --chart-line-expected-move: 1px dotted rgb(from var(--ink) r g b / 0.80);
  --chart-line-crosshair: 1px dashed rgb(from var(--ink) r g b / 0.50);
}
