/* Component primitives. Every rule references tokens.css only — no
   hardcoded colors, spacing, or radii below this line. */

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

body {
  background: var(--base);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.5;
  margin: 0;
  font-variant-numeric: tabular-nums lining-nums;
}

a { color: var(--signature); text-decoration: none; }
a:hover { color: var(--signature-hover); text-decoration: underline; }
a:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-control);
}

h1, h2, h3 { font-weight: 600; line-height: 1.25; margin: 0 0 var(--space-4); color: var(--ink); }
h1 { font-size: var(--text-xl); }
h2 { font-size: var(--text-lg); margin-top: var(--space-6); }
h3 { font-size: var(--text-base); }

/* Pairs a heading with an action (a "+ New X" button) on the same line.
   Reused wherever a list or section needs a create/action affordance —
   the page header above a table, a dashboard section, a detail-page
   subsection. Absorbs the heading's own top margin so spacing stays
   consistent whether or not the button is present. */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-top: var(--space-6);
}
.section-header > h1, .section-header > h2, .section-header > h3 { margin: 0; }
.section-header:first-child { margin-top: 0; }

/* Two or more buttons side by side, e.g. multiple actions in a section
   header. Plain flex + gap — no visual grouping beyond spacing. */
.btn-group { display: flex; gap: var(--space-2); flex-wrap: wrap; }

.icon { display: inline-block; vertical-align: -0.15em; flex-shrink: 0; }
.icon--spinner { animation: spin 800ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Button ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-control);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color var(--duration) var(--ease),
              border-color var(--duration) var(--ease),
              color var(--duration) var(--ease);
}
.btn:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }

.btn--primary { background: var(--signature); border-color: var(--signature); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--signature-hover); border-color: var(--signature-hover); }
.btn--primary:active:not(:disabled) { background: var(--signature-pressed); border-color: var(--signature-pressed); }

.btn--secondary { background: var(--base); border-color: var(--hairline); color: var(--ink); }
.btn--secondary:hover:not(:disabled) { background: var(--surface); }
.btn--secondary:active:not(:disabled) { background: var(--surface-raised); }

.btn--danger { background: var(--base); border-color: var(--danger); color: var(--danger); }
.btn--danger:hover:not(:disabled) { background: var(--surface); }
.btn--danger:active:not(:disabled) { background: var(--surface-raised); }

/* A borderless text button for the small in-row actions on a record
   page (edit, remove, directions) — present when you look for it,
   silent when you don't, so a list of rows reads as content rather
   than as a column of buttons. */
.btn--ghost {
  background: none; border-color: transparent; color: var(--ink-muted);
  font-size: var(--text-xs); padding: var(--space-1) 0;
}
.btn--ghost:hover:not(:disabled) { color: var(--signature); }

.btn--loading { color: transparent; position: relative; pointer-events: none; }
.btn--loading .icon--spinner { color: var(--ink); position: absolute; inset: 0; margin: auto; }

/* ---- Form fields ---- */
.field { display: flex; flex-direction: column; gap: var(--space-1); margin-bottom: var(--space-4); }
.field label { font-size: var(--text-sm); font-weight: 500; color: var(--ink); }
.field .help { font-size: var(--text-xs); color: var(--ink-muted); }
.field .errorlist { list-style: none; margin: 0; padding: 0; color: var(--danger); font-size: var(--text-xs); display: flex; align-items: center; gap: var(--space-1); }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="search"], select, textarea {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--ink);
  background: var(--base);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-control);
  padding: var(--space-2) var(--space-3);
  transition: border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none;
  border-color: var(--signature);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
input:disabled, select:disabled, textarea:disabled { background: var(--surface); color: var(--ink-muted); cursor: not-allowed; }
input.has-error, select.has-error, textarea.has-error { border-color: var(--danger); }

/* Django's {{ form.as_p }} wraps each field in <p> with no hook classes —
   style it generically so every generic create-form page benefits. */
form p { margin: 0 0 var(--space-4); display: flex; flex-direction: column; gap: var(--space-1); }
form p label { font-size: var(--text-sm); font-weight: 500; color: var(--ink); }
form ul.errorlist { list-style: none; margin: 0 0 var(--space-1); padding: 0; color: var(--danger); font-size: var(--text-xs); }

/* Compact form laid out in a row instead of Django's default one-per-line
   stack — used for the small "attach/add one thing" forms scattered
   through detail pages (attach a contact, add a time block, edit a
   source) so they don't each cost a full screen's worth of scroll. */
.inline-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-3);
  margin: var(--space-2) 0;
}
/* Label beside its input, not stacked above it — halves the vertical
   cost of each field, and the field only ever takes the width its
   content needs (label + input), never a block-level full row. */
.inline-form .field {
  flex-direction: row;
  align-items: center;
  margin-bottom: 0;
  width: auto;
  min-width: 0;
}
.inline-form .field label { white-space: nowrap; }
.inline-form input, .inline-form select {
  width: auto;
  max-width: 12rem;
}

/* A denser card for small utility widgets (attach-one-thing forms,
   short lists) — the roomy default padding is wasted on content that's
   a couple of lines tall. */
.card--tight { padding: var(--space-3) var(--space-4); margin-bottom: var(--space-3); }
.card--tight h2, .card--tight h3 { margin: 0 0 var(--space-2); font-size: var(--text-sm); }

/* Two-column layout for detail pages: the left column carries the
   things you edit most (stage, contacts, schedule), the right column
   carries reference material (financials, timeline) — so the page's
   most-used controls sit together above the fold instead of one long
   single-column scroll. Collapses to one column on narrow viewports. */
.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: var(--space-5);
  align-items: start;
}
@media (max-width: 56rem) {
  .detail-grid { grid-template-columns: 1fr; }
}

/* ---- Record header: the at-a-glance band that opens every page about
   one thing — a project, a task, a contact, an invoice, a create form.
   Same shape everywhere: eyebrow (what kind of record), name, subtitle,
   state + actions on the right, then optional facts underneath. Landing
   on any page, the same three questions are answered in the same three
   places. On a project it also carries a stage stepper — stage is a real
   sequence for client work, so a stepper earns its keep there; it's the
   one place in the app an ordered device is justified by the content. ---- */
.record-header {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  padding: var(--space-5) var(--space-6);
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-card);
  margin-bottom: var(--space-5);
}
.record-header__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.record-header__id { font-family: var(--font-mono); font-size: var(--text-2xl); font-weight: 600; margin: 0; }
.record-header__eyebrow {
  font-family: var(--font-mono); font-size: var(--text-xs); text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--ink-muted);
}
.record-header__subtitle { font-family: var(--font-display); font-style: italic; color: var(--ink-muted); font-size: var(--text-lg); }
.record-header__meta { display: flex; gap: var(--space-2); align-items: center; }

/* A record's lifecycle state, stamped rather than tagged — reserved for
   the one state that defines the whole record (a project's stage), not
   a general-purpose badge. */
.stamp {
  font-family: var(--font-mono); font-weight: 600; font-size: var(--text-xs);
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--signature); border: 2px solid var(--signature); border-radius: var(--radius-control);
  padding: var(--space-2) var(--space-4); transform: rotate(-4deg); display: inline-block;
}

/* ---- Quick-contact: phone/email as tappable chips with a one-click
   copy action, wherever a contact's channels need to surface inline
   (record headers, contact rows) instead of forcing a click-through. ---- */
.quick-contact { display: flex; gap: var(--space-2); margin-top: var(--space-2); flex-wrap: wrap; }
.contact-pair { display: inline-flex; align-items: stretch; }
.contact-pair a {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--font-mono); font-size: var(--text-xs); font-weight: 600;
  color: var(--signature); background: var(--surface-raised);
  border-radius: var(--radius-control) 0 0 var(--radius-control);
  padding: var(--space-1) var(--space-2);
}
.contact-pair a:hover { background: var(--signature); color: #fff; text-decoration: none; }
.copy-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 24px; flex-shrink: 0;
  font-size: var(--text-xs); color: var(--signature); background: var(--surface-raised);
  border: none; border-left: 1px solid var(--surface);
  border-radius: 0 var(--radius-control) var(--radius-control) 0; cursor: pointer; padding: 0;
}
.copy-btn:hover { background: var(--signature); color: #fff; }
.copy-btn.is-copied { background: var(--success); color: #fff; }

/* One continuous bar segmented per stage, with the stage names read off
   underneath — progress through a fixed sequence is a quantity, so it
   reads faster as a filled length than as a row of dots. */
.stage-track { display: flex; gap: 2px; list-style: none; margin: 0; padding: 0; }
.stage-track li { flex: 1; display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }
.stage-track__dot { height: 6px; border-radius: 3px; background: var(--hairline); }
.stage-track li:first-child .stage-track__dot { border-radius: 3px 0 0 3px; }
.stage-track li:last-child .stage-track__dot { border-radius: 0 3px 3px 0; }
.stage-track li.done .stage-track__dot,
.stage-track li.current .stage-track__dot { background: var(--signature); }
.stage-track__label {
  font-family: var(--font-mono); font-size: var(--text-xs); letter-spacing: 0.03em;
  text-transform: uppercase; color: var(--ink-muted); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.stage-track li.done .stage-track__label { color: var(--signature); font-weight: 600; }
.stage-track li.current .stage-track__label { color: var(--ink); font-weight: 600; }
@media (max-width: 40rem) {
  .stage-track__label { display: none; }
  .stage-track li.current .stage-track__label { display: inline; }
}

/* Facts sit in their own ruled box below the header's own content — the
   hairline grid is drawn by the gap, so every cell is separated by
   exactly one rule with no doubled borders. */
.fact-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 1px; background: var(--hairline);
  border: 1px solid var(--hairline); border-radius: var(--radius-control); overflow: hidden;
}
.fact-tile {
  background: var(--paper);
  padding: var(--space-3) var(--space-4);
}
.fact-tile__label {
  font-family: var(--font-mono); font-size: var(--text-xs); text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--ink-muted);
}
.fact-tile__value { font-size: var(--text-sm); font-weight: 600; color: var(--ink); margin-top: 2px; }

/* ---- Disclosure: a form that doesn't need to be visible until asked
   for (edit a source, add a time block) collapses behind a
   button-styled <summary> — no JS, just native <details>. Keeps a
   section scannable at a glance instead of showing every edit control
   at once. ---- */
summary { cursor: pointer; list-style: none; }
summary::-webkit-details-marker { display: none; }
summary::marker { content: ""; }
.disclosure-toggle {
  display: inline-flex; align-items: center; gap: var(--space-1);
  font-size: var(--text-xs); color: var(--ink-muted); font-weight: 500;
}
.disclosure-toggle:hover { color: var(--ink); }
.disclosure-toggle .icon { transition: transform var(--duration) var(--ease); }
details[open] > summary .disclosure-toggle .icon { transform: rotate(180deg); }
details > .inline-form { padding-top: var(--space-3); }

/* ---- Record rows: a compact single line per item (contact, time
   block, task) instead of a stacked mini-form-per-row. ---- */
.record-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3); padding: var(--space-2) 0;
  border-bottom: 1px solid var(--hairline);
}
.record-row:last-of-type { border-bottom: none; }
.record-row__main { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; min-width: 0; }
.record-row__meta { font-size: var(--text-sm); color: var(--ink-muted); }

.task-row__dot {
  width: 15px; height: 15px; border-radius: 50%; flex-shrink: 0;
  border: 1.5px solid var(--hairline); display: inline-flex; align-items: center; justify-content: center;
}
.task-row--done .task-row__dot { background: var(--success); border-color: var(--success); color: #fff; }
.task-row--done .task-row__title { color: var(--ink-muted); text-decoration: line-through; }

/* ---- Panel: a card that identifies its content category by a colored
   top edge + matching icon badge, so a row of them reads by shape/color
   before a single word is read. Combine with .card (or .card--tight)
   for the box itself — .panel only adds the identity strip. Pair with
   a .panel--<name> variant that sets --cat-color/--cat-tint; a bare
   .panel with neither (e.g. a passive log like a timeline) stays
   neutral on purpose. ---- */
.panel { position: relative; overflow: hidden; background: var(--paper); }
.panel::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--cat-color, var(--hairline));
}
/* The heading is a label for the card, not a title competing with the
   record's own name — mono caps at body-copy weight keeps it in the
   furniture layer where the colored edge already does the identifying. */
.panel h2, .panel h3 {
  display: flex; align-items: center; gap: var(--space-2);
  font-family: var(--font-mono); font-size: var(--text-xs); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-muted);
}
.panel-icon {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--cat-tint, var(--surface-raised)); color: var(--cat-color, var(--ink-muted));
}
/* The strip needs clearance the default tight padding doesn't leave. */
.panel.card--tight { padding: var(--space-4); }
.panel--contacts { --cat-color: var(--cat-contacts); --cat-tint: var(--cat-contacts-tint); }
.panel--schedule { --cat-color: var(--cat-schedule); --cat-tint: var(--cat-schedule-tint); }
.panel--tasks { --cat-color: var(--cat-tasks); --cat-tint: var(--cat-tasks-tint); }
.panel--comms { --cat-color: var(--cat-comms); --cat-tint: var(--cat-comms-tint); }

/* ---- Tabs: two views of one record that must not cost a round trip to
   switch between. The panels are both in the page and a checked radio
   picks which one shows — no JS, and no re-fetch of a page you already
   have. Markup order is inputs, .tabbar, then the panels as siblings. ---- */
.tab-input { position: absolute; opacity: 0; pointer-events: none; }
.tabbar {
  display: flex; gap: var(--space-5);
  border-bottom: 1px solid var(--hairline); margin-bottom: var(--space-5);
}
.tab-label {
  display: inline-flex; align-items: center; gap: var(--space-2);
  font-family: var(--font-mono); font-size: var(--text-xs); font-weight: 600;
  letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-muted);
  padding: var(--space-3) 0; cursor: pointer;
  border-bottom: 2px solid transparent; position: relative; top: 1px;
}
.tab-label:hover { color: var(--ink); }
.tab-count {
  font-size: var(--text-xs); font-weight: 600; color: var(--ink-muted);
  background: var(--surface-raised); border-radius: var(--radius-card); padding: 0 var(--space-2);
}
.tab-panel { display: none; }
#tab-overview:checked ~ #panel-overview { display: grid; }
#tab-comms:checked ~ #panel-comms { display: block; }
#tab-overview:checked ~ .tabbar label[for="tab-overview"],
#tab-comms:checked ~ .tabbar label[for="tab-comms"] {
  color: var(--signature); border-bottom-color: var(--signature);
}
.tab-input:focus-visible ~ .tabbar label[for="tab-overview"],
.tab-input:focus-visible ~ .tabbar label[for="tab-comms"] {
  outline: 2px solid var(--focus-ring); outline-offset: 2px;
}

/* ---- One message in the thread list. Heavier than a .record-row on
   purpose: a message has a sender, a time, a subject and a body, and
   the row is where you decide whether it concerns this order. ---- */
.comms-row {
  display: flex; gap: var(--space-3);
  padding: var(--space-4) 0; border-bottom: 1px solid var(--hairline);
}
.comms-row:last-child { border-bottom: none; }
/* Not hidden — filed as unrelated is a judgment about the message, not
   a way to make it disappear — but visibly demoted until hovered. */
.comms-row--unrelated { opacity: 0.55; }
.comms-row--unrelated:hover { opacity: 1; }
.comms-row__dir { width: 34px; height: 34px; }
.comms-row__body { flex: 1; min-width: 0; }
.comms-row__head {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: var(--space-3); flex-wrap: wrap;
}
.comms-row__who { font-weight: 600; font-size: var(--text-sm); }
.comms-row__arrow { color: var(--ink-muted); font-weight: 400; margin: 0 var(--space-1); }
.comms-row__address, .comms-row__time {
  font-family: var(--font-mono); font-size: var(--text-xs); color: var(--ink-muted);
}
.comms-row__time { white-space: nowrap; }
.comms-row__subject { font-size: var(--text-sm); font-weight: 600; margin-top: 3px; }
.comms-row__snippet { font-size: var(--text-sm); color: var(--ink-muted); margin-top: 3px; max-width: 65ch; }
.comms-row__channel {
  display: inline-flex; align-items: center; gap: var(--space-1);
  font-family: var(--font-mono); font-size: var(--text-xs);
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-muted);
}
.comms-row__foot {
  display: flex; align-items: center; gap: var(--space-4);
  margin-top: var(--space-2); flex-wrap: wrap;
}
.comms-row__toggle-form { margin-left: auto; }
.comms-toggle {
  display: inline-flex; align-items: center; gap: var(--space-1);
  font-family: var(--font-mono); font-size: var(--text-xs); font-weight: 600;
  letter-spacing: 0.03em; text-transform: uppercase;
  border-radius: var(--radius-control); padding: var(--space-1) var(--space-3);
  cursor: pointer; border: 1px solid transparent;
  transition: color var(--duration) var(--ease), border-color var(--duration) var(--ease);
}
.comms-toggle:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.comms-toggle.is-related { background: var(--cat-comms-tint); color: var(--cat-comms); }
.comms-toggle.is-unrelated {
  background: none; color: var(--ink-muted); border: 1px dashed var(--hairline);
}
.comms-toggle.is-unrelated:hover { color: var(--ink); border-color: var(--ink-muted); }

/* ---- Avatar: initials in a circle, for a row whose subject is a
   person (a contact, a comms sender) rather than a record. ---- */
.avatar {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
  background: var(--surface-raised); color: var(--signature);
  font-family: var(--font-mono); font-size: var(--text-xs); font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
}

/* ---- Card ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-card);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
}
.card h2, .card h3 { margin-top: 0; }

/* ---- Badge ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  font-weight: 500;
  padding: 2px var(--space-2);
  border-radius: var(--radius-card);
  border: 1px solid var(--hairline);
  color: var(--ink-muted);
  background: var(--base);
}
.badge--success { color: var(--success); border-color: var(--success); }
.badge--danger { color: var(--danger); border-color: var(--danger); }

/* ---- Site shell / nav ---- */
.site-header { border-bottom: 1px solid var(--hairline); background: var(--base); }
.site-nav {
  max-width: 72rem;
  margin: 0 auto;
  padding: var(--space-4) var(--space-5);
  display: flex;
  align-items: center;
  gap: var(--space-5);
  flex-wrap: wrap;
}
.site-nav__brand { font-weight: 600; font-size: var(--text-lg); color: var(--ink); }
.site-nav__brand:hover { color: var(--ink); text-decoration: none; }
.site-nav__links { display: flex; gap: var(--space-4); align-items: center; flex-wrap: wrap; }
.site-nav__link { color: var(--ink-muted); padding-bottom: 2px; border-bottom: 2px solid transparent; }
.site-nav__link:hover { color: var(--ink); text-decoration: none; }
.site-nav__link--active { color: var(--ink); border-bottom-color: var(--signature); }
.site-nav__search { margin-left: auto; position: relative; display: flex; align-items: center; }
.site-nav__search .icon { position: absolute; left: var(--space-2); color: var(--ink-muted); pointer-events: none; }
.site-nav__search input { padding-left: calc(var(--space-2) * 2 + 16px); }
.site-nav__user { display: flex; align-items: center; gap: var(--space-3); color: var(--ink-muted); font-size: var(--text-sm); }

main { max-width: 72rem; margin: 0 auto; padding: var(--space-6) var(--space-5) var(--space-8); }

/* ---- Table ---- */
.table-wrap { overflow-x: auto; border: 1px solid var(--hairline); border-radius: var(--radius-card); }
table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
thead th {
  text-align: left;
  font-weight: 500;
  color: var(--ink-muted);
  background: var(--surface);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--hairline);
}
tbody td { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--hairline); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface); }

.pagination { display: flex; align-items: center; gap: var(--space-3); margin-top: var(--space-4); font-size: var(--text-sm); color: var(--ink-muted); }
.pagination .btn { padding: var(--space-1) var(--space-3); }

/* ---- Empty state ---- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-7) var(--space-4);
  color: var(--ink-muted);
  text-align: center;
}
.empty-state .icon { color: var(--ink-muted); }

/* ---- Banner (flash messages) ---- */
.banner {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-control);
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--text-sm);
  margin: 0 0 var(--space-4);
}
.banner--success { border-color: var(--success); color: var(--success); }
.banner--error { border-color: var(--danger); color: var(--danger); }

/* ---- Stat callout — the one dominant signature-color moment on a screen ---- */
.stat-callout {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-5);
  border-radius: var(--radius-card);
  background: var(--signature);
  color: #fff;
}
.stat-callout:hover { background: var(--signature-hover); text-decoration: none; }
.stat-callout__value { font-size: var(--text-xl); font-weight: 600; }
.stat-callout__label { font-size: var(--text-sm); opacity: 0.9; }

/* ---- Lists ---- */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.list > li { padding: var(--space-2) 0; border-bottom: 1px solid var(--hairline); display: flex; align-items: center; gap: var(--space-2); }
.list > li:last-child { border-bottom: none; }

/* ---- Timeline ---- */
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-3); }
.timeline > li { display: flex; gap: var(--space-3); align-items: flex-start; }
.timeline .icon { color: var(--ink-muted); margin-top: 2px; }
.timeline__meta { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--ink-muted); }

/* A record whose identity is a name rather than a code (a person, a task,
   an SOP) gets the display serif instead of the mono order-number
   treatment — a name set in 40px mono reads as a serial number. */
.record-header__name {
  font-family: var(--font-display); font-size: var(--text-xl); font-weight: 600;
  line-height: 1.15; margin: 0;
}
/* Form pages and short records don't need the full band's presence. */
.record-header--compact { padding: var(--space-4) var(--space-5); gap: var(--space-3); }
.record-header__lede { color: var(--ink-muted); font-size: var(--text-sm); max-width: 62ch; margin: 0; }
.record-header__meta { flex-wrap: wrap; justify-content: flex-end; }

/* Back-to-the-parent link above a record header. Always the first thing
   in the content well, always pointing one level up — a detail page you
   can only leave via the browser button is a dead end. */
.breadcrumb {
  display: inline-flex; align-items: center; gap: var(--space-1);
  font-family: var(--font-mono); font-size: var(--text-xs); letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--ink-muted); margin-bottom: var(--space-3);
}
.breadcrumb:hover { color: var(--signature); text-decoration: none; }

/* ---- Page head: the list-page counterpart of a record header. Same
   eyebrow/title/action arrangement, no card around it, because a list
   has no single record to frame. ---- */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-5);
}
.page-head__eyebrow {
  font-family: var(--font-mono); font-size: var(--text-xs); text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--ink-muted);
}
.page-head h1 { margin: 0; font-family: var(--font-display); }
.page-head__count { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--ink-muted); }

/* ---- Stat tiles: a row of headline numbers at the top of a summary
   screen. One tile may carry --accent to become the screen's single
   loud moment (pending approvals); the rest stay quiet so it works. ---- */
.tiles {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: var(--space-3); margin-bottom: var(--space-5);
}
.stat-tile {
  display: flex; flex-direction: column; gap: var(--space-1);
  padding: var(--space-4) var(--space-5);
  background: var(--paper); border: 1px solid var(--hairline);
  border-radius: var(--radius-card); color: var(--ink);
  transition: border-color var(--duration) var(--ease), transform var(--duration) var(--ease);
}
a.stat-tile:hover { text-decoration: none; border-color: var(--signature); }
.stat-tile__label {
  display: flex; align-items: center; gap: var(--space-2);
  font-family: var(--font-mono); font-size: var(--text-xs); text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--ink-muted);
}
.stat-tile__value { font-family: var(--font-mono); font-size: var(--text-xl); font-weight: 600; }
.stat-tile__hint { font-size: var(--text-xs); color: var(--ink-muted); }
.stat-tile--accent { background: var(--signature); border-color: var(--signature); color: #fff; }
.stat-tile--accent .stat-tile__label,
.stat-tile--accent .stat-tile__hint { color: rgba(255,255,255,0.85); }
a.stat-tile--accent:hover { background: var(--signature-hover); border-color: var(--signature-hover); }
/* Nothing pending is a *good* state, not an alert — it drops back to a
   quiet tile so the red only ever means "there is work waiting". */
.stat-tile--calm { background: var(--paper); }

/* ---- Key/value grid: the ruled replacement for a bare <dl>. Same
   hairline-by-gap trick as .fact-row. ---- */
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 1px;
      background: var(--hairline); border: 1px solid var(--hairline);
      border-radius: var(--radius-control); overflow: hidden; margin: 0; }
.kv > div { background: var(--paper); padding: var(--space-3) var(--space-4); }
.kv dt, .kv__label {
  font-family: var(--font-mono); font-size: var(--text-xs); text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--ink-muted);
}
.kv dd, .kv__value { margin: 2px 0 0; font-size: var(--text-sm); font-weight: 600; }
.kv__value--plain { font-weight: 400; }

/* ---- Money: an amount is a quantity you compare down a column, so it
   is mono, right-aligned and tabular everywhere it appears. ---- */
.amount { font-family: var(--font-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
td.amount, th.amount { text-align: right; }
.amount--total { font-weight: 600; font-size: var(--text-base); }
.amount--due { color: var(--signature); }
.amount--settled { color: var(--success); }

/* The bottom line of a document: totals as a small right-aligned ledger
   rather than a paragraph, so invoiced/paid/outstanding line up. */
.money-summary {
  display: flex; flex-direction: column; gap: var(--space-2);
  margin-left: auto; min-width: 16rem;
  padding: var(--space-3) var(--space-4);
  background: var(--surface); border-radius: var(--radius-control);
}
.money-summary__row { display: flex; justify-content: space-between; gap: var(--space-4); font-size: var(--text-sm); }
.money-summary__row--strong {
  border-top: 1px solid var(--hairline); padding-top: var(--space-2);
  font-weight: 600;
}
.money-summary__label { color: var(--ink-muted); }

/* ---- Nav: a curated primary bar, with the full registry-driven
   resource list folded into a disclosure. Every registered resource
   stays reachable (and in the HTML), without nineteen equal-weight
   links pushing the four you actually use off the bar. ---- */
.nav-menu { position: relative; }
.nav-menu > summary {
  display: inline-flex; align-items: center; gap: var(--space-1);
  color: var(--ink-muted); font-size: var(--text-base); padding-bottom: 2px;
  border-bottom: 2px solid transparent;
}
.nav-menu > summary:hover { color: var(--ink); }
.nav-menu[open] > summary { color: var(--ink); }
.nav-menu[open] > summary .icon { transform: rotate(180deg); }
.nav-menu__panel {
  position: absolute; z-index: 20; top: calc(100% + var(--space-3)); left: 0;
  min-width: 22rem;
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-1) var(--space-4);
  padding: var(--space-4); background: var(--paper);
  border: 1px solid var(--hairline); border-radius: var(--radius-card);
  box-shadow: 0 8px 24px rgba(26, 25, 19, 0.1);
}
.nav-menu__panel a { font-size: var(--text-sm); color: var(--ink); padding: 2px 0; }
.nav-menu__panel a:hover { color: var(--signature); text-decoration: none; }
.site-nav__link { display: inline-flex; align-items: center; gap: var(--space-2); }
.site-nav__link .icon { color: var(--ink-muted); }
.site-nav__link--active .icon { color: var(--signature); }
/* The count rides the nav link itself, so pending work is visible from
   every page instead of only the dashboard. */
.nav-pip {
  font-family: var(--font-mono); font-size: 11px; font-weight: 600; line-height: 1;
  padding: 3px var(--space-1); border-radius: var(--radius-card);
  background: var(--signature); color: #fff; min-width: 17px; text-align: center;
}

/* ---- Form page: a create/edit form is one column of fields and one
   commit button. Constrained to a readable measure — a text input
   stretched to 72rem invites nobody to fill it in. ---- */
.form-page { max-width: 40rem; }
.form-page--wide { max-width: 100%; }
.form-actions {
  display: flex; align-items: center; gap: var(--space-3);
  margin-top: var(--space-5); padding-top: var(--space-4);
  border-top: 1px solid var(--hairline);
}
.form-actions .btn--ghost { font-size: var(--text-sm); }
.form-page form p input[type="text"], .form-page form p input[type="email"],
.form-page form p input[type="password"], .form-page form p input[type="number"],
.form-page form p input[type="date"], .form-page form p select,
.form-page form p textarea, .form-page .field input, .form-page .field select,
.form-page .field textarea { width: 100%; }

/* ---- Checkbox grid: many boolean options (a role's grants) read as a
   scannable multi-column list, not a mile-long single stack. ---- */
.checkbox-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
  gap: var(--space-1) var(--space-4);
}
.checkbox-grid label {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-sm); padding: var(--space-1) 0; cursor: pointer;
}
.checkbox-grid label:hover { color: var(--signature); }
.checkbox-grid code { font-family: var(--font-mono); font-size: var(--text-xs); }

/* ---- Link cards: a directory screen (admin) where each destination
   needs a name, an icon and a sentence saying what it's for. ---- */
.link-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); gap: var(--space-3); }
.link-card {
  position: relative;
  display: flex; gap: var(--space-3); padding: var(--space-4);
  background: var(--paper); border: 1px solid var(--hairline);
  border-radius: var(--radius-card); color: var(--ink);
  transition: border-color var(--duration) var(--ease);
}
.link-card:hover { border-color: var(--signature); }
.link-card > .icon { color: var(--cat-color, var(--ink-muted)); }
.link-card__title { font-weight: 600; font-size: var(--text-sm); }
.link-card__title a { color: var(--ink); }
/* The title is the card's real link; this overlay makes the whole card
   clickable without nesting one anchor inside another — the secondary
   "+ New" links sit above it on their own stacking level. */
.link-card__link::after { content: ""; position: absolute; inset: 0; }
.link-card__link:hover { color: var(--signature); text-decoration: none; }
.link-card__aside { position: relative; z-index: 1; }
.link-card__desc { font-size: var(--text-xs); color: var(--ink-muted); margin-top: 2px; }
.link-card__aside { margin-top: var(--space-2); display: flex; gap: var(--space-3); }
.link-card__aside a { font-family: var(--font-mono); font-size: var(--text-xs); }

.panel--money { --cat-color: var(--cat-money); --cat-tint: var(--cat-money-tint); }
.panel--docs { --cat-color: var(--cat-docs); --cat-tint: var(--cat-docs-tint); }
.panel--admin { --cat-color: var(--cat-admin); --cat-tint: var(--cat-admin-tint); }
.panel--projects { --cat-color: var(--signature); --cat-tint: #FBE3DD; }

/* A stamp in a state that isn't the signature red — a settled invoice
   or a closed record shouldn't shout in the colour reserved for
   "needs you". */
.stamp--success { color: var(--success); border-color: var(--success); }
.stamp--muted { color: var(--ink-muted); border-color: var(--hairline); }

/* ---- Search: the query is the page, so the field is the page's
   headline rather than a control tucked above the results. ---- */
.search-hero { display: flex; gap: var(--space-2); margin-bottom: var(--space-5); }
.search-hero input[type="search"], .search-hero input[type="text"] {
  flex: 1; font-size: var(--text-lg); padding: var(--space-3) var(--space-4);
}
.result-row { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) 0;
              border-bottom: 1px solid var(--hairline); }
.result-row:last-child { border-bottom: none; }
.result-row__kind {
  font-family: var(--font-mono); font-size: var(--text-xs); text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--ink-muted); min-width: 7rem;
}
.result-row__title { font-size: var(--text-sm); font-weight: 600; }

/* ---- Auth: a signed-out page has no nav and no record — the form is
   the whole screen, so it centres rather than sitting top-left in an
   otherwise empty 72rem well. ---- */
.auth-page { max-width: 24rem; margin: var(--space-7) auto; }
.auth-page h1 { font-family: var(--font-display); text-align: center; }
.auth-page .card { background: var(--paper); }
.auth-page form p input, .auth-page form p select { width: 100%; }
.auth-page .btn { width: 100%; justify-content: center; }
.auth-divider {
  display: flex; align-items: center; gap: var(--space-3); margin: var(--space-4) 0;
  font-family: var(--font-mono); font-size: var(--text-xs); text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--ink-muted);
}
.auth-divider::before, .auth-divider::after {
  content: ""; flex: 1; height: 1px; background: var(--hairline);
}
.auth-page .provider-btn { margin-bottom: var(--space-2); }

/* A monospace secret shown exactly once (an agent API key) — selectable,
   wrapping, and visually a thing to copy rather than a sentence. */
.secret {
  font-family: var(--font-mono); font-size: var(--text-sm); word-break: break-all;
  background: var(--surface-raised); border-radius: var(--radius-control);
  padding: var(--space-2) var(--space-3); user-select: all;
}

/* .panel asks for the raised --paper ground, but .card is defined after
   it and was quietly winning the cascade, so every panel came out the
   same flat --surface as the page furniture. Stated once here, after
   both, so a panel actually lifts off the base the way the colored edge
   assumes it does. */
.card.panel { background: var(--paper); }

/* The bar carries six destinations, a search field and the account
   block; at laptop widths the search was wrapping to a second row.
   Tighter rhythm and a search field that yields first keeps it on one
   line without dropping anything. */
.site-nav { gap: var(--space-4); }
.site-nav__links { gap: var(--space-3); }
.site-nav__link { font-size: var(--text-sm); }
.site-nav__search input { width: 13rem; max-width: 22vw; }
.site-nav__brand { margin-right: var(--space-1); }
@media (max-width: 68rem) {
  .site-nav__user span { display: none; }
}
/* Below a wide desktop the six labelled destinations plus search plus the
   account block no longer fit on one line. The icons go first — they are
   a recognition aid beside the word, never the label itself — and the
   search field narrows before anything is dropped. */
@media (max-width: 90rem) {
  .site-nav__link .icon { display: none; }
  .site-nav__search input { width: 11rem; }
  .site-nav { gap: var(--space-3); }
  .site-nav__links { gap: var(--space-3); }
}
/* The account name is the one variable-width thing in the bar — an
   agent user is called "estimator v3" and a person can be called
   anything — so it is the part that gives way, rather than being
   allowed to push search onto a second row. */
.site-nav__user > span {
  max-width: 10ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.site-nav__search { min-width: 0; }
.site-nav__search input { min-width: 0; }

/* An approval card's answer field needs air between the agent's
   reasoning and the box you type into — they are two different
   voices. */
.panel > form > .field { margin-top: var(--space-3); }
/* A form page's card holds the work, so it takes the raised ground the
   header band already uses — a grey panel behind near-white inputs
   reads as disabled. */
.form-page > .card { background: var(--paper); }

/* Generic-table cells. The table walks a schema, so it will print a raw
   flag, a raw id, or nothing at all — these keep those legible without
   the page needing to know what kind of record it is showing. */
.cell-empty { color: var(--ink-muted); }
.cell-flag.is-on { color: var(--success); font-weight: 600; }
.cell-id { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--ink-muted); }

/* ---- "Used before" chips: the line items this business actually
   writes, offered as a starting point above the add-a-line form. One
   click fills the form and stops — the price is a judgment every time,
   so it is never committed on the person's behalf. ---- */
.suggest-row {
  display: flex; align-items: center; gap: var(--space-2);
  flex-wrap: wrap; margin: var(--space-3) 0 var(--space-2);
}
.suggest-row__label {
  display: inline-flex; align-items: center; gap: var(--space-1);
  font-family: var(--font-mono); font-size: var(--text-xs); text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--ink-muted);
}
.suggest-chip {
  display: inline-flex; align-items: baseline; gap: var(--space-2);
  font-family: var(--font-sans); font-size: var(--text-xs); color: var(--ink);
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius-control); padding: var(--space-1) var(--space-2);
  cursor: pointer;
  transition: border-color var(--duration) var(--ease), background-color var(--duration) var(--ease);
}
.suggest-chip:hover { border-color: var(--signature); background: var(--base); }
.suggest-chip:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.suggest-chip__price { font-family: var(--font-mono); color: var(--ink-muted); }

/* One line of a document is one row of controls: a wide description and
   four short numbers. A grid rather than wrapped flex, so the columns
   line up with the table above instead of reflowing into an L-shape as
   soon as the description gets long. */
.line-item-form {
  display: grid;
  grid-template-columns: minmax(8rem, 1fr) 7rem 5rem 5rem 5rem auto;
  gap: var(--space-3);
  align-items: end;
  margin-top: var(--space-3);
}
.line-item-form .field { margin-bottom: 0; }
.line-item-form input { width: 100%; max-width: none; }
@media (max-width: 56rem) {
  .line-item-form { grid-template-columns: 1fr 1fr; }
  .line-item-form .field--grow { grid-column: 1 / -1; }
  .line-item-form button { grid-column: 1 / -1; justify-content: center; }
}

.panel--time { --cat-color: var(--cat-time); --cat-tint: var(--cat-time-tint); }

/* A running clock is the one thing on a project page that is true only
   right now, so it gets a live-looking mark — the only pulse in the
   system, earned because the state it reports is genuinely changing. */
.time-running { color: var(--cat-time); display: inline-flex; align-items: center; gap: var(--space-1); }
.time-running .icon { animation: time-pulse 2s var(--ease) infinite; }
@keyframes time-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) {
  .time-running .icon { animation: none; }
}

/* ---- Bill-the-hours: the one control on a draft invoice that turns
   maintained state into a document line. Set apart from the manual
   add-a-line form because it is not data entry — the quantity is
   already known, and only the rate is being asked for. ---- */
.bill-hours {
  display: flex; align-items: flex-end; gap: var(--space-3); flex-wrap: wrap;
  margin-top: var(--space-3); padding: var(--space-3) var(--space-4);
  background: var(--cat-time-tint); border-radius: var(--radius-control);
}
.bill-hours__lede {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-sm); flex: 1 1 16rem;
}
.bill-hours__lede .icon { color: var(--cat-time); }
.bill-hours .field { margin-bottom: 0; }
.bill-hours input { max-width: 8rem; }

.panel--trips { --cat-color: var(--cat-trips); --cat-tint: var(--cat-trips-tint); }

/* Work that is happening right now, above everything merely waiting. */
.open-now .record-row { padding: var(--space-3) 0; }
.open-now .inline-form { margin: 0; }

/* Answering a message is the point of reading one, so the action sits in
   the row rather than behind a click into a detail page. */
.comms-row__reply {
  display: inline-flex; align-items: center; gap: var(--space-1);
  font-family: var(--font-mono); font-size: var(--text-xs); font-weight: 600;
  letter-spacing: 0.03em; text-transform: uppercase; color: var(--cat-comms);
}
.comms-row__reply:hover { text-decoration: none; color: var(--signature); }
/* The same affordance as Reply, but a POST — so it is a button that has
   to be talked out of looking like one. */
button.comms-row__reply {
  background: none; border: 0; padding: 0; cursor: pointer;
}
.comms-row__foot form { display: inline-flex; margin: 0; }

/* ---- SOP: the written procedure, shown where the action is taken.
   Quiet by default — someone who does this daily should not scroll past
   the instructions, someone doing it first time should not go looking. ---- */
.sop { margin: var(--space-3) 0; }
.sop__toggle {
  display: inline-flex; align-items: center; gap: var(--space-2);
  font-family: var(--font-mono); font-size: var(--text-xs); letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--cat-docs);
}
.sop__toggle:hover { color: var(--ink); }
.sop__version {
  font-size: 11px; color: var(--ink-muted); background: var(--surface-raised);
  border-radius: var(--radius-card); padding: 0 var(--space-1);
}
.sop__body {
  margin-top: var(--space-2); padding: var(--space-3) var(--space-4);
  background: var(--cat-docs-tint); border-radius: var(--radius-control);
  font-size: var(--text-sm); max-width: 68ch;
}

/* A stamp for a state that is neither finished nor wrong — a van still
   out, a clock still running. Uses the schedule hue rather than danger:
   nothing has gone wrong, something is simply still open. */
.stamp--warn { color: var(--cat-schedule); border-color: var(--cat-schedule); }

/* A fact whose value is the problem — kilometres nobody logged. Colored
   only where the number is non-zero, so a clean record stays quiet. */
.fact-tile__value.is-warn { color: var(--cat-schedule); }

/* A break in an odometer history: mileage between one trip's end and the
   next one's start. Sits inline in the table, tinted rather than
   bordered, because it is a note about the rows around it and not a row
   of its own. */
.row-gap td {
  background: var(--cat-schedule-tint);
  color: var(--cat-schedule);
  font-size: var(--text-xs);
  text-align: center;
}
.row-gap:hover td { background: var(--cat-schedule-tint); }

/* Numbers line up on their last digit or they cannot be compared by eye. */
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* An action name or a keystroke quoted inline in prose — a 403 naming
   the grant you are short of, a page pointing at the "/" shortcut. */
kbd, code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--surface-raised);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-control);
  padding: 1px var(--space-1);
}
