/* PermitScope operator dashboard · design system
   ---------------------------------------------------------------------
   Per vault/10-Decisions/2026-05-01-dashboard-ux-polish-pass.md.

   Single-file design system: tokens, reset, layout, components, dark
   mode. No build step. Vendored at /static/css/permitscope.css and
   loaded by base.html.j2 with the same `?v={{ build_sha }}` cache-bust
   the vendored htmx uses, so a redeploy invalidates browser caches.

   Aesthetic direction: "Permit Office Terminal" — Linear's discipline,
   GovUK's civic seriousness, Plausible's calm, trading-terminal
   density on observability tabs. Explicitly NOT AI-bubble pastel
   gradients, oversized hero numbers, or Bootstrap admin clones.

   Sections:
     1. Design tokens (light) ........... lines ~30-130
     2. Design tokens (dark) ............ lines ~135-220
     3. Reset + base typography ......... lines ~225-310
     4. Layout (sidebar + topbar + main) lines ~315-460
     5. Buttons ........................ lines ~465-580
     6. Inputs + forms ................. lines ~585-660
     7. Cards + sections ............... lines ~665-720
     8. Badges + status dots + alerts .. lines ~725-830
     9. Tables ......................... lines ~835-920
    10. Summary tiles ................... lines ~925-970
    11. Tabs + sidebar nav .............. lines ~975-1050
    12. HTMX async-button contract ...... lines ~1055-1100
    13. PDF preview iframe .............. lines ~1105-1130
    14. Misc utilities .................. lines ~1135-1180
   ---------------------------------------------------------------------
*/

/* ──────────────────────────────────────────────────────────────────
   1. Design tokens — light mode (default)
   ──────────────────────────────────────────────────────────────────
   Naming follows USWDS / Carbon convention: layer-purpose-step.
   Step `0` is the inverse-most surface; step `9` is the boldest text.
   Palette is warm-neutral (subtle yellow-brown undertone) — explicitly
   NOT cold blue-gray, which reads as "AI bubble admin". One canonical
   accent (indigo, slightly desaturated). Status colors carry shape +
   color so they're color-blind safe.
   ────────────────────────────────────────────────────────────────── */
:root {
  /* Neutrals — warm grayscale (zinc family with a touch of warmth) */
  --gray-0:  #ffffff;
  --gray-50: #fafaf9;
  --gray-100:#f5f5f4;
  --gray-200:#e7e5e4;
  --gray-300:#d6d3d1;
  --gray-400:#a8a29e;
  --gray-500:#78716c;
  --gray-600:#57534e;
  --gray-700:#44403c;
  --gray-800:#292524;
  --gray-900:#1c1917;

  /* Accent — indigo-cobalt (less saturated than tailwind's default) */
  --accent-50:  #eef2ff;
  --accent-100: #e0e7ff;
  --accent-200: #c7d2fe;
  --accent-400: #818cf8;
  --accent-500: #6366f1;
  --accent-600: #4f46e5;
  --accent-700: #4338ca;
  --accent-800: #3730a3;

  /* Semantic status — paired with status-dot shape (never color-only) */
  --ok-100:  #d1fae5;  --ok-500:  #10b981;  --ok-700:  #047857;
  --warn-100:#fef3c7;  --warn-500:#f59e0b;  --warn-700:#b45309;
  --err-100: #fee2e2;  --err-500: #ef4444;  --err-700: #b91c1c;
  --info-100:#dbeafe;  --info-500:#3b82f6;  --info-700:#1d4ed8;
  --pending-100: #ede9fe; --pending-500: #8b5cf6; --pending-700: #6d28d9;

  /* Semantic surface tokens — what templates actually reference */
  --bg-app:        var(--gray-50);     /* outermost canvas */
  --bg-surface:    var(--gray-0);      /* cards, table rows */
  --bg-surface-2:  var(--gray-100);    /* nested / sticky headers */
  --bg-surface-3:  var(--gray-200);    /* hover row, code chips */
  --bg-overlay:    rgba(28,25,23,0.4); /* modal scrim */

  --fg-default:    var(--gray-900);
  --fg-muted:      var(--gray-500);
  --fg-subtle:     var(--gray-400);
  --fg-on-accent:  var(--gray-0);
  --fg-link:       var(--accent-700);
  --fg-link-hover: var(--accent-800);

  --border-subtle:  var(--gray-200);
  --border-default: var(--gray-300);
  --border-strong:  var(--gray-400);
  --border-focus:   var(--accent-500);

  --action-primary:        var(--accent-600);
  --action-primary-hover:  var(--accent-700);
  --action-primary-active: var(--accent-800);
  --action-success:        var(--ok-700);
  --action-success-hover:  #065f46;
  --action-destructive:    var(--err-700);
  --action-destructive-hover: #991b1b;

  --status-ok-bg:      var(--ok-100);    --status-ok-fg:      var(--ok-700);
  --status-warn-bg:    var(--warn-100);  --status-warn-fg:    var(--warn-700);
  --status-err-bg:     var(--err-100);   --status-err-fg:     var(--err-700);
  --status-info-bg:    var(--info-100);  --status-info-fg:    var(--info-700);
  --status-pending-bg: var(--pending-100); --status-pending-fg: var(--pending-700);
  --status-neutral-bg: var(--gray-200);  --status-neutral-fg: var(--gray-700);
  --status-accent-bg:  var(--accent-100); --status-accent-fg: var(--accent-700);

  /* Type scale — Linear-style 11/12/13/14/16/20/24/32 */
  --text-2xs: 11px;
  --text-xs:  12px;
  --text-sm:  13px;
  --text-md:  14px;
  --text-lg:  16px;
  --text-xl:  20px;
  --text-2xl: 24px;
  --text-3xl: 32px;

  /* System sans + mono stacks. NO Google Fonts (Tailscale-internal,
     $0 budget, want native crispness on every OS). */
  --font-sans:
    system-ui, -apple-system, "Segoe UI Variable Display", "Segoe UI",
    Cantarell, Ubuntu, "Helvetica Neue", Arial, sans-serif;
  --font-mono:
    "SF Mono", "Cascadia Mono", "Cascadia Code", "JetBrains Mono",
    "Fira Code", Menlo, Consolas, "Liberation Mono", monospace;

  /* Spacing — 4px base, used as multiplied scale. */
  --space-0:  0;
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-8:  32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* Radii — flat surfaces, sharp data. */
  --radius-sm: 3px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-pill: 999px;

  /* Elevation — single shadow used only for popovers. Flat by default. */
  --shadow-popover:
    0 1px 2px rgba(28,25,23,0.06),
    0 4px 12px rgba(28,25,23,0.10);

  /* Motion — short, mechanical. Operator tool, not a marketing site. */
  --motion-fast:   100ms;
  --motion-medium: 180ms;
  --easing:        cubic-bezier(0.2, 0, 0.2, 1);

  /* Layout dimensions */
  --sidebar-w:        228px;
  --sidebar-w-mini:   56px;
  --topbar-h:         48px;
  --content-max-w:    1280px;
  --content-pad:      var(--space-6);
}

/* ──────────────────────────────────────────────────────────────────
   2. Design tokens — dark mode
   ──────────────────────────────────────────────────────────────────
   Triggered by EITHER `data-theme="dark"` on <html> (operator
   manual choice persisted in localStorage) OR `prefers-color-scheme:
   dark` (OS preference). Manual choice wins via CSS specificity.
   ────────────────────────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-app:        #0c0a09;
    --bg-surface:    #18171a;
    --bg-surface-2:  #1f1d20;
    --bg-surface-3:  #2a282b;

    --fg-default:    #f4f4f3;
    --fg-muted:      #a8a29e;
    --fg-subtle:     #78716c;
    --fg-on-accent:  #ffffff;
    --fg-link:       #a5b4fc;
    --fg-link-hover: #c7d2fe;

    --border-subtle:  #2a282b;
    --border-default: #3a3735;
    --border-strong:  #555050;
    --border-focus:   var(--accent-400);

    --action-primary:       var(--accent-500);
    --action-primary-hover: var(--accent-400);
    --action-primary-active: var(--accent-600);

    --status-ok-bg:      #064e3b; --status-ok-fg:      #6ee7b7;
    --status-warn-bg:    #78350f; --status-warn-fg:    #fcd34d;
    --status-err-bg:     #7f1d1d; --status-err-fg:     #fca5a5;
    --status-info-bg:    #1e3a8a; --status-info-fg:    #93c5fd;
    --status-pending-bg: #4c1d95; --status-pending-fg: #c4b5fd;
    --status-neutral-bg: #2a282b; --status-neutral-fg: #d6d3d1;
    --status-accent-bg:  #312e81; --status-accent-fg:  #c7d2fe;
  }
}
:root[data-theme="dark"] {
  --bg-app:        #0c0a09;
  --bg-surface:    #18171a;
  --bg-surface-2:  #1f1d20;
  --bg-surface-3:  #2a282b;

  --fg-default:    #f4f4f3;
  --fg-muted:      #a8a29e;
  --fg-subtle:     #78716c;
  --fg-on-accent:  #ffffff;
  --fg-link:       #a5b4fc;
  --fg-link-hover: #c7d2fe;

  --border-subtle:  #2a282b;
  --border-default: #3a3735;
  --border-strong:  #555050;
  --border-focus:   var(--accent-400);

  --action-primary:       var(--accent-500);
  --action-primary-hover: var(--accent-400);
  --action-primary-active: var(--accent-600);

  --status-ok-bg:      #064e3b; --status-ok-fg:      #6ee7b7;
  --status-warn-bg:    #78350f; --status-warn-fg:    #fcd34d;
  --status-err-bg:     #7f1d1d; --status-err-fg:     #fca5a5;
  --status-info-bg:    #1e3a8a; --status-info-fg:    #93c5fd;
  --status-pending-bg: #4c1d95; --status-pending-fg: #c4b5fd;
  --status-neutral-bg: #2a282b; --status-neutral-fg: #d6d3d1;
  --status-accent-bg:  #312e81; --status-accent-fg:  #c7d2fe;
}

/* ──────────────────────────────────────────────────────────────────
   3. Reset + base typography
   ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; tab-size: 4; }
body {
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: 1.5;
  color: var(--fg-default);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-variant-numeric: tabular-nums lining-nums;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  letter-spacing: -0.011em;
  color: var(--fg-default);
}
h1 { font-size: var(--text-2xl); line-height: 1.2; letter-spacing: -0.02em; }
h2 { font-size: var(--text-xl); line-height: 1.25; letter-spacing: -0.015em; }
h3 { font-size: var(--text-lg); line-height: 1.3; }
h4 { font-size: var(--text-md); line-height: 1.4; }
p  { margin: 0; }

a {
  color: var(--fg-link);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--fg-link) 35%, transparent);
  text-underline-offset: 2px;
  transition: color var(--motion-fast) var(--easing);
}
a:hover { color: var(--fg-link-hover); text-decoration-color: currentColor; }

code, kbd, samp, pre {
  font-family: var(--font-mono);
  font-size: 0.92em;
  font-variant-ligatures: none;
}
code:not(pre code) {
  background: var(--bg-surface-3);
  padding: 0 4px;
  border-radius: var(--radius-sm);
  font-size: 0.88em;
  color: var(--fg-default);
  border: 1px solid var(--border-subtle);
}
pre {
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  line-height: 1.5;
  overflow-x: auto;
}

/* Focus rings — visible everywhere, WCAG AA contrast */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

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

/* Skip-to-content link — keyboard a11y */
.skip-to-main {
  position: absolute;
  top: -100px;
  left: var(--space-3);
  background: var(--bg-surface);
  color: var(--fg-default);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  z-index: 100;
  text-decoration: none;
  font-weight: 600;
}
.skip-to-main:focus { top: var(--space-3); }

/* ──────────────────────────────────────────────────────────────────
   4. Layout — persistent sidebar + topbar + main
   ──────────────────────────────────────────────────────────────────
   Grid: sidebar (fixed-width column) + everything else (1fr).
   Topbar is sticky inside the right column. Main scrolls. Layout
   degrades to single column under 880px (mobile / narrow windows).
   ────────────────────────────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-brand {
  padding: var(--space-5) var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.sidebar-brand .logo {
  width: 24px; height: 24px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--gray-900);
  color: var(--gray-0);
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: var(--text-xs);
  letter-spacing: 0.04em;
  font-family: var(--font-mono);
}
:root[data-theme="dark"] .sidebar-brand .logo {
  background: var(--accent-500);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .sidebar-brand .logo {
    background: var(--accent-500);
  }
}
.sidebar-brand .name {
  font-weight: 700;
  font-size: var(--text-md);
  letter-spacing: -0.01em;
}
.sidebar-brand .env {
  margin-left: auto;
  font-size: var(--text-2xs);
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-family: var(--font-mono);
}

.sidebar-nav {
  padding: var(--space-3) var(--space-2);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.sidebar-section {
  margin-top: var(--space-4);
}
.sidebar-section-label {
  padding: 0 var(--space-3) var(--space-1);
  font-size: var(--text-2xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-subtle);
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px var(--space-3);
  border-radius: var(--radius-md);
  color: var(--fg-muted);
  font-weight: 500;
  font-size: var(--text-sm);
  text-decoration: none;
  transition:
    background var(--motion-fast) var(--easing),
    color var(--motion-fast) var(--easing);
  position: relative;
}
.sidebar-link .icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.8;
}
.sidebar-link:hover {
  background: var(--bg-surface-2);
  color: var(--fg-default);
  text-decoration: none;
}
.sidebar-link[aria-current="page"] {
  color: var(--fg-default);
  background: var(--bg-surface-2);
  font-weight: 600;
}
.sidebar-link[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: -2px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: var(--accent-600);
  border-radius: 2px;
}

.sidebar-footer {
  margin-top: auto;
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-subtle);
  font-size: var(--text-2xs);
  color: var(--fg-subtle);
  font-family: var(--font-mono);
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
}

.app-main-column {
  display: flex;
  flex-direction: column;
  min-width: 0; /* allows children to shrink */
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--topbar-h);
  background: color-mix(in srgb, var(--bg-app) 85%, transparent);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-5);
  gap: var(--space-4);
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  flex: 1;
}
.topbar-page-title {
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--fg-default);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.operator-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--fg-muted);
}
.operator-chip strong {
  color: var(--fg-default);
  font-weight: 600;
}
.theme-toggle {
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 4px 8px;
  font-size: var(--text-xs);
  color: var(--fg-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: color var(--motion-fast), border-color var(--motion-fast);
}
.theme-toggle:hover { color: var(--fg-default); border-color: var(--border-default); }

.app-main {
  padding: var(--space-5) var(--content-pad) var(--space-8);
  max-width: var(--content-max-w);
  width: 100%;
  margin: 0 auto;
}
.app-main--wide { max-width: none; }

@media (max-width: 880px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: relative;
    height: auto;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
  }
  .sidebar-brand { border-bottom: none; padding: var(--space-3) var(--space-4); }
  .sidebar-nav { flex-direction: row; padding: 0 var(--space-2); flex-wrap: wrap; }
  .sidebar-section { margin-top: 0; }
  .sidebar-section-label { display: none; }
  .sidebar-footer { display: none; }
}

/* ──────────────────────────────────────────────────────────────────
   5. Buttons — taxonomy: primary, secondary, ghost, success, destructive
   ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1.4;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition:
    background var(--motion-fast) var(--easing),
    border-color var(--motion-fast) var(--easing),
    color var(--motion-fast) var(--easing),
    transform var(--motion-fast) var(--easing);
  user-select: none;
}
.btn:active { transform: translateY(0.5px); }
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

/* Sizes */
.btn-sm { padding: 3px 8px; font-size: var(--text-xs); }
.btn-lg { padding: 9px 16px; font-size: var(--text-md); }

/* Primary — single canonical action per view */
.btn-primary {
  background: var(--action-primary);
  color: var(--fg-on-accent);
  border-color: var(--action-primary);
}
.btn-primary:hover:not(:disabled) {
  background: var(--action-primary-hover);
  border-color: var(--action-primary-hover);
  color: var(--fg-on-accent);
  text-decoration: none;
}
.btn-primary:active:not(:disabled) { background: var(--action-primary-active); }

/* Secondary — surface + border, neutral actions */
.btn-secondary {
  background: var(--bg-surface);
  color: var(--fg-default);
  border-color: var(--border-default);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--bg-surface-2);
  color: var(--fg-default);
  text-decoration: none;
  border-color: var(--border-strong);
}

/* Ghost — transparent, tertiary */
.btn-ghost {
  background: transparent;
  color: var(--fg-muted);
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) {
  background: var(--bg-surface-2);
  color: var(--fg-default);
  text-decoration: none;
}

/* Success — for actions that mean "the contractor gets the email" */
.btn-success {
  background: var(--action-success);
  color: var(--fg-on-accent);
  border-color: var(--action-success);
}
.btn-success:hover:not(:disabled) {
  background: var(--action-success-hover);
  border-color: var(--action-success-hover);
  color: var(--fg-on-accent);
  text-decoration: none;
}

/* Destructive — release, refund, suppress */
.btn-destructive {
  background: var(--bg-surface);
  color: var(--action-destructive);
  border-color: color-mix(in srgb, var(--action-destructive) 35%, var(--border-default));
}
.btn-destructive:hover:not(:disabled) {
  background: var(--action-destructive);
  color: var(--fg-on-accent);
  border-color: var(--action-destructive);
  text-decoration: none;
}

/* Icon-only square */
.btn-icon {
  padding: 0;
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
}

/* Button group */
.btn-group { display: inline-flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* ──────────────────────────────────────────────────────────────────
   6. Inputs + forms
   ────────────────────────────────────────────────────────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.field-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--fg-default);
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.field-label .required {
  color: var(--err-500);
  font-weight: 600;
}
.field-hint {
  font-size: var(--text-xs);
  color: var(--fg-muted);
  line-height: 1.4;
}

.input,
.select,
.textarea {
  background: var(--bg-surface);
  color: var(--fg-default);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 6px 10px;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  width: 100%;
  transition: border-color var(--motion-fast) var(--easing),
              box-shadow var(--motion-fast) var(--easing);
}
.input:hover, .select:hover, .textarea:hover { border-color: var(--border-strong); }
.input:focus-visible,
.select:focus-visible,
.textarea:focus-visible {
  border-color: var(--border-focus);
  outline: 2px solid color-mix(in srgb, var(--border-focus) 30%, transparent);
  outline-offset: 0;
}
.textarea { min-height: 80px; resize: vertical; font-family: var(--font-mono); }

.checkbox-row, .radio-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-sm);
  cursor: pointer;
}
.checkbox-row input, .radio-row input {
  width: 14px; height: 14px; margin: 0; accent-color: var(--accent-600);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-3) var(--space-4);
}

/* Choice list — selectable radio/checkbox cards (email picker, etc.).
   The whole row is the label's hit target; :has(:checked) highlights
   the selected row with the accent edge so the operator always sees
   which address will receive the send. */
.choice-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.choice {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-surface);
  transition: border-color var(--motion-fast) var(--easing),
              background var(--motion-fast) var(--easing);
}
.choice:hover { border-color: var(--border-strong); }
.choice:has(input:checked) {
  border-color: var(--accent-500);
  background: color-mix(in srgb, var(--accent-500) 6%, var(--bg-surface));
}
.choice input[type="radio"],
.choice input[type="checkbox"] {
  margin-top: 3px;
  accent-color: var(--accent-600);
  flex-shrink: 0;
}
.choice > label { flex: 1; cursor: pointer; min-width: 0; }
.choice--disabled { opacity: 0.55; }
.choice--disabled > label { cursor: not-allowed; }
.choice .choice-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.choice .choice-title code {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--fg-default);
}
.choice .choice-meta {
  margin-top: var(--space-1);
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  font-size: var(--text-xs);
  color: var(--fg-muted);
}

/* ──────────────────────────────────────────────────────────────────
   7. Cards + sections
   ────────────────────────────────────────────────────────────────── */
.section { margin-bottom: var(--space-6); }
.section + .section { margin-top: 0; }
.section-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border-subtle);
}
.section-header .titles { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.section-header .title { font-size: var(--text-lg); font-weight: 600; }
.section-header .subtitle { font-size: var(--text-xs); color: var(--fg-muted); }
.section-header .toolbar {
  display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.card-header {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  background: var(--bg-surface);
}
.card-header .title { font-weight: 600; font-size: var(--text-md); }
.card-header .subtitle {
  font-size: var(--text-xs); color: var(--fg-muted); margin-top: 2px;
}
.card-body { padding: var(--space-4); }
.card-body--flush { padding: 0; } /* tables flush against card edges */
.card-footer {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface-2);
  font-size: var(--text-xs);
  color: var(--fg-muted);
}

/* Feature cards — the page's ONE highlighted next-action surface.
   Flat tinted surface + accent left edge (NO gradients per the design
   charter). color-mix against the semantic surface token keeps both
   themes correct automatically — this replaces the raw-palette
   `--accent-50` / `--warn-50` gradient inline styles that rendered a
   light band with invisible white text in dark mode (the 2026-06-10
   operator screenshot bug). */
.card--feature-accent {
  border-color: color-mix(in srgb, var(--accent-500) 35%, var(--border-subtle));
  border-left: 3px solid var(--accent-500);
  background: color-mix(in srgb, var(--accent-500) 5%, var(--bg-surface));
}
.card--feature-accent > .card-header {
  background: transparent;
  border-bottom-color: color-mix(in srgb, var(--accent-500) 18%, var(--border-subtle));
}
.card--feature-warn {
  border-color: color-mix(in srgb, var(--warn-500) 35%, var(--border-subtle));
  border-left: 3px solid var(--warn-500);
  background: color-mix(in srgb, var(--warn-500) 5%, var(--bg-surface));
}
.card--feature-warn > .card-header {
  background: transparent;
  border-bottom-color: color-mix(in srgb, var(--warn-500) 18%, var(--border-subtle));
}

/* Page header — top of every page below the topbar */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-6);
}
.page-header .titles { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.page-header h1 { font-size: var(--text-2xl); }
.page-header .subtitle {
  color: var(--fg-muted);
  font-size: var(--text-sm);
  max-width: 60ch;
}
.page-header .toolbar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

.breadcrumbs {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: var(--text-xs);
  color: var(--fg-muted);
  margin-bottom: var(--space-2);
}
.breadcrumbs a { color: var(--fg-muted); text-decoration: none; }
.breadcrumbs a:hover { color: var(--fg-default); text-decoration: underline; }
.breadcrumbs .sep { color: var(--fg-subtle); }

/* ──────────────────────────────────────────────────────────────────
   8. Badges + status dots + alerts
   ──────────────────────────────────────────────────────────────────
   Status badges ALWAYS pair color with a leading shape (status-dot)
   so color-blind operators read state correctly.
   ────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 6px;
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 500;
  line-height: 1.5;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  background: var(--status-neutral-bg);
  color: var(--status-neutral-fg);
  white-space: nowrap;
}
.badge--mono {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.badge--ok      { background: var(--status-ok-bg);      color: var(--status-ok-fg); }
.badge--warn    { background: var(--status-warn-bg);    color: var(--status-warn-fg); }
.badge--err     { background: var(--status-err-bg);     color: var(--status-err-fg); }
.badge--info    { background: var(--status-info-bg);    color: var(--status-info-fg); }
.badge--pending { background: var(--status-pending-bg); color: var(--status-pending-fg); }
.badge--neutral { background: var(--status-neutral-bg); color: var(--status-neutral-fg); }
.badge--accent  { background: var(--status-accent-bg);  color: var(--status-accent-fg); }

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  flex-shrink: 0;
  border-radius: 50%;
  background: currentColor;
}
.status-dot--ring   { background: transparent; border: 1.5px solid currentColor; }
.status-dot--square { border-radius: 1px; }
.status-dot--bar    { width: 10px; height: 2px; border-radius: 1px; }

.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-2);
  font-size: var(--text-sm);
  line-height: 1.5;
}
.alert .alert-icon {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin-top: 2px;
}
.alert .alert-body { min-width: 0; flex: 1; }
.alert .alert-title { font-weight: 600; margin-bottom: 2px; }
.alert--ok    { background: var(--status-ok-bg);    color: var(--status-ok-fg);    border-color: color-mix(in srgb, var(--status-ok-fg) 30%, transparent); }
.alert--warn  { background: var(--status-warn-bg);  color: var(--status-warn-fg);  border-color: color-mix(in srgb, var(--status-warn-fg) 30%, transparent); }
.alert--err   { background: var(--status-err-bg);   color: var(--status-err-fg);   border-color: color-mix(in srgb, var(--status-err-fg) 30%, transparent); }
.alert--info  { background: var(--status-info-bg);  color: var(--status-info-fg);  border-color: color-mix(in srgb, var(--status-info-fg) 30%, transparent); }
.alert a { color: inherit; text-decoration: underline; }

.empty-state {
  text-align: center;
  padding: var(--space-10) var(--space-6);
  border: 1px dashed var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  align-items: center;
}
.empty-state .title { font-weight: 600; font-size: var(--text-md); }
.empty-state .hint { color: var(--fg-muted); font-size: var(--text-sm); max-width: 50ch; }

/* ──────────────────────────────────────────────────────────────────
   9. Tables — dense, honest, sortable-ready
   ──────────────────────────────────────────────────────────────────
   13px tabular monospace numerics. Borders only where they help scan.
   Right-align numerics, left-align text, monospace for IDs/timestamps.
   ────────────────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  -webkit-overflow-scrolling: touch;
}
.card .table-wrap {
  border: none;
  border-radius: 0;
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums lining-nums;
}
table.data th,
table.data td {
  text-align: left;
  padding: 8px var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: top;
}
table.data thead th {
  background: var(--bg-surface-2);
  font-weight: 600;
  font-size: var(--text-2xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-muted);
  white-space: nowrap;
  position: sticky;
  top: 0;
  border-bottom: 1px solid var(--border-default);
}
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover td { background: var(--bg-surface-2); }
table.data td.num,
table.data th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
table.data td.mono,
table.data th.mono {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}
table.data td.muted { color: var(--fg-muted); }
table.data caption {
  caption-side: top;
  text-align: left;
  padding: var(--space-3) var(--space-3) var(--space-2);
  font-weight: 600;
  font-size: var(--text-md);
}
.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;
}

/* ──────────────────────────────────────────────────────────────────
   10. Summary tiles — the four-up row at the top of pages
   ────────────────────────────────────────────────────────────────── */
.tile-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}
.tile {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  overflow: hidden;
}
.tile::before {
  content: "";
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: 2px;
  background: var(--border-subtle);
}
.tile--ok::before    { background: var(--ok-500); }
.tile--warn::before  { background: var(--warn-500); }
.tile--err::before   { background: var(--err-500); }
.tile--info::before  { background: var(--info-500); }
.tile--accent::before{ background: var(--accent-600); }
.tile .label {
  font-size: var(--text-2xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.tile .value {
  font-size: var(--text-2xl);
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums lining-nums;
  color: var(--fg-default);
}
.tile .hint {
  font-size: var(--text-xs);
  color: var(--fg-muted);
}

/* ──────────────────────────────────────────────────────────────────
   11. Definition lists / metadata grids
   ────────────────────────────────────────────────────────────────── */
dl.meta {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px var(--space-4);
  font-size: var(--text-sm);
}
dl.meta dt {
  color: var(--fg-muted);
  font-weight: 500;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  align-self: center;
}
dl.meta dd { color: var(--fg-default); }

dl.meta-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  font-size: var(--text-sm);
}
dl.meta-stack dt {
  color: var(--fg-muted);
  font-size: var(--text-2xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  margin-bottom: 2px;
}

/* ──────────────────────────────────────────────────────────────────
   12. HTMX async-button contract
   ──────────────────────────────────────────────────────────────────
   Built into the async_button macro. Spinner sits in a sibling span
   that opacity-fades in via the .htmx-request class HTMX 2.x toggles
   on elements with [hx-indicator]. The button itself gets
   hx-disabled-elt="this" so HTMX sets [disabled] for free during the
   request — no double-submit, no event-handler gymnastics.
   ────────────────────────────────────────────────────────────────── */
.htmx-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  opacity: 0;
  transition: opacity var(--motion-medium) var(--easing);
  color: var(--fg-muted);
  font-size: var(--text-xs);
  vertical-align: middle;
  pointer-events: none;
}
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { opacity: 1; }
.htmx-request .btn { cursor: progress; }

.spinner {
  width: 12px; height: 12px;
  flex-shrink: 0;
  border: 1.5px solid color-mix(in srgb, currentColor 30%, transparent);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: ps-spin 700ms linear infinite;
  display: inline-block;
}
.spinner--lg { width: 16px; height: 16px; border-width: 2px; }
@keyframes ps-spin { to { transform: rotate(360deg); } }

/* ──────────────────────────────────────────────────────────────────
   13. PDF preview iframe
   ────────────────────────────────────────────────────────────────── */
.pdf-frame {
  width: 100%;
  height: 720px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-surface-2);
  display: block;
}
.pdf-frame-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-surface-2);
  border: 1px solid var(--border-default);
  border-bottom: none;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  font-size: var(--text-xs);
  color: var(--fg-muted);
  font-family: var(--font-mono);
}
.pdf-frame-header + .pdf-frame { border-radius: 0 0 var(--radius-md) var(--radius-md); border-top: none; }

/* Review workspace — the contractor review page's primary job is: read
   the pack, pick a recipient, send. A focused two-pane layout (PDF hero +
   sticky action rail) replaces the prior vertical stack of nested cards
   ("boxes inside boxes") per
   vault/10-Decisions/2026-06-10-review-workspace-layout.md. The rail is
   compact + sticky so Send is always one glance away; the PDF gets the
   viewport height instead of a cramped iframe inside a card body. */
.review {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: var(--space-4);
  align-items: start;
  margin-bottom: var(--space-8);
}
.review-main { min-width: 0; }
.review-rail {
  position: sticky;
  top: calc(var(--topbar-h) + var(--space-4));
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  border: 1px solid var(--border-default);
  border-left: 3px solid var(--accent-500);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  padding: var(--space-4);
}
.review-rail .rail-title { font-size: var(--text-lg); font-weight: 600; letter-spacing: -0.01em; }
.review-rail .rail-meta { font-size: var(--text-xs); color: var(--fg-muted); line-height: 1.6; margin-top: 2px; }
.pdf-frame--tall { height: calc(100vh - 184px); min-height: 560px; }
@media (max-width: 1100px) {
  .review { grid-template-columns: 1fr; }
  .review-rail { position: static; }
  .pdf-frame--tall { height: 640px; }
}

/* ──────────────────────────────────────────────────────────────────
   14. Misc utilities + signal blocks (legacy parcel cards)
   ────────────────────────────────────────────────────────────────── */
.muted { color: var(--fg-muted); }
.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-lg { font-size: var(--text-lg); }
.mono { font-family: var(--font-mono); font-variant-ligatures: none; }
.nowrap { white-space: nowrap; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.w-full { width: 100%; }
.right { margin-left: auto; }

/* Legacy signal block (parcel JSONB renderer) — kept and re-skinned */
.signal-block {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
}
.signal-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  column-gap: var(--space-4);
  row-gap: 4px;
  font-size: var(--text-sm);
}
.signal-grid dt {
  color: var(--fg-muted);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  white-space: nowrap;
}
.signal-grid dd { color: var(--fg-default); }
.ul-clean { list-style: none; padding-left: 0; margin: 0; }
.ul-clean li { padding: 2px 0; }

/* Parcel disclosure cards — server-rendered <details> */
details.parcel-card {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  margin-bottom: var(--space-2);
  overflow: hidden;
}
details.parcel-card > summary {
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  font-size: var(--text-sm);
  user-select: none;
}
details.parcel-card > summary::-webkit-details-marker { display: none; }
details.parcel-card > summary::before {
  content: "▸";
  color: var(--fg-subtle);
  font-size: var(--text-xs);
}
details.parcel-card[open] > summary::before { content: "▾"; }
details.parcel-card[open] > summary {
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface-2);
}
details.parcel-card .parcel-body { padding: var(--space-3) var(--space-4) var(--space-4); }

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

/* Sub-tab strip (used inside pages) */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: var(--space-4);
  overflow-x: auto;
}
.tabs a, .tabs button {
  padding: 8px var(--space-3);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--fg-muted);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  font-family: inherit;
  transition: color var(--motion-fast), border-color var(--motion-fast);
}
.tabs a:hover, .tabs button:hover { color: var(--fg-default); text-decoration: none; }
.tabs a[aria-current="page"], .tabs button[aria-pressed="true"], .tabs a.active {
  color: var(--fg-default);
  border-bottom-color: var(--accent-600);
  font-weight: 600;
}

/* App footer — quiet attribution line under main content (Census ToS
   requires the ACS attribution on every ACS-surfacing page). */
.app-footer {
  font-size: var(--text-xs);
  color: var(--fg-subtle);
  padding: var(--space-3) var(--space-5);
  text-align: center;
}
