/* Components (W-39, D-35): every reusable piece of the interface, defined once, on design tokens only.
   Screens (home.css, app.css) place these pieces; they never restyle them (tests/test_design_system.py R8).
   Pieces with more than one element have a macro in templates/_components.html. */

/* ── Layout and text ─────────────────────────────────── */
.container { width: var(--container); margin-inline: auto; }
.text-accent { color: var(--accent); }
.eyebrow {
  margin: 0; font-family: var(--font-mono); font-size: var(--t-label); font-weight: var(--fw-strong);
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-secondary);
}
/* Text read at length: more room between its lines and a longest line, counted in the element's own size.
   It goes on the element that holds the text (a paragraph, a list), never on a box. */
.reading { line-height: var(--lh-read); max-width: var(--measure); }

/* ── Buttons: on <a> or <button> ─────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  font: inherit; font-size: var(--t-base); font-weight: var(--fw-strong); line-height: 1.2; text-decoration: none;
  padding: var(--s-3) var(--s-6); border: 1px solid transparent; border-radius: var(--r-md);
  cursor: pointer; transition: border-color var(--d-fast) var(--ease-out), filter var(--d-fast) var(--ease-out);
}
.btn-primary { color: var(--text-on-accent); background: var(--accent-gradient); font-weight: var(--fw-heading); }
.btn-primary:not(:disabled, [aria-disabled="true"]):hover { filter: brightness(1.08); }
.btn-secondary { color: var(--text-primary); background: transparent; border-color: var(--border-strong); }
.btn-secondary:not(:disabled, [aria-disabled="true"]):hover { border-color: var(--accent-ring); }
.btn-danger { color: var(--danger); background: var(--danger-soft); border-color: var(--danger); }
/* A quiet action: one that repeats on every row or sits beside others. A pill in outline and body type
   that answers the pointer; a state pill is monospaced and never reacts. */
.btn-quiet {
  padding: var(--s-1) var(--s-3); font-size: var(--t-sm); letter-spacing: var(--ls-sm); font-weight: var(--fw-medium); white-space: nowrap;
  color: var(--text-primary); background: transparent; border-color: var(--border-strong); border-radius: var(--r-full);
}
.btn-quiet:not(:disabled, [aria-disabled="true"]):hover { border-color: var(--accent-ring); }
.btn-sm { font-size: var(--t-sm); letter-spacing: var(--ls-sm); padding: var(--s-2) var(--s-3); border-radius: var(--r-xs); }
/* The button the current step asks for: a ring, drawn for a button that sits on a card (--bg-elevated). */
.btn-next { box-shadow: 0 0 0 3px var(--bg-elevated), 0 0 0 5px var(--accent); }
.btn-next:focus-visible { outline-offset: 7px; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; filter: none; }
/* A .btn on a span is a picture of a button (the home's sample card): it never looks clickable. */
span.btn { cursor: default; pointer-events: none; }

/* ── Pills, chips, scores ────────────────────────────── */
.pill {
  display: inline-flex; align-items: center; gap: var(--s-2); padding: 3px var(--s-3);
  font-family: var(--font-mono); font-size: var(--t-xs); font-weight: var(--fw-regular); line-height: 1.4; white-space: nowrap;
  border: 1px solid transparent; border-radius: var(--r-full);
}
.pill-accent, .pill-live { color: var(--accent); background: var(--accent-soft); }
.pill-warning { color: var(--warning); background: var(--warning-soft); }
.pill-danger { color: var(--danger); background: var(--danger-soft); }
.pill-success { color: var(--success); background: var(--success-soft); }
.pill-muted { color: var(--text-secondary); border-color: var(--border-strong); }
.pill-live::before { content: ""; width: 6px; height: 6px; border-radius: var(--r-full); background: var(--accent); }
/* The mark of focus beats when its region just changed, then rests (W-54 R39). A script adds the class to
   the mark the server drew at rest; the server never writes it. Two counted passes of 2.4 s: 4.8 s in all,
   under the 5 s from which a movement that starts by itself needs a way to pause it. */
@keyframes pill-pulse {
  from { box-shadow: 0 0 0 0 var(--accent-ring); }
  to { box-shadow: 0 0 0 8px transparent; }
}
.pill-pulse { animation: pill-pulse 2.4s var(--ease-out) 2; }
/* A person's decision (W-52): ink on the whole colour, and the strong weight. Between the advice and the
   decision only the decision is solid (D-10, D-40); the map of the decision is the only way to a page. These
   rules come after the pill itself: they weigh the same in the cascade, and the later weight wins. */
.pill-solid-accent { color: var(--text-on-accent); background: var(--accent); }
.pill-solid-warning { color: var(--text-on-accent); background: var(--warning); }
.pill-solid-danger { color: var(--text-on-accent); background: var(--danger); }
.pill-solid-accent, .pill-solid-warning, .pill-solid-danger { font-weight: var(--fw-strong); }
/* The pill of the decision in its own card: more room on both axes, the same letter. */
.pill-lg { padding: var(--s-1) var(--s-4); }
.chip {
  display: inline-flex; align-items: center; padding: 2px var(--s-2);
  font-family: var(--font-mono); font-size: var(--t-xs); color: var(--text-secondary);
  border: 1px solid var(--border-default); border-radius: var(--r-xs);
}
.chip-accent { color: var(--accent); border-color: var(--accent-ring); }
.score {
  display: inline-flex; align-items: center; padding: 3px var(--s-3); border-radius: var(--r-xs);
  font-family: var(--font-mono); font-size: var(--t-sm); font-weight: var(--fw-regular); font-variant-numeric: tabular-nums;
  color: var(--text-on-accent);   /* the ground is the step's: macro score(value, max_score) */
}
/* A step of the ramp (W-52): the colour of a score or of a rubric level, from red (0) to green (5), and nothing
   else. It goes beside the piece that gives the shape: a score, the small box, the mark of a level. The macro
   level_class picks the step, so the colour never travels without its number. */
.level-0 { background: var(--level-0); color: var(--text-on-accent); }
.level-1 { background: var(--level-1); color: var(--text-on-accent); }
.level-2 { background: var(--level-2); color: var(--text-on-accent); }
.level-3 { background: var(--level-3); color: var(--text-on-accent); }
.level-4 { background: var(--level-4); color: var(--text-on-accent); }
.level-5 { background: var(--level-5); color: var(--text-on-accent); }
/* The small box of a step: a number inside a chip or inside a link. The shape only: the letter is the one of
   the place it sits in, the colour is its step's. */
.level-box { display: inline-block; padding: 0 var(--s-1); border-radius: var(--r-xs); }

/* ── Cards ───────────────────────────────────────────── */
.card { padding: var(--s-6); background: var(--bg-elevated); border: 1px solid var(--border-default); border-radius: var(--r-lg); }
.card-raised { background: var(--bg-glass-strong); border-radius: var(--r-md); }
.card-glow { border-color: transparent; box-shadow: 0 0 0 1px var(--accent-ring), 0 0 48px var(--accent-glow); }
/* A card that asks for attention with its outline alone, no glow: staff screens. */
.card-accent { border-color: var(--accent-ring); }
.card-compact { padding: var(--s-4); border-radius: var(--r-md); }

/* ── Coverage bar: macro bar(label, value) ───────────── */
.bar-row {
  display: grid; grid-template-columns: minmax(0, 8rem) minmax(0, 1fr) 3rem; align-items: center;
  gap: var(--s-3); font-size: var(--t-sm); letter-spacing: var(--ls-sm);
}
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-secondary); }
.bar { display: block; height: 6px; overflow: hidden; border-radius: var(--r-full); background: var(--border-default); }
.bar > span { display: block; width: var(--bar-value, 0%); height: 100%; border-radius: inherit; background: var(--accent); }
/* The quiet variant (W-53): a wrapper that makes the bar inside it a thin grey line, for a share that is not a
   score. The macro bar_track prints the same. */
.bar-quiet .bar { height: 4px; }
.bar-quiet .bar > span { background: var(--text-secondary); }
.bar-value { font-family: var(--font-mono); font-size: var(--t-xs); text-align: right; color: var(--text-secondary); }

/* ── Bar with marks: macro bar_scale(value, marks) (W-50). The track of a bar, always drawn, a mark at each
   threshold and the label of each mark floating beside it, under the track. A mark and its label read the
   --bar-value the macro gives them. A label is 98 px wide and sits 6 px from its mark; the scale leaves half a
   label (49 px) free at each end of the track, and a label never starts before that room nor ends after it:
   near an edge it slides under its mark. Drawn for a filled card: the halo of a mark is --bg-glass-strong. ── */
.bar-scale { position: relative; height: 62px; margin: var(--s-3) 49px 0; }
.bar-scale > dl { margin: 0; }
.bar-mark {
  position: absolute; top: -4px; left: var(--bar-value); translate: calc(-1 * var(--bar-value)) 0;
  width: 2px; height: 14px; border-radius: 1px;
  background: var(--text-primary); box-shadow: 0 0 0 2px var(--bg-glass-strong);
}
.bar-tag {
  position: absolute; top: 14px; left: calc(var(--bar-value) - 49px); width: 98px;
  font-size: var(--t-xs); letter-spacing: var(--ls-sm); color: var(--text-secondary);
}
.bar-tag-before { left: max(calc(var(--bar-value) - 104px), -49px); text-align: right; }
.bar-tag-after { left: min(calc(var(--bar-value) + 6px), calc(100% - 49px)); text-align: left; }
.bar-tag-center { text-align: center; }
.bar-tag dt, .bar-tag dd { display: inline; }
.bar-tag dd { margin: 0 0 0 var(--s-1); color: var(--text-primary); }

/* ── Suggested question: macro suggestion(index, question, tag) ── */
.suggestion {
  display: flex; align-items: flex-start; gap: var(--s-3); padding: var(--s-3) var(--s-4);
  border: 1px solid var(--border-default); border-radius: var(--r-md);
}
.suggestion-index { padding-top: 2px; font-family: var(--font-mono); font-size: var(--t-xs); color: var(--accent); }
.suggestion-body { display: grid; justify-items: start; gap: var(--s-2); min-width: 0; }
.suggestion-question { font-size: var(--t-sm); letter-spacing: var(--ls-sm); line-height: 1.45; }

/* ── A figure with its label: macro stat(label, value) ── */
.stat {
  display: grid; gap: var(--s-1); padding: var(--s-3) var(--s-4);
  background: var(--bg-glass-strong); border: 1px solid var(--border-default); border-radius: var(--r-md);
}
.stat-label, .facts.facts-stat dt {
  font-family: var(--font-mono); font-size: var(--t-label); letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-secondary);
}
.stat-value, .facts-stat dd, .stat-figure { font-size: var(--t-xl); font-weight: 800; font-variant-numeric: tabular-nums; }
.facts-stat dd, .stat-figure { font-weight: var(--fw-heading); }   /* a figure on a staff screen, in a list of facts or alone in a card (W-50): the lighter weight */

/* ── Links: any <a> without a class of its own ───────── */
:where(a) { color: var(--accent); }

/* ── Top bar: the home and every staff page ──────────── */
.topbar { background: var(--bg-deep); border-bottom: 1px solid var(--border-subtle); }
.topbar-inner { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3) var(--s-8); padding-block: var(--s-4); }
.brand { display: inline-flex; align-items: center; gap: var(--s-2); margin-right: auto; font-weight: 700; letter-spacing: -0.01em; color: var(--text-primary); text-decoration: none; }
.brand-mark { flex: none; width: 8px; height: 8px; border-radius: var(--r-full); background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.topnav { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3) var(--s-6); font-size: var(--t-sm); letter-spacing: var(--ls-sm); }
.topnav a { color: var(--text-secondary); text-decoration: none; }
.topnav a:hover { color: var(--text-primary); }
.topnav a[aria-current="page"] { color: var(--accent); }
.topnav form { margin: 0; }
@media (max-width: 760px) {
  .topnav { order: 3; width: 100%; }
  .brand { flex: 1 1 0; min-width: 0; }
}

/* ── Forms ───────────────────────────────────────────── */
.input {
  box-sizing: border-box; max-width: 100%; font: inherit; color: var(--text-primary); background: var(--bg-input);
  padding: var(--s-2) var(--s-3); border: 1px solid var(--border-default); border-radius: var(--r-sm);
}
textarea.input { resize: vertical; }
.input:focus { background: var(--bg-input-focus); border-color: var(--border-strong); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.input:disabled { color: var(--text-disabled); cursor: not-allowed; }
.input-sm { font-size: var(--t-sm); letter-spacing: var(--ls-sm); line-height: 1.2; }
/* One track that may shrink: a <select> with a long option must not widen the form past its container. */
.form-stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s-2); }
.form-stack label, .form-stack legend { font-size: var(--t-sm); letter-spacing: var(--ls-sm); font-weight: var(--fw-medium); }
.form-stack .btn { justify-self: start; margin-top: var(--s-2); }
.form-stack .btn-block { justify-self: stretch; }
.form-inline { display: inline-flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); margin: 0 var(--s-2) var(--s-2) 0; }
.hint { margin: 0; max-width: var(--measure); font-size: var(--t-xs); letter-spacing: var(--ls-sm); color: var(--text-tertiary); }
.field-error { margin: 0; font-size: var(--t-sm); letter-spacing: var(--ls-sm); color: var(--danger); }

/* ── Alerts: a message in a block ────────────────────── */
.alert { margin: 0 0 var(--s-4); padding: var(--s-3) var(--s-4); font-size: var(--t-sm); letter-spacing: var(--ls-sm); border: 1px solid var(--border-default); border-radius: var(--r-sm); }
.alert :where(p) { margin: 0; }
.alert-danger { color: var(--danger); background: var(--danger-soft); border-color: transparent; }
.alert-success { color: var(--success); background: var(--success-soft); border-color: transparent; }
.alert-info { background: var(--info-soft); }

/* ── Data table (wrap it in .table-scroll) ───────────── */
.table { width: 100%; border-collapse: collapse; font-size: var(--t-sm); letter-spacing: var(--ls-sm); }
.table caption { padding-bottom: var(--s-2); text-align: left; font-size: var(--t-xs); letter-spacing: var(--ls-sm); color: var(--text-tertiary); }
.table th, .table td { padding: var(--s-3); text-align: left; vertical-align: top; border-bottom: 1px solid var(--border-subtle); }
.table th { font-weight: var(--fw-strong); }
.table thead th { color: var(--text-secondary); }

/* ── Facts: a <dl> of label and value; .facts-stat makes them figures ── */
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--s-3); margin: 0 0 var(--s-3); }
.facts dt { font-size: var(--t-xs); letter-spacing: var(--ls-sm); color: var(--text-tertiary); }
.facts dd { margin: 0; }
.facts-compact { grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); margin: 0; }

/* ── Fold: a block that folds from its title band, <details class="fold"> with the title in its
   <summary>. The band takes the colour of the block's group: .fold-info or .fold-accent; .fold-danger is
   the block of what cannot be used now, with its border too. ── */
.fold { min-width: 0; background: var(--bg-elevated); border: 1px solid var(--border-default); border-radius: var(--r-md); }
/* The letter of a title band, said once: the band of a fold and the title of a part (W-50) read it here. */
.fold > summary, .part-title {
  padding: 10px var(--s-4);
  font-family: var(--font-mono); font-size: var(--t-label); font-weight: var(--fw-strong); line-height: 1.4;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-secondary);
}
/* What only a band that folds has: its row, its corners and the hand. The title of a part must not look like it. */
.fold > summary {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  border-radius: calc(var(--r-md) - 1px);
  cursor: pointer; list-style: none;
}
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::after {
  content: ""; flex: none; width: 7px; height: 7px; border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor; transform: rotate(45deg); transition: transform var(--d-fast) var(--ease-out);
}
.fold[open] > summary { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.fold[open] > summary::after { transform: rotate(-135deg); }
.fold > summary :where(h2, h3) { margin: 0; font: inherit; letter-spacing: inherit; }
/* An icon as the first thing of a band (macro icon): it keeps its size, and the title stays beside it, so the
   arrow is still the last thing of the band. */
.fold > summary > svg { flex: none; }
.fold > summary > svg + :where(h2, h3) { margin-right: auto; }
.fold > :not(summary) { padding: var(--s-4); }
.fold > :not(summary) + :not(summary) { padding-top: 0; }
.part-info > .part-title, .fold-info > summary { color: var(--info); background: var(--info-soft); }
.part-accent > .part-title, .fold-accent > summary { color: var(--accent); background: var(--accent-soft); }
.fold-danger { border-color: var(--danger-ring); }
.fold-danger > summary { color: var(--danger); background: var(--danger-soft); }
/* The mark of a folded block that got something new: a dot and a word, in the colour of its title.
   No display here: the `hidden` attribute hides it until a script shows it. */
.fold-new { margin-right: auto; }
.fold-new::before {
  content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 6px;
  border-radius: var(--r-full); background: currentColor; vertical-align: middle;
}
/* One short flash around a block whose content just changed; a script adds the class. */
@keyframes fold-flash {
  from { box-shadow: 0 0 0 2px var(--accent); }
  to { box-shadow: 0 0 0 2px transparent; }
}
.fold-flash { animation: fold-flash 1.2s var(--ease-out); }

/* ── Part: a box under a title band that does not fold (W-50). <div class="part"> holds a heading with
   .part-title and a <div class="part-body">; without a title it is a plain box. The band has the letter and the
   two tints of a fold's, and its tint says who wrote the part, never a state: .part-info what was recorded,
   .part-accent what the system wrote. .part-raised fills the box of what the system wrote. ── */
.part { min-width: 0; border: 1px solid var(--border-default); border-radius: var(--r-sm); }
.part-title { margin: 0; border-radius: calc(var(--r-sm) - 1px) calc(var(--r-sm) - 1px) 0 0; }
.part-body { padding: var(--s-3) var(--s-4); }
.part-body > :first-child { margin-top: 0; }
.part-body > :last-child { margin-bottom: 0; }
.part-raised { background: var(--bg-glass-strong); }

/* ── Scroller: a box that scrolls inside itself; whoever places it sets its max-height.
   Positioned, so the visually hidden labels of what it holds scroll with it and not with the page. ── */
.scroller { position: relative; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

/* ── Steps: macro steps(labels, current). Where a process is: done steps carry a check, the rest
   their number (a CSS counter: the <ol> already says it), and exactly one is the current step. ── */
.stepper {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); margin: 0; padding: 10px var(--s-4);
  list-style: none; counter-reset: step; font-size: var(--t-xs); letter-spacing: var(--ls-sm); color: var(--text-tertiary);
}
.stepper li { display: flex; align-items: center; gap: var(--s-2); white-space: nowrap; counter-increment: step; }
.stepper li + li::before { content: ""; width: var(--s-6); height: 1px; background: var(--border-strong); }
.stepper-mark {
  display: inline-grid; place-items: center; width: 20px; height: 20px; border: 1px solid var(--border-strong);
  border-radius: var(--r-full); font-family: var(--font-mono); font-size: var(--t-xs); font-weight: var(--fw-regular); line-height: 1;
}
.stepper-mark:empty::before { content: counter(step); }
.stepper-done { color: var(--text-secondary); }
.stepper-done .stepper-mark { color: var(--text-on-accent); background: var(--text-secondary); border-color: transparent; }
.stepper [aria-current="step"] { color: var(--text-primary); font-weight: var(--fw-medium); }
.stepper [aria-current="step"] .stepper-mark { color: var(--text-on-accent); background: var(--accent); border-color: transparent; }
/* Inside a card the bar lines up with the card's text. */
.stepper-flush { padding-inline: 0; }

/* ── Guide: macro guide(). One sentence that says where you are and what comes next ── */
.guide { display: flex; align-items: center; gap: var(--s-2); margin: 0; padding: 10px var(--s-4); font-size: var(--t-sm); letter-spacing: var(--ls-sm); }
.guide svg { flex: none; color: var(--accent); }

/* ── Bento: tiles of different sizes ─────────────────── */
.bento { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s-4); }
.bento-wide { grid-column: span 2; }
.bento-tall { grid-row: span 2; }
@media (max-width: 1024px) {
  .bento { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .bento { grid-template-columns: minmax(0, 1fr); }
  .bento-wide, .bento-tall { grid-column: auto; grid-row: auto; }
}

/* ── Staged reveal (R20): one pass, complete before 5 s, no script ──
   Inside a .stagger container, .stagger-1 … .stagger-6 fade in one after another and stay;
   .stagger-only-1 arrives with step 1 and leaves when step 2 arrives. The last step starts at 3 s and
   lasts 0.5 s: moving content longer than 5 s would need a pause control the home cannot have. */
@keyframes stagger-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
@keyframes stagger-out {
  to { opacity: 0; visibility: hidden; }
}
.stagger .stagger-1, .stagger .stagger-2, .stagger .stagger-3,
.stagger .stagger-4, .stagger .stagger-5, .stagger .stagger-6 {
  opacity: 0; animation: stagger-in 0.5s var(--ease-out) forwards;
}
.stagger .stagger-1 { animation-delay: 0.3s; }
.stagger .stagger-2 { animation-delay: 0.9s; }
.stagger .stagger-3 { animation-delay: 1.5s; }
.stagger .stagger-4 { animation-delay: 2s; }
.stagger .stagger-5 { animation-delay: 2.5s; }
.stagger .stagger-6 { animation-delay: 3s; }
.stagger .stagger-only-1 {
  opacity: 0;
  animation: stagger-in 0.5s var(--ease-out) 0.3s forwards, stagger-out 0.3s var(--ease-out) 0.9s forwards;
}
@media (prefers-reduced-motion: reduce) {
  .stagger .stagger-1, .stagger .stagger-2, .stagger .stagger-3,
  .stagger .stagger-4, .stagger .stagger-5, .stagger .stagger-6 { animation: none; opacity: 1; transform: none; }
  .stagger .stagger-only-1 { animation: none; opacity: 0; visibility: hidden; }
  .fold-flash { animation: none; }
  .pill-pulse { animation: none; }
}
