/*
 * PushPel Internal Console — shared design system.
 *
 * One source of truth for design tokens, typography, layout, the shared header/nav, buttons,
 * forms, tables, cards, and status pills. This replaces the three drifting per-page stylesheets.
 *
 * Aesthetic: a considered, trustworthy accounting-firm look — deep ink navy on warm paper, a
 * single restrained sage accent reserved for verified/positive signals, a real type scale pairing
 * a quiet serif for display headings with a precise sans for the working UI. No gradients, no
 * decoration for its own sake. Accessible: visible focus rings, sufficient contrast, semantic
 * landmarks, and a respect for reduced-motion.
 *
 * Self-contained: system font stacks only (no external CDNs / web fonts), so the asset-presence and
 * no-external-CDN tests stay green and the console works on a private network with no egress.
 */

:root {
  /* ---- Palette -------------------------------------------------------- */
  --ink-900: #16202e; /* deepest ink navy — primary text, header */
  --ink-800: #1f2c3d;
  --ink-700: #2c3b4f;
  --ink-600: #3d4f66;
  --ink-500: #5a6b80;
  --ink-400: #7a8a9c;
  --ink-300: #aab4c0;

  --paper-0: #ffffff;
  --paper-50: #faf8f4; /* warm parchment — page background */
  --paper-100: #f3efe7;
  --paper-200: #e7e1d6;
  --line: #ddd6c9; /* hairline borders on paper */
  --line-strong: #c7bfae;

  --sage-700: #2f5d4f; /* accent — verified / positive / brand */
  --sage-600: #3a7361;
  --sage-500: #4a8a75;
  --sage-100: #e1ece7;

  --amber-700: #8a5a16;
  --amber-100: #f5e8d2;

  --rust-700: #99372a; /* danger / blocked / failed */
  --rust-600: #b04437;
  --rust-100: #f6e0db;

  --info-700: #2b4a78;
  --info-100: #dde6f2;

  /* ---- Semantic tokens ------------------------------------------------ */
  --bg-page: var(--paper-50);
  --bg-surface: var(--paper-0);
  --bg-sunken: var(--paper-100);
  --text-strong: var(--ink-900);
  --text: var(--ink-700);
  --text-muted: var(--ink-500);
  --text-faint: var(--ink-400);
  --border: var(--line);
  --accent: var(--sage-700);
  --accent-text: #ffffff;
  --focus-ring: 0 0 0 3px rgba(58, 115, 97, 0.35);

  /* ---- Type ----------------------------------------------------------- */
  --font-sans: "Inter", "Segoe UI", "Helvetica Neue", system-ui, -apple-system, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino,
    Georgia, "Times New Roman", serif;
  --font-mono: "SFMono-Regular", "JetBrains Mono", "Cascadia Code", Consolas,
    "Liberation Mono", monospace;

  --step--1: 0.82rem;
  --step-0: 0.95rem;
  --step-1: 1.1rem;
  --step-2: 1.35rem;
  --step-3: 1.7rem;
  --step-4: 2.2rem;

  /* ---- Space (8px base) ----------------------------------------------- */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 48px;
  --s-8: 64px;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(22, 32, 46, 0.06);
  --shadow: 0 4px 16px rgba(22, 32, 46, 0.08);
  --shadow-lg: 0 12px 32px rgba(22, 32, 46, 0.12);

  --maxw: 1200px;
}

* {
  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.55;
  color: var(--text);
  background-color: var(--bg-page);
  /* A barely-there paper grain so large parchment fields do not read as flat AI gradient. */
  background-image: radial-gradient(rgba(22, 32, 46, 0.025) 1px, transparent 1px);
  background-size: 22px 22px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-serif);
  color: var(--text-strong);
  line-height: 1.2;
  margin: 0 0 var(--s-3);
  font-weight: 600;
  letter-spacing: -0.01em;
}

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 {
  margin: 0 0 var(--s-3);
}

a {
  color: var(--sage-700);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

.eyebrow {
  font-family: var(--font-sans);
  font-size: var(--step--1);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-weight: 700;
  color: var(--accent);
  margin: 0 0 var(--s-2);
}

.muted {
  color: var(--text-muted);
}
.faint {
  color: var(--text-faint);
}
.mono {
  font-family: var(--font-mono);
  font-size: 0.86em;
}
.numeric {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.hidden {
  display: none !important;
}

/* ---- Skip link --------------------------------------------------------- */
.skip-link {
  position: absolute;
  left: var(--s-3);
  top: -48px;
  background: var(--ink-900);
  color: #fff;
  padding: var(--s-2) var(--s-4);
  border-radius: var(--radius-sm);
  z-index: 100;
  transition: top 120ms ease;
}
.skip-link:focus {
  top: var(--s-3);
  text-decoration: none;
}

/* =======================================================================
   SHARED HEADER / NAVIGATION — single source of truth for every page.
   ======================================================================= */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--ink-900);
  color: #e8edf3;
  border-bottom: 1px solid #0d141d;
  box-shadow: var(--shadow-sm);
}

.app-header__inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 var(--s-5);
  display: flex;
  align-items: center;
  gap: var(--s-5);
  min-height: 60px;
}

.app-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s-3);
  color: #fff;
  font-family: var(--font-serif);
  font-size: var(--step-1);
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.app-brand:hover {
  text-decoration: none;
}
.app-brand__mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--sage-600);
  color: #fff;
  font-family: var(--font-sans);
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: -0.04em;
}
.app-brand__sub {
  font-family: var(--font-sans);
  font-size: var(--step--1);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-300);
  padding-left: var(--s-3);
  border-left: 1px solid #34465c;
}

.app-nav {
  display: flex;
  align-items: center;
  gap: var(--s-1);
  flex: 1;
  flex-wrap: wrap;
}
.app-nav__link {
  color: var(--ink-300);
  font-size: var(--step-0);
  font-weight: 500;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--radius-sm);
  line-height: 1.2;
  white-space: nowrap;
}
.app-nav__link:hover {
  color: #fff;
  background: #243246;
  text-decoration: none;
}
.app-nav__link[aria-current="page"] {
  color: #fff;
  background: #243246;
  box-shadow: inset 0 -2px 0 var(--sage-500);
}

.app-identity {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin-left: auto;
  white-space: nowrap;
}
.app-identity__who {
  text-align: right;
  line-height: 1.25;
}
.app-identity__email {
  display: block;
  color: #fff;
  font-size: var(--step--1);
  font-weight: 600;
}
.app-identity__role {
  display: inline-block;
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--ink-900);
  background: var(--sage-100);
  padding: 1px var(--s-2);
  border-radius: 999px;
}

/* =======================================================================
   PAGE LAYOUT
   ======================================================================= */
.page {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: var(--s-6) var(--s-5) var(--s-8);
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--s-4);
  flex-wrap: wrap;
  margin-bottom: var(--s-5);
}
.page-head h1 {
  margin: 0;
}
.page-head__meta {
  color: var(--text-muted);
  font-size: var(--step-0);
  margin: var(--s-1) 0 0;
}

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2);
  list-style: none;
  padding: 0;
  margin: 0 0 var(--s-4);
  font-size: var(--step--1);
  color: var(--text-muted);
}
.breadcrumb li::after {
  content: "/";
  margin-left: var(--s-2);
  color: var(--text-faint);
}
.breadcrumb li:last-child::after {
  content: "";
}

.toolbar {
  display: flex;
  gap: var(--s-2);
  flex-wrap: wrap;
  align-items: center;
}

/* =======================================================================
   CARDS / PANELS
   ======================================================================= */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--border);
}
.card__head h2,
.card__head h3 {
  margin: 0;
  font-size: var(--step-1);
}
.card__body {
  padding: var(--s-5);
}
.card__body--flush {
  padding: 0;
}

/* =======================================================================
   COLLAPSIBLE SECTION — the one reusable expand/collapse pattern.
   A <details>/<summary> styled as a card: serif title, animated chevron,
   smooth open, accessible (native disclosure semantics + focus ring).
   ======================================================================= */
.collapsible {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.collapsible + .collapsible {
  margin-top: var(--s-4);
}
.collapsible__summary {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-5);
  cursor: pointer;
  list-style: none;
  user-select: none;
}
/* Hide the native disclosure triangle (we draw our own chevron). */
.collapsible__summary::-webkit-details-marker {
  display: none;
}
.collapsible__summary::marker {
  content: "";
}
.collapsible__summary:hover {
  background: var(--paper-50);
}
.collapsible__summary:focus-visible {
  outline: none;
  box-shadow: inset var(--focus-ring);
}
.collapsible__chevron {
  flex: none;
  width: 9px;
  height: 9px;
  border-right: 2px solid var(--text-faint);
  border-bottom: 2px solid var(--text-faint);
  transform: rotate(-45deg);
  transition: transform 160ms ease, border-color 160ms ease;
}
.collapsible[open] > .collapsible__summary .collapsible__chevron {
  transform: rotate(45deg);
}
.collapsible__summary:hover .collapsible__chevron {
  border-color: var(--accent);
}
.collapsible__heading {
  display: flex;
  align-items: baseline;
  gap: var(--s-3);
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}
.collapsible__title {
  font-family: var(--font-serif);
  font-size: var(--step-1);
  font-weight: 600;
  color: var(--text-strong);
  letter-spacing: -0.01em;
}
.collapsible__subtitle {
  font-size: var(--step--1);
  color: var(--text-muted);
}
.collapsible__meta {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
}
.collapsible__body {
  padding: var(--s-5);
  border-top: 1px solid var(--border);
}
.collapsible__body--flush {
  padding: 0;
}
/* A gentle reveal on open (skipped under reduced-motion via the global rule). */
.collapsible[open] > .collapsible__body {
  animation: collapsible-reveal 180ms ease;
}
@keyframes collapsible-reveal {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.grid {
  display: grid;
  gap: var(--s-5);
}
.grid--2 {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}
.grid--3 {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.grid--4 {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.stack {
  display: grid;
  gap: var(--s-5);
}
.stack--tight {
  gap: var(--s-3);
}

/* Metric tile */
.metric {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s-4) var(--s-5);
  box-shadow: var(--shadow-sm);
}
.metric__label {
  display: block;
  font-size: var(--step--1);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: var(--s-2);
}
.metric__value {
  display: block;
  font-family: var(--font-serif);
  font-size: var(--step-3);
  color: var(--text-strong);
  font-variant-numeric: tabular-nums;
}
.metric__note {
  display: block;
  font-size: var(--step--1);
  color: var(--text-faint);
  margin-top: var(--s-1);
}

/* Definition rows */
.deflist {
  display: grid;
  gap: 0;
  margin: 0;
}
.deflist > div {
  display: flex;
  justify-content: space-between;
  gap: var(--s-4);
  padding: var(--s-2) 0;
  border-bottom: 1px dashed var(--border);
}
.deflist > div:last-child {
  border-bottom: 0;
}
.deflist dt {
  color: var(--text-muted);
  font-weight: 500;
}
.deflist dd {
  margin: 0;
  color: var(--text-strong);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* =======================================================================
   STATUS PILLS
   ======================================================================= */
.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  font-size: var(--step--1);
  font-weight: 600;
  line-height: 1;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--bg-sunken);
  color: var(--text);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.7;
}
.pill--bare::before {
  display: none;
}
.pill--neutral {
  background: var(--paper-100);
  color: var(--ink-600);
  border-color: var(--line-strong);
}
.pill--info {
  background: var(--info-100);
  color: var(--info-700);
  border-color: #c3d2e8;
}
.pill--progress {
  background: var(--amber-100);
  color: var(--amber-700);
  border-color: #e7d3ad;
}
.pill--good,
.pill--success {
  background: var(--sage-100);
  color: var(--sage-700);
  border-color: #c4ddd3;
}
.pill--warn {
  background: var(--amber-100);
  color: var(--amber-700);
  border-color: #e7d3ad;
}
.pill--danger,
.pill--blocked {
  background: var(--rust-100);
  color: var(--rust-700);
  border-color: #e9c4bd;
}

/* =======================================================================
   STATUS BOARD — the console's at-a-glance command center.
   A responsive grid of client cards; each card is scannable in under a
   second (name, identities, a row of per-return state pills, signal chips).
   Built from the same tokens as everything else — no new aesthetic.
   ======================================================================= */
.board {
  display: grid;
  gap: var(--s-4);
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  align-items: start;
}

.board-card {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--s-4) var(--s-5);
  cursor: pointer;
  text-align: left;
  width: 100%;
  font: inherit;
  color: inherit;
  transition: box-shadow 120ms ease, border-color 120ms ease, transform 120ms ease;
}
.board-card:hover {
  box-shadow: var(--shadow);
  transform: translateY(-1px);
  text-decoration: none;
}
.board-card:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
/* Left accent rail communicates triage at a glance: rust = needs a human now. */
.board-card--attention {
  border-left-color: var(--rust-600);
}
.board-card--progress {
  border-left-color: var(--amber-700);
}
.board-card--done {
  border-left-color: var(--sage-600);
}

.board-card__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-3);
}
.board-card__name {
  font-family: var(--font-serif);
  font-size: var(--step-1);
  font-weight: 600;
  color: var(--text-strong);
  letter-spacing: -0.01em;
  line-height: 1.25;
}
.board-card__id {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-faint);
  margin-top: 2px;
}
.board-card__when {
  font-size: var(--step--1);
  color: var(--text-faint);
  white-space: nowrap;
  flex: none;
}

/* The row of per-return state pills. */
.board-card__returns {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}
.board-card__return {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
}
.board-card__year {
  font-variant-numeric: tabular-nums;
  font-size: var(--step--1);
  font-weight: 700;
  color: var(--text-muted);
}

/* Signal chips: identities, businesses, open tickets, books. */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--step--1);
  font-weight: 600;
  line-height: 1;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--bg-sunken);
  color: var(--text-muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.chip strong {
  color: var(--text-strong);
  font-variant-numeric: tabular-nums;
}
.chip--alert {
  background: var(--rust-100);
  color: var(--rust-700);
  border-color: #e9c4bd;
}
.chip--alert strong {
  color: var(--rust-700);
}
.chip--accent {
  background: var(--sage-100);
  color: var(--sage-700);
  border-color: #c4ddd3;
}
.chip--accent strong {
  color: var(--sage-700);
}

/* Small rust dot marking a needs-attention row in dense tables. */
.attn-dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--rust-600);
  box-shadow: 0 0 0 3px var(--rust-100);
}

/* Segmented filter (All / Needs attention / Active) — a quiet toggle group. */
.segmented {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-surface);
}
.segmented button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: var(--step--1);
  font-weight: 600;
  padding: 7px 13px;
  cursor: pointer;
  width: auto;
  white-space: nowrap;
  border-right: 1px solid var(--line-strong);
}
.segmented button:last-child {
  border-right: 0;
}
.segmented button:hover {
  background: var(--bg-sunken);
}
.segmented button[aria-pressed="true"] {
  background: var(--ink-900);
  color: #fff;
}
.segmented button .count {
  font-variant-numeric: tabular-nums;
  opacity: 0.8;
  margin-left: 4px;
}

/* =======================================================================
   BUTTONS
   ======================================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  font-family: var(--font-sans);
  font-size: var(--step-0);
  font-weight: 600;
  line-height: 1;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
  text-decoration: none;
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn--primary {
  background: var(--sage-700);
  color: #fff;
  border-color: var(--sage-700);
}
.btn--primary:hover:not(:disabled) {
  background: var(--sage-600);
  border-color: var(--sage-600);
  text-decoration: none;
}
.btn--ghost {
  background: var(--bg-surface);
  color: var(--ink-700);
  border-color: var(--line-strong);
}
.btn--ghost:hover:not(:disabled) {
  background: var(--bg-sunken);
  text-decoration: none;
}
.btn--subtle {
  background: transparent;
  color: var(--ink-600);
  border-color: transparent;
  padding: 6px 10px;
}
.btn--subtle:hover:not(:disabled) {
  background: var(--bg-sunken);
  text-decoration: none;
}
.btn--danger {
  background: transparent;
  color: var(--rust-700);
  border-color: var(--rust-100);
}
.btn--danger:hover:not(:disabled) {
  background: var(--rust-100);
  text-decoration: none;
}
.btn--sm {
  padding: 6px 12px;
  font-size: var(--step--1);
}

/* =======================================================================
   FORMS
   ======================================================================= */
.field {
  display: grid;
  gap: var(--s-2);
  margin-bottom: var(--s-4);
}
.field > span,
.field > label {
  font-size: var(--step--1);
  font-weight: 600;
  color: var(--text-strong);
}
input,
select,
textarea {
  font-family: inherit;
  font-size: var(--step-0);
  color: var(--text-strong);
  background: var(--bg-surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  width: 100%;
}
input::placeholder {
  color: var(--text-faint);
}
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  border-color: var(--sage-600);
  box-shadow: var(--focus-ring);
}
.input--inline {
  width: auto;
}
.form-error {
  color: var(--rust-700);
  font-size: var(--step--1);
  font-weight: 600;
  min-height: 1.2em;
  margin: 0;
}

/* Filter bar */
.filterbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3);
  align-items: flex-end;
}
.filterbar .field {
  margin-bottom: 0;
}

/* =======================================================================
   TABLES
   ======================================================================= */
.table-wrap {
  overflow-x: auto;
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--step-0);
}
table.data thead th {
  text-align: left;
  font-size: var(--step--1);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 700;
  padding: var(--s-3) var(--s-4);
  border-bottom: 2px solid var(--line-strong);
  background: var(--bg-sunken);
  white-space: nowrap;
}
table.data tbody td {
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.data tbody tr:last-child td {
  border-bottom: 0;
}
table.data tbody tr.is-clickable {
  cursor: pointer;
}
table.data tbody tr.is-clickable:hover {
  background: var(--paper-50);
}
table.data td.num,
table.data th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
table.data th[aria-sort] {
  cursor: pointer;
  user-select: none;
}
table.data th[aria-sort]::after {
  content: " \2195";
  color: var(--text-faint);
}
table.data th[aria-sort="ascending"]::after {
  content: " \2191";
  color: var(--accent);
}
table.data th[aria-sort="descending"]::after {
  content: " \2193";
  color: var(--accent);
}

.empty {
  padding: var(--s-7) var(--s-5);
  text-align: center;
  color: var(--text-muted);
}
.empty__title {
  font-family: var(--font-serif);
  font-size: var(--step-1);
  color: var(--text);
  margin-bottom: var(--s-2);
}

/* =======================================================================
   TIMELINE (engagement state machine)
   ======================================================================= */
.timeline {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  list-style: none;
  padding: 0;
  margin: 0;
}
.timeline__step {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-sunken);
  color: var(--text-muted);
  font-size: var(--step--1);
  font-weight: 600;
}
.timeline__step[data-status="done"] {
  background: var(--sage-100);
  border-color: #c4ddd3;
  color: var(--sage-700);
}
.timeline__step[data-status="current"] {
  background: var(--ink-900);
  border-color: var(--ink-900);
  color: #fff;
}
.timeline__step .dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: currentColor;
}

/* =======================================================================
   PROVENANCE / source chips
   ======================================================================= */
.provenance {
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
  font-size: var(--step--1);
  color: var(--text-muted);
}
.provenance__src {
  font-weight: 600;
  color: var(--text);
}
.src-chip {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 1px 7px;
  border-radius: 5px;
  background: var(--paper-100);
  color: var(--ink-600);
  border: 1px solid var(--border);
}
.src-chip--extracted_fact {
  background: var(--info-100);
  color: var(--info-700);
  border-color: #c3d2e8;
}
.src-chip--questionnaire {
  background: var(--sage-100);
  color: var(--sage-700);
  border-color: #c4ddd3;
}
.src-chip--computation,
.src-chip--computed {
  background: var(--amber-100);
  color: var(--amber-700);
  border-color: #e7d3ad;
}

.banner {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-radius: var(--radius);
  font-size: var(--step-0);
  border: 1px solid;
}
.banner--good {
  background: var(--sage-100);
  border-color: #c4ddd3;
  color: var(--sage-700);
}
.banner--warn {
  background: var(--amber-100);
  border-color: #e7d3ad;
  color: var(--amber-700);
}
.banner--danger {
  background: var(--rust-100);
  border-color: #e9c4bd;
  color: var(--rust-700);
}

.code-block {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  background: var(--ink-900);
  color: #d6e0ec;
  padding: var(--s-4);
  border-radius: var(--radius);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* =======================================================================
   LOGIN (centered card, used when there is no session)
   ======================================================================= */
.auth-wrap {
  min-height: calc(100vh - 60px);
  display: grid;
  place-items: center;
  padding: var(--s-6) var(--s-4);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--s-6);
}

/* =======================================================================
   FEEDBACK / LOADING
   ======================================================================= */
.loading {
  padding: var(--s-6);
  text-align: center;
  color: var(--text-muted);
}
.spinner {
  width: 22px;
  height: 22px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 999px;
  display: inline-block;
  animation: spin 700ms linear infinite;
  vertical-align: middle;
  margin-right: var(--s-2);
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.toast {
  position: fixed;
  right: var(--s-5);
  bottom: var(--s-5);
  background: var(--ink-900);
  color: #fff;
  padding: var(--s-3) var(--s-4);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 60;
  max-width: 360px;
}
.toast--danger {
  background: var(--rust-700);
}

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

@media (max-width: 720px) {
  .app-brand__sub {
    display: none;
  }
  .app-header__inner {
    flex-wrap: wrap;
    padding: var(--s-2) var(--s-4);
  }
  .app-identity__who {
    display: none;
  }
  .page {
    padding: var(--s-5) var(--s-4) var(--s-7);
  }
}

/* ---- Ads · per-ad visitor journey rail ------------------------------- */
/* One ad = one card; the rail draws its measured funnel left to right. The signature device is the
   connector: it reads "% kept" while visitors flow and severs to a red ✕ at the first step that went
   to zero, so a dead-end ad looks like a dead end. Counts are mono (data face); the ad title serif. */
.adcard {
  margin: 0;
}
.adcard__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  flex-wrap: wrap;
  margin-bottom: var(--s-2);
}
.adcard__summary {
  font-size: var(--step--1);
  color: var(--text-muted);
  letter-spacing: 0.01em;
}
.adrail {
  display: flex;
  align-items: stretch;
  gap: 0;
  overflow-x: auto;
  padding: var(--s-3) 0 var(--s-1);
  scrollbar-width: thin;
}
.adrail__node {
  flex: 0 0 auto;
  min-width: 116px;
  max-width: 200px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--s-2) var(--s-3) var(--s-2) 0;
}
.adrail__node--origin {
  min-width: 168px;
  padding: var(--s-3);
  margin-right: var(--s-1);
  background: var(--bg-sunken);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  gap: 3px;
}
.adrail__node--spent {
  opacity: 0.45;
}
.adrail__step {
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-weight: 600;
  color: var(--text-faint);
  line-height: 1.2;
}
.adrail__title {
  font-family: var(--font-serif);
  font-size: var(--step-1);
  font-weight: 600;
  color: var(--text-strong);
  line-height: 1.15;
}
.adrail__count {
  font-size: var(--step-3);
  font-weight: 600;
  color: var(--text-strong);
  line-height: 1.05;
}
.adrail__sub {
  font-size: var(--step--1);
  color: var(--text-muted);
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.adrail__link {
  flex: 0 0 auto;
  width: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
}
.adrail__linklabel {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  color: var(--text-faint);
  white-space: nowrap;
}
.adrail__arrow {
  font-size: 1.25rem;
  line-height: 1;
  color: var(--line-strong);
}
.adrail__link--sever .adrail__linklabel {
  color: var(--rust-700);
}
.adrail__link--sever .adrail__arrow {
  color: var(--rust-700);
  font-weight: 700;
}
.adrail__link--faint .adrail__arrow,
.adrail__link--dead .adrail__arrow {
  color: var(--line);
}
