/* ==========================================================================
   Referral Ready — Design Tokens
   A restrained, professional healthcare-SaaS system: neutral surfaces, one
   confident primary color, calm status colors, and a consistent type/space/
   radius/elevation scale. Governing principle (Finding #23 §2a): simple
   workflow + sophisticated presentation — never simple workflow + a
   simplistic-looking interface. No decorative or novelty elements.
   ========================================================================== */
:root {
  /* Surfaces — light lavender environment (Visual Elevation 3/3) */
  --color-bg: #f5f3fb;
  --color-bg-subtle: #ece8f7;
  --color-surface: #ffffff;
  --color-surface-alt: #fafafd;

  /* Borders */
  --color-border: #e4e0f1;
  --color-border-strong: #cfc8e6;

  /* Text */
  --color-text: #1c1536;
  --color-text-muted: #5d5878;
  --color-text-faint: #8d87a6;

  /* Primary (brand) — indigo */
  --color-primary: #4f46e5;
  --color-primary-dark: #3f37c9;
  --color-primary-light: #ece9fd;
  --color-primary-border: #cac2f5;

  /* Navy — top bar / headline ink */
  --color-navy: #190f3d;
  --color-navy-ink: #150c33;

  /* Teal — "ready" accent */
  --color-teal: #0f9e8e;
  --color-teal-dark: #0b7b6f;

  /* Status: amber (not ready / caution) */
  --color-amber-bg: #fdf3dd;
  --color-amber-border: #ecc471;
  --color-amber-text: #8a5a05;

  /* Status: green/teal (ready / satisfied) */
  --color-green-bg: #e1f8f1;
  --color-green-border: #7fd9bf;
  --color-green-text: #0d6e5d;

  /* Status: coral (staff attention / unresolved association / ambiguity —
     more significant than ordinary incompleteness, but not a critical
     conflict; distinct from both amber and red) */
  --color-coral-bg: #fdeee5;
  --color-coral-border: #e8a877;
  --color-coral-text: #9a4a1a;

  /* Status: red (genuine alert — wrong patient / identity conflict / blocked
     critical mismatch only; never ordinary incompleteness) */
  --color-red-bg: #fbeceb;
  --color-red-border: #e9b3af;
  --color-red-text: #a3312b;

  /* Radius scale */
  --radius-sm: 7px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --radius-full: 999px;

  /* Spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 40px;

  /* Elevation */
  --shadow-xs: 0 1px 2px rgba(25, 15, 61, 0.05);
  --shadow-sm: 0 1px 2px rgba(25, 15, 61, 0.04), 0 2px 10px rgba(25, 15, 61, 0.06);
  --shadow-md: 0 8px 24px rgba(25, 15, 61, 0.1);
  --shadow-modal: 0 20px 60px rgba(15, 9, 35, 0.32);

  /* Type scale */
  --text-xs: 12px;
  --text-sm: 13px;
  --text-base: 14.5px;
  --text-md: 15.5px;
  --text-lg: 19px;
  --text-xl: 28px;
  --text-2xl: 30px;

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;

  --transition-fast: 0.14s ease;
}

* { box-sizing: border-box; }

/* Form controls don't inherit font-family from the page by default in any
   browser (a long-standing UA-stylesheet quirk) — without this, any button/
   input/select/textarea lacking its own explicit `font: inherit` silently
   renders in the OS default (e.g. Arial) instead of Inter. This is the
   single global fix so every control inherits Inter, rather than hunting
   down each individual class. */
button, input, select, textarea, optgroup {
  font-family: inherit;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, p { margin: 0; }

a { color: var(--color-primary); }

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ==========================================================================
   App shell — header / brand / navigation
   ========================================================================== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: 13px 28px;
  background: var(--color-navy);
  border-bottom: 1px solid var(--color-navy);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  background: none;
  border: none;
  padding: 4px;
  margin: -4px;
  font: inherit;
  text-align: left;
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: background var(--transition-fast);
}
.brand:hover { background: rgba(255, 255, 255, 0.08); }
.brand:hover .brand-name { color: #fff; }

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: transparent;
  border: 3px solid var(--color-teal);
  border-right-color: rgba(15, 158, 142, 0.25);
  color: #fff;
  font-weight: 700;
  font-size: 12.5px;
  letter-spacing: 0.4px;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.28; }
.brand-name { font-weight: 650; font-size: 14.5px; color: #fff; transition: color var(--transition-fast); }
.brand-sub { font-size: 11.5px; color: rgba(255, 255, 255, 0.55); }

.app-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-btn {
  background: none;
  border: 1px solid transparent;
  color: rgba(255, 255, 255, 0.72);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  padding: 8px 15px;
  border-radius: var(--radius-full);
  transition: background var(--transition-fast), color var(--transition-fast);
  white-space: nowrap;
}
.nav-btn:hover { color: #fff; background: rgba(255, 255, 255, 0.08); }
.nav-btn.is-active {
  color: var(--color-navy-ink);
  background: #ffffff;
}
.nav-btn.is-active:hover { color: var(--color-navy-ink); background: #ffffff; }
.nav-btn--ghost {
  color: rgba(255, 255, 255, 0.45);
  font-weight: 500;
}
.nav-btn--ghost:hover { color: rgba(255, 255, 255, 0.78); background: rgba(255, 255, 255, 0.08); }

.nav-divider {
  width: 1px;
  height: 18px;
  background: rgba(255, 255, 255, 0.18);
  margin: 0 6px;
  flex-shrink: 0;
}

/* ==========================================================================
   Page shell / headings
   ========================================================================== */
.app-main {
  max-width: 800px;
  margin: 0 auto;
  padding: var(--space-7) var(--space-6) 72px;
}

.view-heading { margin-bottom: var(--space-6); }
.view-eyebrow {
  margin: 0 0 6px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-primary);
}
.view-heading h1 { margin: 0 0 4px; font-size: 34px; font-weight: 800; letter-spacing: -0.02em; color: var(--color-navy-ink); }
.view-subtext { margin: 2px 0; color: var(--color-text-muted); font-size: var(--text-sm); line-height: 1.5; }

.section-label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-faint);
  margin: var(--space-7) 0 var(--space-3);
  font-weight: 650;
}

/* ==========================================================================
   First-visit orientation modal + persistent "How to Explore" control
   (approved wording/behavior unchanged — visual tokens only, Item 2).
   ========================================================================== */
.view-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.view-heading-row h1 { margin: 0 0 4px; }

.btn--howto {
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  color: var(--color-primary);
  font-size: var(--text-sm);
  font-weight: 650;
  padding: 10px 18px;
  border-radius: var(--radius-full);
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--shadow-xs);
  transition: background var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.btn--howto:hover { border-color: var(--color-primary); background: var(--color-primary-light); box-shadow: var(--shadow-sm); }

.orientation-modal {
  max-width: 480px;
  padding: 32px 30px 28px;
  text-align: left;
  overflow-y: auto;
}
.orientation-modal h2 {
  margin: 0 0 15px;
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--color-text);
}
.orientation-body {
  margin: 0 0 14px;
  font-size: var(--text-base);
  line-height: 1.62;
  color: var(--color-text);
}
.orientation-secondary {
  margin: 0 0 14px;
  font-size: var(--text-base);
  line-height: 1.62;
  color: var(--color-text);
}
.orientation-modal .action-row { margin-top: var(--space-6); }

/* Persistent, non-blocking feedback CTA on the Referral Inbox (Finding #9b) —
   "Passive Feedback," the only Feedback entry point (Finding #25 §22: the
   earlier Automatic Post-Scenario Feedback Popup was removed entirely). Its
   full-width placement, wording, and button are strategically important to
   the validation instrument and are preserved exactly. */
.feedback-inbox-cta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  background: var(--color-primary-light);
  border: 1px solid var(--color-primary-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  margin-bottom: var(--space-5);
}
.feedback-inbox-cta-content {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex: 1 1 240px;
}
.feedback-inbox-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--color-surface);
  color: var(--color-primary);
  flex-shrink: 0;
  box-shadow: var(--shadow-xs);
}
.feedback-inbox-cta p {
  margin: 0;
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--color-navy-ink);
}

/* Filter toggle */
.filter-toggle {
  display: flex;
  gap: 6px;
  margin-bottom: var(--space-4);
}
.filter-btn {
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-full);
  padding: 8px 17px;
  font-size: var(--text-xs);
  font-weight: 650;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}
.filter-btn:hover { color: var(--color-navy-ink); border-color: var(--color-primary-border); }
.filter-btn.is-active {
  background: var(--color-navy);
  border-color: var(--color-navy);
  color: #fff;
}
.filter-btn.is-active:hover { color: #fff; }

.checklist-disclaimer {
  margin: var(--space-4) 2px 0;
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  line-height: 1.55;
}

/* ==========================================================================
   Progress ring — shared by the Inbox cards and the referral-detail hero.
   A presentation-only visualization of the same receivedCount/total values
   already shown as text; introduces no new data.
   ========================================================================== */
.progress-ring-track { fill: none; stroke: var(--color-bg-subtle); }
.progress-ring-fill {
  fill: none;
  stroke: var(--color-amber-border);
  stroke-linecap: round;
  transition: stroke-dashoffset 0.5s ease;
}
.progress-ring-text {
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 700;
  fill: var(--color-navy-ink);
}
/* Ready state: a solid filled teal disc with white fraction text, rather
   than a ring — the approved stronger visual payoff for a completed
   referral. Values are still derived from the same receivedCount/total. */
.progress-ring--ready .progress-ring-track { fill: var(--color-teal); stroke: none; }
.progress-ring--ready .progress-ring-fill { display: none; }
.progress-ring--ready .progress-ring-text { fill: #ffffff; }

/* ==========================================================================
   Referral Inbox — toolbar (filter + sort)
   ========================================================================== */
.queue-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.queue-toolbar .filter-toggle { margin-bottom: 0; }

.sort-control {
  display: flex;
  align-items: center;
  gap: 8px;
}
.sort-control label {
  font-size: var(--text-xs);
  font-weight: 650;
  color: var(--color-text-faint);
  white-space: nowrap;
}
.sort-control select {
  font: inherit;
  font-size: var(--text-xs);
  font-weight: 650;
  color: var(--color-navy-ink);
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  cursor: pointer;
  box-shadow: var(--shadow-xs);
}
.sort-control select:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 1px; }

/* ==========================================================================
   Referral Inbox — vertical work queue
   ========================================================================== */
.referral-queue {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.queue-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
  width: 100%;
  text-align: left;
  background: var(--color-surface);
  font: inherit;
  color: inherit;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast), transform var(--transition-fast);
}
.queue-row--ready {
  background: var(--color-green-bg);
  border-color: var(--color-green-border);
}
.queue-row:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.queue-row--not-ready:hover { border-color: var(--color-border-strong); }
.queue-row--ready:hover { border-color: var(--color-teal); }
.queue-row:focus-visible { outline-offset: 2px; }

.queue-row-main { min-width: 0; flex: 1 1 auto; }
.queue-row-name { display: flex; flex-direction: column; }
.queue-row-surname {
  font-size: 18px;
  font-weight: 750;
  color: var(--color-navy-ink);
  letter-spacing: -0.01em;
}
.queue-row-given {
  margin-top: 1px;
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--color-text-muted);
}
.queue-row-reason {
  margin-top: 2px;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.queue-row-missing {
  margin-top: 9px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
}
.queue-row-missing-label {
  font-size: 10.5px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-amber-text);
  margin-right: 1px;
}
.missing-chip {
  display: inline-block;
  background: var(--color-amber-bg);
  border: 1px solid var(--color-amber-border);
  color: var(--color-amber-text);
  font-size: 12px;
  font-weight: 650;
  padding: 4px 11px;
  border-radius: var(--radius-full);
  white-space: nowrap;
}
.queue-row-ready-line {
  margin-top: 9px;
  font-size: var(--text-sm);
  font-weight: 650;
  color: var(--color-teal-dark);
  display: flex;
  align-items: center;
  gap: 6px;
}
.ready-line-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--color-teal);
  color: #fff;
  font-size: 10px;
  flex-shrink: 0;
}

.queue-row-meta {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
.queue-row-date {
  font-size: 11.5px;
  color: var(--color-text-faint);
  white-space: nowrap;
}

/* Open-row affordance — purely decorative; the entire row is already the
   clickable control (role="listitem" button), so this never carries its
   own click handler or competes with that behavior. */
.queue-row-arrow {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--color-primary-light);
  color: var(--color-primary);
  font-size: 18px;
  line-height: 1;
}
.queue-row--ready .queue-row-arrow { background: rgba(15, 158, 142, 0.12); color: var(--color-teal-dark); }

/* ==========================================================================
   Status badges — a leading dot plus label reads as a modern SaaS status
   chip without any per-instance markup change (app.js only ever toggles
   badge--green / badge--amber, unchanged).
   ========================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px 5px 10px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
}
.badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.badge--amber {
  background: var(--color-amber-bg);
  border-color: var(--color-amber-border);
  color: var(--color-amber-text);
}
.badge--green {
  background: var(--color-teal);
  border-color: var(--color-teal);
  color: #fff;
}
.badge--green::before { display: none; }
.badge-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
}
.badge--large { font-size: 13.5px; padding: 7px 16px; }
.badge--large::before { display: none; }

/* Back link */
.back-link {
  background: none;
  border: none;
  color: var(--color-primary);
  font-size: var(--text-sm);
  cursor: pointer;
  padding: 0;
  margin-bottom: var(--space-5);
  font-weight: 650;
  display: inline-flex;
  align-items: center;
}
.back-link:hover { color: var(--color-primary-dark); text-decoration: underline; }

/* ==========================================================================
   Status hero (referral Ready / Not Ready) — the dominant focal point of
   the referral-detail page: a large ring + headline, not a slim banner.
   ========================================================================== */
.status-hero {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  padding: var(--space-5) var(--space-6);
  border-radius: var(--radius-lg);
  border: 1px solid;
  margin-bottom: var(--space-2);
}
.status-hero--amber {
  background: var(--color-amber-bg);
  border-color: var(--color-amber-border);
  color: var(--color-amber-text);
}
.status-hero--green {
  background: var(--color-green-bg);
  border-color: var(--color-green-border);
  color: var(--color-green-text);
}
.status-hero-ring { flex-shrink: 0; line-height: 0; }
.status-hero-body { min-width: 0; }
.status-hero-titles {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 11px;
  margin-bottom: 6px;
}
#statusBannerTitle {
  font-size: 24px;
  font-weight: 750;
  letter-spacing: -0.01em;
}
.status-banner-sub {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid var(--color-green-border);
}
#statusBannerCount {
  font-size: var(--text-base);
  font-weight: 650;
  color: var(--color-text);
}

/* ==========================================================================
   Checklist (required items)
   ========================================================================== */
.checklist {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.checklist-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 15px 18px 15px 15px;
  border-bottom: 1px solid var(--color-border);
  border-left: 3px solid transparent;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}
.checklist-item:last-child { border-bottom: none; }
.checklist-item--missing { border-left-color: var(--color-amber-border); }
.checklist-item--received { border-left-color: var(--color-green-border); }

.checklist-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 25px;
  height: 25px;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}
.checklist-icon--received {
  background: var(--color-green-bg);
  color: var(--color-green-text);
  border: 1px solid var(--color-green-border);
}
.checklist-icon--missing {
  background: var(--color-amber-bg);
  color: var(--color-amber-text);
  border: 1px solid var(--color-amber-border);
}
.checklist-icon--config {
  background: var(--color-primary-light);
  color: var(--color-primary);
  border: 1px solid var(--color-primary-border);
}

.checklist-item-label {
  flex: 1;
  font-size: var(--text-base);
  background: none;
  border: none;
  text-align: left;
  padding: 0;
  color: inherit;
  font: inherit;
  cursor: default;
  border-radius: 4px;
}
.checklist-item-label.is-linkable {
  cursor: pointer;
  color: var(--color-primary);
}
.checklist-item-label.is-linkable:hover { color: var(--color-primary-dark); text-decoration: underline; text-underline-offset: 2px; }

.checklist-item-status {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.01em;
  padding: 4px 11px;
  border-radius: var(--radius-full);
  border: 1px solid transparent;
  white-space: nowrap;
}
.checklist-item--received {
  background: #f3fbf8;
}
.checklist-item--received .checklist-item-status {
  color: var(--color-green-text);
  background: var(--color-green-bg);
  border-color: var(--color-green-border);
}
.checklist-item--received:hover { background: var(--color-surface-alt); }
.checklist-item--missing {
  background: #fffcf4;
}
.checklist-item--missing .checklist-item-status {
  color: var(--color-amber-text);
  background: var(--color-amber-bg);
  border-color: var(--color-amber-border);
}

/* Callout */
.callout {
  margin-top: var(--space-5);
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-md);
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  font-size: var(--text-base);
  color: var(--color-text-muted);
  line-height: 1.55;
}
.callout strong { color: var(--color-text); }

/* Also Received (associated but non-qualifying documents) — the base class
   is structural only; the two modifiers below carry the actual semantic
   meaning, since this card is reused for two genuinely different states
   (Finding #25 §20): an informational, no-action-needed associated document
   (--info, e.g. Helen's DEXA appointment confirmation) versus a document
   that genuinely needs staff attention to resolve (--review, the Unmatched
   Documents list). Never recolor the base class itself. */
.associated-doc-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
  padding: var(--space-4) var(--space-5);
  margin-bottom: var(--space-3);
}
.associated-doc-card:last-child { margin-bottom: 0; }
.associated-doc-card--info {
  background: var(--color-primary-light);
  border-color: var(--color-primary-border);
}
.associated-doc-card--review {
  background: var(--color-coral-bg);
  border-color: var(--color-coral-border);
}
.associated-doc-note {
  margin: var(--space-2) 0 0;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.55;
}

/* ==========================================================================
   Actions / buttons
   ========================================================================== */
.action-row {
  margin-top: var(--space-7);
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.btn {
  padding: 12px 22px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit;
  font-size: var(--text-base);
  font-weight: 650;
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast), color var(--transition-fast);
}
.btn--primary {
  background: var(--color-primary);
  color: #fff;
  box-shadow: var(--shadow-xs);
}
.btn--primary:hover { background: var(--color-primary-dark); }

.btn--secondary {
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  color: var(--color-text);
}
.btn--secondary:hover { border-color: var(--color-primary); color: var(--color-primary); }

.btn:disabled {
  background: var(--color-bg-subtle);
  border-color: var(--color-border);
  color: var(--color-text-faint);
  cursor: not-allowed;
  box-shadow: none;
}

/* ==========================================================================
   Incoming Document / Match event
   ========================================================================== */
.doc-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 4px 20px;
}
.doc-card-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-3);
  padding: 13px 0;
  border-bottom: 1px solid var(--color-border);
  font-size: var(--text-base);
}
.doc-card-row:last-child { border-bottom: none; }
.doc-label { color: var(--color-text-faint); font-size: var(--text-sm); }
.doc-value { font-weight: 650; text-align: right; }

.match-result {
  margin-top: var(--space-6);
  padding: var(--space-6) var(--space-5) var(--space-5);
  border-radius: var(--radius-lg);
  background: var(--color-green-bg);
  border: 1px solid var(--color-green-border);
  text-align: center;
}
.match-result-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto var(--space-4);
  border-radius: 50%;
  background: var(--color-green-text);
  color: #fff;
  font-size: 26px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(20, 107, 60, 0.28);
}
.match-detail {
  margin: var(--space-3) 0 4px;
  font-weight: 650;
  font-size: var(--text-md);
  color: var(--color-text);
}
.match-explain {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.5;
}

/* ==========================================================================
   Feedback
   ========================================================================== */
.feedback-view { max-width: 620px; margin: 0 auto; }
.feedback-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  padding: 40px 40px 36px;
}
.feedback-card .view-heading { text-align: center; margin-bottom: var(--space-7); }
.feedback-card .view-heading h1 { font-size: 28px; }
.feedback-question {
  font-size: 17px;
  font-weight: 650;
  margin: 4px 0 var(--space-5);
  line-height: 1.5;
  color: var(--color-navy-ink);
}
.rating-row {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  justify-content: center;
}
.rating-btn {
  width: 44px;
  height: 44px;
  border-radius: 11px;
  border: 1.5px solid var(--color-border-strong);
  background: var(--color-surface);
  font: inherit;
  font-size: var(--text-md);
  font-weight: 700;
  color: var(--color-navy-ink);
  cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast), color var(--transition-fast), transform var(--transition-fast);
}
.rating-btn:hover { border-color: var(--color-primary); color: var(--color-primary); transform: translateY(-1px); }
.rating-btn.is-selected {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}
.rating-scale-labels {
  display: flex;
  justify-content: space-between;
  margin-top: var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}

.comment-block {
  margin-top: var(--space-6);
}
.comment-block label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 650;
  margin-bottom: var(--space-2);
}
.optional-tag {
  font-weight: 500;
  color: var(--color-text-faint);
  text-transform: none;
  letter-spacing: normal;
}
.comment-block textarea {
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 11px 13px;
  font: inherit;
  font-size: var(--text-base);
  color: var(--color-text);
  resize: vertical;
  transition: border-color var(--transition-fast);
}
.comment-block textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}

.feedback-thanks {
  background: var(--color-green-bg);
  border: 1px solid var(--color-green-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  margin-bottom: var(--space-6);
  text-align: center;
}
.feedback-thanks-title {
  margin: 0;
  font-weight: 650;
  color: var(--color-green-text);
  font-size: var(--text-md);
}

/* ==========================================================================
   Modals
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(14, 20, 32, 0.5);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  max-width: 520px;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-modal);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border);
}
.modal-head h3 { margin: 0; font-size: var(--text-md); font-weight: 650; }
.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: var(--color-text-faint);
  padding: 2px 6px;
  border-radius: 4px;
  transition: color var(--transition-fast);
}
.modal-close:hover { color: var(--color-text); }
.modal-body {
  margin: 0;
  padding: var(--space-5);
  overflow-y: auto;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.6;
  white-space: pre-wrap;
  color: var(--color-text);
}
#docModalSourceLink {
  margin: 0 var(--space-5) var(--space-5);
}

/* ==========================================================================
   Referral Requirements (Finding #10)
   ========================================================================== */
.requirements-intro {
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--color-text-muted);
  margin: 0 0 var(--space-5);
}
.referral-type-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}
.add-requirement-block {
  margin-top: var(--space-5);
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-md);
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
}
.add-requirement-block label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 650;
  margin-bottom: var(--space-2);
}
.add-requirement-row {
  display: flex;
  gap: var(--space-3);
}
.add-requirement-row input[type="text"] {
  flex: 1;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  font: inherit;
  font-size: var(--text-base);
  transition: border-color var(--transition-fast);
}
.add-requirement-row input[type="text"]:focus { outline: none; border-color: var(--color-primary); }
.add-requirement-note {
  margin: var(--space-3) 0 0;
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  line-height: 1.55;
}

/* ==========================================================================
   Test a Document (Finding #10)
   ========================================================================== */
.nophi-warning {
  background: var(--color-amber-bg);
  border: 1px solid var(--color-amber-border);
  color: var(--color-amber-text);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  font-size: var(--text-base);
  line-height: 1.55;
  margin-bottom: var(--space-6);
}
.testdoc-upload-block {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
}
.testdoc-upload-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 650;
  margin-bottom: var(--space-2);
}
.testdoc-hint {
  margin: var(--space-3) 0 0;
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  line-height: 1.55;
}
.testdoc-examples { margin-bottom: var(--space-6); }
.testdoc-examples-label {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-faint);
  margin: 0 0 var(--space-3);
}
.testdoc-scenario-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-3);
}
.testdoc-scenario-card {
  text-align: left;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-4);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: box-shadow var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast);
}
.testdoc-scenario-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.testdoc-scenario-card:focus-visible { outline-offset: 2px; }
.testdoc-scenario-title { font-size: var(--text-base); font-weight: 700; color: var(--color-navy-ink); }
.testdoc-scenario-desc { font-size: var(--text-sm); color: var(--color-text-muted); line-height: 1.5; }
.testdoc-scenario-card--match { border-top: 3px solid var(--color-teal); }
.testdoc-scenario-card--review { border-top: 3px solid var(--color-coral-border); }
.testdoc-scenario-card--conflict { border-top: 3px solid var(--color-red-border); }
.testdoc-error {
  background: var(--color-red-bg);
  border: 1px solid var(--color-red-border);
  color: var(--color-red-text);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-base);
  margin-bottom: var(--space-4);
}
.testdoc-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
}
.testdoc-stages {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  position: relative;
  padding-left: 30px;
}
.testdoc-stages::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--color-border);
}
.testdoc-stage { position: relative; }
.testdoc-stage::before {
  content: "";
  position: absolute;
  left: -30px;
  top: 3px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--color-primary);
  border: 2px solid var(--color-surface);
  box-shadow: 0 0 0 2px var(--color-primary-border);
}
.testdoc-stage-title {
  margin: 0 0 4px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-faint);
}
.testdoc-stage-body { font-size: var(--text-base); line-height: 1.55; }
.testdoc-stage-body p { margin: 0 0 4px; }
.testdoc-stage-body p:last-child { margin-bottom: 0; }
.testdoc-match-line { font-weight: 650; }
.testdoc-needs-review { font-weight: 650; color: var(--color-coral-text); }
.testdoc-source-link { display: inline-block; margin-top: var(--space-4); }
.testdoc-mismatch-block {
  background: var(--color-red-bg);
  border: 1px solid var(--color-red-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  margin-top: var(--space-2);
}
.testdoc-mismatch-block p { margin: 0 0 4px; font-size: var(--text-base); line-height: 1.5; color: var(--color-text); }
.testdoc-mismatch-block p:last-child { margin-bottom: 0; }
.testdoc-mismatch-title { font-weight: 700; color: var(--color-red-text); font-size: var(--text-base); }
.associate-row {
  display: flex;
  gap: var(--space-3);
  margin-top: var(--space-3);
  flex-wrap: wrap;
}
.associate-select {
  flex: 1 1 220px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font: inherit;
  font-size: var(--text-base);
  background: var(--color-surface);
  transition: border-color var(--transition-fast);
}
.associate-select:focus { outline: none; border-color: var(--color-primary); }

/* Compact customer-facing result card — Document → Determination → Referral
   Impact (Finding #25 §21). Replaces the old seven-stage technical trace as
   the primary presentation; the underlying result object/processing logic
   (testdoc.js) is unchanged, this only changes how it is communicated. */
.testdoc-result {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
}
.testdoc-result-doc {
  display: flex;
  align-items: baseline;
  gap: 9px;
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}
.testdoc-result-doc-title { font-size: var(--text-md); font-weight: 750; color: var(--color-navy-ink); }
.testdoc-result-doc-meta { font-size: var(--text-xs); color: var(--color-text-faint); }

.testdoc-result-block {
  border-radius: var(--radius-md);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
  border: 1px solid var(--color-border);
  background: var(--color-surface-alt);
}
.testdoc-result-block:last-of-type { margin-bottom: 0; }
.testdoc-result-block-label {
  margin: 0 0 7px;
  font-size: 10.5px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-faint);
}
.testdoc-result-block p { margin: 0 0 5px; font-size: var(--text-base); line-height: 1.5; color: var(--color-text); }
.testdoc-result-block p:last-child { margin-bottom: 0; }
.testdoc-result-block-headline { font-weight: 700; }

.testdoc-result--match .testdoc-result-block--determination {
  background: var(--color-green-bg);
  border-color: var(--color-green-border);
}
.testdoc-result--match .testdoc-result-block--determination .testdoc-result-block-label { color: var(--color-green-text); }

.testdoc-result--review .testdoc-result-block--determination {
  background: var(--color-coral-bg);
  border-color: var(--color-coral-border);
}
.testdoc-result--review .testdoc-result-block--determination .testdoc-result-block-label { color: var(--color-coral-text); }

.testdoc-result--conflict .testdoc-result-block--determination {
  background: var(--color-red-bg);
  border-color: var(--color-red-border);
}
.testdoc-result--conflict .testdoc-result-block--determination .testdoc-result-block-label { color: var(--color-red-text); }

.testdoc-result-block--impact-neutral {
  background: var(--color-primary-light);
  border-color: var(--color-primary-border);
}
.testdoc-result-block--impact-neutral .testdoc-result-block-label { color: var(--color-primary); }

.testdoc-result-readiness {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
}

[hidden] { display: none !important; }

/* ==========================================================================
   Responsive — tablet
   ========================================================================== */
@media (max-width: 860px) {
  .app-main { max-width: 100%; padding: var(--space-6) var(--space-5) 64px; }
}

/* ==========================================================================
   Responsive — mobile (~375px and below)
   ========================================================================== */
@media (max-width: 600px) {
  .app-header { padding: 11px 16px; flex-wrap: wrap; row-gap: 8px; }
  .brand-sub { display: none; }
  .app-nav { flex-wrap: wrap; row-gap: 6px; gap: 2px; }
  .nav-divider { display: none; }
  .nav-btn { padding: 8px 10px; }

  .app-main { padding: var(--space-5) var(--space-4) 56px; }
  .view-heading h1 { font-size: 23px; }

  .queue-toolbar { flex-direction: column; align-items: stretch; }
  .sort-control { justify-content: space-between; }
  .sort-control select { flex: 1; min-width: 0; }
  .queue-row { padding: var(--space-3); gap: var(--space-3); }
  .queue-row-date { display: none; }

  .doc-card-row { flex-direction: column; align-items: flex-start; gap: 2px; }
  .doc-value { text-align: left; }

  .status-hero { padding: var(--space-4) var(--space-5); gap: var(--space-4); }
  .status-hero-titles { row-gap: 6px; }
  #statusBannerTitle { font-size: 20px; }

  .rating-btn { width: 40px; height: 40px; font-size: var(--text-base); }

  .checklist-item { padding: 14px 15px; }

  .btn { padding: 12px 18px; }
  .action-row { gap: var(--space-2); }

  .orientation-modal { padding: 26px 20px 22px; }
}
