/* Self-hosted type: Prata (display) + Space Grotesk (body). No external requests. */
@font-face {
  font-family: 'Prata';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/static/fonts/prata-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Space Grotesk';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/static/fonts/spacegrotesk-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Space Grotesk';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/static/fonts/spacegrotesk-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Space Grotesk';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url(/static/fonts/spacegrotesk-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Space Grotesk';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url(/static/fonts/spacegrotesk-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/*
  CostBleed design system
  ------------------------------------------------------------------------
  Hand-written CSS. No framework, no build step, no external requests.
  Dark, premium, investigative. Crimson is an accent for risk and action —
  it is never a background flood. See docs/UI_UX_SPEC.md for the palette
  contract and AGENTS.md "UI rules" for the non-negotiables this file
  implements.

  Contents
    1. Design tokens (custom properties)
    2. Reset & base
    3. Type scale
    4. Layout shell (rail / topbar / main)
    5. Buttons
    6. Forms
    7. Cards & stat tiles
    8. Data tables
    9. Decision ledger
    10. Severity / state pills
    11. Finding card
    12. Evidence chips
    13. Tabs
    14. Review workspace (3-column)
    15. Document viewer
    16. Empty states, toasts, flash
    17. Auth / error pages
    18. Utilities
    19. Accessibility & motion
    20. Responsive breakpoints
*/

/* ==========================================================================
   1. Design tokens
   ========================================================================== */

:root {
  /* -- palette (docs/UI_UX_SPEC.md) -------------------------------------- */
  --obsidian: #09090b;
  --charcoal: #151519;
  --graphite: #25262c;
  --garnet: #74121c;
  --crimson: #a31528;
  --dark-ruby: #530b13;
  --bone-ivory: #f1ece5;
  --cold-stone: #bdb8b1;
  --amber: #c28a32;
  --muted-green: #768675;

  /*
    Accessibility adjustment: raw --crimson on --obsidian/--charcoal measures
    2.55:1 / 2.34:1, below the WCAG AA 4.5:1 text minimum. --crimson-tint is
    a lightened step toward --bone-ivory (mix ratio 0.40) used anywhere
    crimson appears as *text* or as a small graphical accent on a dark
    surface (severity/state colour, links, icon glyphs). It measures
    5.35:1 on obsidian and 4.90:1 on charcoal. Raw --crimson and --garnet
    remain reserved for solid fills / borders where the foreground on top
    of them is always --bone-ivory (6.63:1 / 9.68:1 — verified below).
  */
  --crimson-tint: #c26b74;

  /* -- surfaces ------------------------------------------------------------ */
  --surface-canvas: var(--obsidian);
  --surface-raised: var(--charcoal);
  --surface-overlay: var(--graphite);
  --surface-sunken: #060607;
  --border-subtle: #2c2d33;
  --border-strong: #3a3b42;

  /* -- text ------------------------------------------------------------- */
  --text-primary: var(--bone-ivory);
  --text-secondary: var(--cold-stone);
  --text-muted: #8b8781;
  --text-on-fill: var(--bone-ivory);
  --text-link: var(--crimson-tint);

  /* -- semantic accents (see SEVERITY_TOKENS / STATE_TOKENS in render.py) */
  --accent-info: var(--cold-stone);
  --accent-support: var(--muted-green);
  --accent-warning: var(--amber);
  --accent-risk: var(--crimson-tint);
  --accent-risk-fill: var(--dark-ruby);
  --accent-action: var(--crimson);

  /* -- spacing scale ------------------------------------------------------ */
  --space-1: 0.25rem;   /* 4px */
  --space-2: 0.5rem;    /* 8px */
  --space-3: 0.75rem;   /* 12px */
  --space-4: 1rem;      /* 16px */
  --space-5: 1.5rem;    /* 24px */
  --space-6: 2rem;      /* 32px */
  --space-7: 3rem;      /* 48px */
  --space-8: 4rem;      /* 64px */

  /* -- radius: deliberately restrained; sharp corners read more precise
     and less "startup-friendly" than heavy rounding (brand/tokens.css). -- */
  --radius-sm: 2px;
  --radius-md: 3px;
  --radius-lg: 4px;
  --radius-pill: 2px;

  /* -- elevation (dark theme: soft black shadow + faint top highlight) --- */
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 4px 16px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.02) inset;
  --shadow-3: 0 12px 32px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.03) inset;
  --shadow-focus: 0 0 0 3px rgba(194, 107, 116, 0.45);

  /* -- type ----------------------------------------------------------------- */
  --font-display: Didot, "Bodoni MT", Georgia, "Times New Roman", serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;

  --text-display: 2.75rem;
  --text-h1: 2rem;
  --text-h2: 1.5rem;
  --text-h3: 1.125rem;
  --text-body: 1rem;
  --text-small: 0.875rem;
  --text-micro: 0.75rem;

  --leading-tight: 1.2;
  --leading-normal: 1.5;
  --leading-relaxed: 1.7;

  --rail-width: 15.5rem;
  --topbar-height: 4rem;
  --content-max: 76rem;

  --transition-fast: 130ms cubic-bezier(0.2, 0, 0, 1);
  --transition-normal: 180ms cubic-bezier(0.2, 0, 0, 1);

  /* Display figures (the confident numbers): sans, tabular, tight. Dense
     table cells stay mono; anything 1.25rem and larger uses this. */
  --font-figures: var(--font-ui);
}

/* ==========================================================================
   2. Reset & base
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
  -webkit-text-size-adjust: 100%;
}

body,
h1, h2, h3, h4, h5, h6,
p, figure, blockquote, dl, dd {
  margin: 0;
}

ul[class], ol[class] {
  list-style: none;
  margin: 0;
  padding: 0;
}

img, picture, svg {
  max-width: 100%;
  display: block;
}

table {
  border-collapse: collapse;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

a {
  color: var(--text-link);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

a:hover {
  text-decoration-thickness: 2px;
}

body {
  background: var(--surface-canvas);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--text-body);
  line-height: var(--leading-normal);
  min-height: 100vh;
}

/* ==========================================================================
   3. Type scale
   ========================================================================== */

.display {
  font-family: var(--font-display);
  font-size: var(--text-display);
  line-height: var(--leading-tight);
  font-weight: 500;
  letter-spacing: -0.01em;
}

h1, .h1 {
  font-family: var(--font-display);
  font-size: var(--text-h1);
  line-height: var(--leading-tight);
  font-weight: 600;
}

h2, .h2 {
  font-family: var(--font-display);
  font-size: var(--text-h2);
  line-height: var(--leading-tight);
  font-weight: 600;
}

h3, .h3 {
  font-family: var(--font-ui);
  font-size: var(--text-h3);
  line-height: var(--leading-tight);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}

.eyebrow {
  font-family: var(--font-ui);
  font-size: var(--text-micro);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 600;
}

.lede {
  font-size: 1.0625rem;
  color: var(--text-secondary);
  line-height: var(--leading-relaxed);
}

.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }

.mono, .tabular {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   4. Layout shell
   ========================================================================== */

.skip-link {
  position: absolute;
  left: var(--space-3);
  top: -3rem;
  background: var(--bone-ivory);
  color: var(--obsidian);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-weight: 600;
  z-index: 1000;
  transition: top var(--transition-fast);
}

.skip-link:focus {
  top: var(--space-3);
}

.app-shell {
  display: grid;
  grid-template-columns: var(--rail-width) 1fr;
  min-height: 100vh;
}

/* No signed-in user (login, unauthenticated 401): the rail-width column
   collapses away entirely rather than leaving an empty gutter. */
.app-shell--bare {
  grid-template-columns: 1fr;
}

.content--bare {
  max-width: none;
  padding: 0;
}

.rail {
  background: var(--surface-raised);
  border-right: 1px solid var(--border-subtle);
  padding: var(--space-5) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.rail__brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-2);
}

.rail__brand-glyph {
  flex: none;
  color: var(--text-secondary);
}

.rail__brand-mark {
  font-family: var(--font-display);
  font-size: 1.375rem;
  font-weight: 600;
  color: var(--text-primary);
}

.rail__brand-mark .rail__brand-accent {
  color: var(--accent-risk);
}

.rail__nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.rail__link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: var(--text-small);
  font-weight: 500;
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.rail__link:hover {
  background: var(--surface-overlay);
  color: var(--text-primary);
  text-decoration: none;
}

.rail__link[aria-current="page"] {
  background: var(--surface-overlay);
  color: var(--text-primary);
  border-left-color: var(--accent-action);
  font-weight: 600;
}

.rail__link-glyph {
  font-size: 0.9em;
  width: 1.25em;
  text-align: center;
  color: var(--text-muted);
}

.rail__link[aria-current="page"] .rail__link-glyph {
  color: var(--accent-risk);
}

.rail__footer {
  margin-top: auto;
  padding: var(--space-3) var(--space-2) 0;
  border-top: 1px solid var(--border-subtle);
  font-size: var(--text-micro);
  color: var(--text-muted);
}

.main-column {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: 0 var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
  background: color-mix(in srgb, var(--surface-canvas) 92%, transparent);
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar__context {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  font-size: var(--text-small);
}

.topbar__tenant {
  font-family: var(--font-mono);
  font-size: var(--text-micro);
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-primary);
  white-space: nowrap;
}

.topbar__divider {
  color: var(--border-strong);
}

.topbar__project {
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-shrink: 0;
}

.topbar__user {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-small);
}

.topbar__user-avatar {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  background: var(--surface-overlay);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-micro);
  color: var(--text-primary);
}

.topbar__user-role {
  color: var(--text-muted);
}

.content {
  flex: 1;
  padding: var(--space-6);
  max-width: var(--content-max);
  width: 100%;
}

.content--wide {
  max-width: none;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-5);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
}

.page-header__title-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.page-header__actions {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
}

/* ==========================================================================
   5. Buttons
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-small);
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  line-height: 1;
  transition: background var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast);
}

.btn:active {
  transform: translateY(1px);
}

.btn--primary {
  background: var(--crimson);
  border-color: var(--crimson);
  color: var(--text-on-fill);
}

.btn--primary:hover {
  background: var(--garnet);
  border-color: var(--garnet);
  text-decoration: none;
}

.btn--ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.btn--ghost:hover {
  background: var(--surface-overlay);
  text-decoration: none;
}

.btn--danger {
  background: transparent;
  border-color: var(--crimson-tint);
  color: var(--crimson-tint);
}

.btn--danger:hover {
  background: var(--dark-ruby);
  color: var(--bone-ivory);
  border-color: var(--dark-ruby);
  text-decoration: none;
}

.btn--small {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-micro);
}

.btn--block {
  width: 100%;
}

.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ==========================================================================
   6. Forms
   ========================================================================== */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.field__label {
  font-size: var(--text-small);
  font-weight: 600;
  color: var(--text-secondary);
}

.field__hint {
  font-size: var(--text-micro);
  color: var(--text-muted);
}

.field__error {
  font-size: var(--text-micro);
  color: var(--crimson-tint);
}

.input,
.textarea,
.select {
  background: var(--surface-sunken);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  color: var(--text-primary);
  font-size: var(--text-body);
  width: 100%;
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-muted);
}

.textarea {
  min-height: 6rem;
  resize: vertical;
}

.input:focus,
.textarea:focus,
.select:focus {
  outline: none;
  border-color: var(--crimson-tint);
  box-shadow: var(--shadow-focus);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-small);
}

.filter-bar {
  margin-bottom: var(--space-5);
  align-items: flex-end;
}

.filter-bar .field {
  margin-bottom: 0;
  min-width: 12rem;
}

.form-actions {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  flex-wrap: wrap;
}

/* honeypot fields used by public forms — visually and semantically hidden */
.hp-field {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* ==========================================================================
   7. Cards & stat tiles
   ========================================================================== */

.card {
  background: var(--surface-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-1);
}

.card--flush {
  padding: 0;
  overflow: hidden;
}

.card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: var(--space-4);
}

/* One instrument, not six floating widgets: the portfolio totals sit in a
   single ruled strip, cells divided by hairlines, each with a short tone
   tick and a confident figure. */
.stat-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr));
  gap: 1px;
  background: var(--border-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-1);
}

.stat-cell {
  background: var(--surface-raised);
  padding: var(--space-4) var(--space-5) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
}

.stat-cell::before {
  content: "";
  width: 1.75rem;
  height: 2px;
  background: var(--border-strong);
  margin-bottom: var(--space-1);
}

.stat-cell[data-tone="risk"]::before { background: var(--accent-risk); }
.stat-cell[data-tone="warning"]::before { background: var(--accent-warning); }
.stat-cell[data-tone="support"]::before { background: var(--accent-support); }

.stat-cell__label {
  font-size: var(--text-micro);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  font-weight: 600;
  min-height: 2.9em; /* room for two label lines: keeps every figure on one baseline */
}

.stat-cell__value {
  font-family: var(--font-figures);
  font-variant-numeric: tabular-nums lining-nums;
  font-size: 1.5rem;
  font-weight: 620;
  letter-spacing: -0.015em;
  color: var(--text-primary);
  line-height: 1.15;
  white-space: nowrap;
}

.stat-cell[data-tone="risk"] .stat-cell__value {
  color: var(--crimson-tint);
}

.stat-cell__currency {
  font-family: var(--font-mono);
  font-size: var(--text-micro);
  font-weight: 400;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-right: var(--space-1);
}

.stat-cell__footnote {
  font-size: var(--text-micro);
  color: var(--text-muted);
}

/* ==========================================================================
   8. Data tables
   ========================================================================== */

.table-scroll {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-small);
  background: var(--surface-raised);
}

.data-table caption {
  text-align: left;
  padding: var(--space-4) var(--space-4) var(--space-2);
  font-family: var(--font-display);
  font-size: var(--text-h3);
  font-weight: 600;
  color: var(--text-primary);
  caption-side: top;
}

.data-table thead th {
  text-align: left;
  font-size: var(--text-micro);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  font-weight: 600;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}

.data-table tbody td,
.data-table tbody th {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  vertical-align: middle;
  text-align: left;
}

.data-table tbody th {
  font-weight: 600;
}

.data-table tbody tr:last-child td,
.data-table tbody tr:last-child th {
  border-bottom: none;
}

.data-table tbody tr {
  transition: background var(--transition-fast);
}

.data-table tbody tr:hover {
  background: var(--surface-overlay);
}

.data-table td.num,
.data-table th.num {
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.data-table .row-link {
  color: inherit;
  text-decoration: none;
  display: block;
}

.data-table .row-link:hover {
  text-decoration: underline;
}

/* ==========================================================================
   9. Decision ledger
   ========================================================================== */

/* The decision ledger reads as one horizontal instrument band on desktop:
   five cells left to right, ending on the recommended hold — the figure the
   client is actually deciding on, and the most confident object on the
   screen. Below 900px it folds back into stacked ledger rows. */
.ledger {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) minmax(0, 1.35fr);
  gap: 1px;
  background: var(--border-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-2);
}

.ledger__row {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  background: var(--surface-raised);
  min-width: 0;
}

.ledger__row[data-bucket="potential_bleed"] {
  background: color-mix(in srgb, var(--dark-ruby) 20%, var(--surface-raised));
}

.ledger__label {
  font-size: var(--text-micro);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  font-weight: 600;
}

.ledger__amount {
  font-family: var(--font-figures);
  font-variant-numeric: tabular-nums lining-nums;
  font-size: 1.375rem;
  font-weight: 620;
  letter-spacing: -0.015em;
  color: var(--text-primary);
  display: inline-flex;
  align-items: baseline;
  gap: var(--space-1);
  white-space: nowrap;
}

.ledger__row[data-bucket="potential_bleed"] .ledger__amount,
.ledger__row[data-bucket="recommended_hold"] .ledger__amount {
  color: var(--crimson-tint);
}

/* The hold cell: a crimson rule across its head — the ledger line of the
   brand mark — and the largest figure on the band. */
.ledger__row[data-bucket="recommended_hold"] {
  position: relative;
  background: color-mix(in srgb, var(--dark-ruby) 34%, var(--surface-raised));
  padding-top: var(--space-4);
}

.ledger__row[data-bucket="recommended_hold"]::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--crimson);
}

.ledger__row[data-bucket="recommended_hold"] .ledger__label {
  color: var(--text-primary);
  font-weight: 700;
}

.ledger__row[data-bucket="recommended_hold"] .ledger__amount {
  font-size: 1.875rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.ledger__currency {
  font-family: var(--font-mono);
  font-size: var(--text-micro);
  font-weight: 400;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

@media (max-width: 900px) {
  .ledger {
    grid-template-columns: 1fr;
  }

  .ledger__row {
    flex-direction: row;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-3) var(--space-5);
  }

  .ledger__row[data-bucket="recommended_hold"]::before {
    height: 1px;
  }
}

.ledger__footer {
  grid-column: 1 / -1;
  display: flex;
  padding: var(--space-2) var(--space-5);
  background: var(--surface-sunken);
  font-size: var(--text-micro);
  color: var(--text-muted);
}

.ledger__footer span {
  font-variant-numeric: tabular-nums;
}

.ledger__footer span + span {
  margin-left: var(--space-5);
  padding-left: var(--space-5);
  border-left: 1px solid var(--border-subtle);
}

/* ==========================================================================
   10. Severity / state pills
   ========================================================================== */

/* "Engraved" pills: a bevelled medallion rather than a flat SaaS badge --
   a soft top highlight, a recessed inner shadow and a hairline border tinted
   toward the accent, with the text set in small caps-style tracking. Colour
   is decoration only: the aria-hidden glyph and the label text underneath
   both still carry the meaning on their own. */
.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.14rem var(--space-2);
  border-radius: var(--radius-pill);
  font-size: var(--text-micro);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  line-height: 1.4;
  border: 1px solid color-mix(in srgb, var(--pill-accent, var(--border-strong)) 45%, var(--border-strong));
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--pill-accent, var(--border-strong)) 16%, var(--surface-overlay)),
    var(--surface-overlay)
  );
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    inset 0 -1px 1.5px rgba(0, 0, 0, 0.4);
  color: var(--text-primary);
  white-space: nowrap;
}

.pill__glyph {
  color: var(--pill-accent, var(--text-muted));
  font-size: 0.85em;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.5));
}

.pill--severity-info { --pill-accent: var(--accent-info); border-color: var(--accent-info); }
.pill--severity-low { --pill-accent: var(--accent-support); border-color: var(--accent-support); }
.pill--severity-medium { --pill-accent: var(--accent-warning); border-color: var(--accent-warning); }
.pill--severity-high { --pill-accent: var(--accent-risk); border-color: var(--accent-risk); }
.pill--severity-critical {
  --pill-accent: var(--accent-risk);
  border-color: var(--accent-risk);
  background: color-mix(in srgb, var(--accent-risk-fill) 55%, var(--surface-overlay));
}

.pill--state-draft,
.pill--state-machine_checked,
.pill--state-closed_no_action { --pill-accent: var(--accent-info); border-color: var(--accent-info); }
.pill--state-awaiting_human_review,
.pill--state-clarification_requested,
.pill--state-resolved_adjusted { --pill-accent: var(--accent-warning); border-color: var(--accent-warning); }
.pill--state-validated,
.pill--state-resolved_supported { --pill-accent: var(--accent-support); border-color: var(--accent-support); }
.pill--state-rejected { --pill-accent: var(--accent-risk); border-color: var(--accent-risk); }

/* ==========================================================================
   11. Finding card
   ========================================================================== */

.finding-card {
  background: var(--surface-raised);
  border: 1px solid var(--border-subtle);
  border-left: 3px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  box-shadow: var(--shadow-1);
}

.finding-card[data-severity="high"],
.finding-card[data-severity="critical"] {
  border-left-color: var(--accent-risk);
}

.finding-card[data-severity="medium"] {
  border-left-color: var(--accent-warning);
}

.finding-card__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.finding-card__taxonomy {
  font-size: var(--text-micro);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 700;
}

.finding-card__title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-primary);
  margin-top: var(--space-1);
}

.finding-card__pills {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  align-items: center;
}

.finding-card__amount {
  text-align: right;
  flex-shrink: 0;
}

.finding-card__amount-label {
  font-size: var(--text-micro);
  color: var(--text-muted);
  display: block;
}

.finding-card__amount-value {
  font-family: var(--font-figures);
  font-variant-numeric: tabular-nums lining-nums;
  font-size: 1.5rem;
  font-weight: 620;
  letter-spacing: -0.015em;
  color: var(--text-primary);
  white-space: nowrap;
}

/* Read as a considered reviewer's note, not a bug-ticket description: serif
   body copy at a slightly larger size, set in the primary ink rather than
   the muted secondary tone. */
.finding-card__rationale {
  font-family: var(--font-display);
  font-size: 1.0625rem;
  color: var(--text-primary);
  line-height: var(--leading-relaxed);
}

/* Generic label/value grid -- reused by finding cards, the baseline tab and
   anywhere else a fixed set of short facts needs a scannable layout. */
.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: var(--space-4);
}

.finding-card__meta-grid {
  padding: var(--space-4) 0;
  border-top: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
}

.meta-item dt {
  font-size: var(--text-micro);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: var(--space-1);
}

.meta-item dd {
  font-size: var(--text-small);
  color: var(--text-primary);
  margin: 0;
}

.finding-card__section-title {
  font-size: var(--text-micro);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: var(--space-2);
}

.finding-card__sources {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.finding-card__calc-link {
  font-size: var(--text-small);
}

/* Calculation proof: a small ledger-within-the-ledger so a reviewer can walk
   the arithmetic by eye -- expression in mono on the left, the resulting
   figure right-aligned in tabular numerals, the final row (the answer)
   picked out with a ruled top and a filled ground. */
.calc-proof {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface-sunken);
}

.calc-proof__row {
  display: grid;
  grid-template-columns: minmax(6rem, 0.85fr) minmax(0, 1.6fr) auto;
  align-items: baseline;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
}

.calc-proof__row:last-child {
  border-bottom: none;
  border-top: 1px solid var(--border-strong);
  background: var(--surface-overlay);
}

.calc-proof__label {
  font-size: var(--text-micro);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.calc-proof__expression {
  font-size: var(--text-small);
  color: var(--text-secondary);
  overflow-wrap: anywhere;
}

.calc-proof__row:last-child .calc-proof__expression {
  color: var(--text-primary);
  font-weight: 600;
}

.calc-proof__value {
  text-align: right;
  font-size: var(--text-small);
  font-weight: 600;
  color: var(--text-primary);
  border-left: 1px solid var(--border-subtle);
  padding-left: var(--space-3);
}

.calc-proof__row:last-child .calc-proof__value {
  font-size: 1rem;
  border-left-color: var(--border-strong);
}

.finding-card__reviewer {
  font-size: var(--text-small);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.finding-card__limitations {
  font-size: var(--text-micro);
  color: var(--text-muted);
  border-left: 2px solid var(--border-strong);
  padding-left: var(--space-3);
}

.finding-card__review-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border-subtle);
}

.finding-card__review-actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* ==========================================================================
   12. Evidence chips
   ========================================================================== */

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--surface-sunken);
  color: var(--text-primary);
  font-size: var(--text-micro);
  text-decoration: none;
  max-width: 100%;
}

.chip:hover {
  border-color: var(--crimson-tint);
  text-decoration: none;
}

.chip__glyph {
  color: var(--text-muted);
  flex-shrink: 0;
}

.chip__label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip__page {
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ==========================================================================
   13. Tabs
   ========================================================================== */

.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: var(--space-5);
  overflow-x: auto;
}

.tabs__link {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-small);
  font-weight: 600;
  color: var(--text-secondary);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

.tabs__link:hover {
  color: var(--text-primary);
  text-decoration: none;
}

.tabs__link[aria-current="page"] {
  color: var(--text-primary);
  border-bottom-color: var(--accent-action);
}

/* ==========================================================================
   14. Review workspace (3 column)
   ========================================================================== */

.review-grid {
  display: grid;
  grid-template-columns: 18rem minmax(0, 1.6fr) minmax(0, 1.4fr);
  gap: var(--space-4);
  align-items: start;
}

.review-column {
  background: var(--surface-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  min-height: 24rem;
  max-height: calc(100vh - var(--topbar-height) - var(--space-8));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.review-column__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  background: var(--surface-raised);
  z-index: 1;
}

.review-column__count {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--text-micro);
  color: var(--text-muted);
}

.review-column__body {
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  overflow-wrap: anywhere;
}

.review-column__body--flush {
  padding: 0;
}

.package-nav__group-label {
  font-size: var(--text-micro);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: var(--space-2) var(--space-2) var(--space-1);
}

/* Claim lines thread down the column like a ledger spine: a hairline runs
   behind small node squares; the active line's node fills crimson. */
.package-nav__item {
  display: block;
  position: relative;
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-6);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--text-primary);
  border: 1px solid transparent;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.package-nav__item::before {
  content: "";
  position: absolute;
  left: calc(var(--space-3) + 2px);
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--border-subtle);
}

.package-nav__item:first-of-type::before {
  top: 1.1rem;
}

.package-nav__item:last-of-type::before {
  bottom: auto;
  height: 1.1rem;
}

.package-nav__item::after {
  content: "";
  position: absolute;
  left: var(--space-3);
  top: 0.95rem;
  width: 5px;
  height: 5px;
  background: var(--surface-raised);
  border: 1px solid var(--text-muted);
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.package-nav__item:hover {
  background: var(--surface-overlay);
  text-decoration: none;
}

.package-nav__item[aria-current="true"] {
  background: var(--surface-overlay);
  border-color: var(--border-strong);
}

.package-nav__item[aria-current="true"]::after {
  background: var(--crimson);
  border-color: var(--crimson);
}

.package-nav__item[aria-current="true"] .package-nav__item-title {
  color: var(--crimson-tint);
}

.package-nav__item-title {
  font-size: var(--text-small);
  font-weight: 600;
  transition: color var(--transition-fast);
}

.package-nav__item-description {
  margin: 0;
  color: var(--text-muted);
  font-size: var(--text-micro);
}

.package-nav__item-meta {
  font-size: var(--text-micro);
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  margin-top: var(--space-1);
}

.review-workspace-findings {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-4);
}

/* ==========================================================================
   15. Document viewer
   ========================================================================== */

.document-viewer {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-4);
}

.document-viewer__meta {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  font-size: var(--text-micro);
  color: var(--text-muted);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
}

.document-viewer__meta strong {
  color: var(--text-primary);
  font-weight: 600;
}

.document-viewer__quote {
  background: color-mix(in srgb, var(--dark-ruby) 30%, var(--surface-sunken));
  border-left: 3px solid var(--accent-risk);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}

.document-viewer__quote-label {
  font-size: var(--text-micro);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

.document-viewer__quote-text {
  font-family: var(--font-display);
  font-size: 1.0625rem;
  line-height: var(--leading-relaxed);
  color: var(--text-primary);
}

/* "Paper under glass": the extracted page sits on a faintly warmer, recessed
   surface, framed like a slide under a glass plate, with small registration
   ticks at the corners echoing a QS drawing set. Serif type reads like a
   printed page rather than app chrome. */
.document-viewer__page-text {
  position: relative;
  font-family: var(--font-display);
  font-size: 0.975rem;
  line-height: var(--leading-relaxed);
  color: var(--text-secondary);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--bone-ivory) 5%, transparent), transparent 6rem),
    var(--surface-sunken);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    inset 0 0 2.5rem rgba(0, 0, 0, 0.4);
}

.document-viewer__page-text::before,
.document-viewer__page-text::after {
  content: "";
  position: absolute;
  width: 0.5rem;
  height: 0.5rem;
  border-color: var(--text-muted);
  opacity: 0.55;
  pointer-events: none;
}

.document-viewer__page-text::before {
  top: var(--space-2);
  left: var(--space-2);
  border-top: 1px solid var(--text-muted);
  border-left: 1px solid var(--text-muted);
}

.document-viewer__page-text::after {
  bottom: var(--space-2);
  right: var(--space-2);
  border-bottom: 1px solid var(--text-muted);
  border-right: 1px solid var(--text-muted);
}

/* The cited span reads as a reviewer's pencil mark, not a highlighter --
   a crimson underline plus a weight shift, never colour alone (the <mark>
   element and surrounding prose already carry the semantic meaning). */
mark.cited-span {
  background: transparent;
  color: var(--text-primary);
  font-weight: 600;
  padding: 0;
  border-radius: 0;
  border-bottom: 2px solid var(--accent-risk);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.document-viewer__reason {
  font-size: var(--text-micro);
  color: var(--text-muted);
}

/* ==========================================================================
   16. Empty states, toasts, flash
   ========================================================================== */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-6) var(--space-5);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, color-mix(in srgb, var(--surface-overlay) 35%, transparent), transparent);
  color: var(--text-secondary);
}

.empty-state__glyph {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  font-size: 1.125rem;
  color: var(--text-muted);
}

.empty-state__title {
  font-family: var(--font-display);
  font-size: var(--text-h3);
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-primary);
  font-weight: 600;
}

.empty-state__description {
  font-size: var(--text-small);
  color: var(--text-muted);
  max-width: 34rem;
}

.toast-region {
  position: fixed;
  bottom: var(--space-5);
  right: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: 100;
  width: min(24rem, calc(100vw - 2 * var(--space-5)));
}

.flash-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}

.flash {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--surface-overlay);
  font-size: var(--text-small);
  box-shadow: var(--shadow-2);
}

.flash__message {
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
}

.flash--success { border-color: var(--accent-support); }
.flash--warning { border-color: var(--accent-warning); }
.flash--error { border-color: var(--accent-risk); }
.flash--info { border-color: var(--accent-info); }

.flash__close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: var(--text-small);
  line-height: 1;
  padding: var(--space-1);
}

.flash__close:hover {
  color: var(--text-primary);
}

/* ==========================================================================
   17. Auth / error pages
   ========================================================================== */

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  background:
    radial-gradient(circle at 24% 12%, color-mix(in srgb, var(--dark-ruby) 20%, transparent), transparent 46%),
    repeating-linear-gradient(to bottom, transparent 0 43px, rgba(241, 236, 229, 0.035) 43px 44px),
    var(--surface-canvas);
}

.auth-card {
  position: relative;
  width: 100%;
  max-width: 26rem;
  background: var(--surface-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-7) var(--space-6) var(--space-6);
  box-shadow: var(--shadow-3);
}

.auth-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background: var(--crimson);
}

.auth-card__mark {
  display: block;
  margin-bottom: var(--space-4);
  color: var(--text-secondary);
}

.auth-card__brand {
  font-family: var(--font-display);
  font-size: 1.625rem;
  letter-spacing: 0.01em;
  margin-bottom: var(--space-2);
}

.auth-card__brand .rail__brand-accent { color: var(--accent-risk); }

.auth-card__tagline {
  color: var(--text-muted);
  font-size: var(--text-small);
  margin-bottom: var(--space-6);
}

.auth-card__footnote {
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border-subtle);
  font-size: var(--text-micro);
  color: var(--text-muted);
}

.auth-card__flash {
  margin-bottom: var(--space-5);
}

.error-shell {
  min-height: 60vh;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: var(--space-3);
  max-width: 34rem;
}

.error-shell__code {
  font-family: var(--font-mono);
  color: var(--text-muted);
  font-size: var(--text-small);
  letter-spacing: 0.05em;
}

/* ==========================================================================
   18. Utilities
   ========================================================================== */

.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;
}

.stack { display: flex; flex-direction: column; }
.stack > * + * { margin-top: var(--space-4); }
.stack--tight > * + * { margin-top: var(--space-2); }
.stack--loose > * + * { margin-top: var(--space-6); }

.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

.cluster--between {
  justify-content: space-between;
}

.card > .cluster {
  margin-bottom: var(--space-2);
}

.card > h2,
.card > h3 {
  margin-bottom: var(--space-3);
}

.card > h2:last-child,
.card > h3:last-child {
  margin-bottom: 0;
}

.section {
  margin-bottom: var(--space-7);
}

.section__title {
  margin-bottom: var(--space-3);
}

.divider {
  border: none;
  border-top: 1px solid var(--border-subtle);
  margin: var(--space-5) 0;
}

/* ==========================================================================
   19. Accessibility & motion
   ========================================================================== */

:focus-visible {
  outline: 2px solid var(--crimson-tint);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.btn:focus-visible,
.pill:focus-visible {
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ==========================================================================
   20. Responsive breakpoints
   ========================================================================== */

@media (max-width: 1100px) {
  .review-grid {
    grid-template-columns: 1fr;
  }

  .review-column {
    max-height: none;
  }
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .rail {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    padding: var(--space-3) var(--space-4);
  }

  .rail__nav {
    flex-direction: row;
  }

  .rail__link {
    border-left: none;
    border-bottom: 3px solid transparent;
  }

  .rail__link[aria-current="page"] {
    border-left-color: transparent;
    border-bottom-color: var(--accent-action);
  }

  .rail__footer {
    display: none;
  }

  .topbar {
    padding: 0 var(--space-4);
  }

  .content {
    padding: var(--space-4);
  }
}

@media (max-width: 640px) {
  .card-grid {
    grid-template-columns: 1fr;
  }

  .finding-card__amount {
    text-align: left;
  }

  .page-header {
    flex-direction: column;
    align-items: stretch;
  }
}


/* Brand mark, inline beside the wordmark. Inherits ink colour so it
   works on either surface; only the crimson thread is fixed. */
.brand-mark {
  display: inline-block;
  vertical-align: -0.22em;
  margin-right: 0.45rem;
  flex: none;
}


/* Attribution in the rail footer: present, never competing with the tenant. */
.rail__by {
  margin: 0.3rem 0 0;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  color: var(--text-muted, #8b8780);
}
.rail__by strong { color: var(--text-secondary, #bdb8b1); font-weight: 600; }

/* ==========================================================================
   Set-up flow — the path from an empty project to a reviewed package.
   Forms here are where a surveyor types contractual figures, so the fields
   read like a document being filled in rather than a web form: generous
   labels, hairline rules, numbers in tabular figures.
   ========================================================================== */

.form-card,
.setup-step {
  background: var(--surface-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.form-card {
  padding: var(--space-6);
  max-width: 56rem;
}

.form-row { margin-bottom: var(--space-5); }

.form-row > label {
  display: block;
  margin-bottom: var(--space-2);
  font-family: var(--font-ui);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text-primary);
}

.form-optional {
  margin-left: 0.4rem;
  font-weight: 400;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.form-row input[type="text"],
.form-row input[type="file"],
.form-row select,
.form-row textarea {
  width: 100%;
  padding: 0.62rem 0.75rem;
  background: var(--surface-sunken);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 0.95rem;
}

/* Amounts and percentages line up when they are compared, so they are typed
   in the same figures they are read in. */
.form-row input[inputmode="decimal"] {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
  max-width: 16rem;
}

.form-row textarea {
  font-family: var(--font-mono);
  font-size: 0.86rem;
  line-height: var(--leading-normal);
  resize: vertical;
}

.form-row input:focus-visible,
.form-row select:focus-visible,
.form-row textarea:focus-visible {
  outline: none;
  border-color: var(--crimson-tint);
  box-shadow: var(--shadow-focus);
}

.form-row input[aria-invalid="true"] { border-color: var(--danger, var(--crimson)); }

.form-row--check > label {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 500;
}
.form-row--check input { width: auto; }

.form-hint {
  margin: var(--space-2) 0 0;
  font-size: 0.84rem;
  line-height: var(--leading-normal);
  color: var(--text-muted);
  max-width: 46rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: var(--space-5);
}

.form-actions {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  margin-top: var(--space-6);
  padding-top: var(--space-5);
  border-top: 1px solid var(--border-subtle);
}

.form-error,
.form-note {
  max-width: 56rem;
  margin: 0 0 var(--space-5);
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-sm);
  border-left: 3px solid;
  font-size: 0.92rem;
  line-height: var(--leading-normal);
}
.form-error {
  background: var(--accent-risk-fill);
  border-left-color: var(--crimson);
  color: var(--text-primary);
}
.form-note {
  background: var(--surface-sunken);
  border-left-color: var(--muted-green);
  color: var(--text-secondary);
}

/* -- the four steps ------------------------------------------------------- */

.setup-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  max-width: 62rem;
  position: relative;
}

/* The crimson thread runs through the four step nodes, surfacing in the
   gaps between panels — the same seam that traces a claim to a decision. */
.setup-steps::before {
  content: "";
  position: absolute;
  left: calc(var(--space-5) + 1.2rem);
  top: 1.5rem;
  bottom: 2.5rem;
  width: 1px;
  background: linear-gradient(180deg, var(--crimson), rgba(163, 21, 40, 0.12));
}

.setup-step {
  overflow: hidden;
  position: relative;
  z-index: 1;
  transition: border-color var(--transition-normal), box-shadow var(--transition-normal);
}

.setup-step.is-open {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-2);
}

.setup-step__head {
  display: grid;
  grid-template-columns: 2.4rem 1fr auto;
  gap: var(--space-4);
  align-items: start;
  padding: var(--space-5);
}

.setup-step__number {
  width: 2.4rem;
  height: 2.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  background: var(--surface-raised);
  font-family: var(--font-display);
  font-size: 1.05rem;
  line-height: 1;
  color: var(--text-secondary);
}

.setup-step.is-open .setup-step__number {
  border-color: var(--crimson);
  color: var(--text-primary);
}

.setup-step.is-done .setup-step__number {
  border-color: color-mix(in srgb, var(--muted-green) 55%, transparent);
  color: var(--muted-green);
}

.setup-step__title h2 {
  margin: 0 0 var(--space-2);
  font-family: var(--font-display);
  font-size: 1.24rem;
  color: var(--text-primary);
}

.setup-step__hint,
.setup-step__lede {
  margin: 0;
  font-size: 0.9rem;
  line-height: var(--leading-relaxed);
  color: var(--text-secondary);
  max-width: 44rem;
}
.setup-step__lede { margin-bottom: var(--space-5); }

.setup-step__state {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-2);
  text-align: right;
}

.setup-step__detail {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* State is text plus a glyph, never colour alone. */
.pill--done,
.pill--todo {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.18rem 0.55rem;
  border-radius: var(--radius-pill);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 1px solid;
}
.pill--done {
  color: var(--muted-green);
  border-color: color-mix(in oklab, var(--muted-green) 45%, transparent);
  background: color-mix(in oklab, var(--muted-green) 12%, transparent);
}
.pill--todo {
  color: var(--text-muted);
  border-color: var(--border-strong);
  background: var(--surface-sunken);
}

/* Only the open step shows its form; the others stay a one-line summary. */
.setup-step__body { display: none; }
.setup-step.is-open .setup-step__body {
  display: block;
  padding: 0 var(--space-5) var(--space-6);
  border-top: 1px solid var(--border-subtle);
  padding-top: var(--space-5);
}

.analyse-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--border-subtle);
}
.analyse-row:last-of-type { border-bottom: 0; }
.analyse-row__meta {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.83rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.page-head {
  margin-bottom: var(--space-6);
}

.page-head__eyebrow {
  margin: 0 0 var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--text-micro);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-muted);
}

.page-head h1 {
  margin: 0;
}

.page-head__lede {
  margin: var(--space-3) 0 0;
  font-size: 1rem;
  line-height: var(--leading-relaxed);
  color: var(--text-secondary);
  max-width: 46rem;
}

@media (max-width: 720px) {
  .setup-step__head { grid-template-columns: 2rem 1fr; }
  .setup-step__state { grid-column: 2; align-items: flex-start; text-align: left; }
  .analyse-row { flex-direction: column; align-items: flex-start; }
}


/* The seal in the application rail. */

/* The mark: neutral lines follow the rail text colour; the bleed line is
   crimson in the SVG itself and always a step bolder. */
.rail__brand-glyph { vertical-align: -0.2em; }
