/* convivial.css — the Convivial Design Kit, assembled as one hand-written
   stylesheet (no build step). Layer order: tokens → foundations → layout →
   components. Identity is the token layer: reskin by overriding variables,
   never by forking components. Source of truth: the convivial-design skill
   (.claude/skills/convivial-design/). */

/* Convivial — type tokens.
   System stacks only; nothing is fetched from a CDN. Sans is the default
   read/UI face; serif stays available for long-form prose via --font-serif;
   mono is data. */
:root {
  --font-serif: "Charter", "Bitstream Charter", "Iowan Old Style",
    "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code",
    Menlo, Consolas, monospace;

  /* Type scale — a minor-third (1.2) modular scale off an 18px root. */
  --step--1: 0.833rem;
  --step-0: 1rem;
  --step-1: 1.2rem;
  --step-2: 1.44rem;
  --step-3: 1.728rem;
  --step-4: 2.074rem;
  --step-5: 2.488rem;

  /* Measure — reading columns cap near 65 characters. */
  --measure: 65ch;
}

/* Convivial — spacing, rule weight, and radius tokens. */
:root {
  /* Spacing scale — one geometric ladder; layout gaps come from here. */
  --space-3xs: 0.25rem;
  --space-2xs: 0.5rem;
  --space-xs: 0.75rem;
  --space-s: 1rem;
  --space-m: 1.5rem;
  --space-l: 2rem;
  --space-xl: 3rem;
  --space-2xl: 4.5rem;

  /* Rule weight and radius. Soft, two-tier rounding after Notion: controls take
     --radius, larger surfaces (cards, empty states) take --radius-lg. */
  --rule-hair: 1px;
  --radius: 6px;
  --radius-lg: 12px;
}

/* Convivial — colour tokens.
   Light theme tuned after Notion. The neutrals are WARM (a faint brown-grey
   bias) and the ink is a warm near-black, which is what makes the paper read
   soft rather than clinical. One restrained blue accent for links and focus;
   a small semantic set carries status meaning. Buttons earn emphasis by
   inverting their ground, so the accent stays rare. */
:root {
  --paper: #faf9f6;
  --paper-raised: #ffffff;
  --paper-sunken: #f1f0ec;
  --ink: #37352f;
  --ink-soft: #787774;
  --ink-faint: #9b9a97;
  --rule: #eae8e2;
  --rule-strong: #dcd9d1;

  /* One restrained accent — a deep ink-adjacent teal, particular enough to be
     a signature where a stock blue would read generic. Links and focus only;
     buttons don't use it. 6.5:1 on --paper. */
  --accent: #14665c;
  --accent-strong: #0e4b44;

  /* Semantic status — Notion's callout palette, carrying meaning (badges, flashes). */
  --good: #3f7d5c;
  --good-bg: #eaf3ec;
  --warn: #96690c;
  --warn-bg: #faeeda;
  --crit: #c0413b;
  --crit-bg: #fbe7e6;

  --focus: var(--accent);
}

/* Dark theme — a warm charcoal, not a cool one, to keep the paper feel. The ink
   stays a warm off-white and the accent lifts to a brighter blue so it holds on
   the dark ground. Buttons flip automatically because they're defined against
   --ink / --paper. The viewer's toggle (data-theme) wins over the OS preference
   in both directions. */
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1f1e1c;
    --paper-raised: #292825;
    --paper-sunken: #191817;
    --ink: #e7e5e0;
    --ink-soft: #9e9c95;
    --ink-faint: #6e6c65;
    --rule: #34322e;
    --rule-strong: #46443f;
    --accent: #55b3a4;
    --accent-strong: #7ccabd;
    --good: #7fb18c;
    --good-bg: #1e2a20;
    --warn: #cda054;
    --warn-bg: #2c2413;
    --crit: #e08079;
    --crit-bg: #2e1b18;
  }
}

:root[data-theme="light"] {
  --paper: #faf9f6; --paper-raised: #ffffff; --paper-sunken: #f1f0ec;
  --ink: #37352f; --ink-soft: #787774; --ink-faint: #9b9a97;
  --rule: #eae8e2; --rule-strong: #dcd9d1;
  --accent: #14665c; --accent-strong: #0e4b44;
  --good: #3f7d5c; --good-bg: #eaf3ec;
  --warn: #96690c; --warn-bg: #faeeda;
  --crit: #c0413b; --crit-bg: #fbe7e6;
}
:root[data-theme="dark"] {
  --paper: #1f1e1c; --paper-raised: #292825; --paper-sunken: #191817;
  --ink: #e7e5e0; --ink-soft: #9e9c95; --ink-faint: #6e6c65;
  --rule: #34322e; --rule-strong: #46443f;
  --accent: #55b3a4; --accent-strong: #7ccabd;
  --good: #7fb18c; --good-bg: #1e2a20;
  --warn: #cda054; --warn-bg: #2c2413;
  --crit: #e08079; --crit-bg: #2e1b18;
}

/* Convivial — foundations.
   A minimal reset plus classless element styles: the design is the type,
   measure, hierarchy, and whitespace. Every element carries its own meaning,
   so it is styled directly — no class needed to make bare HTML read correctly. */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--step-0);
  line-height: 1.6;
  color: var(--ink);
  background: var(--paper);
  text-rendering: optimizeLegibility;
}

/* Headings: serif display — the "design like a book" thesis made visible.
   Document headings speak Charter; app chrome (stat values, dialog titles,
   nav, labels) stays sans via its own explicit rules. Full-strength ink —
   never dimmer than body. */
h1, h2, h3, h4 {
  font-family: var(--font-serif);
  line-height: 1.2;
  font-weight: 700;
  text-wrap: balance;
  color: var(--ink);
  margin: 0;
}
h1 { font-size: var(--step-4); }
h2 { font-size: var(--step-3); }
h3 { font-size: var(--step-2); }
h4 { font-size: var(--step-1); }

p, ul, ol, blockquote, pre, table, figure { margin: 0; }

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
a:hover { color: var(--accent-strong); }

strong { font-weight: 650; }
small { font-size: var(--step--1); color: var(--ink-soft); }

blockquote {
  border-left: 3px solid var(--rule-strong);
  padding-left: var(--space-s);
  color: var(--ink-soft);
  font-style: italic;
}

hr {
  border: 0;
  border-top: var(--rule-hair) solid var(--rule);
  margin: var(--space-l) 0;
}

code, kbd, samp {
  font-family: var(--font-mono);
  font-size: 0.9em;
}
code {
  background: var(--paper-sunken);
  color: var(--ink);
  padding: 0.1em 0.35em;
  border-radius: var(--radius);
}
pre {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  color: var(--ink);
  background: var(--paper-sunken);
  border: var(--rule-hair) solid var(--rule);
  border-radius: var(--radius);
  padding: var(--space-s);
  overflow-x: auto;
}
pre code { background: none; padding: 0; }

/* Tables read like a ledger: hairline rules, tabular figures, no zebra noise. */
table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
caption { text-align: left; color: var(--ink-soft); padding-bottom: var(--space-2xs); }
th, td {
  text-align: left;
  vertical-align: middle;
  padding: var(--space-2xs) var(--space-s);
  border-bottom: var(--rule-hair) solid var(--rule);
}
thead th {
  font-family: var(--font-sans);
  font-size: var(--step--1);
  font-weight: 650;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--ink-soft);
  border-bottom: 2px solid var(--rule-strong);
}

/* Forms — controls speak sans. Explicit ink so a label never inherits a
   colour that collapses against its ground. */
label { font-family: var(--font-sans); font-weight: 550; font-size: var(--step--1); color: var(--ink); }

input, textarea, select {
  font-family: var(--font-sans);
  font-size: var(--step-0);
  color: var(--ink);
  background: var(--paper-raised);
  border: var(--rule-hair) solid var(--rule-strong);
  border-radius: var(--radius);
  padding: var(--space-2xs) var(--space-xs);
  width: 100%;
}
input::placeholder, textarea::placeholder { color: var(--ink-faint); }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--accent); }

/* A visible focus ring everywhere, always. */
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

::selection { background: color-mix(in srgb, var(--accent) 22%, transparent); }

img { max-width: 100%; height: auto; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* Convivial — layout primitives.
   A small set of composition helpers, not a thousand utility classes.
   Vertical rhythm and inline grouping come from gap, never per-element margins,
   so the markup stays reorderable and the rhythm survives edits. */

/* container — the reading column. */
.container { width: 100%; max-width: 72ch; margin-inline: auto; padding-inline: var(--space-m); }
.prose { max-width: var(--measure); }

/* stack — vertical rhythm from gap, never from per-element margins. */
.stack { display: flex; flex-direction: column; gap: var(--space-s); }
.stack-l { display: flex; flex-direction: column; gap: var(--space-l); }
.stack-xs { display: flex; flex-direction: column; gap: var(--space-2xs); }

/* cluster — inline groups (button rows, tag lists) that wrap gracefully. */
.cluster { display: flex; flex-wrap: wrap; gap: var(--space-2xs); align-items: center; }

/* grid — auto-fitting cards; no media queries needed. */
.grid { display: grid; gap: var(--space-m); grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr)); }

/* grid--stats — a denser floor for stat/KPI rows. A tile whose value is "42"
   doesn't need a card's 16rem, and the card floor makes a five-stat row wrap
   into a ragged 2-2-1 on a half-screen window. */
.grid--stats { grid-template-columns: repeat(auto-fit, minmax(min(100%, 9rem), 1fr)); }

/* Convivial — components.
   A thin layer, only for what elements can't express alone. Emphasis comes from
   contrast, not colour. Native <dialog>/<details> do the overlay work; the few
   Stimulus controllers are condiment doses, never load-bearing. */

/* Button — emphasis by contrast, not colour. Primary inverts the ground
   (black-on-white / white-on-black); secondary is an outline; ghost is an
   underlined word. Anchors and buttons look identical. */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2xs);
  font-family: var(--font-sans); font-size: var(--step-0); font-weight: 600;
  line-height: 1; text-decoration: none; cursor: pointer;
  color: var(--paper); background: var(--ink);
  border: var(--rule-hair) solid var(--ink); border-radius: var(--radius);
  padding: 0.6em 1em; transition: opacity 120ms ease;
}
.button:hover { opacity: 0.85; color: var(--paper); text-decoration: none; }
.button:disabled, .button[aria-disabled="true"] { opacity: 0.4; cursor: not-allowed; }

.button--quiet { background: transparent; color: var(--ink); border-color: var(--rule-strong); }
.button--quiet:hover { background: var(--paper-sunken); color: var(--ink); opacity: 1; }

.button--ghost { background: transparent; color: var(--accent); border-color: transparent; padding-inline: 0.4em; }
.button--ghost:hover { background: transparent; color: var(--accent-strong); text-decoration: underline; opacity: 1; }

/* Card — a crisp white sheet on the warm paper, softly rounded. No drop
   shadow; the border does the raising, so it uses --rule-strong — the faint
   --rule disappears against the paper (the Notion trap, on structural edges). */
.card {
  background: var(--paper-raised);
  border: var(--rule-hair) solid var(--rule-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-m);
}

/* Badge — a small stamped label; status variants use the semantic tokens.
   nowrap + middle alignment keep it from disturbing table row height. */
.badge {
  display: inline-flex; align-items: center; vertical-align: middle;
  white-space: nowrap;
  font-family: var(--font-sans); font-size: var(--step--1); font-weight: 600;
  letter-spacing: 0.02em; line-height: 1;
  padding: 0.35em 0.6em; border-radius: var(--radius);
  background: var(--paper-sunken); color: var(--ink-soft);
}
.badge--good { background: var(--good-bg); color: var(--good); }
.badge--warn { background: var(--warn-bg); color: var(--warn); }
.badge--crit { background: var(--crit-bg); color: var(--crit); }

/* Flash — a dismissible notice. A severity stripe plus a semantic tint carry
   state; explicit ink text so nothing collapses in either theme. */
.flash {
  display: flex; gap: var(--space-s); align-items: start;
  padding: var(--space-s); border-radius: var(--radius);
  border: var(--rule-hair) solid var(--rule);
  border-left: 3px solid var(--ink-soft);
  background: var(--paper-raised); color: var(--ink);
}
.flash--good { border-left-color: var(--good); background: var(--good-bg); }
.flash--warn { border-left-color: var(--warn); background: var(--warn-bg); }
.flash--crit { border-left-color: var(--crit); background: var(--crit-bg); }
.flash__body { flex: 1; }
.flash__dismiss { background: none; border: 0; color: var(--ink-soft); cursor: pointer; font-size: var(--step-1); line-height: 1; padding: 0 var(--space-2xs); }

/* Nav — a masthead rule, links in sans. Current page is marked, not guessed. */
.nav { display: flex; flex-wrap: wrap; gap: var(--space-m); align-items: baseline; padding-block: var(--space-s); border-bottom: 2px solid var(--rule-strong); font-family: var(--font-sans); }
.nav a { color: var(--ink-soft); text-decoration: none; font-weight: 550; }
.nav a:hover { color: var(--ink); }
.nav a[aria-current] { color: var(--ink); text-decoration: underline; text-underline-offset: 6px; text-decoration-thickness: 2px; }
.nav__brand { font-weight: 700; color: var(--ink); font-size: var(--step-1); }

/* Pagination — hairline-boxed page links; current inverts. */
.pagination { display: flex; gap: 0; font-family: var(--font-sans); font-variant-numeric: tabular-nums; }
.pagination a, .pagination span { padding: var(--space-3xs) var(--space-xs); border: var(--rule-hair) solid var(--rule-strong); margin-left: -1px; text-decoration: none; color: var(--ink-soft); }
.pagination a:hover { color: var(--ink); }
.pagination a:first-child, .pagination span:first-child { border-top-left-radius: var(--radius); border-bottom-left-radius: var(--radius); }
.pagination a:last-child, .pagination span:last-child { border-top-right-radius: var(--radius); border-bottom-right-radius: var(--radius); }
.pagination a[aria-current], .pagination span[aria-current] { background: var(--ink); color: var(--paper); border-color: var(--ink); position: relative; z-index: 1; }

/* Field — label + control + hint, stacked. */
.field { display: flex; flex-direction: column; gap: var(--space-3xs); }
.field__hint { font-size: var(--step--1); color: var(--ink-soft); }
.field__error { font-size: var(--step--1); color: var(--crit); font-weight: 650; font-family: var(--font-sans); }

/* Empty state — the honest "nothing here yet", not a dead end. */
.empty { text-align: center; padding: var(--space-xl) var(--space-m); color: var(--ink-soft); border: 1px dashed var(--rule-strong); border-radius: var(--radius-lg); }

/* An eyebrow / uppercase label for section kickers. */
.eyebrow { font-family: var(--font-sans); font-size: var(--step--1); font-weight: 650; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-faint); }

/* ========================================================================
   Web-app tier — the parts a real application needs beyond a document:
   an app shell, overlays, record-oriented display, richer forms, icons,
   and loading states. Native <dialog>/<details> do the work; JavaScript
   stays at condiment dose (four small Stimulus controllers).
   ===================================================================== */

/* --- Icons: one inline SVG sprite, sized by font, coloured by currentColor.
   No icon font, no CDN. Render <svg class="icon"><use href="#i-check"/></svg>. */
.icon {
  width: 1.15em; height: 1.15em; flex: none; display: inline-block;
  vertical-align: -0.18em;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
.icon--lg { width: 1.5em; height: 1.5em; }
.icon--dots { fill: currentColor; stroke: none; }

/* --- Skip link: hidden until focused, first thing in the DOM. */
.skip-link {
  position: fixed; top: -4rem; left: var(--space-s); z-index: 100;
  background: var(--ink); color: var(--paper);
  font-family: var(--font-sans); font-weight: 600;
  padding: var(--space-2xs) var(--space-s); border-radius: var(--radius);
  transition: top 120ms ease;
}
.skip-link:focus { top: var(--space-s); }

/* --- Visually hidden, but available to screen readers. */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* --- App shell: sidebar + top bar + scrolling content. Collapses to an
   off-canvas drawer under 768px; toggle .is-nav-open (sidebar_controller). */
.app {
  display: grid;
  grid-template-columns: var(--app-sidebar-w, 16rem) 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas: "sidebar topbar" "sidebar content";
  min-height: 100vh;
}
.app__sidebar {
  grid-area: sidebar; background: var(--paper-sunken);
  border-right: var(--rule-hair) solid var(--rule);
  display: flex; flex-direction: column; gap: var(--space-s);
  padding: var(--space-s); overflow-y: auto;
}
.app__brand { font-family: var(--font-sans); font-weight: 700; font-size: var(--step-1); color: var(--ink); padding: var(--space-2xs); }
/* The top bar carries the 2px ledger rule — the same masthead stroke as .nav
   and thead, so the signature runs through document and app alike. */
.app__topbar {
  grid-area: topbar; background: var(--paper);
  border-bottom: 2px solid var(--rule-strong);
  display: flex; align-items: center; gap: var(--space-s);
  padding: var(--space-2xs) var(--space-m);
}
.app__topbar-spacer { flex: 1; }
.app__content { grid-area: content; overflow: auto; padding: var(--space-l); }
.app__nav { display: flex; flex-direction: column; gap: 2px; font-family: var(--font-sans); }
.app__nav-heading { font-size: var(--step--1); text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-faint); font-weight: 650; padding: var(--space-s) var(--space-xs) var(--space-3xs); }
.app__nav a {
  display: flex; align-items: center; gap: var(--space-2xs);
  padding: var(--space-2xs) var(--space-xs); border-radius: var(--radius);
  color: var(--ink-soft); text-decoration: none; font-weight: 550;
}
.app__nav a:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); color: var(--ink); }
.app__nav a[aria-current] { background: color-mix(in srgb, var(--ink) 9%, transparent); color: var(--ink); }
.app__menu-button { display: none; }
@media (max-width: 767px) {
  .app { grid-template-columns: 1fr; grid-template-areas: "topbar" "content"; }
  .app__menu-button { display: inline-flex; }
  .app__sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(80vw, 16rem); z-index: 50;
    transform: translateX(-100%); transition: transform 160ms ease;
  }
  .app.is-nav-open::before { content: ""; position: fixed; inset: 0; z-index: 40; background: color-mix(in srgb, #000 45%, transparent); }
  .app.is-nav-open .app__sidebar { transform: none; }
}

/* --- Modal: native <dialog>. Turbo-Frame friendly; Escape closes for free. */
dialog {
  border: var(--rule-hair) solid var(--rule); border-radius: var(--radius-lg);
  padding: 0; width: min(92vw, 32rem);
  background: var(--paper-raised); color: var(--ink);
  box-shadow: 0 12px 48px color-mix(in srgb, #000 28%, transparent);
}
dialog::backdrop { background: color-mix(in srgb, #000 45%, transparent); }
.dialog__header { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-s); padding: var(--space-m) var(--space-m) 0; }
.dialog__title { font-family: var(--font-sans); font-weight: 650; font-size: var(--step-1); margin: 0; }
.dialog__body { padding: var(--space-s) var(--space-m); }
.dialog__footer { display: flex; justify-content: flex-end; gap: var(--space-2xs); padding: var(--space-2xs) var(--space-m) var(--space-m); }

/* --- Dropdown menu: native <details>. menu_controller closes it on outside
   click / Escape / selection. Right-align with .menu__list--right. */
.menu { position: relative; display: inline-block; font-family: var(--font-sans); }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.menu__list {
  position: absolute; z-index: 30; top: calc(100% + 4px); left: 0;
  min-width: 12rem; display: flex; flex-direction: column;
  background: var(--paper-raised); border: var(--rule-hair) solid var(--rule);
  border-radius: var(--radius); padding: var(--space-3xs);
  box-shadow: 0 6px 24px color-mix(in srgb, var(--ink) 16%, transparent);
}
.menu__list--right { left: auto; right: 0; }
.menu__item {
  display: flex; align-items: center; gap: var(--space-2xs); width: 100%;
  padding: var(--space-2xs) var(--space-xs); border-radius: var(--radius);
  background: none; border: 0; text-align: left; cursor: pointer;
  font: inherit; font-weight: 500; color: var(--ink); text-decoration: none;
}
.menu__item:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); }
.menu__item--danger { color: var(--crit); }
.menu__sep { height: 1px; background: var(--rule); margin: var(--space-3xs) 0; }

/* --- Toasts: transient, corner-stacked notices (deliver via Turbo Streams
   into #toasts). toast_controller auto-dismisses. Shares the flash language. */
.toasts { position: fixed; z-index: 80; bottom: var(--space-m); right: var(--space-m); display: flex; flex-direction: column; gap: var(--space-2xs); width: min(92vw, 24rem); }
.toast {
  display: flex; gap: var(--space-2xs); align-items: start;
  background: var(--paper-raised); color: var(--ink);
  border: var(--rule-hair) solid var(--rule); border-left: 3px solid var(--ink-soft);
  border-radius: var(--radius); padding: var(--space-s);
  box-shadow: 0 6px 24px color-mix(in srgb, var(--ink) 18%, transparent);
  animation: toast-in 160ms ease;
}
.toast--good { border-left-color: var(--good); }
.toast--warn { border-left-color: var(--warn); }
.toast--crit { border-left-color: var(--crit); }
.toast__body { flex: 1; }
.toast__dismiss { background: none; border: 0; color: var(--ink-soft); cursor: pointer; font-size: var(--step-1); line-height: 1; padding: 0 var(--space-2xs); }
@keyframes toast-in { from { opacity: 0; transform: translateY(0.5rem); } }

/* --- Description list: key/value for record "show" pages. */
.detail-list { display: grid; grid-template-columns: max-content 1fr; gap: var(--space-2xs) var(--space-l); font-family: var(--font-sans); margin: 0; }
.detail-list dt { color: var(--ink-soft); font-size: var(--step--1); font-weight: 600; }
.detail-list dd { margin: 0; color: var(--ink); }
@media (max-width: 480px) { .detail-list { grid-template-columns: 1fr; gap: 0; } .detail-list dd { margin-bottom: var(--space-2xs); } }

/* --- Stat / KPI tile for dashboards. */
.stat { display: flex; flex-direction: column; gap: var(--space-3xs); }
.stat__label { font-family: var(--font-sans); font-size: var(--step--1); font-weight: 650; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-soft); }
.stat__value { font-family: var(--font-sans); font-size: var(--step-4); font-weight: 680; letter-spacing: -0.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat__delta { font-family: var(--font-sans); font-size: var(--step--1); font-weight: 600; display: inline-flex; align-items: center; gap: var(--space-3xs); }
.stat__delta--up { color: var(--good); }
.stat__delta--down { color: var(--crit); }

/* --- Table upgrades: hover, numeric alignment, sortable headers, sticky head,
   row actions, and responsive stacking (.table--stacked + td[data-label]). */
.table--hover tbody tr:hover { background: color-mix(in srgb, var(--ink) 4%, transparent); }
.table--sticky thead th { position: sticky; top: 0; background: var(--paper); z-index: 1; }
.col-num { text-align: right; font-variant-numeric: tabular-nums; }
/* col-nowrap — short data cells ("3h ago", a status badge + time, a two-word
   header) read worse broken across lines than they cost in width. Deliberately
   a per-column opt-in, not a table default: long text columns must stay free
   to wrap or narrow screens lose them entirely. */
.col-nowrap { white-space: nowrap; }
/* Group headers inside a table: one <tbody> per group, its first row a
   full-width <th scope="colgroup"> ("June", a tenant, a customer). Styled by
   the semantic attribute — the markup already carries the meaning, so no
   class is needed. */
tbody th[scope="colgroup"] {
  font-family: var(--font-sans);
  font-size: var(--step--1);
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  text-align: left;
  padding-top: var(--space-m);
  border-bottom: var(--rule-hair) solid var(--rule-strong);
}
.row-actions { display: flex; gap: var(--space-3xs); justify-content: flex-end; }
th[aria-sort] { cursor: pointer; user-select: none; white-space: nowrap; }
th[aria-sort]:hover { color: var(--ink); }
.sort-ind { opacity: 0.3; }
th[aria-sort="ascending"] .sort-ind, th[aria-sort="descending"] .sort-ind { opacity: 1; }
@media (max-width: 640px) {
  .table--stacked thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table--stacked tr { display: block; border: var(--rule-hair) solid var(--rule); border-radius: var(--radius); padding: var(--space-2xs) var(--space-s); margin-bottom: var(--space-2xs); }
  .table--stacked td { display: flex; justify-content: space-between; gap: var(--space-s); border: 0; padding: var(--space-3xs) 0; text-align: right; }
  .table--stacked td::before { content: attr(data-label); font-family: var(--font-sans); font-size: var(--step--1); font-weight: 600; color: var(--ink-soft); text-align: left; }
}

/* --- Forms II: grouping, required marks, toggle, choices, add-ons, actions. */
fieldset { border: var(--rule-hair) solid var(--rule); border-radius: var(--radius); padding: var(--space-s) var(--space-m) var(--space-m); margin: 0; }
legend { font-family: var(--font-sans); font-weight: 650; font-size: var(--step--1); text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-soft); padding-inline: var(--space-2xs); }
.req { color: var(--crit); font-weight: 650; }

.switch { display: inline-flex; align-items: center; gap: var(--space-2xs); cursor: pointer; font-family: var(--font-sans); }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__track { flex: none; width: 2.25rem; height: 1.3rem; padding: 2px; border-radius: 999px; background: var(--rule-strong); transition: background 120ms ease; }
.switch__thumb { display: block; width: calc(1.3rem - 4px); height: calc(1.3rem - 4px); border-radius: 999px; background: #fff; box-shadow: 0 1px 2px color-mix(in srgb, #000 30%, transparent); transition: transform 120ms ease; }
.switch input:checked + .switch__track { background: var(--accent); }
.switch input:checked + .switch__track .switch__thumb { transform: translateX(0.95rem); }
.switch input:focus-visible + .switch__track { outline: 2px solid var(--focus); outline-offset: 2px; }

.choices { display: flex; flex-direction: column; gap: var(--space-2xs); }
.choice { display: flex; align-items: center; gap: var(--space-2xs); font-family: var(--font-sans); }

.input-group { display: flex; align-items: stretch; }
.input-group > * { border-radius: 0; margin-left: -1px; }
.input-group > :first-child { margin-left: 0; border-top-left-radius: var(--radius); border-bottom-left-radius: var(--radius); }
.input-group > :last-child { border-top-right-radius: var(--radius); border-bottom-right-radius: var(--radius); }
.input-group > input:focus { position: relative; z-index: 1; }
.input-group__addon { display: inline-flex; align-items: center; white-space: nowrap; padding: 0 var(--space-xs); background: var(--paper-sunken); border: var(--rule-hair) solid var(--rule-strong); color: var(--ink-soft); font-family: var(--font-sans); }

.form-actions { display: flex; gap: var(--space-2xs); justify-content: flex-end; align-items: center; padding-top: var(--space-s); border-top: var(--rule-hair) solid var(--rule); }
.form-actions--start { justify-content: flex-start; }

/* --- Loading: spinner, button busy state, skeleton, Turbo progress bar. */
.spinner { display: inline-block; width: 1.15em; height: 1.15em; border: 2px solid color-mix(in srgb, var(--ink) 25%, transparent); border-top-color: var(--ink); border-radius: 999px; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.button[aria-busy="true"] { color: transparent; pointer-events: none; position: relative; }
.button[aria-busy="true"]::after { content: ""; position: absolute; inset: 0; margin: auto; width: 1em; height: 1em; border: 2px solid color-mix(in srgb, var(--paper) 45%, transparent); border-top-color: var(--paper); border-radius: 999px; animation: spin 0.7s linear infinite; }
.skeleton { color: transparent; border-radius: var(--radius); background: linear-gradient(90deg, var(--paper-sunken), color-mix(in srgb, var(--ink) 8%, var(--paper-sunken)), var(--paper-sunken)); background-size: 200% 100%; animation: skeleton 1.4s ease-in-out infinite; }
@keyframes skeleton { to { background-position: -200% 0; } }
.turbo-progress-bar { height: 2px; background: var(--accent); }

/* ------------------------------------------------------------------------
   Tier two — built when a product first needed them. Same disciplines:
   native elements do the work, JavaScript stays at condiment dose.
   --------------------------------------------------------------------- */

/* --- Tabs: proper ARIA tablist; tabs_controller toggles aria-selected and
   panel visibility, and handles arrow keys. With JS off every panel shows,
   which reads fine (progressive enhancement). */
.tabs { display: flex; flex-direction: column; gap: var(--space-m); }
.tabs__list { display: flex; gap: var(--space-2xs); border-bottom: 2px solid var(--rule); font-family: var(--font-sans); }
.tabs__tab {
  appearance: none; background: none; border: 0; border-bottom: 2px solid transparent;
  margin-bottom: -2px; padding: var(--space-2xs) var(--space-xs);
  font: inherit; font-weight: 600; color: var(--ink-soft); cursor: pointer;
}
.tabs__tab:hover { color: var(--ink); }
.tabs__tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.tabs__panel[hidden] { display: none; }

/* --- Breadcrumbs: the hierarchy trail on deep record pages. No JS. */
.breadcrumbs ol { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2xs); list-style: none; margin: 0; padding: 0; font-family: var(--font-sans); font-size: var(--step--1); }
.breadcrumbs li { display: inline-flex; align-items: center; gap: var(--space-2xs); }
.breadcrumbs li:not(:first-child)::before { content: "/"; color: var(--ink-faint); }
.breadcrumbs a { color: var(--ink-soft); text-decoration: none; }
.breadcrumbs a:hover { color: var(--ink); text-decoration: underline; }
.breadcrumbs [aria-current] { color: var(--ink); font-weight: 600; }

/* --- Avatar: image or initials. A circle is right for a face; like the switch,
   it's a shape convention, not decoration. Stack with .avatar-group. */
.avatar {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 2.25rem; height: 2.25rem; border-radius: 999px; overflow: hidden;
  background: var(--paper-sunken); color: var(--ink-soft);
  font-family: var(--font-sans); font-weight: 650; font-size: var(--step--1);
  text-transform: uppercase; user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar--sm { width: 1.6rem; height: 1.6rem; font-size: 0.7rem; }
.avatar--lg { width: 3rem; height: 3rem; font-size: var(--step-0); }
.avatar-group { display: inline-flex; }
.avatar-group .avatar { border: 2px solid var(--paper); margin-left: -0.6rem; }
.avatar-group .avatar:first-child { margin-left: 0; }

/* --- Tooltip: CSS-only, shown on hover and keyboard focus. The trigger must be
   focusable (a button, link, or tabindex="0"). Put the same text in aria-label
   or title so screen readers get it — data-tip is visual only. Keep tips short. */
.tooltip { position: relative; display: inline-flex; }
.tooltip::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 7px); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--paper); font-family: var(--font-sans); font-size: var(--step--1); font-weight: 500;
  padding: var(--space-3xs) var(--space-2xs); border-radius: var(--radius); white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity 120ms ease; z-index: 60;
}
.tooltip::before {
  content: ""; position: absolute; bottom: calc(100% + 2px); left: 50%; transform: translateX(-50%);
  border: 5px solid transparent; border-top-color: var(--ink);
  opacity: 0; pointer-events: none; transition: opacity 120ms ease; z-index: 60;
}
.tooltip:hover::after, .tooltip:hover::before,
.tooltip:focus-visible::after, .tooltip:focus-visible::before { opacity: 1; }

/* --- Progress & meter: styled native elements — accessible and determinate.
   <progress> shows a task's completion; <meter> shows a level, colouring by
   its low/high/optimum bounds. Distinct from the indeterminate .spinner. */
progress { appearance: none; -webkit-appearance: none; width: 100%; height: 0.5rem; border: 0; border-radius: 999px; background: var(--paper-sunken); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--paper-sunken); border-radius: 999px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 999px; }
progress::-moz-progress-bar { background: var(--accent); }
meter { width: 100%; height: 0.5rem; }
meter::-webkit-meter-bar { background: var(--paper-sunken); border: 0; border-radius: 999px; }
meter::-webkit-meter-optimum-value { background: var(--good); border-radius: 999px; }
meter::-webkit-meter-suboptimum-value { background: var(--warn); border-radius: 999px; }
meter::-webkit-meter-even-less-good-value { background: var(--crit); border-radius: 999px; }
meter:-moz-meter-optimum::-moz-meter-bar { background: var(--good); }
meter:-moz-meter-sub-optimum::-moz-meter-bar { background: var(--warn); }
meter:-moz-meter-sub-sub-optimum::-moz-meter-bar { background: var(--crit); }
