/* Workforce Story: a census-board look for a hospital system's HR data.
   UI chrome uses the tokens below; chart series use the validated data-viz palette in app.js. */
:root {
  color-scheme: light;
  --bg: #eef3f6;
  --surface: #fcfdfd;
  --ink: #12293a;
  --ink-2: #44596a;
  --muted: #687b8a;
  --rule: #d3dde4;
  --rule-strong: #a9b8c4;
  --accent: #0d6f6b;
  --accent-wash: #dcefed;
  --board: #ffffff;
  --board-ink: #13315c;
  --focus: #0d6f6b;
  --radius-lg: 14px;
  --radius-sm: 6px;
  --font: "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0c161d; --surface: #13202a; --ink: #e3ebf0; --ink-2: #a9b9c4; --muted: #8597a4;
    --rule: #263844; --rule-strong: #3b5160; --accent: #46b5ae; --accent-wash: #173a3b;
    --board: #101c25; --board-ink: #cfe0f5; --focus: #6fd0c9;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c161d; --surface: #13202a; --ink: #e3ebf0; --ink-2: #a9b9c4; --muted: #8597a4;
  --rule: #263844; --rule-strong: #3b5160; --accent: #46b5ae; --accent-wash: #173a3b;
  --board: #101c25; --board-ink: #cfe0f5; --focus: #6fd0c9;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font);
  font-size: 17px; line-height: 1.55; font-variant-numeric: tabular-nums;
}
a { color: var(--accent); text-underline-offset: 3px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 16px; top: 12px; z-index: 10; background: var(--surface); padding: 8px 12px; }
h1, h2, h3 { margin: 0; line-height: 1.15; letter-spacing: -0.01em; text-wrap: balance; }
p { margin: 0; }

/* ---------- masthead and filters */
.masthead {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; display: flex; gap: 16px; align-items: center; justify-content: space-between;
  flex-wrap: wrap; padding: 12px max(16px, calc((100vw - 1240px) / 2)); background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: 12px; }
.mark { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); position: relative; flex: none; }
.mark::before, .mark::after { content: ""; position: absolute; background: var(--surface); border-radius: 1px; }
.mark::before { width: 12px; height: 4px; left: 7px; top: 11px; }
.mark::after { width: 4px; height: 12px; left: 11px; top: 7px; }
.brand-name { font-weight: 800; font-size: 16px; }
.brand-sub { font-size: 13px; color: var(--muted); }
.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--rule-strong); border-radius: 999px; padding: 3px; margin: 0; background: var(--surface); }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: block; padding: 5px 13px; border-radius: 999px; font-size: 14px; font-weight: 500; color: var(--ink-2); cursor: pointer; }
.seg input:checked + span { background: var(--ink); color: var(--surface); }
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 1px; }
.theme-toggle { border: 1px solid var(--rule-strong); background: var(--surface); color: var(--ink-2); width: 36px; height: 36px; border-radius: 50%; cursor: pointer; display: grid; place-items: center; }

/* ---------- census board hero */
main { max-width: 1240px; margin: 0 auto; padding: 0 16px; }
.census { padding: 56px 0 40px; display: grid; gap: 28px; }
.census-intro { max-width: 820px; display: grid; gap: 16px; }
.census h1 { font-size: clamp(30px, 4.6vw, 52px); font-weight: 800; letter-spacing: -0.02em; }
.lede { font-size: 18px; color: var(--ink-2); max-width: 66ch; }
.board {
  display: grid; grid-template-columns: repeat(4, 1fr); background: var(--board); border: 2px solid var(--board-ink);
  border-radius: var(--radius-lg); overflow: hidden; color: var(--board-ink);
  box-shadow: inset 0 0 0 6px var(--board), inset 0 0 0 7px color-mix(in srgb, var(--board-ink) 18%, transparent);
}
.cell { padding: 20px 22px 18px; border-left: 1px solid color-mix(in srgb, var(--board-ink) 22%, transparent); display: grid; gap: 2px; align-content: start; }
.cell:first-child { border-left: 0; }
.cell .label { font-size: 15px; font-weight: 700; }
.cell .value { font-size: clamp(40px, 6vw, 68px); font-weight: 800; letter-spacing: -0.03em; line-height: 1.05; }
.cell .delta { font-size: 14px; color: var(--ink-2); }
.ribbon { margin: 0; display: grid; gap: 8px; }
.ribbon figcaption { font-size: 14px; color: var(--muted); }
.ribbon-canvas { position: relative; height: 150px; }

/* ---------- chapters */
.chapters { display: grid; grid-template-columns: 210px 1fr; gap: 40px; align-items: start; }
.rail { position: sticky; top: 84px; }
.rail ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; counter-reset: ch; }
.rail a { display: flex; gap: 10px; align-items: baseline; padding: 7px 10px; border-radius: var(--radius-sm); color: var(--ink-2); text-decoration: none; font-weight: 500; font-size: 15px; }
.rail a .n { font-weight: 800; color: var(--muted); min-width: 1ch; }
.rail a[aria-current="true"] { background: var(--accent-wash); color: var(--ink); }
.rail a[aria-current="true"] .n { color: var(--accent); }
.chapter { padding: 8px 0 64px; scroll-margin-top: 84px; display: grid; gap: 22px; }
.chapter + .chapter { border-top: 1px solid var(--rule); padding-top: 48px; }
.ch-head { display: flex; align-items: center; gap: 12px; color: var(--accent); font-weight: 700; font-size: 15px; }
.ch-head .n { width: 28px; height: 28px; border-radius: 50%; border: 2px solid currentColor; display: grid; place-items: center; font-weight: 800; font-size: 14px; }
.chapter h2 { font-size: clamp(26px, 3.2vw, 38px); font-weight: 800; max-width: 26ch; letter-spacing: -0.015em; }
.chapter .body { color: var(--ink-2); max-width: 68ch; font-size: 17px; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.kpi { padding: 14px 16px 14px 0; display: grid; gap: 2px; }
.kpi + .kpi { padding-left: 16px; border-left: 1px solid var(--rule); }
.kpi .v { font-size: 26px; font-weight: 800; letter-spacing: -0.01em; }
.kpi .l { font-size: 14px; color: var(--muted); line-height: 1.35; }
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.chart { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-lg); padding: 18px 18px 12px; display: grid; gap: 10px; margin: 0; min-width: 0; align-content: start; grid-template-rows: auto auto 1fr; }
.chart-foot { align-self: end; }
.chart.wide { grid-column: 1 / -1; }
.chart h3 { font-size: 16px; font-weight: 700; }
.chart .sub { font-size: 14px; color: var(--muted); margin-top: 2px; }
.chart .canvas { position: relative; height: 260px; }
.chart.short .canvas { height: 220px; }
.chart-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; min-height: 28px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); list-style: none; margin: 0; padding: 0; }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.legend i.line { height: 3px; width: 16px; border-radius: 2px; }
.legend i.event { width: 0; height: 12px; border-left: 2px dashed var(--muted); border-radius: 0; }
.table-btn { font: inherit; font-size: 13px; color: var(--accent); background: none; border: 0; padding: 4px 0; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.data-table { max-height: 260px; overflow: auto; border: 1px solid var(--rule); border-radius: var(--radius-sm); }
.data-table table { border-collapse: collapse; width: 100%; font-size: 13px; }
.data-table th, .data-table td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--rule); white-space: nowrap; }
.data-table th { position: sticky; top: 0; background: var(--surface); color: var(--muted); font-weight: 700; }
.data-table td.num, .data-table th.num { text-align: right; }

/* ---------- agent section */
.agent { border-top: 2px solid var(--ink); padding: 48px 0 56px; display: grid; gap: 24px; }
.agent h2 { font-size: clamp(26px, 3.2vw, 38px); font-weight: 800; }
.agent-lede { color: var(--ink-2); max-width: 70ch; }
.harness { display: grid; grid-template-columns: 1.1fr 1fr; gap: 20px; }
.flow { list-style: none; counter-reset: step; margin: 0; padding: 0; display: grid; gap: 0; }
.flow li { counter-increment: step; display: grid; grid-template-columns: 34px 1fr; column-gap: 12px; padding: 0 0 18px; position: relative; }
.flow li::before { content: counter(step); grid-row: span 2; width: 30px; height: 30px; border-radius: 50%; background: var(--ink); color: var(--surface); display: grid; place-items: center; font-weight: 800; font-size: 14px; }
.flow li:not(:last-child)::after { content: ""; position: absolute; left: 14px; top: 32px; bottom: 2px; width: 2px; background: var(--rule-strong); }
.flow strong { font-size: 16px; }
.flow span { color: var(--ink-2); font-size: 15px; }
.guards { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-lg); padding: 20px 22px; }
.guards h3, .questions h3 { font-size: 17px; margin-bottom: 10px; }
.guards ul { margin: 0; padding-left: 18px; display: grid; gap: 8px; color: var(--ink-2); font-size: 15px; }
.guards strong { color: var(--ink); }
code { font-size: 0.9em; background: var(--accent-wash); padding: 1px 5px; border-radius: 4px; }
.questions ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.questions li { border: 1px solid var(--rule-strong); border-radius: 999px; padding: 6px 14px; font-size: 15px; background: var(--surface); }

.foot { max-width: 1240px; margin: 0 auto; padding: 24px 16px 48px; border-top: 1px solid var(--rule); color: var(--muted); font-size: 14px; display: grid; gap: 6px; }

/* ---------- tooltip */
.tip { position: fixed; z-index: 20; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--rule-strong);
  border-radius: 8px; padding: 8px 10px; font-size: 13px; box-shadow: 0 6px 20px rgb(0 0 0 / 0.14); min-width: 140px; max-width: 280px; }
.tip .t { color: var(--muted); margin-bottom: 4px; }
.tip .row { display: flex; align-items: center; gap: 8px; }
.tip .row b { font-weight: 800; font-size: 14px; }
.tip .row i { width: 14px; height: 3px; border-radius: 2px; flex: none; }
.tip .row span { color: var(--ink-2); }

/* ---------- responsive */
@media (max-width: 960px) {
  .chapters { grid-template-columns: 1fr; gap: 0; }
  .rail { position: sticky; top: 61px; z-index: 4; background: var(--bg); margin: 0 -16px; padding: 8px 16px; border-bottom: 1px solid var(--rule); overflow-x: auto; }
  .rail ol { display: flex; gap: 4px; width: max-content; }
  .harness { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  body { font-size: 16px; }
  .masthead { position: static; }
  .rail { top: 0; }
  .board { grid-template-columns: repeat(2, 1fr); }
  .cell:nth-child(3) { border-left: 0; }
  .cell:nth-child(n+3) { border-top: 1px solid color-mix(in srgb, var(--board-ink) 22%, transparent); }
  .charts { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi:nth-child(3) { border-left: 0; padding-left: 0; }
  .kpi:nth-child(n+3) { border-top: 1px solid var(--rule); }
  .census { padding-top: 32px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
