/* components.css — the canonical shared component layer for the candidate tool suite.
   Source of truth: docs/design/incoming/2026-08-04-component-unification/handoff/COMPONENTS.md
   (Claude Design spec, token-audited clean 2026-08-04).

   WHY this file exists: every tool re-implemented the same primitives (its own card, chip,
   stat tile, control). The drift-locked inline <style> twins (canvass/voter-tool ↔ demo/*)
   can't hold shared classes without breaking byte-identity — so the shared classes live HERE,
   loaded in <head> after theme.css and before tool CSS, consumed by real tools AND their demo
   twins alike. Tool files keep only their own layout (grid/flex/gap); structure lives here.

   LAW: tokens only (no raw hex outside a var(--x,#fallback) or a %23-encoded data-URI chevron);
   44px min tap; :focus-visible only; every transition/transform collapses under reduced motion;
   never a dotted/●-lozenge status pill. Enforced by scripts/check-components.js.

   Component 2 (modal + bottom sheet) is the EXISTING sheet.css / sheet.js (a11y contract already
   guarded by test-sheet-q800.js) — per-tool modals migrate onto that, not a new class here.
   The disclosure half of component 6 is the EXISTING details.disclosure standard (Q490). */

/* ─────────────────────────────────────────────────────────────────────────
   Conventions (shared by every component below)
   ───────────────────────────────────────────────────────────────────────── */

/* One focus ring for the whole system. :focus-visible only, never bare :focus. */
.card-frame:focus-visible,
.chip:focus-visible,
.stat-tile.is-link:focus-visible,
.ctl:focus-visible,
.opt-card:focus-visible,
.opt-card > input:focus-visible + .opt-card__body {
  outline: var(--bw-ink) solid var(--accent);
  outline-offset: var(--space-1);
}

/* System disabled treatment: never changes layout size. */
.chip[disabled], .chip[aria-disabled="true"],
.ctl[disabled], .ctl[aria-disabled="true"],
.opt-card.is-disabled {
  opacity: .5;
  cursor: not-allowed;
}

/* ─────────────────────────────────────────────────────────────────────────
   1 · Card frame
   ───────────────────────────────────────────────────────────────────────── */
.card-frame {
  background: var(--surface);
  border: var(--bw-hair) solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-soft);
  padding: var(--space-4);
}
@media (min-width: 560px) { .card-frame { padding: var(--space-5); } }

.card-frame--pop {
  border: var(--bw-ink) solid var(--ink);
  box-shadow: var(--shadow-pop-sm);
}
.card-frame--sunken {
  background: var(--surface-sunken);
  border: 0;
  border-radius: var(--r-md);
  box-shadow: none;
  padding: var(--space-3);
}

.card-frame__head {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  justify-content: space-between;
}
.card-frame__title {
  font-family: var(--font-display);
  font-size: var(--fs-lead);
  line-height: var(--lh-tight);
  color: var(--ink);
  margin: 0;
}
.card-frame--dense .card-frame__title { font-size: var(--fs-body); }
.card-frame__meta {
  font-size: var(--fs-small);
  line-height: var(--lh-relaxed);
  color: var(--muted);
  margin: var(--space-1) 0 0;
}
.card-frame__body { margin-top: var(--space-4); }
.card-frame__body > * + * { margin-top: var(--space-3); }
.card-frame__divider {
  height: var(--bw-hair);
  background: var(--line);
  border: 0;
  margin: var(--space-4) calc(var(--space-5) * -1);
}
.card-frame__foot {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
}

/* interactive card: hover/active only when it is a link/button */
.card-frame.is-link { cursor: pointer; transition: border-color var(--dur-fast) ease, box-shadow var(--dur-fast) ease; }
.card-frame.is-link:hover { border-color: var(--line-strong); box-shadow: var(--shadow-soft-lg); }
.card-frame--pop.is-link { transition: box-shadow var(--dur-quick) ease, transform var(--dur-quick) ease; }
.card-frame--pop.is-link:hover { box-shadow: var(--shadow-pop); transform: translate(calc(var(--space-1) * -.5), calc(var(--space-1) * -.5)); }
.card-frame--pop.is-link:active { box-shadow: var(--shadow-pop-sm); transform: translate(0, 0); }

/* selected multi-select list card */
.card-frame.is-selected { border: var(--bw) solid var(--accent); background: var(--accent-soft); }

@media (max-width: 560px) {
  .card-frame__head { flex-direction: column; }
  .card-frame__foot > .btn, .card-frame__foot > .card-frame__foot-btn { width: 100%; }
}

/* ─────────────────────────────────────────────────────────────────────────
   3 · Chip / pill  (never a dotted ● lozenge — status reads through the word)
   ───────────────────────────────────────────────────────────────────────── */
.chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  border-radius: var(--r-pill);
  padding: var(--space-2) var(--space-3);
  font-size: var(--fs-small);
  font-weight: 500;
  line-height: var(--lh-compact);
  white-space: nowrap;
}
/* hit area rule: 44px without enlarging the visual box */
.chip::after {
  content: "";
  position: absolute;
  inset-inline: 0;
  inset-block: calc((44px - 100%) / 2);
  min-height: 44px;
}
.chip__count { font-variant-numeric: tabular-nums; }

/* filter chip (interactive toggle) */
.chip--filter {
  background: var(--surface);
  border: var(--bw-hair) solid var(--line-strong);
  color: var(--ink-2);
  cursor: pointer;
  transition: background-color var(--dur-fast) ease, border-color var(--dur-fast) ease, color var(--dur-fast) ease;
}
.chip--filter:hover { background: var(--surface-sunken); color: var(--ink); }
.chip--filter[aria-pressed="true"], .chip--filter.is-on {
  background: var(--accent-soft);
  border: var(--bw) solid var(--accent);
  color: var(--accent-strong);
  font-weight: 600;
}
.chip--filter[aria-pressed="true"]:hover, .chip--filter.is-on:hover { border-color: var(--accent-strong); }
.chip--filter:active { transform: scale(.97); }

/* tag chip (read-only status/category) */
.chip--tag { border: 0; background: var(--surface-sunken); color: var(--ink-2); }
.chip--tag.is-ok { background: var(--ok-soft); color: var(--ok); }
.chip--tag.is-accent { background: var(--accent-soft); color: var(--accent-strong); }
.chip--tag.is-warn { background: transparent; color: var(--warn); border: var(--bw-hair) solid color-mix(in srgb, var(--warn) 40%, transparent); }
.chip--tag.is-bad { background: transparent; color: var(--bad); border: var(--bw-hair) solid color-mix(in srgb, var(--bad) 40%, transparent); }

/* dense contexts: status as plain text, not a chip */
.status-text { font-size: var(--fs-caption); font-weight: 600; color: var(--muted); }
.status-text.is-ok { color: var(--ok); }
.status-text.is-warn { color: var(--warn); }
.status-text.is-bad { color: var(--bad); }

.chip-row { display: flex; flex-wrap: wrap; gap: var(--space-2); }
@media (max-width: 560px) {
  .chip-row--scroll {
    flex-wrap: nowrap;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    padding-inline: var(--space-4);
    scrollbar-width: none;
  }
  .chip-row--scroll::-webkit-scrollbar { display: none; }
}

/* ─────────────────────────────────────────────────────────────────────────
   4 · Stat tile
   ───────────────────────────────────────────────────────────────────────── */
.stat-tile {
  background: var(--surface);
  border: var(--bw-hair) solid var(--line);
  border-radius: var(--r);
  padding: var(--space-4);
  min-width: 0;
  flex: 1 1 0;
}
.stat-tile--standalone { box-shadow: var(--shadow-soft); }
.stat-tile--sunken { background: var(--surface-sunken); border: 0; border-radius: var(--r-md); padding: var(--space-3) var(--space-4); }
.stat-tile--pop { background: var(--ink); border: 0; }
.stat-tile--pop .stat-tile__value { color: var(--surface); }
.stat-tile--pop .stat-tile__label { color: var(--line); }

.stat-tile__value {
  font-family: var(--font-display);
  font-size: var(--fs-d2);
  line-height: var(--lh-compact);
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
  color: var(--ink);
}
.stat-tile--hero .stat-tile__value { font-size: var(--fs-mega); }
.stat-tile__value .unit { font-size: var(--fs-lead); color: var(--muted); font-weight: 500; }
.stat-tile__label {
  font-size: var(--fs-eyebrow);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 600;
  color: var(--muted);
  line-height: var(--lh-normal);
  margin-top: var(--space-2);
}
.stat-tile__delta { font-size: var(--fs-caption); font-weight: 600; line-height: var(--lh-normal); }
.stat-tile__delta.is-ok { color: var(--ok); }
.stat-tile__delta.is-bad { color: var(--bad); }
.stat-tile__delta.is-flat { color: var(--muted); }
.stat-tile__empty { color: var(--muted); }

/* optional single-percentage meter */
.stat-tile__meter { height: var(--space-2); background: var(--surface-sunken); border-radius: var(--r-track); margin-top: var(--space-3); overflow: hidden; }
.stat-tile--pop .stat-tile__meter { background: var(--line); }
.stat-tile__meter > i { display: block; height: 100%; background: var(--accent); border-radius: var(--r-track); }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--space-3); }
@media (min-width: 760px) { .stat-row { gap: var(--space-4); } }

.stat-tile.is-link { cursor: pointer; transition: border-color var(--dur-fast) ease; }
.stat-tile.is-link:hover { border-color: var(--line-strong); }
.stat-tile.is-link:active { transform: translateY(var(--bw-hair)); }

/* ─────────────────────────────────────────────────────────────────────────
   5 · Control set  (opt-in classes; adopt per tool. 44px min, 16px text.)
   ───────────────────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: var(--space-2); }
.field__label { font-size: var(--fs-small); font-weight: 600; color: var(--ink); line-height: var(--lh-normal); }
.field__hint { font-size: var(--fs-caption); color: var(--muted); line-height: var(--lh-normal); }
.field__msg { font-size: var(--fs-caption); font-weight: 600; color: var(--bad); line-height: var(--lh-normal); }

.ctl {
  background-color: var(--surface);
  border: var(--bw-hair) solid var(--line-strong);
  border-radius: var(--r);
  padding: var(--space-3);
  min-height: 44px;
  font-size: var(--fs-form);
  line-height: var(--lh-normal);
  color: var(--ink);
  transition: border-color var(--dur-fast) ease, background-color var(--dur-fast) ease;
}
.ctl::placeholder { color: var(--muted); }
.ctl:hover { border-color: var(--ink-2); }
.ctl:focus, .ctl:focus-visible { border: var(--bw) solid var(--accent); outline: var(--bw-ink) solid var(--accent); outline-offset: var(--space-1); }
textarea.ctl { min-height: calc(var(--space-8) * 2); line-height: var(--lh-relaxed); resize: vertical; }

/* branded select — background-color (NOT the shorthand, which resets the caret) + a %23-encoded
   token-hex chevron (data-URIs can't read CSS vars; %2356535F == --muted, %232A2730 == --ink-2). */
select.ctl {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4.5l4 4 4-4' stroke='%2356535F' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  background-size: var(--space-3);
  padding-inline-end: calc(var(--space-3) * 3);
}
select.ctl:focus {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4.5l4 4 4-4' stroke='%232A2730' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

.ctl.is-error { border: var(--bw) solid var(--bad); }
.ctl.is-error:focus { outline-color: var(--bad); border-color: var(--bad); }
.ctl[readonly] { background-color: var(--surface-sunken); border-color: var(--line); }
.ctl[disabled] { background-color: var(--surface-sunken); border-color: var(--line); color: var(--muted); }

/* checkbox / radio row — whole row is the 44px target */
.check { display: flex; align-items: center; gap: var(--space-3); min-height: 44px; cursor: pointer; }
.check > input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); flex: none; }

/* ─────────────────────────────────────────────────────────────────────────
   6 · Option card  (disclosure half = existing details.disclosure, Q490)
   ───────────────────────────────────────────────────────────────────────── */
.opt-card {
  position: relative;
  display: flex;
  gap: var(--space-3);
  background: var(--surface);
  border: var(--bw-hair) solid var(--line-strong);
  border-radius: var(--r);
  padding: var(--space-4);
  min-height: 44px;
  cursor: pointer;
  transition: border-color var(--dur-fast) ease, background-color var(--dur-fast) ease;
}
.opt-card > input { position: absolute; opacity: 0; pointer-events: none; }
.opt-card:hover { border-color: var(--ink-2); }
.opt-card:active { transform: scale(.995); }
.opt-card__mark {
  flex: none;
  width: 20px;
  height: 20px;
  margin-top: var(--space-1);
  border: var(--bw) solid var(--line-strong);
  border-radius: var(--r-mark);
}
.opt-card--radio .opt-card__mark { border-radius: var(--r-pill); }
.opt-card__body { display: flex; flex-direction: column; }
.opt-card__title { display: block; font-family: var(--font-display); font-size: var(--fs-body); line-height: var(--lh-tight); color: var(--ink); }
.opt-card__desc { display: block; font-size: var(--fs-small); line-height: var(--lh-relaxed); color: var(--muted); margin-top: var(--space-1); }

.opt-card > input:checked ~ .opt-card__mark,
.opt-card.is-on .opt-card__mark { background: var(--accent); border-color: var(--accent); }
.opt-card:has(> input:checked), .opt-card.is-on {
  border: var(--bw) solid var(--accent);
  background: var(--accent-soft);
}
.opt-card:has(> input:checked) .opt-card__title, .opt-card.is-on .opt-card__title { font-weight: 600; }
.opt-card--recommended.is-on { border: var(--bw-ink) solid var(--ink); box-shadow: var(--shadow-pop-sm); }
.opt-card.is-disabled { border-color: var(--line); background: var(--surface-sunken); }

.opt-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--space-3); }
@media (max-width: 560px) { .opt-grid { grid-template-columns: 1fr; } }

/* ─────────────────────────────────────────────────────────────────────────
   Reduced motion — every transition/transform above collapses to none.
   ───────────────────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .card-frame.is-link, .card-frame--pop.is-link,
  .chip--filter, .stat-tile.is-link, .ctl, .opt-card {
    transition: none;
  }
  .card-frame--pop.is-link:hover, .card-frame--pop.is-link:active,
  .chip--filter:active, .stat-tile.is-link:active, .opt-card:active {
    transform: none;
  }
}
