# Dashboard kit: components.css

The dashboard kit is the older half of Sean's design system: `components.css`
and the dashboard skeleton `starter.html`. It is for data dashboards and
reference pages that carry many numbers. Personal pages, the portfolio, and long
written pages use `site.css` and the starters described in `agents.md`; read that
file first. A dashboard can link both stylesheets (tokens.css, then
components.css, then site.css) and take the site header, footer, and glitch title
from site.css.

Everything here keeps working on the ~30 pages that already link it. Class and
token names are never renamed or removed.

---

## 1. Tokens (most-used; the full set is in tokens.css)

```
/* generator tier - four knobs re-skin the entire system */
--accent-h    195   cyan, the one rationed accent
--secondary-h 320   neon pink, state and second series only
--base-h      252   cool-rich neutral hue for every surface and text step
--contrast    1     0.85 calm ... 1.2 high-contrast (dark mode)

/* surfaces - five-step elevation, depth from lightness not shadow */
--color-bg              page canvas
--color-surface         card / panel / banded section
--color-surface-hover   row hover, faint fill
--color-surface-raised  raised control, button rest
--color-surface-overlay floating overlay, command palette

/* text - four steps, never pure white */
--color-text            body and headings
--color-text-secondary  supporting copy
--color-text-muted      labels, captions, chrome
--color-text-disabled   disabled, ghost
--text-alpha-90/70/50/30/15   text at opacity, for use over a variable background

/* borders */
--color-border   --color-border-emphasis   --color-border-strong

/* accent */
--color-accent          the rationed cyan
--color-accent-hover    hover on accent surfaces
--color-accent-solid-hover  hover on a solid accent fill
--color-accent-border   interactive border
--color-secondary       neon pink, state only
--accent-muted          selected background tint
--accent-subtle         faint accent wash (active row, active chip)
--color-accent-rgb / --color-secondary-rgb   for legacy rgba(var(...), x) call sites

/* status - fixed semantic hues, never accent-swapped */
--color-success  --color-warning  --color-danger  --color-info
--color-success-subtle  --color-warning-subtle  --color-danger-subtle  --color-info-subtle

/* chart series - HEX on purpose, see section 4 */
--green --blue --red --amber --purple --cyan --yellow --orange

/* type */
--font-sans     Inter, body and UI and every heading except the one hero
--font-mono     JetBrains Mono, numbers / code / uppercase labels
--font-display  Big Shoulders Display, the ONE hero header per page
--text-xs (13px FLOOR) --text-sm --text-label --text-base --text-lg
--text-xl --text-2xl --text-3xl --text-4xl        all fluid clamp()
--text-label    the one size for every uppercase mono label
--leading-tight/-snug/-normal/-relaxed   --measure 65ch (older pages only; never cap new text with it)
--tracking-display (-0.03em)  --tracking-tight (-0.01em)  --tracking-label (0.12em)

/* spacing */
--space-xs/sm/md/lg/xl     fluid
--space-1 2 3 4 5 6 8 10 12 16    fixed, 4px base
--space-section            fluid band padding

/* motion */
--duration-instant 80ms  --duration-fast 150ms
--duration-normal 250ms  --duration-slow 400ms
--ease-out (default)  --ease-in  --ease-in-out  --ease-spring  --ease-bounce

/* shadow, focus, radius, layout */
--shadow-sm/-md/-lg  --shadow-ring  --shadow-float  --shadow-float-lg
--focus-ring         use on :focus-visible, never :focus
--radius 0 (and every --radius-* except) --radius-full 9999px
--max-width 1100px   --sidebar-w 260px   --wide-max 1600px (.section-inner.wide)

/* table heat - accent at rising alpha, re-derives with the accent knob */
--heat-1  --heat-2  --heat-3  --heat-4
```

Light mode ships too. It activates on `:root.light` or `html[data-theme="light"]`;
both hooks work. Every token above re-derives, so a page built on tokens flips for
free. Persist the choice in `localStorage` and set the class before first paint.

Compatibility aliases exist for older pages and stay supported permanently:
`--bg --surface --surface2 --surface3 --surface-hover --text --text-dim
--text-muted --text-secondary --text-disabled --accent --accent2 --secondary
--border --border-emphasis`. New code should use the `--color-*` names.

---

## 2. Dashboard page shell

A left nav rail owns section wayfinding at 1100px and up. Below 1100px the rail
becomes a slide-in sheet opened by a top-bar menu button. One link list serves
both, so there is nothing to keep in sync.

```html
<body class="has-rail">

<!-- mobile top bar: hidden at >=1100px -->
<header class="nav-top">
  <button class="nav-menu-btn" id="menuBtn" aria-label="Open navigation"
          aria-expanded="false" aria-controls="navRail">
    <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor"
         stroke-width="2" stroke-linecap="round"><line x1="3" y1="6" x2="21" y2="6"/>
      <line x1="3" y1="12" x2="21" y2="12"/><line x1="3" y1="18" x2="21" y2="18"/></svg>
  </button>
  <span class="nav-rail-brand"><span class="nav-rail-mark">St</span>Dashboard</span>
  <div class="nav-top-controls"><!-- theme toggle, export, etc. --></div>
</header>

<!-- the rail: fixed column on desktop, slide-in sheet on mobile -->
<div class="nav-rail-scrim" id="railScrim"></div>
<aside class="nav-rail" id="navRail" aria-label="Section navigation">
  <div class="nav-rail-brand"><span class="nav-rail-mark">St</span>Dashboard</div>
  <nav class="nav-rail-inner">
    <div class="nav-rail-group">Overview</div>
    <a class="nav-rail-link" href="#summary"><span class="nav-rail-num">01</span>Summary</a>
    <a class="nav-rail-link" href="#detail"><span class="nav-rail-num">02</span>Detail</a>
  </nav>
  <div class="nav-rail-foot"><!-- theme toggle, version --></div>
</aside>

<main>
  <section id="summary" class="section">
    <div class="section-inner">
      <div class="section-num">01</div>
      <h2 class="section-title">Headline.</h2>
      <p class="section-desc">One supporting sentence.</p>
      <!-- content -->
    </div>
  </section>
</main>
</body>
```

`body.has-rail` reserves `--sidebar-w` of left padding at 1100px and up and
removes it below. `.section` alternates `--color-bg` and `--color-surface`
automatically via `:nth-child(odd of .section)`, which gives the banded rhythm for
free; keep sections as siblings for it to work. Plain `.section-inner` is a
centered 960px column; it stays for the older pages that use it, and no new page
uses it. A new dashboard puts `.wide` on every `.section-inner`, so it grows with
the viewport to `--wide-max` (1600px). Widths inside it come from grid columns
(halves, two thirds and a third), never from a max-width on text: a paragraph
fills the column it sits in, and grids gain columns, not whitespace.

Band shading is positional, never semantic. If a page composes its sections from
data or from parts built elsewhere, keep them siblings in document order after
the last render so the alternation reads as one rhythm; a run of the same shade
or a lone stripe at a join is the seam showing.

Scroll-spy is the only script the rail needs. Key the map by each section's real
`id`, never by `href.slice(1)`:

```js
const links = [...document.querySelectorAll('.nav-rail-link')];
const map = new Map(links.map(a => [a.getAttribute('href').slice(1), a]));
const sections = [...document.querySelectorAll('.section[id]')];
function spy(){
  let cur = null;
  for (const s of sections) if (s.getBoundingClientRect().top <= 96) cur = s;
  if (innerHeight + scrollY >= document.documentElement.scrollHeight - 2)
    cur = sections[sections.length - 1];
  links.forEach(a => a.classList.remove('active'));
  const link = cur && map.get(cur.id);
  if (link) link.classList.add('active');
}
addEventListener('scroll', () => requestAnimationFrame(spy), { passive: true });
spy();
```

Mobile sheet: toggle `.open` on both `.nav-rail` and `.nav-rail-scrim`, keep
`aria-expanded` on the menu button in sync, close on scrim click, on Escape, and
on any rail link click. Every tap target in the rail is at least 44px tall
already; do not shrink `.nav-rail-link` padding.

---

## 3. Component class registry

Everything below ships in components.css. Use these before inventing anything.

```
ds-reset                                    box-sizing reset opt-in

nav, nav-brand, nav-links, nav-controls     simple sticky top bar (legacy pattern;
                                              the rail is the default for multi-
                                              section pages)
nav-rail, nav-rail-brand, nav-rail-mark,    left section-nav rail with scroll-spy;
  nav-rail-inner, nav-rail-group,             becomes a slide-in sheet under 1100px
  nav-rail-link (.active), nav-rail-num,      (full contract: agents.md)
  nav-rail-foot, nav-rail-scrim (.open)
nav-top, nav-menu-btn, nav-top-controls     mobile top bar + menu button
body.has-rail                               reserves the rail column on desktop

section, section-inner                      auto-banded page section + centered column
section-num, section-title, section-desc    section chrome
subsection, subsection-title,               subsection chrome
  subsection-desc
h-display                                   the ONE Big Shoulders hero header

card, card-title, card-desc                 flat card, no gradient, no blur
kpi (.secondary), kpi-label, kpi-value,     left-bar KPI marker
  kpi-delta (.up/.down/.flat), kpi-grid       (kpi-grid is the auto-fit container)
stat-band > stat > stat-eyebrow,            headline number row, divided cells
  stat-value, stat-meta
info-row, info-label, info-value            label/value row with bottom border

data-table (.dense)                         bare table, no card wrapper
  thead th, tbody td, tr.total, tfoot         (tr.total / tfoot = emphasized totals)
  td.num / th.num                             right-aligned mono tabular numerics
  td.pos / td.neg                             success / danger colored numerics
  .fit (+ .cols-2 ... .cols-8)                table hugs its content, capped by
                                                column count; values stay next to
                                                their labels (the tables appendix)
  .prose                                      cells hold sentences: lets the table
                                                wrap inside .table-scroll instead
                                                of scrolling sideways
  td.cell-label / th.cell-label               the label column, 24ch floor so a
                                                two-word label never stacks; a LAST
                                                label column takes no floor
  th.wrap / td.wrap, .nowrap                  wrap one header or cell; pin one
  td.sorted                                   tint on the sorted column's cells;
                                                the active th[aria-sort] underlines
  td.heat-1 ... td.heat-4                     magnitude tint on the one column that
                                                carries the story; never a row stripe
detail-note                                 the basis line attached to a figure
                                              (muted mono, own gap); inside td.num
                                              it drops under the figure
table-notes > li                            the notes under a table, at the
                                              table's width; two columns when wide
table-scroll (.sticky-head)                 REQUIRED wrapper for any data-table;
                                              .sticky-head caps it at 70vh and pins
                                              the header inside it. Without it the
                                              header sits in place, never sticky
scroll-x                                    generic wide-content scroll wrapper
                                              (chart canvases, wide blocks)
split (.hug)                                two-up grid, one column under 30ch per
                                              column. .hug: the first block keeps
                                              its content width and the partner
                                              takes the rest, or drops under it
                                              (the table-plus-notes shape, sec. 9)
prose-cols                                  long standalone prose in two columns
                                              at 1000px and up
section-inner.wide                          the dashboard column, to --wide-max
nowrap / tnum                               never-break string; tabular figures
                                              on a number outside a table

btn (.primary / .secondary)                 buttons
search-input                                underline search field, no box
badge (.success/.warning/.danger/.info)     status pill, uppercase
pill (.success/.warning/.danger/.info/      status dot + label
  .live)                                      (.live pulses)
delta (.up/.down/.flat/.plain)              change chip with a triangle glyph
chip (.active), chip-close                  removable / selectable filter chip
tabs > tab (.active)                        underline tabs. Never put page
                                              sections behind tabs (the tables appendix)
segmented > button (.active)                segmented control: switches the view
                                              of ONE dataset (a chart's metric)
toolbar, toolbar-group, toolbar-spacer      filter bar row

progress (.positive/.warning/.danger/       progress bar; inner <span style="width:%">
  .secondary/.sm/.lg) > span
progress-block, progress-block-head,        labelled progress group
  progress-block-value
sparkline (.lg)                             fixed slot for a Chart.js micro chart

drawer-scrim (.open), drawer (.open),       right slide-in panel
  drawer-head, drawer-title, drawer-body,
  drawer-close
empty-state, empty-state-icon,              empty state
  empty-state-title, empty-state-desc
error-state, error-state-icon,              error state
  error-state-title, error-state-desc
stale (.fresh/.aging/.dead)                 "updated 3m ago" freshness dot
skeleton-row                                table loading placeholder, opacity pulse

focus-ring                                  token focus ring on :focus-visible
bg-signal                                   flat fixed canvas fill; paints no
                                              decoration. Optional first body child
spotlight                                   inert layout wrapper, kept for
                                              compatibility. Paints nothing
read-progress                               scroll-linked reading progress bar
reveal                                      scroll-driven fade-up; visible by
                                              default, animates only where supported
reveal-stagger                              children rise in sequence on scroll;
                                              same progressive-enhancement rules
sr-only                                     screen-reader-only live regions

hover-lift / hover-border                   the two canonical card hovers: lift +
                                              shadow, or accent border pickup
toast (.show/.success/.danger)              bottom-right toast; JS adds .show,
                                              removes it after ~2.6s
switch > input + switch-track               toggle. <label class="switch">
                                              <input type="checkbox">
                                              <span class="switch-track"></span>
                                              Label</label>. Spring thumb travel
field > field-label + input,                boxed form input with label, help and
  field-help, field-error                     error lines; aria-invalid="true"
                                              turns the border danger
[data-tip] ([data-tip-pos="bottom"])        pure-CSS tooltip on hover/focus;
                                              short label text only
dialog.modal, modal-head, modal-title,      native <dialog>; open with
  modal-body, modal-foot, modal-close         showModal(). Entrance/exit are CSS
                                              (@starting-style), no JS animation
details.accordion > summary,                native disclosure; body height
  accordion-body                              animates where supported, snaps
                                              elsewhere. Stack them for an FAQ
theme-btn (+ data-theme-toggle)             THE light/dark toggle; pair with
                                              theme.js (section 5). Sun in dark,
                                              moon in light, circle wipe
kbd                                         a literal key named in documentation
                                              prose. Never a badge advertising a
                                              shortcut (agents.md)
callout (.success/.warning/.danger/.info),  left-bar inline note block
  callout-title
link                                        animated underline, grows from left
tabs.animated                               opt-in: active tab underline grows in
progress.indeterminate                      unknown-duration loading bar
data-table th[aria-sort]                    sortable-header arrows; page JS sorts
glow-grid > glow-card                       opt-in cursor border glow across a
                                              card grid (helper in section 5)
count-up                                    tabular-nums pin for rolled-up KPI
                                              numbers (helper in section 5)
```

`@property` still registers `--angle`, `--glow-x`, `--glow-y`, and
`--glow-opacity` so older pages that set them do not break, but nothing in the
system reads them any more. Do not build new effects on them.

---

## 4. Chart.js

Pin 4.4.7. The Canvas API cannot resolve CSS custom properties at paint time, so
chart colors are read out of the computed style at build time. The eight series
tokens are HEX for exactly that reason; every other color in the system is OKLCH.

```html
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.7/dist/chart.umd.min.js"
        integrity="sha384-vsrfeLOOY6KuIYKDlmVH5UiBmgIdB1oEf7p01YgWHuqmOHfZr374+odEv96n9tNC"
        crossorigin="anonymous"></script>
<script src="https://design.seantippen.com/chart-gutter.js"></script>
```

`chart-gutter.js` is required on every page that draws a chart, directly after
Chart.js. Chart.js sizes the y-axis gutter by measuring a tick label when the
chart is built; a chart built before the webfont lands measures the default face,
and when the real face arrives the leading digit is clipped for good ("1,200"
prints ",200"). The file re-measures every chart when each font wave settles.
Do not paste a local re-measure block alongside it.

```js
const tok = n => getComputedStyle(document.documentElement).getPropertyValue(n).trim();

Chart.defaults.color = tok('--color-text-muted');
Chart.defaults.borderColor = tok('--color-border');
Chart.defaults.font.family = tok('--font-sans');
Chart.defaults.font.size = 12;              // the size rules applies to charts too
Chart.defaults.scale.grid.color = tok('--color-border');
Chart.defaults.scale.ticks.color = tok('--color-text-muted');
Chart.defaults.scale.border = { display: false };
Chart.defaults.plugins.legend.display = false;
Chart.defaults.plugins.tooltip.backgroundColor = tok('--color-surface-raised');
Chart.defaults.plugins.tooltip.titleColor = tok('--color-text');
Chart.defaults.plugins.tooltip.bodyColor = tok('--color-text-secondary');
Chart.defaults.plugins.tooltip.borderColor = tok('--color-border');
Chart.defaults.plugins.tooltip.borderWidth = 1;
Chart.defaults.plugins.tooltip.cornerRadius = 0;   // radius 0 holds in charts

// series colors: tok('--green') tok('--blue') tok('--red') tok('--amber')
//                tok('--purple') tok('--cyan') tok('--yellow') tok('--orange')
// fills: append '66' (40%) or '22' (13%) to the hex.
```

`--color-accent` is OKLCH, so it is not directly usable as a canvas fill string in
older engines. Round-trip it through a 1x1 canvas when you need the live accent as
a hex:

```js
function tokenToHex(name){
  const c = document.createElement('canvas'); c.width = c.height = 1;
  const ctx = c.getContext('2d'); ctx.fillStyle = '#000'; ctx.fillStyle = tok(name);
  ctx.fillRect(0, 0, 1, 1);
  const d = ctx.getImageData(0, 0, 1, 1).data;
  return '#' + [d[0], d[1], d[2]].map(v => v.toString(16).padStart(2, '0')).join('');
}
```

Always give a chart canvas a sized parent and wrap it in `.scroll-x`. With
`maintainAspectRatio: false`, set an explicit height on that parent or the canvas
grows without bound. Re-read the tokens and call `chart.update()` after a theme
flip, otherwise the chart keeps the old palette.

Chart craft, on every chart:

- Kill the default look: x-axis grid off, y-axis ticks capped
  (`maxTicksLimit: 4`), no legend for a single series, area fills at low alpha,
  and the endpoint value labelled on a trend line so nobody walks to the axis.
- Every colour difference has a meaning the reader can see: a legend, a key, or
  a sentence. Never colour part of a chart without one.
- Series colours are clearly distinct in hue and lightness. Two near-identical
  hues make the legend useless. Label every series.
- Axis labels wrap, they never truncate. A cut label ("Mauldin High Schoo") has
  stopped naming its category. Chart.js stacks an array of strings as lines:

```js
/* One string if it fits, otherwise at most two lines, split at a word. */
const wrapLabel = (text, cap = 16) => {
  const s = String(text);
  if (s.length <= cap) return s;
  const lines = [];
  let cur = '';
  s.split(' ').forEach(w => {
    if (!cur) { cur = w; return; }
    if ((cur + ' ' + w).length <= cap) { cur += ' ' + w; return; }
    lines.push(cur); cur = w;
  });
  if (cur) lines.push(cur);
  return lines.length <= 2 ? lines : [lines[0], lines.slice(1).join(' ')];
};
```

If two lines are not enough, the chart is the wrong form for that many long
categories; use a table.

---

## 5. Interaction helpers (optional JS)

Two registry components need a few lines of page JS (copy these verbatim), and the
theme toggle is a linked script. Every one respects reduced motion.

**Count-up KPI numbers.** Mark the value `class="count-up" data-count="8142"`
(optional `data-prefix="$"`, `data-suffix="%"`, `data-decimals="1"`). Rolls once
when scrolled into view; writes the final value immediately under reduced motion.

```js
function initCountUps(){
  const els = document.querySelectorAll('.count-up[data-count]');
  if (!els.length) return;
  const rm = matchMedia('(prefers-reduced-motion: reduce)');
  const fmt = (el, v) => {
    const d = +(el.dataset.decimals || 0);
    el.textContent = (el.dataset.prefix || '') +
      v.toLocaleString('en-US', { minimumFractionDigits: d, maximumFractionDigits: d }) +
      (el.dataset.suffix || '');
  };
  const roll = el => {
    const target = parseFloat(el.dataset.count), t0 = performance.now(), dur = 900;
    const step = now => {
      const p = Math.min((now - t0) / dur, 1), e = 1 - Math.pow(1 - p, 3);
      fmt(el, target * e);
      if (p < 1) requestAnimationFrame(step);
    };
    requestAnimationFrame(step);
  };
  const io = new IntersectionObserver(entries => entries.forEach(en => {
    if (!en.isIntersecting) return;
    io.unobserve(en.target);
    rm.matches ? fmt(en.target, parseFloat(en.target.dataset.count)) : roll(en.target);
  }), { threshold: 0.4 });
  els.forEach(el => io.observe(el));
}
```

**Glow grid.** One pointermove listener on the container feeds every card's
`--mx/--my`. The CSS in components.css does the rest.

```js
function initGlowGrids(){
  document.querySelectorAll('.glow-grid').forEach(grid => {
    const cards = grid.querySelectorAll('.glow-card');
    let raf = 0;
    grid.addEventListener('pointermove', e => {
      if (raf) return;
      raf = requestAnimationFrame(() => {
        raf = 0;
        cards.forEach(card => {
          const r = card.getBoundingClientRect();
          card.style.setProperty('--mx', (e.clientX - r.left) + 'px');
          card.style.setProperty('--my', (e.clientY - r.top) + 'px');
        });
      });
    });
  });
}
```

**Theme toggle.** Every page with a light/dark switch uses the system's: the
`.theme-btn` button (components.css) and `theme.js`. The new theme wipes in as a
circle from the button; the sun shows in dark mode and the moon in light mode.
Do not hand-roll a toggle.

```html
<!-- FIRST line in <head>, so a saved light theme paints with no flash -->
<script>try{if(localStorage.getItem('theme')==='light'){var h=document.documentElement;h.classList.add('light');h.setAttribute('data-theme','light')}}catch(e){}</script>

<button class="theme-btn" data-theme-toggle aria-label="Toggle light and dark theme">
  <svg class="icon-sun" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor"
       stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="5"/>
    <line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/>
    <line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/>
    <line x1="1" y1="12" x2="3" y2="12"/><line x1="21" y1="12" x2="23" y2="12"/>
    <line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/></svg>
  <svg class="icon-moon" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor"
       stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/></svg>
</button>

<script src="https://design.seantippen.com/theme.js" defer></script>
```

theme.js saves the choice, sets both light-mode hooks tokens.css reads, keeps
`color-scheme` and `theme-color` in step, re-applies the theme after an Astro
router swap, and fires a `themechange` event on `document`. A page with charts
listens for it, re-reads its tokens, and calls `chart.update()`. On a phone the
button stays in the top bar beside the menu button; it never hides inside the
menu.

---

## Appendix: tables

Rules for tables of figures, from the reporting dashboards. They exist because a
table that breaks them reads wrong, not as taste.

- One-row-per-record data is a `.data-table`, not a card grid.
- One value per cell. Never `4,312 / 3,423` or two metrics in one cell; give each
  metric its own column.
- The value column stays addable: parents and the total only. A breakdown of a
  parent gets its own small table whose total ties to that parent. Indentation
  alone is not hierarchy.
- Values sit next to their labels: a four-column table does not stretch across a
  1920 screen. Use `.fit` with `.cols-N`, or give the table a partner beside it.
- A label column is at least as wide as its longest ordinary label, so labels do
  not wrap one word per line.
- Every comparison names its reference ("1.3x the 2025 rate") and every money
  figure names its basis (gross, net, before fees).
- Numbers are mono, tabular, and right-aligned (`td.num`, `th.num`).
- Colour in a table means something stated in a note. No zebra stripes.
- Every `.data-table` sits inside `.table-scroll`. Sentences in cells take
  `.prose`; long tables take `.table-scroll.sticky-head`.
- A total the reader cannot follow line by line does not ship.
