:root {
  /* KinDox identity tokens (Gate 1). Every value below is a direct swap from
     the approved KinDox Brand & Product Design System — same variable names,
     same usages throughout this file, so no layout/selector below needed to
     change. Contrast-checked against --paper/--panel exactly as before:
     --ink-900/700/500 and --accent all clear WCAG AA (4.5:1) for text;
     KinDox Blue Bright is deliberately NOT used here — it fails AA as text
     (2.9:1) and is reserved for large graphic use only, per the design system. */
  --ink-900: #0e1a2b;
  --ink-700: #3a4a5f;
  --ink-500: #5c6b80;
  --ink-300: #8998aa;
  --paper: #f5f7fa;
  --paper-sunken: #eef2f6;
  --hero-tint: #e7f2ff;
  --panel: #ffffff;
  --border: #dce3ec;
  --border-soft: #e8edf3;
  --accent: #0b63c4;
  --accent-dark: #0b1f3b;
  --accent-light: #e7f2ff;
  --warn: #92400e;
  --warn-bg: #fbeedc;
  --error: #b91c1c;
  --error-bg: #fbe7e7;
  --ok: #15803d;
  --ok-bg: #e6f4ea;
  --high: #991b1b;
  --high-bg: #fbe2e2;
  /* Full brand palette (KinDox Brand Identity v1.0) additions below.
     KinDox Blue Bright (#2D9CFF) — the literal brand-sheet "KinDox Blue" —
     stays decorative/graphic-only (icon, large accents) for the same reason
     noted above: it fails AA as text. --accent remains the accessible blue
     used for buttons/links/focus. Support Teal (#7EDFD4) is intentionally
     pale ("wellbeing/human focus" per the brand sheet) — used as a soft
     surface tint with dark text on top, never as small/thin text itself. */
  --accent-bright: #2d9cff;
  --support-teal: #7edfd4;
  --support-teal-bg: #eafbf8;
  --support-teal-text: #0f6b60;
  --overdue: #b45309;
  --overdue-bg: #fef3e2;
  --focus-ring: #0b63c4;
  --disabled-bg: #eef2f6;
  --disabled-text: #a9b4c2;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 2px rgba(11, 31, 59, 0.06), 0 4px 12px rgba(11, 31, 59, 0.05);
  --shadow-card: 0 1px 3px rgba(11, 31, 59, 0.08), 0 6px 18px rgba(11, 31, 59, 0.07);

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

  /* Type scale — floor raised to 0.76rem (~12px); most secondary/meta text
     sits at 0.85-0.9rem so it stays comfortable for the 50-80 audience. */
  --text-xs: 0.76rem;
  --text-sm: 0.88rem;
  --text-base: 0.95rem;
  --text-lg: 1.05rem;
  --text-xl: 1.3rem;
  --text-2xl: 1.6rem;

  --font-display: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-body: 'Public Sans', system-ui, -apple-system, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;

  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink-900);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
}
.skip-link:focus {
  left: 8px;
  top: 8px;
  background: var(--panel);
  padding: 8px 12px;
  z-index: 1000;
  border-radius: var(--radius);
}

#app-root {
  max-width: 880px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}

h1 {
  font-size: 1.6rem;
  font-weight: 600;
  margin: 0 0 4px;
  color: var(--ink-900);
}

h2 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0 0 14px;
  color: var(--ink-700);
}

.muted {
  color: var(--ink-500);
}
.small {
  font-size: 0.85rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}

/* Onboarding */
.onboarding-screen {
  padding-top: 40px;
}
.onboarding-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: 4px;
}
.onboarding-mark {
  border-radius: 12px;
  display: block;
  flex-shrink: 0;
}
.disclaimer-panel .subtitle {
  color: var(--accent);
  font-weight: 500;
  margin: 0 0 4px;
  letter-spacing: 0.02em;
}
.onboarding-positioning {
  color: var(--ink-700);
  font-size: var(--text-base);
  margin: 0 0 20px;
}
.disclaimer-text p {
  color: var(--ink-700);
  margin: 0 0 12px;
}
.onboarding-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 20px 0;
  font-size: 0.95rem;
  color: var(--ink-700);
}
.checkbox-row input {
  margin-top: 3px;
}

.field {
  display: block;
  margin-bottom: 16px;
}
.field span {
  display: block;
  font-weight: 500;
  font-size: 0.88rem;
  color: var(--ink-700);
  margin-bottom: 6px;
}
.field input[type='text'],
.field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  background: var(--panel);
  color: var(--ink-900);
}
.field input[type='text']:focus,
.field select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.form-errors {
  background: var(--error-bg);
  color: var(--error);
  border-radius: 6px;
  padding: 12px 14px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}
.form-errors p {
  margin: 0;
}

/* Buttons */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--ink-700);
  padding: 9px 16px;
  min-height: 44px;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
}
.btn:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  color: #fff;
}
.btn-secondary {
  background: var(--panel);
}
.btn-danger {
  background: var(--error);
  border-color: var(--error);
  color: #fff;
}

/* Case shell */
.case-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-bottom: var(--space-2);
}
.case-header-identity {
  display: flex;
  align-items: center;
  gap: 10px;
}
.case-header-identity h1 {
  font-size: var(--text-xl);
}
.case-header-mark {
  border-radius: 7px;
  display: block;
  flex-shrink: 0;
}
.case-header-controls {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

/* The always-visible local-persistence indicator. Deliberately small and calm —
   this is the one piece of "storage" vocabulary a customer sees, phrased in
   plain language (see caseShell.js statusText()), never file/IndexedDB jargon. */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 600;
  white-space: nowrap;
}
/* "Saved on this device" is clearer than jargon like "locally" for this
   audience, but doesn't fit comfortably at phone width — swap to "Saved"
   there. Both strings render at all times; CSS alone decides which shows,
   same convention as capture-row/capture-single. */
.status-pill-short {
  display: none;
}
.status-pill::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: currentColor;
  flex-shrink: 0;
}

/* Small secondary links in the header (Case & Backup / Safety Information) —
   deliberately understated so they never compete with the primary nav. */
.header-menu {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.header-menu-link {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--ink-700);
  padding: 6px 12px;
  min-height: 36px;
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.header-menu-link:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}
.header-menu-link.nav-tab-active {
  background: var(--accent-light);
  border-color: var(--accent-light);
  color: var(--accent-dark);
}

.status-bar {
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 0.9rem;
  margin-bottom: 8px;
  border: 1px solid var(--border);
}
.status-ok {
  background: var(--ok-bg);
  color: var(--ok);
  border-color: transparent;
}
/* The header's "Saved on this device" pill specifically uses Support Teal
   (a calm, positive/safe signal per the brand system) — more specific than
   the generic .status-ok so any other status-bar use elsewhere is unaffected. */
.status-pill.status-ok {
  background: var(--support-teal-bg);
  color: var(--support-teal-text);
}
.status-warn {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: transparent;
}
.status-error {
  background: var(--error-bg);
  color: var(--error);
  border-color: transparent;
}
.status-pending {
  background: var(--accent-light);
  color: var(--accent-dark);
  border-color: transparent;
}
.status-neutral {
  background: var(--panel);
  color: var(--ink-500);
}

.banner {
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 0.88rem;
  margin-bottom: 16px;
}
.banner-info {
  background: var(--accent-light);
  color: var(--accent-dark);
}
.banner-error {
  background: var(--error-bg);
  color: var(--error);
}

.activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.88rem;
  color: var(--ink-700);
}
.activity-list li {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.activity-list li:last-child {
  border-bottom: none;
}
.activity-id {
  font-family: 'SFMono-Regular', Consolas, monospace;
  color: var(--accent-dark);
  margin-right: 6px;
}

/* Recent Activity — reads as a human case history: the event and its human
   record ID lead; the LOG-### id stays available (traceability) but small
   and subordinate, never the first thing the eye lands on. */
.activity-entry {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}
.activity-main {
  min-width: 0;
}
.activity-event {
  font-weight: 600;
  color: var(--ink-900);
}
.activity-ref {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--accent);
  margin-left: 6px;
}
.activity-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  flex-shrink: 0;
  white-space: nowrap;
}
.activity-time {
  font-size: var(--text-xs);
  color: var(--ink-500);
}
.activity-logid {
  font-size: 0.66rem;
  color: var(--ink-300);
  font-family: 'SFMono-Regular', Consolas, monospace;
}

/* Factual Patterns category summary — small, secondary; the priority rows
   above (in .attention-card) already carry the strongest signals. */
.pattern-category-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.placeholder-panel {
  background: var(--paper);
  border-style: dashed;
  box-shadow: none;
}

/* Nav — a restrained pill-track strip for the 7 day-to-day case areas
   (desktop/tablet). Scrolls horizontally rather than wrapping once it no
   longer fits (see the 480px breakpoint below), so it never breaks into a
   second confusing row. Hidden on narrow viewports in favor of the bottom
   tab bar (.mobile-tabbar) — see the max-width:640px block below. */
.case-nav {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  margin: var(--space-4) 0 var(--space-4);
  background: var(--paper-sunken);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  padding: 4px;
  overflow-x: auto;
}
.nav-tab {
  appearance: none;
  border: none;
  background: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  min-height: 44px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--ink-500);
  cursor: pointer;
  white-space: nowrap;
  box-sizing: border-box;
}
.nav-tab:hover {
  color: var(--accent-dark);
}
.nav-tab-active {
  background: var(--accent);
  color: #fff;
}
.nav-tab-active:hover {
  color: #fff;
}

/* Stat grid — small elevated cards, distinct from the flatter .panel */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-3);
}
.stat-tile {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-value {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--ink-900);
}
.stat-label {
  font-size: var(--text-xs);
  color: var(--ink-500);
}

/* Card — a touch more depth than .panel, used for record list rows on mobile
   and anywhere content is presented as a discrete item rather than a form. */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: var(--space-4);
}

/* Unified badge/chip — the one status/state visual language across the app
   (incident severity + status, action status/overdue, commitment active state,
   archived state). Replaces the previously inconsistent .severity-badge /
   .status-bar-inline / plain-text treatments. */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.7;
  white-space: nowrap;
}
.badge-neutral { background: var(--paper); color: var(--ink-500); border: 1px solid var(--border); }
.badge-info { background: var(--accent-light); color: var(--accent-dark); }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-error { background: var(--error-bg); color: var(--error); }
.badge-high { background: var(--high-bg); color: var(--high); }
.badge-overdue { background: var(--overdue-bg); color: var(--overdue); }

/* App brand wordmark — shown in the persistent header on every screen except
   Dashboard, where the resident's name takes over as the page's real subject. */
.wordmark {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--accent-dark);
}
.wordmark-accent {
  color: var(--accent);
}

/* Dashboard hero — the resident's name is the one place a warmer display
   face appears in the live app; everywhere else (including document titles)
   stays in the operational body face, per the approved redesign. */
.dashboard-hero {
  background: var(--hero-tint);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-5);
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-5);
  margin-bottom: var(--space-5);
}
.resident-name {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 600;
  margin: 0;
  color: var(--ink-900);
}
.hero-eyebrow {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 6px;
}
.hero-sub {
  margin: 6px 0 0;
  color: var(--ink-700);
  font-size: var(--text-sm);
}
.hero-actions {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.btn-lg {
  font-size: var(--text-base);
  font-weight: 600;
  padding: 13px 22px;
  border-radius: 10px;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/* Needs Attention — each row states a real consequence and carries its own
   action straight to the record involved; never a dead-end bullet list. */
.section-label {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-500);
  margin: var(--space-5) 0 var(--space-3);
}
.attention-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.attention-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  background: var(--paper-sunken);
}
.attention-row .icon-badge {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.attention-row-error .icon-badge { background: var(--error-bg); color: var(--error); }
.attention-row-overdue .icon-badge { background: var(--overdue-bg); color: var(--overdue); }
.attention-row-warn .icon-badge { background: var(--warn-bg); color: var(--warn); }
.attention-row-info .icon-badge { background: var(--accent-light); color: var(--accent-dark); }
.home-record-cta {
  font-size: 1.05rem !important;
  padding: 16px 26px !important;
  box-shadow: 0 6px 16px rgba(11, 99, 196, 0.22);
}

/* Home — Recent activity, sourced from the same combined chronology feed as
   Timeline, never the internal ActivityLog phrasing. */
.recent-activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}
.recent-activity-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border-soft);
}
.recent-activity-row:last-child { border-bottom: none; }
.recent-activity-row .icon-badge {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--paper-sunken);
  color: var(--ink-700);
}
.recent-activity-body { flex: 1; min-width: 0; }
.recent-activity-summary { font-weight: 600; font-size: var(--text-sm); margin: 0; color: var(--ink-900); }
.recent-activity-meta { font-size: var(--text-xs); color: var(--ink-500); margin: 2px 0 0; }

.home-action-teaser p { margin: 0 0 var(--space-3); color: var(--ink-700); }
.home-action-teaser .btn { background: none; border: none; padding: 0; color: var(--accent-dark); font-weight: 600; }

/* Records — the advanced filing cabinet, tiles instead of nav tabs. */
.record-tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-3);
  margin-top: var(--space-4);
}
.record-tile {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  text-align: left;
  cursor: pointer;
}
.record-tile-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--accent-light);
  color: var(--accent-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.record-tile-icon svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.6; }
.record-tile-body { flex: 1; display: flex; flex-direction: column; }
.record-tile-body strong { font-size: var(--text-base); color: var(--ink-900); }
.record-tile-body span { font-size: var(--text-xs); color: var(--ink-500); }
.record-tile-arrow { color: var(--ink-300); font-size: 1.1rem; }

/* Record Something's 5-choice sheet — a label plus a one-line description
   per choice, reusing the existing .quickadd-btn shell (see the mobile
   sheet rules above) rather than introducing a new button component. */
.quickadd-btn.choice { align-items: flex-start; background: var(--panel); border: 1px solid var(--border); color: var(--ink-900); }
.quickadd-btn-text { display: flex; flex-direction: column; gap: 2px; text-align: left; }
.quickadd-btn-text strong { font-size: var(--text-base); font-weight: 600; }
.quickadd-btn-text span { font-size: var(--text-xs); font-weight: 400; color: var(--ink-500); }

/* Timeline — the human phrase for each entry's type, leading the same way
   the mock-up showed ("Something happened · 09:15"). */
.chronology-kind { font-size: var(--text-xs); font-weight: 700; color: var(--accent-dark); text-transform: uppercase; letter-spacing: 0.03em; }

/* Expected Care — Today section on Home, the exception follow-up sheet, and
   the setup/history screen. All additive; nothing here overrides an existing rule. */
.today-item { border: 1px solid var(--border-soft); border-radius: var(--radius); padding: var(--space-3) var(--space-4); margin-bottom: var(--space-2); }
.today-item:last-child { margin-bottom: 0; }
.today-item-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: var(--space-2); gap: var(--space-2); }
.today-item-title { font-weight: 700; font-size: var(--text-base); color: var(--ink-900); }
.today-item-time { font-size: var(--text-xs); color: var(--ink-500); font-variant-numeric: tabular-nums; white-space: nowrap; }
.today-btns { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.tbtn { flex: 1; min-width: 64px; text-align: center; padding: 9px 6px; border-radius: var(--radius); font-size: var(--text-sm); font-weight: 700; border: 1.5px solid var(--border); background: var(--panel); color: var(--ink-700); cursor: pointer; }
.tbtn.primary-done { background: var(--ok); border-color: var(--ok); color: #fff; flex-basis: 100%; padding: 12px 6px; font-size: var(--text-base); }
.tbtn.late { color: var(--overdue); }
.tbtn.missed { color: var(--error); }
.tbtn.unsure { color: var(--ink-500); }
.tbtn.different { color: var(--accent); }
.completed-row { display: flex; align-items: flex-start; gap: var(--space-3); }
.completed-meta { font-size: var(--text-sm); color: var(--ink-500); line-height: 1.5; }
.completed-meta b { color: var(--ink-900); font-weight: 700; }
.today-recorder-setup { margin-bottom: var(--space-2); }
.today-recorder-prompt { font-size: var(--text-sm); font-weight: 600; color: var(--ink-700); margin: 0 0 var(--space-3); }
.contributor-chip-row { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.contributor-chip { padding: 10px var(--space-4); border-radius: 999px; border: 1.5px solid var(--border); background: var(--panel); color: var(--ink-900); font-weight: 700; font-size: var(--text-sm); cursor: pointer; }
.contributor-chip:hover { border-color: var(--accent); color: var(--accent-dark); }

/* People/Attribution — header switcher, attribution line on record detail
   screens, and the relationship quick-fill suggestions on People/onboarding. */
.contributor-control { font-size: var(--text-sm); color: var(--ink-700); background: none; border: none; cursor: pointer; padding: 6px 8px; border-radius: 6px; }
.contributor-control:hover { background: var(--paper-sunken); }
.contributor-control b { color: var(--ink-900); }
.attribution-line { margin-top: var(--space-3); }
.quick-suggest-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: var(--space-2); }

.exception-status-line { font-size: var(--text-sm); color: var(--ink-700); margin: 0 0 var(--space-3); }
.evidence-attach-btn { display: inline-flex; align-items: center; gap: var(--space-2); position: relative; overflow: hidden; width: 100%; justify-content: center; margin-bottom: var(--space-3); }
.evidence-attach-btn input[type='file'] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.evidence-attach-btn-disabled { opacity: 0.5; }
.evidence-attach-btn-disabled input[type='file'] { cursor: not-allowed; }

.day-picker-input { display: flex; gap: var(--space-2); }
.day-toggle { display: flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 50%; border: 1.5px solid var(--border); font-size: var(--text-xs); font-weight: 700; color: var(--ink-500); cursor: pointer; }
.day-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.day-toggle:has(input:checked) { background: var(--accent); border-color: var(--accent); color: #fff; }

.stat-tile.stat-done .stat-value { color: var(--ok); }
.stat-tile.stat-late .stat-value { color: var(--overdue); }
.stat-tile.stat-different .stat-value { color: var(--accent); }
.stat-tile.stat-missed .stat-value { color: var(--error); }
.stat-tile.stat-unsure .stat-value,
.stat-tile.stat-notlogged .stat-value { color: var(--ink-300); }
.fact-list { list-style: none; margin: 0; padding: 0; }
.fact-list li { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; padding: var(--space-2) 0; border-top: 1px solid var(--border-soft); font-size: var(--text-sm); color: var(--ink-700); }
.fact-list li:first-child { border-top: none; }

.attention-body { flex: 1; min-width: 0; }
.attention-title { font-weight: 600; font-size: var(--text-base); margin: 0; }
.attention-sub { font-size: var(--text-sm); color: var(--ink-500); margin: 2px 0 0; }
.attention-action {
  background: none;
  border: none;
  color: var(--accent-dark);
  font-weight: 600;
  font-size: var(--text-sm);
  cursor: pointer;
  white-space: nowrap;
  padding: 12px 4px;
  margin: -12px -4px;
  min-height: 44px;
}
.attention-action:hover { text-decoration: underline; }

/* Case overview — demoted from six shadowed stat tiles to one quiet strip;
   useful at a glance, never the headline of the page. */
.overview-strip {
  display: flex;
  flex-wrap: wrap;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.overview-strip > div {
  flex: 1 1 110px;
  padding: var(--space-3) var(--space-4);
  text-align: center;
  border-left: 1px solid var(--border);
}
.overview-strip > div:first-child { border-left: none; }
.overview-strip strong { display: block; font-size: 1.15rem; color: var(--ink-900); }
.overview-strip span { font-size: var(--text-xs); color: var(--ink-500); }

/* Factual Patterns — collapses to one quiet line until a pattern genuinely
   exists, so the dashboard never manufactures significance. */
.patterns-collapsed {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  color: var(--ink-500);
}

/* Evidence — human descriptions lead; technical metadata (filename, MIME
   type, SHA-256, sharing history) moves under one Details disclosure per
   item. Nothing is removed, only reordered — see evidenceScreen.js. */
.evidence-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) 2px;
  border-bottom: 1px solid var(--border-soft);
}
.ev-icon {
  width: 40px;
  height: 40px;
  border-radius: 9px;
  background: var(--accent-light);
  color: var(--accent-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.ev-title {
  font-weight: 600;
  font-size: var(--text-base);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.id-chip {
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: var(--text-xs);
  color: var(--ink-300);
  font-weight: 400;
}
.ev-meta {
  font-size: var(--text-sm);
  color: var(--ink-500);
  margin: 2px 0 0;
}
details.tech-details {
  margin-top: var(--space-3);
}
details.tech-details summary {
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--accent-dark);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
  min-height: 44px;
}
details.tech-details summary::-webkit-details-marker { display: none; }
details.tech-details summary::before {
  content: '\203A';
  display: inline-block;
  transition: transform 0.15s;
  font-size: 1.1em;
}
details.tech-details[open] summary::before { transform: rotate(90deg); }

/* Empty states — explain what the feature is for and offer the one action
   that fixes it, instead of a bare "no records match". */
.empty-state {
  text-align: center;
  padding: var(--space-6) var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--paper-sunken);
}
.empty-state .icon-lg {
  width: 34px;
  height: 34px;
  color: var(--accent);
  margin: 0 auto 14px;
}
.empty-state h3 { font-size: 1.05rem; margin: 0 0 8px; }
.empty-state p {
  color: var(--ink-500);
  font-size: var(--text-sm);
  max-width: 44ch;
  margin: 0 auto 18px;
}

/* Documents — the flagship screen: a journey stepper plus five differentiated
   cards, each explaining what it does, when to use it and what it includes. */
.doc-journey {
  display: flex;
  align-items: center;
  margin: var(--space-2) 0 var(--space-5);
  overflow-x: auto;
}
.doc-journey .step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 100px;
  text-align: center;
}
.doc-journey .step .dot {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: 600;
}
.doc-journey .step span {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--ink-500);
}
.doc-journey .line {
  flex: 1;
  height: 1px;
  background: var(--border);
  min-width: 20px;
  margin-bottom: 24px;
}
.doc-flagship-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: var(--space-4);
}
.doc-flagship-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-5);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.doc-flagship-stage {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0;
}
.doc-flagship-card h3 { font-size: 1.2rem; margin: 0; }
.doc-flagship-what { font-size: var(--text-sm); color: var(--ink-700); margin: 0; }
.doc-flagship-meta { font-size: var(--text-sm); color: var(--ink-500); margin: 0; }
.doc-flagship-meta strong { color: var(--ink-700); font-weight: 600; }
.doc-flagship-card .btn-primary { margin-top: auto; align-self: flex-start; }

/* Generated-document export actions — Download PDF is visually primary
   (btn-primary btn-lg), Share/Print are equal secondary actions. Wraps
   naturally on medium widths; stacks to full-width, comfortably tappable
   buttons on phones rather than ever overflowing horizontally. */
.doc-export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
  margin: var(--space-2) 0 var(--space-3);
}
@media (max-width: 480px) {
  .doc-export-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .doc-export-actions .btn {
    width: 100%;
    justify-content: center;
  }
}

/* Lists / tables */
.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}
.list-header h2 {
  margin: 0;
}
.guidance {
  color: var(--ink-500);
  font-size: var(--text-sm);
  max-width: 60ch;
  margin: 4px 0 0;
}
.filter-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 16px;
}
.field-inline {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
}
.field-inline span {
  font-weight: 500;
  color: var(--ink-700);
}
.field-inline select,
.field-inline input {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.88rem;
}
.field-inline.grow {
  flex: 1;
  min-width: 180px;
}
.checkbox-row.inline {
  margin: 0;
  padding-bottom: 6px;
}

.table-scroll {
  overflow-x: auto;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.data-table th {
  text-align: left;
  padding: 8px 10px;
  color: var(--ink-500);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.row-clickable {
  cursor: pointer;
}
.row-clickable:hover {
  background: var(--accent-light);
}
.preview-cell {
  max-width: 260px;
}

/* Record IDs are preserved everywhere but never lead — a small muted tag
   under the more human-relevant column (date, filename), not its own
   prominent leading column. */
.rec-id {
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: var(--text-xs);
  color: var(--ink-300);
  margin-top: 2px;
}


/* Detail */
.detail-grid {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 8px 16px;
  margin: 0 0 16px;
}
.detail-grid dt {
  color: var(--ink-500);
  font-size: 0.85rem;
  font-weight: 500;
}
.detail-grid dd {
  margin: 0;
  color: var(--ink-900);
}
.pre-wrap {
  white-space: pre-wrap;
}
.mono {
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 0.85rem;
  word-break: break-all;
}

.icon {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.linked-list, .picker-list {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
}
.linked-list li, .picker-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.inline-picker {
  margin-top: 16px;
  padding: 16px;
  background: var(--paper);
  border: 1px dashed var(--border);
  border-radius: 8px;
}

.field-help {
  margin: 0 0 6px;
  font-size: 0.8rem;
  color: var(--ink-500);
}
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--panel);
  color: var(--ink-900);
  resize: vertical;
}
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}
.form-actions.form-actions-start {
  justify-content: flex-start;
  flex-wrap: wrap;
}
.btn-small {
  padding: 4px 10px;
  min-height: 36px;
  font-size: 0.8rem;
}

/* Evidence quick capture — mobile is the primary capture experience, so the
   camera-first option sits first and larger; "Choose a file" (gallery/PDF/etc)
   stays available right beside it, never removed. */
.capture-row {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-3);
}
.capture-option {
  flex: 1 1 200px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  text-align: center;
  background: var(--paper);
}
.capture-option span {
  display: block;
  font-size: var(--text-sm);
  color: var(--ink-500);
  margin-top: var(--space-2);
}
.capture-option input[type='file'] {
  width: 100%;
}
/* Which capture control is visible is decided purely by the device's primary
   pointer, never by user-agent/device-name sniffing — a touch-primary device
   (phone, a tablet with no pointer attached) keeps the real-device-tested
   two-option flow; a mouse/trackpad-primary device (laptop, desktop, or a
   tablet WITH a pointer attached) instead gets one plain "+ Add Evidence"
   control. Both pieces of markup exist at all times; only visibility changes. */
.capture-single {
  display: none;
}
@media (pointer: fine) {
  .capture-row {
    display: none;
  }
  .capture-single {
    display: inline-flex;
    align-items: center;
    position: relative;
    overflow: hidden;
    margin-bottom: var(--space-3);
  }
  .capture-single input[type='file'] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
  }
  .capture-single-disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }
  .capture-single-disabled input[type='file'] {
    cursor: not-allowed;
  }
}

.evidence-thumb-wrap {
  text-align: center;
  margin-bottom: var(--space-3);
}
.evidence-thumb {
  max-width: 100%;
  max-height: 220px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(27, 36, 48, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 20px;
}
.modal-box {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 440px;
  width: 100%;
  padding: 24px;
}
.modal-box h2 {
  margin-top: 0;
}
.modal-box p {
  white-space: pre-line;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  flex-wrap: wrap;
}

/* Evidence viewer (image lightbox) */
.evidence-viewer-box {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  /* Flex items default to min-width:auto, which refuses to shrink below the
     content's natural width — on a narrow phone viewport that pushed this
     box (and its Close button) past the right edge. min-width:0 lets the
     100%-width above actually take effect. */
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.viewer-header h2 {
  margin: 0;
  font-size: 1rem;
  overflow-wrap: anywhere;
  min-width: 0; /* same fix, one level down: let the title shrink/wrap instead of pushing Close off-screen */
  flex: 1;
}
.viewer-body {
  flex: 1;
  min-height: 160px;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper);
  padding: 16px;
}
.viewer-body p {
  max-width: 48ch;
  text-align: center;
}
.viewer-image {
  max-width: 100%;
  max-height: 65vh;
  object-fit: contain;
  display: block;
}
.viewer-details {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
}
.viewer-details summary {
  cursor: pointer;
  color: var(--ink-500);
}
.viewer-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

/* Mobile-first field capture: single-column forms, larger touch targets, no
   horizontal overflow. Desktop/tablet layout above this breakpoint is untouched. */
@media (max-width: 480px) {
  #app-root {
    padding: 16px 12px 60px;
  }
  .panel {
    padding: 16px;
  }
  .case-header {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
  }
  .case-header-controls {
    justify-content: space-between;
  }
  .attention-sub {
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .attention-row {
    padding: 10px var(--space-4);
    flex-wrap: wrap;
    row-gap: 4px;
  }
  .attention-action {
    flex-basis: 100%;
    text-align: right;
  }
  .status-pill-full {
    display: none;
  }
  .status-pill-short {
    display: inline;
  }
  .case-nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: var(--space-3) -12px var(--space-2);
    padding: 0 12px;
  }
  .detail-grid {
    grid-template-columns: 1fr;
    gap: 2px 0;
  }
  .detail-grid dt {
    margin-top: 12px;
  }
  .detail-grid dt:first-child {
    margin-top: 0;
  }
  .filter-row {
    flex-direction: column;
    align-items: stretch;
  }
  .field-inline.grow {
    min-width: 0;
  }
  .list-header {
    flex-direction: column;
    align-items: stretch;
  }
  .mono {
    font-size: 0.78rem;
  }

  /* Record tables become stacked cards on phones — each <tr> is a card, each
     <td> a labelled row using its data-label attribute. Desktop/tablet keep
     the plain table above this breakpoint. The clickable/whole-row behavior
     (.row-clickable, data-action on the <tr>) is unchanged. */
  .table-scroll {
    overflow-x: visible;
  }
  .data-table thead {
    display: none;
  }
  .data-table, .data-table tbody, .data-table tr, .data-table td {
    display: block;
    width: 100%;
  }
  .data-table tr {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: var(--space-3) var(--space-4);
    margin-bottom: var(--space-3);
  }
  .data-table td {
    border-bottom: none;
    padding: 4px 0;
    display: flex;
    gap: var(--space-2);
    justify-content: space-between;
    text-align: right;
  }
  .data-table td::before {
    content: attr(data-label);
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--ink-500);
    text-align: left;
    flex-shrink: 0;
  }
  .data-table td.preview-cell {
    max-width: none;
    text-align: right;
  }

  /* Mobile navigation — the restrained desktop pill nav and the small header
     links give way to a fixed bottom tab bar prioritising the four things a
     phone user actually reaches for mid-conversation: Home, Evidence, a
     central Record action, and Attention. Everything else (Communications,
     Actions & Promises, Care-Plan Commitments, Chronology, Documents, Case &
     Backup, Safety) is one tap away under More — never removed, just not
     competing for permanent thumb-reach real estate. */
  .case-nav {
    display: none;
  }
  .header-menu {
    display: none;
  }
  #app-root {
    padding-bottom: 84px;
  }
  .dashboard-hero {
    padding: var(--space-4);
    align-items: stretch;
  }
  .resident-name {
    font-size: 1.6rem;
  }
  .hero-actions {
    width: 100%;
  }
  .hero-actions .btn-lg {
    flex: 1 1 auto;
    justify-content: center;
  }
}

/* Mobile bottom tab bar — hidden above 480px, where the pill nav (.case-nav)
   is used instead. Fixed positioning + safe-area padding for iOS. */
.mobile-tabbar {
  display: none;
}
@media (max-width: 480px) {
  .mobile-tabbar {
    display: flex;
    align-items: center;
    justify-content: space-around;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 400;
    padding: 8px 6px calc(8px + env(safe-area-inset-bottom, 0px));
    background: var(--panel);
    border-top: 1px solid var(--border);
  }
}
.mobile-tab-item {
  appearance: none;
  border: none;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--ink-300);
  font-size: var(--text-xs);
  font-weight: 600;
  min-width: 44px;
  min-height: 44px;
  position: relative;
  cursor: pointer;
}
.mobile-tab-item.active {
  color: var(--accent);
}
.mobile-tab-item svg {
  width: 21px;
  height: 21px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.mobile-tab-fab {
  width: 46px;
  height: 46px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: -22px;
  box-shadow: 0 4px 12px rgba(43, 93, 84, 0.4);
}
.mobile-tab-fab svg {
  width: 24px;
  height: 24px;
  stroke: #fff;
  stroke-width: 2;
}
.mobile-badge-count {
  position: absolute;
  top: -2px;
  right: 6px;
  background: var(--error);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  min-width: 15px;
  height: 15px;
  padding: 0 3px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* Mobile sheets — the quick-add ("+") sheet and the More sheet share the same
   overlay/sheet shell as the app's existing confirm modal (#modal-root), just
   anchored to the bottom of the screen instead of centered. */
.mobile-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(27, 36, 48, 0.4);
  z-index: 500;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.mobile-sheet {
  background: var(--panel);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.16);
  padding: 14px 18px calc(18px + env(safe-area-inset-bottom, 0px));
  width: 100%;
  max-width: 480px;
}
.mobile-sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  margin: 0 auto 14px;
}
.mobile-sheet-title {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-500);
  margin: 0 0 12px;
  text-align: center;
}
.quickadd-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 10px;
  min-height: 48px;
  cursor: pointer;
}
.quickadd-btn.primary {
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
}
.quickadd-btn.secondary {
  background: var(--accent-light);
  color: var(--accent-dark);
  border: 1px solid var(--accent-light);
}
.quickadd-btn svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}
.mobile-sheet-cancel {
  display: block;
  width: 100%;
  text-align: center;
  background: none;
  border: none;
  color: var(--ink-500);
  font-size: var(--text-base);
  font-weight: 600;
  padding: 10px;
  min-height: 44px;
  cursor: pointer;
}
.more-sheet-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 70vh;
  overflow-y: auto;
}
.more-sheet-list a,
.more-sheet-list button.more-sheet-link {
  appearance: none;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 4px;
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--ink-700);
  text-decoration: none;
  border-bottom: 1px solid var(--border-soft);
  min-height: 44px;
  box-sizing: border-box;
  cursor: pointer;
}
.more-sheet-list li:last-child button.more-sheet-link {
  border-bottom: none;
}
.more-sheet-list svg {
  width: 20px;
  height: 20px;
  stroke: var(--ink-500);
  fill: none;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

/* Document Builder */
.doc-type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}
.doc-type-btn {
  padding: 16px;
  text-align: left;
  font-weight: 600;
}

/* Document letter typography — replaces the flat <h3>/<ul> "database export"
   look with something that reads as a real letter/report. */
.doc-letterhead {
  margin-bottom: var(--space-5);
}
.doc-letterhead .print-title {
  margin-bottom: 2px;
}
.doc-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-5);
  font-size: var(--text-sm);
  color: var(--ink-500);
  margin: 4px 0 0;
}
.doc-meta-row strong {
  color: var(--ink-700);
}
.doc-addressee {
  margin: var(--space-4) 0 0;
  font-size: var(--text-base);
  color: var(--ink-900);
  /* Recipient lines (name / role / organisation / address) are joined with
     real newlines by complaintProse.js's composeRecipientLines — render
     each on its own line, like a real letter's address block. */
  white-space: pre-line;
}
.doc-incident-group {
  margin-bottom: var(--space-4);
}
.doc-incident-group h4 {
  font-size: var(--text-sm);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--ink-500);
  margin: 0 0 var(--space-2);
}
.doc-subject {
  margin: var(--space-2) 0 var(--space-4);
  font-size: var(--text-base);
  font-weight: 600;
}
.doc-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-1);
}
.doc-brand-mark {
  display: block;
  border-radius: 3px;
  flex-shrink: 0;
}
.doc-brand-word {
  font-weight: 700;
  font-size: var(--text-sm);
  color: var(--accent);
  letter-spacing: 0.01em;
}
.doc-salutation {
  margin: 0 0 var(--space-4);
  font-size: var(--text-base);
  color: var(--ink-900);
}
.doc-quality-check {
  margin: var(--space-4) 0;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  font-size: var(--text-sm);
}
.doc-quality-ready {
  background: var(--ok-bg);
  color: var(--ok);
}
.doc-quality-review {
  background: var(--warn-bg);
  color: var(--warn);
}
.doc-quality-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.doc-quality-check p {
  margin: var(--space-1) 0 0;
}
.doc-quality-list {
  list-style: none;
  margin: var(--space-2) 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.doc-quality-list li {
  background: var(--paper, #fff);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
}
.doc-quality-source {
  font-weight: 700;
  text-transform: uppercase;
  font-size: var(--text-xs, 0.78rem);
  letter-spacing: 0.03em;
  color: var(--ink-500);
}
.doc-quality-problem {
  margin-top: 2px;
  color: var(--ink-900);
}
.doc-quality-current {
  margin-top: var(--space-1);
  font-family: monospace;
  color: var(--ink-700);
  word-break: break-word;
}
.doc-quality-list .btn {
  margin-top: var(--space-2);
}
.doc-evidence-intro {
  color: var(--ink-700);
}

/* Evidence Index — one distinct block per item, human meaning leading,
   technical detail (filename/MIME/size/SHA-256) visually subordinate below. */
.evidence-block {
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--border-soft);
}
.evidence-block:last-child {
  border-bottom: none;
}
.evidence-block-main {
  display: flex;
  gap: var(--space-4);
  align-items: flex-start;
}
.evidence-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--paper-sunken);
}
.evidence-thumb-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-300);
}
.evidence-thumb-placeholder .icon {
  width: 24px;
  height: 24px;
}
.evidence-block-content {
  flex: 1;
  min-width: 0;
}
.evidence-heading {
  margin: 0 0 2px;
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--ink-900);
}
.evidence-subheading {
  margin: 0 0 var(--space-2);
  font-size: var(--text-sm);
  color: var(--ink-500);
}
.evidence-description {
  margin: 0 0 var(--space-2);
  color: var(--ink-700);
}
.evidence-meta-line {
  margin: 0 0 4px;
  font-size: var(--text-sm);
  color: var(--ink-700);
}
.evidence-meta-line strong {
  color: var(--ink-900);
  font-weight: 600;
}
.evidence-technical {
  margin-top: var(--space-3);
  padding: var(--space-3);
  background: var(--paper-sunken);
  border-radius: var(--radius);
}
.evidence-technical-label {
  margin: 0 0 6px;
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-500);
}
.evidence-technical-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px var(--space-3);
  margin: 0;
  font-size: var(--text-xs);
}
.evidence-technical-grid dt {
  color: var(--ink-500);
}
.evidence-technical-grid dd {
  margin: 0;
  color: var(--ink-700);
  word-break: break-word;
}
.evidence-checksum {
  font-size: 0.72rem;
  letter-spacing: 0.01em;
  word-break: break-all;
}

/* Evidence Appendix — the actual exhibits (photograph or metadata note) that
   follow the referenced EVD-xxx numbers in the main document. Each exhibit is
   kept together on one printed page where it fits, so a photograph and its
   heading/SHA-256 are never split across a page break. */
.evidence-exhibit {
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--border-soft);
  page-break-inside: avoid;
  break-inside: avoid;
}
.evidence-exhibit:last-child {
  border-bottom: none;
}
.evidence-exhibit-image {
  display: block;
  max-width: 100%;
  max-height: 520px;
  width: auto;
  height: auto;
  object-fit: contain;
  margin: var(--space-3) 0 var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--paper-sunken);
}
.evidence-exhibit-note {
  margin: var(--space-3) 0 var(--space-2);
  padding: var(--space-3);
  background: var(--paper-sunken);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  color: var(--ink-700);
  font-size: var(--text-sm);
}
.evidence-exhibit-note strong {
  color: var(--ink-900);
  font-weight: 600;
}
.evidence-exhibit-sha {
  margin: 0;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.72rem;
  letter-spacing: 0.01em;
  color: var(--ink-500);
  word-break: break-all;
}
@media (max-width: 480px) {
  .evidence-technical-grid {
    grid-template-columns: 1fr;
    gap: 2px;
  }
  .evidence-technical-grid dt {
    margin-top: 4px;
  }
}
.doc-section {
  margin-bottom: var(--space-5);
}
.doc-section h3 {
  font-size: var(--text-base);
  border-bottom: 1px solid var(--border);
  padding-bottom: var(--space-2);
  margin-bottom: var(--space-3);
}
.doc-body p {
  margin: 0 0 var(--space-3);
}
.doc-numbered-list {
  margin: 0 0 var(--space-3);
  padding-left: 1.4em;
}
.doc-numbered-list > li {
  margin-bottom: var(--space-3);
}
.doc-record-ref {
  color: var(--ink-500);
  font-size: var(--text-xs);
}
.doc-closing {
  margin-top: var(--space-6);
}
.doc-closing p {
  margin: 0 0 2px;
}
.doc-notes-space {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  min-height: 110px;
  margin-top: var(--space-2);
}

/* Chronology */
.chronology-day {
  margin-bottom: 20px;
}
.chronology-day h3, .chronology-day h4 {
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
  margin-bottom: 10px;
}
.chronology-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.chronology-entry {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.chronology-time {
  font-family: 'SFMono-Regular', Consolas, monospace;
  color: var(--ink-500);
  min-width: 46px;
}
.chronology-id {
  font-weight: 600;
  color: var(--accent-dark);
}
.chronology-summary {
  flex: 1;
  min-width: 200px;
}

/* Patterns / Needs Attention */
.pattern-list {
  margin: 0 0 12px;
  padding-left: 20px;
  font-size: 0.9rem;
  color: var(--ink-700);
}
.pattern-list li {
  margin-bottom: 6px;
}
.attention-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.attention-list li {
  padding: 10px 12px;
  border-radius: 6px;
  margin-bottom: 8px;
  font-size: 0.9rem;
}
.attention-error { background: var(--error-bg); color: var(--error); }
.attention-warn { background: var(--warn-bg); color: var(--warn); }
.attention-info { background: var(--accent-light); color: var(--accent-dark); }

.safety-notice {
  margin-top: 24px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--ink-500);
}

/* ---- Print ---- */
.no-print { }
@media print {
  html, body {
    background: #fff !important;
  }
  .no-print, .case-header, .status-bar, .banner, .case-nav {
    display: none !important;
  }
  body * {
    visibility: hidden;
  }
  .document-preview-print, .document-preview-print * {
    visibility: visible;
  }
  .document-preview-print {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    box-shadow: none;
    border: none;
    padding: 0;
    margin: 0;
  }
  #app-root {
    padding: 0;
    max-width: none;
  }
  .print-title {
    font-size: 1.4rem;
    margin-bottom: 4px;
  }
  .print-subtitle {
    color: #444;
    margin-top: 0;
    margin-bottom: 16px;
  }
  /* .doc-section is deliberately NOT in this list: a section can legitimately
     run to several pages (e.g. a long chronology), and forcing the whole
     block to avoid a break pushes it wholesale to the next page — leaving a
     large blank gap behind on the page it didn't fit. Individual small units
     (one chronology day, one table) still avoid breaking internally; a
     heading is kept attached to what follows it instead, which is what
     actually prevents an orphaned heading at the bottom of a page. */
  .chronology-day, .table-scroll, .evidence-block, .evidence-exhibit, section.panel:not(.document-preview-print) {
    break-inside: avoid-page;
  }
  .doc-section h3, .doc-letterhead, .doc-section h4 {
    break-after: avoid-page;
  }
  .doc-section {
    break-inside: auto;
  }
  .data-table {
    font-size: 0.8rem;
  }
  a[href]::after {
    content: '';
  }
  @page {
    margin: 16mm;
  }
}

/* ===========================================================================
   Guided Document Engine — wizard steps, review, editable draft, follow-up.
   Reuses existing tokens/primitives (panel, field, btn, badge, checkbox-row,
   picker-list) throughout; only genuinely new shapes get new classes below.
   =========================================================================== */

.wizard-progress {
  margin: 0 0 var(--space-4);
}
.wizard-progress-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--ink-500);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.wizard-progress-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--paper-sunken);
  margin-top: 6px;
  overflow: hidden;
}
.wizard-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.2s ease;
}

.wizard-compound {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.wizard-radio-group {
  display: flex;
  gap: var(--space-4);
  margin: var(--space-2) 0 var(--space-3);
}
.wizard-radio-group-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: var(--space-2) 0 var(--space-3);
}
.checkbox-row.block {
  margin: 0;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.checkbox-row.block:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-light);
}

.wizard-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-3);
  margin: var(--space-2) 0 var(--space-3);
}
.wizard-pick-card {
  display: block;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
  cursor: pointer;
  background: var(--panel);
}
.wizard-pick-card:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-light);
}
.wizard-pick-card input {
  margin-right: 6px;
}
.wizard-pick-main {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 4px 0 6px;
}
.wizard-pick-date {
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--ink-900);
}
.wizard-pick-summary {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--ink-700);
}

.wizard-tone-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-3);
  margin: var(--space-2) 0 var(--space-3);
}
.wizard-tone-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  cursor: pointer;
  background: var(--panel);
}
.wizard-tone-card:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-light);
}
.wizard-tone-card strong {
  font-size: var(--text-base);
  color: var(--ink-900);
}
.wizard-tone-card span {
  font-size: var(--text-sm);
  color: var(--ink-500);
}
.wizard-tone-card input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.wizard-fullletter-textarea {
  width: 100%;
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.6;
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.draft-section {
  padding: var(--space-4) var(--space-5);
}
.draft-section-removed {
  opacity: 0.6;
  background: var(--paper-sunken);
}

.final-review-list {
  list-style: none;
  margin: 0 0 var(--space-4);
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.final-review-list li {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
}

/* "What now?" contextual guidance — organisational suggestion only, never
   phrased as a legal/medical requirement (see js/util.js's whatNowHtml). */
.what-now {
  margin-top: var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--hero-tint);
  border-radius: var(--radius);
}
.what-now-title {
  margin: 0 0 6px;
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--accent-dark);
}
.what-now-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.what-now-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: var(--text-sm);
  color: var(--ink-700);
}

/* Incident-form contextual guidance (good/bad example) — additive, does not
   change the form's structure or fields. */
.incident-guidance {
  margin: 6px 0 10px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--paper-sunken);
}
.incident-guidance summary {
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--accent-dark);
}
.incident-guidance p {
  margin: 6px 0 0;
}
.incident-guidance-good { color: var(--ok); }
.incident-guidance-bad { color: var(--error); }

@media (max-width: 480px) {
  .wizard-card-grid,
  .wizard-tone-grid {
    grid-template-columns: 1fr;
  }
  .wizard-radio-group {
    flex-direction: column;
    gap: var(--space-2);
  }
}

/* "Information from" picker (shared record-form source selector — see
   js/views/informationFrom.js). Reuses existing field/button styling; these
   rules only lay out the radio options and the reveal panels. */
.infrom-field { border: 1px solid var(--border); border-radius: 10px; padding: var(--space-3); margin: 0 0 var(--space-3); }
.infrom-field > legend { font-weight: 600; padding: 0 6px; font-size: var(--text-sm); color: var(--ink-700); }
.infrom-options { display: flex; flex-direction: column; gap: 2px; margin-top: var(--space-2); }
.infrom-option { display: flex; align-items: center; gap: var(--space-2); padding: 7px 8px; border-radius: 8px; cursor: pointer; }
.infrom-option:hover { background: var(--paper-sunken); }
.infrom-option input { margin: 0; flex-shrink: 0; }
.infrom-option.infrom-me span { font-weight: 600; }
.infrom-subpanel { margin: var(--space-2) 0 0; padding: var(--space-3); background: var(--paper-sunken); border-radius: 8px; }
.infrom-subpanel input[type="text"] { width: 100%; }
.infrom-add-btn { margin-top: var(--space-2); }
