/* ============================================================================
   ELECT — tokens/base.css
   The base token layer. Native CSS variables = the universal language every
   framework (or none) reads identically. See ARCHITECTURE.md §2-3.

   Rules:
   - Inputs (what the host sets) are marked with `base`.
   - Derived values are computed from inputs via calc()/OKLCH — never override
     them by hand.
   - Colors here are PLACEHOLDERS only; the Color Engine overrides them at
     runtime (or, in production, a generated CSS file written once).
   ============================================================================ */

:root {
  /* --- INPUTS (base) — the only roots the host sets ------------------------- */
  --elect-base-brand: #534AB7;   /* brand color = the palette seed */
  --elect-base-unit: 4px;        /* base spacing unit */
  --elect-base-density: 1.5;     /* normal=1.5 · compact=1 · spacious=2.3 (see presets below) */

  /* --- DERIVED: spacing & geometry (calc from base-unit × density) ---------- */
  /* Changing density alone recomputes the whole layout. */
  --elect-bar-gap:    calc(var(--elect-base-unit) * 3 * var(--elect-base-density));
  --elect-bar-radius: calc(var(--elect-base-unit) * 1);
  --elect-bar-width:  calc(var(--elect-base-unit) * 10); /* ~40px default; customizable */
  --elect-bar-min-width: calc(var(--elect-base-unit) * 2); /* ~8px readability floor: below this → scroll, never slivers */
  --elect-chart-pad:  calc(var(--elect-base-unit) * 4 * var(--elect-base-density));
  --elect-legend-gap:    calc(var(--elect-base-unit) * 8 / 3 * var(--elect-base-density));   /* 16px at normal — between legend items, and legend ↔ plot */
  --elect-line-min-step: calc(var(--elect-base-unit) * 4 * var(--elect-base-density));       /* 24px at normal — below this between points → scroll */
  --elect-donut-gap:     calc(var(--elect-base-unit) / 3 * var(--elect-base-density));       /* 2px at normal — surface-colored gap between slices */
  --elect-heatmap-gap:   calc(var(--elect-base-unit) / 3 * var(--elect-base-density));       /* 2px at normal — between cells (proof-1) */
  --elect-card-gap:      calc(var(--elect-base-unit) * 2 * var(--elect-base-density));       /* 12px at normal — a card's title ↔ subtitle ↔ legend ↔ plot */
  --elect-bar-gap-inner: calc(var(--elect-base-unit) * 0.75); /* 3px — between bars of one group (proof-1) */
  --elect-line-width:        calc(var(--elect-base-unit) * 0.375); /* 1.5px — a line series (owner: 2px read heavy) */
  --elect-line-marker-size:  calc(var(--elect-base-unit) * 0.625); /* 2.5px — point (dot) radius */
  /* --elect-waterfall-connector — the line from one waterfall bar's end to the next (SPEC-waterfall Q4).
     NOT set here: unset, it is --elect-chart-axis-line where the chart reads it (a var() set at :root would
     freeze the root's axis color and miss a theme applied on a container). */
  --elect-line-marker-halo:  calc(var(--elect-base-unit) * 1.75);  /* 7px — soft halo radius at full size (hover/focus) */
  --elect-scatter-radius:     calc(var(--elect-base-unit) * 0.875); /* 3.5px — a scatter point */
  --elect-scatter-max-radius: calc(var(--elect-base-unit) * 4.5);   /* 18px — the largest bubble */
  --elect-heatmap-radius:   calc(var(--elect-base-unit) * 0.75);  /* 3px — cell corners (proof-1) */
  --elect-heatmap-min-cell: calc(var(--elect-base-unit) * 7);     /* 28px — narrowest cell, below → scroll */
  --elect-donut-hole: 0.6;                                   /* donut hole = 60% of the radius (pie = 0) */
  --elect-multiples-min-width: calc(var(--elect-base-unit) * 55); /* 220px — narrowest small-multiples panel */
  --elect-multiples-height:    calc(var(--elect-base-unit) * 35); /* 140px — MIN height of a small-multiples panel (they grow to fill) */
  --elect-kpi-radius:    calc(var(--elect-base-unit) * 2.5);  /* 10px — the proof-1 KPI card */
  /* Hover (owner's pick F, 2026-11-15): "mark" (default) = a ring just INSIDE the mark; hover="focus" = every other
     mark fades while the pointer is on one. Line points keep their soft halo (--elect-line-marker-halo-*). */
  --elect-hover-ring:         calc(var(--elect-base-unit) * 0.625);  /* 2.5px inside the mark's edge */
  /* Tooltip (D23): on hover / keyboard focus, at once — fades in while sliding up. */
  --elect-tooltip-bg:     var(--elect-chart-text-primary);
  --elect-tooltip-text:   var(--elect-chart-surface);
  --elect-tooltip-radius: calc(var(--elect-base-unit) * 1.5);  /* 6px */
  --elect-tooltip-gap:    calc(var(--elect-base-unit) * 2);    /* 8px between the mark and the tooltip */
  --elect-tooltip-slide:  calc(var(--elect-base-unit) * 1);    /* 4px — the slide-up on entry */
  --elect-kpi-sparkline-height: calc(var(--elect-base-unit) * 7); /* 28px — the optional KPI trend line */
  --elect-kpi-value-gap: calc(var(--elect-base-unit) * 0.5);  /* 2px — above/below the hero value (proof-1) */
  --elect-kpi-min-width: calc(var(--elect-base-unit) * 45);   /* 180px — the proof-1 KPI card */
  --elect-kpi-delta-pad: calc(var(--elect-base-unit) * 0.25) calc(var(--elect-base-unit) * 2);   /* 1px 8px — the change's pill (owner, 2026-10-05) */
  --elect-kpi-delta-radius: 999px;   /* a pill */
  --elect-kpi-delta-gap: calc(var(--elect-base-unit) * 1.5);   /* 6px — the change ↔ "vs last month" */

  /* --- MOTION (see ARCHITECTURE.md §7) ------------------------------------- */
  --elect-motion-effects-duration: 150ms; /* hover/tooltip/opacity */
  --elect-motion-spatial-duration: 400ms; /* data transforms: reorder/morph */
  --elect-motion-reveal-duration:  650ms; /* initial reveal */
  --elect-motion-easing-standard:   cubic-bezier(0.2, 0, 0, 1);
  --elect-motion-easing-emphasized: cubic-bezier(0.05, 0.7, 0.1, 1); /* decelerate, NO overshoot */
  --elect-motion-overshoot: 0;            /* LAW: 0 on data marks; >0 only on chrome */

  /* --- TYPOGRAPHY ----------------------------------------------------------- */
  /* --elect-font-family is NOT set here: unset, the charts wear the PAGE's font (the
     components fall back to inherit). Set it only to give the charts a font of their own. */
  --elect-text-tick:    11px;  /* axis ticks — smallest, legibility floor */
  --elect-text-label:   12px;  /* legend, axis titles — recede behind the values (owner, 2026-11-15: text hierarchy B) */
  --elect-text-value:   13px;  /* data values on marks */
  --elect-text-title:   15px;  /* chart title */
  --elect-text-display: 36px;  /* KPI value (hero number) */
  --elect-text-weight:      400;
  --elect-text-weight-medium: 500;  /* data values on marks — the most prominent chart text (text hierarchy B) */
  --elect-text-weight-semibold: 600;  /* KPI delta (proof-1) */
  --elect-text-weight-bold: 700;
  --elect-text-leading: 1.4;
  --elect-legend-leading: 1.25;  /* the legend's own line height: its rows stay close to their small keys, whatever the host page's line-height (owner, 2026-10-04) */
  /* LAW: all numeric values use tabular figures → they align in columns and don't jitter on update. */
  --elect-text-numeric: tabular-nums;

  /* --- COLORS (PLACEHOLDER — Color Engine overrides from --elect-base-brand) - */
  --elect-chart-surface:        #f5f0e6;  /* warm light beige */
  --elect-chart-grid-line:      #e7e0d2;
  --elect-chart-axis-line:      #cfc7b6;
  /* The grid's style (owner, 2026-10-05: Off · Solid · Dashed, all light): solid at 0.7; dashed at full color — its
     gaps carry less ink, so at 0.7 it would read fainter than the solid one. */
  --elect-chart-grid-dash:      none;     /* a stroke-dasharray: none = solid · "4 3" = dashed */
  --elect-chart-grid-opacity:   0.7;
  --elect-chart-text-primary:   #2a2724;
  --elect-chart-text-secondary: #6b6358;
  --elect-chart-text-muted:     #847c70;  /* labels/captions — lighter, still >=4.5:1 */
  --elect-chart-mark-stroke:    #4a463f;  /* outline for bars/points */
  /* Cards — the container a chart sits in (D22). The card IS the chart surface; the page behind
     steps one elevation down. The engine derives these per style: outline | elevated | translucent | none. */
  --elect-chart-bg:     var(--elect-chart-surface);   /* transparent inside a translucent card */
  --elect-card-bg:      var(--elect-chart-surface);
  --elect-card-page:    #ebe6dc;
  --elect-card-border:  transparent;
  --elect-card-shadow:  0 1px 2px 0 oklch(0.42 0.14 282 / 0.1), 0 2px 4px 0 oklch(0.42 0.14 282 / 0.07);   /* soft, in the brand's hue (D34) */
  --elect-card-radius:  10px;
  --elect-chart-mark-opacity-muted: 0.4;  /* the other series on hover (D24) — recede, not wash out */
  --elect-scatter-fill-opacity: 0.75;  /* scatter/bubble points: overlaps stay visible */
  --elect-area-fill-opacity: 0.15;  /* line chart "area": tint under a single series */
  --elect-line-marker-halo-opacity: 0.2;  /* the soft halo behind a line point */

  --elect-data-categorical-1: #534ab7;
  --elect-data-categorical-2: #b74a93;
  --elect-data-categorical-3: #4a86b7;
  --elect-data-categorical-4: #6bb74a;
  --elect-data-categorical-5: #b7864a;
  --elect-data-categorical-6: #7a4ab7;
  --elect-data-neutral:  #b3a89a;  /* "Other" + the 7th category */
  /* Mark outlines (bars, legend keys, lines): the same hue, darker — as far as ≥ 3:1 against the
     surface needs (DECISIONS D20). The engine derives them with each palette (Elect.markStroke). */
  --elect-data-categorical-1-stroke: #362490;
  --elect-data-categorical-2-stroke: #8f236f;
  --elect-data-categorical-3-stroke: #256291;
  --elect-data-categorical-4-stroke: #46911f;
  --elect-data-categorical-5-stroke: #916224;
  --elect-data-categorical-6-stroke: #582490;
  --elect-data-neutral-stroke:  #8e8376;
  /* Encodings (DECISIONS D26, experimental). -hatch: 1 = the slot's area marks (bars, slices, legend
     keys) get an oblique hatch in the outline color, and its line is dashed. -outline: 1 = the marks are
     their outline only (business notation's "plan"), line dashed too.
     -line (optional, not set here): the slot's line color when its fill is too pale for a line —
     unset, a line uses the fill.
     -edge (optional, not set here; D29): 1 = the slot's very light fill is read by its outline, so a
     mark whose border is the surface (a donut slice) draws that outline inside itself.
     The engine derives them (Elect.encodingTokens, engine/encodings.js). */
  --elect-data-categorical-1-hatch: 0;
  --elect-data-categorical-2-hatch: 0;
  --elect-data-categorical-3-hatch: 0;
  --elect-data-categorical-4-hatch: 0;
  --elect-data-categorical-5-hatch: 0;
  --elect-data-categorical-6-hatch: 0;
  --elect-data-categorical-1-outline: 0;
  --elect-data-categorical-2-outline: 0;
  --elect-data-categorical-3-outline: 0;
  --elect-data-categorical-4-outline: 0;
  --elect-data-categorical-5-outline: 0;
  --elect-data-categorical-6-outline: 0;
  --elect-hatch-width: calc(var(--elect-base-unit) * var(--elect-base-density) / 4);   /* the hatch line — 1.5px at normal (owner: sparse is fine — D29); follows Density (owner, 2026-11-15) */
  --elect-hatch-step:  calc(var(--elect-base-unit) * var(--elect-base-density));       /* one hatch period — 6px at normal; a mark thinner than this keeps fill + outline only */
  --elect-edge-width: 2px;      /* an outline-only mark's edge ("two hues": its very light fill is read by it) */
  --elect-line-dash: 6 4;
  --elect-line-dot: 2 4;   /* an IBCS forecast line (DECISIONS D28) */
  /* Sequential (low → high) and diverging (low end → neutral middle → high end) ramps,
     7 steps each — placeholders for the default brand; the engine regenerates them. */
  --elect-data-sequential-1: #e3e5ff;
  --elect-data-sequential-2: #bbbef1;
  --elect-data-sequential-3: #9698df;
  --elect-data-sequential-4: #7272cb;
  --elect-data-sequential-5: #534ab7;
  --elect-data-sequential-6: #3d2e99;
  --elect-data-sequential-7: #290b7c;
  --elect-data-diverging-1: #290b7c;
  --elect-data-diverging-2: #7272cb;
  --elect-data-diverging-3: #e3e5ff;
  --elect-data-diverging-4: #e6e6ef;
  --elect-data-diverging-5: #fedfd9;
  --elect-data-diverging-6: #c05c49;
  --elect-data-diverging-7: #6a0000;
  --elect-data-positive: #007c25;  /* sentiment "good" (NOT direction) — vivid + >=4.5:1 as text */
  --elect-data-negative: #b3241f;  /* sentiment "bad"  (NOT direction) — vivid + >=4.5:1 as text */

  /* --- COMPONENT: KPI (ARCHITECTURE Annex A) ------------------------------ */
  /* Deliberately NOT declared here: an alias like var(--elect-chart-surface) on
     :root would be resolved ONCE at the root, so a theme set on a container would
     not reach the card. <elect-kpi> falls back to the semantic tokens where it's
     used; set these only to override:
       --elect-kpi-surface     (default: --elect-chart-surface)
       --elect-kpi-label-text  (default: --elect-chart-text-muted)
       --elect-kpi-value-text  (default: text-primary tinted 22% by the brand — proof-1) */
}

/* --- DENSITY: presets the host/user can apply ----------------------------- */
[data-elect-density="compact"]  { --elect-base-density: 1; }
[data-elect-density="spacious"] { --elect-base-density: 2.3; }
[data-elect-density="normal"]   { --elect-base-density: 1.5; }
/* A custom property's calc() is resolved where it is DECLARED (:root) and then
   inherited as a fixed value — so density set on a CONTAINER would not reach the
   derived spacing. Re-declare ONLY the density-dependent tokens on that element
   (never the colors: that would overwrite a theme applied to the root). Keep
   these in sync with the DERIVED spacing block above. */
[data-elect-density] {
  --elect-bar-gap:   calc(var(--elect-base-unit) * 3 * var(--elect-base-density));
  --elect-chart-pad: calc(var(--elect-base-unit) * 4 * var(--elect-base-density));
  --elect-legend-gap:    calc(var(--elect-base-unit) * 8 / 3 * var(--elect-base-density));   /* 16px at normal — between legend items, and legend ↔ plot */
  --elect-line-min-step: calc(var(--elect-base-unit) * 4 * var(--elect-base-density));       /* 24px at normal — below this between points → scroll */
  --elect-donut-gap:     calc(var(--elect-base-unit) / 3 * var(--elect-base-density));       /* 2px at normal — surface-colored gap between slices */
  --elect-heatmap-gap:   calc(var(--elect-base-unit) / 3 * var(--elect-base-density));       /* 2px at normal — between cells (proof-1) */
  --elect-card-gap:      calc(var(--elect-base-unit) * 2 * var(--elect-base-density));       /* 12px at normal — a card's title ↔ subtitle ↔ legend ↔ plot */
  --elect-hatch-width:   calc(var(--elect-base-unit) * var(--elect-base-density) / 4);   /* 1.5px at normal */
  --elect-hatch-step:    calc(var(--elect-base-unit) * var(--elect-base-density));       /* 6px at normal */
}

/* --- A11y: reduced-motion forces durations to ~0, with no developer code ---- */
@media (prefers-reduced-motion: reduce) {
  :root {
    --elect-motion-effects-duration: 0.01ms;
    --elect-motion-spatial-duration: 0.01ms;
    --elect-motion-reveal-duration:  0.01ms;
  }
}
