@import url('/static/design-tokens.css?v=20261012-ow');

/* ── MedVault — Clinical Light Theme ──────────────────────────────── */
/* Healthcare-grade design: teal accents, light surfaces, high contrast */

:root {
  /* Bridged onto the shared OpenWellness tokens (openwellness-tokens.css,
   * linked before this file); the --ow-* values switch with data-theme. */
  --bg:        var(--ow-bg);
  --surface:   var(--ow-surface);
  --input:     var(--ow-surface-2);
  --accent:    var(--ow-accent);
  --accent-hover: var(--ow-accent-2);
  --accent-light: var(--ow-accent-soft);
  --on-accent: var(--ow-on-accent);
  --on-status: var(--ow-bg);  /* ink on filled status/danger badges: AA in both themes */
  --success:   var(--ow-ok);
  --success-light: var(--ow-ok-bg);
  --warning:   var(--ow-warn);
  --warning-light: var(--ow-warn-bg);
  --danger:    var(--ow-danger);
  --danger-light: var(--ow-danger-bg);
  --text:      var(--ow-ink);
  --text-sec:  var(--ow-ink-2);
  --text-mute: var(--ow-ink-2);  /* real text, so AA ink-2 (ink-3 is placeholder-only) */
  --border:    var(--ow-line);
  --border-hover: rgba(27,29,27,.30);
  --font:      var(--ow-font-sans);
  --radius:    var(--ow-r-md);
  --shadow:    0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,.05), 0 2px 4px rgba(0,0,0,.03);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.06), 0 4px 6px rgba(0,0,0,.04);
}

/* ── Dark theme override — opt-in via <html data-theme="dark"> ─────────
 * Triggered explicitly by the topbar toggle button (state in
 * localStorage.mv_theme via static/theme.js). The legacy --bg / --text /
 * --surface family above is the light defaults; this block remaps the
 * structural tokens so components using either family stay readable in
 * dark mode. Accent and status colours switch with the --ow-* tokens;
 * text on their fills uses --on-accent / --on-status. */
:root[data-theme="dark"] {
  /* Colours come from the --ow-* dark block; only non-token values here. */
  --border-hover: rgba(241,243,239,.28);
  --shadow:    0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.5);
  --shadow-lg: 0 10px 24px rgba(0,0,0,0.6);
  --uuid-color: #fca5a5;   /* red-300 — clears 4.5:1 on the dark page and on --accent-light */
}

:root[data-theme="dark"] .uuid-cell { color: var(--uuid-color); }
:root[data-theme="dark"] .status-active,
:root[data-theme="dark"] .status-admitted { color: #6ee7b7; }  /* emerald-300 readable on dark surfaces */

/* Theme-toggle icon visibility — both icons live in the button DOM, CSS
 * picks which to show based on <html data-theme="...">. Works for both
 * lucide-driven (staff) and inline-SVG (portal) variants. */
.icon-dark-mode { display: none; }
:root[data-theme="dark"] .icon-light-mode { display: none; }
:root[data-theme="dark"] .icon-dark-mode { display: inline-block; }

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 15px;
  /* Reserve the vertical-scrollbar gutter even when not needed, so
     navigating between a short page and a long page doesn't shift
     the layout horizontally by ~15px (the OS scrollbar width). The
     gutter sits to the right of the content and the bar appears
     inside it when needed, exactly where the user expected. */
  scrollbar-gutter: stable;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.text-muted { color: var(--text-mute); font-size: .85rem; }
.text-error { color: var(--danger); }

/* ── Top bar ────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .6rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}

.topbar-brand {
  font-size: 1.25rem;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  letter-spacing: -.02em;
  color: var(--text);
}
.brand-icon { color: var(--accent); width: 22px; height: 22px; vertical-align: text-bottom; }

/* FM2: icon-size utility classes — replace inline style="width:Npx;height:Npx" so
   CSP can drop style-src 'unsafe-inline' (CM1). Apply on the lucide <i> element. */
.icon-14 { width: 14px; height: 14px; }
.icon-15 { width: 15px; height: 15px; }
.icon-16 { width: 16px; height: 16px; }
.icon-18 { width: 18px; height: 18px; vertical-align: text-bottom; }
.icon-48 { width: 48px; height: 48px; color: var(--text-mute); }

/* FM2 sweep 2: file-upload label affordance (label-as-button). */
.sidebar-action-btn.is-upload-label { cursor: pointer; }

/* FM2 sweep 2: small muted helper text. */
.text-xs-muted { font-size: 0.78rem; }

.topbar-right { display: flex; align-items: center; gap: .75rem; }

.user-badge {
  display: flex; align-items: center; gap: .4rem;
  font-size: .8rem; color: var(--text-sec);
  padding: .25rem .6rem; border-radius: 6px;
  background: var(--accent-light); border: 1px solid var(--border);
}
.user-badge .role-tag {
  font-size: .65rem; text-transform: uppercase; font-weight: 700;
  padding: .1rem .35rem; border-radius: 3px;
  background: var(--accent); color: var(--on-accent);
}

.btn-help {
  width: 30px; height: 30px; border-radius: 50%;
  border: 1.5px solid var(--border); background: transparent;
  color: var(--text-mute); font-size: .9rem; font-weight: 600;
  cursor: pointer; transition: all .2s;
  user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.btn-help:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }

.topbar-status { display: flex; align-items: center; gap: .4rem; font-size: .82rem; color: var(--text-mute); }
.staff-lang {
  background: transparent; color: var(--text-sec); border: 1px solid var(--border);
  border-radius: 6px; padding: .25rem .4rem; font-size: .78rem; font-family: var(--font);
  cursor: pointer; outline: none;
}
.staff-lang:hover { color: var(--text); border-color: var(--accent); }
.staff-lang:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(8,145,178,.15); }

.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.status-dot.online  { background: var(--success); box-shadow: 0 0 0 2px var(--success-light); }
.status-dot.offline { background: var(--text-mute); }
/* 2026-05-18 UX-RESID-11 — WCAG 1.4.1 (Use of Colour). Offline state
   was conveyed only by background colour, which is invisible to
   colour-blind users and to anyone reading the screen-reader output.
   The :after pseudo-element appends a textual "•" / "○" so the
   shape distinguishes the states even without colour, plus an
   aria-label-shaped visually-hidden caption when paired with
   .status-dot-label. */
.status-dot.online::after,
.status-dot.offline::after {
  content: "";
  position: absolute;
  width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); border: 0;
}
.status-dot.online::after { content: "online"; }
.status-dot.offline::after { content: "offline"; }
.status-dot { position: relative; }
.status-dot.offline {
  /* Visible non-colour cue — outline ring makes the dot look "empty"
     so a colour-blind user sees a state change between filled
     (online) and outlined (offline) regardless of palette. */
  background: transparent;
  border: 2px solid var(--text-mute);
  width: 12px; height: 12px;
}

/* ── Screens ────────────────────────────────────────────────────── */

.screen { max-width: 1100px; margin: 0 auto; padding: 1.5rem; }
#screen-patient { max-width: none; padding: 0; }
#screen-list { max-width: none; padding: 1.5rem; }

.back-link { display: inline-block; margin-bottom: 1rem; color: var(--text-mute); font-size: .9rem; font-weight: 500; }
.back-link:hover { color: var(--accent); text-decoration: none; }

/* ── Buttons ────────────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: .4rem; padding: .5rem 1.1rem; border: none; border-radius: 8px;
  font-family: var(--font); font-size: .875rem; font-weight: 600;
  cursor: pointer; transition: all .15s ease;
  text-decoration: none;
  /* Suppress text-selection on click — without this, clicking a button
   * label causes the browser's text-selection caret (the blinking I-beam)
   * to land inside the button, especially on WebKit/Edge. The button text
   * is decorative; users never want to copy "+ Care Plan" out of a button. */
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-primary  { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-outline  { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { border-color: var(--border-hover); background: var(--bg); }
.btn-danger   { background: var(--danger); color: var(--on-status); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 85%, var(--text)); }
.btn-lg       { padding: .7rem 1.8rem; font-size: .95rem; }
.btn-sm       { padding: .3rem .7rem; font-size: .8rem; min-height: 24px; }  /* WCAG 2.2 SC 2.5.8 */
.btn-accent   { background: var(--accent); color: var(--on-accent); border: 1px solid var(--accent); margin-left: auto; }
.btn-accent:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-success  { background: var(--success) !important; border-color: var(--success) !important; color: var(--on-status) !important; }

/* ── List Toolbar ───────────────────────────────────────────────── */

.list-toolbar { display: flex; gap: 1rem; align-items: center; margin-bottom: 1.25rem; }
.search-box { flex: 1; position: relative; }
.search-icon { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-mute); pointer-events: none; }
.search-box input {
  width: 100%; padding: .6rem 1rem .6rem 2.25rem; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface); color: var(--text);
  font-size: .95rem; font-family: var(--font); outline: none; transition: all .2s;
  box-shadow: var(--shadow);
}
.search-box input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(8,145,178,.12); }
.search-box input::placeholder { color: var(--text-mute); }

/* ── Data Table ─────────────────────────────────────────────────── */

#patient-table-wrap { overflow-x: auto; }

.data-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.data-table th {
  text-align: left; padding: .6rem .75rem; color: var(--text-mute);
  font-weight: 600; font-size: .78rem; text-transform: uppercase;
  letter-spacing: .04em; border-bottom: 2px solid var(--border); white-space: nowrap;
  background: var(--surface);
}
.data-table td { padding: .7rem .75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tbody tr { cursor: pointer; transition: background .12s; }
.data-table tbody tr:hover { background: var(--accent-light); }

.col-actions { width: 80px; text-align: center; }
.uuid-cell { font-family: "Cascadia Code", "Fira Code", "SF Mono", monospace; font-size: 1rem; font-weight: 600; color: #8b1a1a; }
.file-name-cell { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.status-active  { color: var(--success); font-weight: 600; }
.status-inactive { color: var(--text-mute); }

.btn-del-row {
  padding: .25rem .5rem; font-size: .75rem; background: transparent;
  color: var(--danger); border: 1px solid currentColor; border-radius: 6px;
  cursor: pointer; transition: all .15s;
}
.btn-del-row:hover { background: var(--danger); color: var(--on-status); border-color: var(--danger); }

.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-mute); font-size: 1rem; }

/* ── Form Card ──────────────────────────────────────────────────── */

.form-card { background: var(--surface); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow); max-width: 560px; border: 1px solid var(--border); }
.form-row { margin-bottom: 1rem; }
.form-row label { display: block; margin-bottom: .3rem; font-size: .82rem; color: var(--text-sec); font-weight: 600; }
.req { color: var(--danger); }
.form-row input, .form-row select, .form-row textarea {
  width: 100%; padding: .55rem .75rem; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface); color: var(--text);
  font-family: var(--font); font-size: .95rem; outline: none; transition: all .2s;
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(8,145,178,.1);
}
.form-row textarea { resize: vertical; }
.form-row-half { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

.more-fields { margin-bottom: 1.25rem; border: 1px solid var(--border); border-radius: 8px; padding: .5rem .75rem; }
.more-fields summary { cursor: pointer; color: var(--text-sec); font-size: .9rem; font-weight: 600; user-select: none; }
.more-fields[open] summary { margin-bottom: .75rem; }

.banner { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-size: .9rem; line-height: 1.4; }
.banner-error { background: var(--danger-light); border: 1px solid #FECACA; color: var(--danger); }
.banner-warn  { background: var(--warning-light); border: 1px solid #FDE68A; color: #92400E; }
.banner a { font-weight: 600; }

/* ── Patient Card ───────────────────────────────────────────────── */

.patient-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
  border-left: 4px solid var(--accent);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
}

.pc-main {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.pc-avatar {
  width: 52px; height: 52px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: var(--on-accent); font-size: 1.4rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.pc-info { flex: 1; min-width: 0; }
.pc-info h2 { font-size: 1.2rem; margin-bottom: .2rem; color: var(--text); }
.pc-meta { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; font-size: .85rem; color: var(--text-sec); }
.pc-uuid { font-family: "Cascadia Code", "Fira Code", "SF Mono", monospace; font-size: 1.15rem; font-weight: 700; letter-spacing: .03em; color: #8b1a1a; }
.pb-uuid { font-size: 1rem; font-weight: 600; color: #8b1a1a; font-family: "Cascadia Code", "Fira Code", monospace; }
.uuid-cell { font-family: "Cascadia Code", "Fira Code", "SF Mono", monospace; font-size: 1rem; font-weight: 600; color: #8b1a1a; }

/* Clinical alert badges */
.pb-alerts { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.alert-badge { display: inline-flex; align-items: center; gap: .25rem; padding: .15rem .5rem; border-radius: 4px; font-size: .78rem; font-weight: 600; cursor: default; }
.alert-badge--allergy { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-badge--nkda { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.alert-badge--fall { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.alert-badge--anticoag { background: #fce7f3; color: #9d174d; border: 1px solid #f9a8d4; }
.alert-badge--infection { background: #fef9c3; color: #854d0e; border: 1px solid #fde047; }
.alert-badge--other { background: #e0e7ff; color: #3730a3; border: 1px solid #a5b4fc; }
.alert-edit-btn { background: none; border: 1px dashed var(--border); border-radius: 4px; padding: .1rem .4rem; font-size: .72rem; color: var(--text-mute); cursor: pointer; display: inline-flex; align-items: center; gap: .2rem; }
.alert-edit-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Alert editor modal */
.alert-editor { display: flex; flex-direction: column; gap: .75rem; max-height: 60vh; overflow-y: auto; }
.alert-row { display: flex; align-items: center; gap: .5rem; padding: .4rem .5rem; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); }
.alert-row.active { border-color: var(--accent); background: rgba(8,145,178,.04); }
.alert-row label { display: flex; align-items: center; gap: .4rem; cursor: pointer; font-size: .85rem; font-weight: 500; white-space: nowrap; min-width: 140px; }
.alert-row input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }
.alert-row input[type="text"] { flex: 1; padding: .3rem .5rem; border: 1px solid var(--border); border-radius: 4px; font-size: .85rem; background: var(--surface); color: var(--text); outline: none; }
.alert-row input[type="text"]:focus { border-color: var(--accent); }
.alert-row input[type="text"]::placeholder { color: var(--text-mute); }
.alert-section-label { font-size: .75rem; color: var(--text-mute); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; margin-top: .25rem; }
.pc-clinic-badge { background: var(--accent-light); padding: .15rem .5rem; border-radius: 4px; font-size: .8rem; color: var(--accent); }

/* Correlation alerts in Trends tab */
.correlation-alerts { margin-bottom: 1rem; }
.correlation-card { border: 1px solid var(--border); border-radius: 8px; padding: .75rem; margin-bottom: .5rem; background: var(--surface); }
.correlation-card.high { border-left: 3px solid #DC2626; }
.correlation-card.medium { border-left: 3px solid #D97706; }
.corr-header { display: flex; align-items: center; gap: .5rem; margin-bottom: .4rem; }
.corr-evidence { margin: .3rem 0; padding-left: 1.2rem; font-size: .85rem; color: var(--text-sec); }
.corr-evidence li { margin-bottom: .15rem; }
.corr-rec { font-size: .82rem; color: var(--text-sec); font-style: italic; padding-top: .3rem; border-top: 1px solid var(--border); margin-top: .4rem; }

.pc-tags { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .4rem; }
.tag {
  padding: .15rem .5rem; border-radius: 12px; font-size: .75rem; font-weight: 600;
  background: var(--accent-light); color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
}

.pc-stats {
  display: flex; gap: 1.5rem; flex-shrink: 0;
}

.pc-stat { text-align: center; }
.pc-stat-num { display: block; font-size: 1.4rem; font-weight: 700; color: var(--accent); }
.pc-stat-label { font-size: .75rem; color: var(--text-mute); text-transform: uppercase; letter-spacing: .04em; }

/* ── Tabs ──────────────────────────────────────────────────────── */

.tab-bar {
  display: flex;
  /* Allow the 14-tab patient nav to wrap onto a second row at narrow
     widths instead of overflowing horizontally — operators on 13"
     laptops were losing the rightmost tabs behind the scroll edge. */
  flex-wrap: wrap;
  gap: 0;
  row-gap: 2px;
  margin-bottom: 1.25rem;
  border-bottom: 2px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 0 .5rem;
}
.tab {
  padding: .65rem 1.25rem; background: transparent; border: none;
  color: var(--text-mute); font-size: .9rem; font-weight: 500;
  cursor: pointer; border-bottom: 2px solid transparent;
  margin-bottom: -2px; transition: all .2s;
  font-family: var(--font);
  user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.tab:hover { color: var(--text-sec); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.tab-content { animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* ── Intake history panel (Docs tab) ─────────────────────────── */
.intake-panel-details {
  margin-top: 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.intake-panel-summary {
  cursor: pointer;
  padding: .75rem 1rem;
  font-weight: 600;
  color: var(--text-sec);
  display: flex;
  align-items: center;
  gap: .5rem;
  user-select: none;
}
.intake-panel-summary:hover { background: var(--bg); }
.intake-panel { padding: 1rem; }
.intake-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .75rem;
}
.intake-panel-title { font-size: 1rem; font-weight: 600; margin: 0; }
.intake-empty, .intake-error {
  padding: 1rem;
  text-align: center;
  color: var(--text-mute);
  font-style: italic;
}
.intake-list { list-style: none; margin: 0; padding: 0; }
.intake-row {
  padding: .65rem .5rem;
  border-bottom: 1px solid var(--border);
}
.intake-row:last-child { border-bottom: none; }
.intake-row-summary {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
}
.intake-row-filename {
  flex: 1 1 200px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.intake-row-meta {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .85rem;
  color: var(--text-mute);
}
.intake-row-source, .intake-row-count, .intake-row-time {
  white-space: nowrap;
}
.intake-row-expand {
  padding: .25rem .65rem;
  font-size: .8rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-sec);
}
.intake-row-expand:hover { background: var(--bg); }
.intake-row-extract {
  padding: .25rem .65rem;
  font-size: .8rem;
  background: transparent;
  border: 1px solid var(--accent, #4f46e5);
  border-radius: 4px;
  cursor: pointer;
  color: var(--accent, #4f46e5);
  margin-left: .35rem;
}
.intake-row-extract:hover { background: var(--accent, #4f46e5); color: var(--bg, white); }
.intake-row-detail {
  margin-top: .5rem;
  padding: .75rem;
  background: var(--bg);
  border-radius: 4px;
  font-size: .85rem;
}
.intake-detail-kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: .25rem .75rem;
  margin: 0;
}
.intake-detail-kv dt { color: var(--text-mute); font-weight: 500; }
.intake-detail-kv dd { margin: 0; }
.intake-detail-heading {
  margin: .75rem 0 .25rem;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-sec);
}
.intake-detail-json {
  max-height: 320px;
  overflow: auto;
  padding: .5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: .75rem;
  line-height: 1.4;
  white-space: pre;
}
.intake-detail-loading, .intake-detail-error {
  color: var(--text-mute);
  font-style: italic;
  margin: 0;
}

/* ── Encounter auto-coding suggestions ────────────────────────── */
.enc-coding-suggest-box {
  margin-top: .5rem;
  padding: .65rem .75rem;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  font-size: .85rem;
}
.enc-coding-suggest-box.hidden { display: none; }
.enc-coding-suggest-hint {
  color: var(--text-mute);
  font-size: .78rem;
  margin-bottom: .4rem;
}
.enc-coding-suggest-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .35rem;
  margin: .25rem 0;
}
.enc-coding-suggest-label {
  font-weight: 600;
  font-size: .72rem;
  color: var(--text-mute);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-right: .35rem;
}
.enc-coding-suggest-chip {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .25rem .6rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-family: var(--font);
  font-size: .8rem;
  color: var(--text-sec);
  transition: all .15s;
  max-width: 320px;
}
.enc-coding-suggest-chip:hover {
  background: var(--accent-soft, #e6f1fb);
  border-color: var(--accent);
  color: var(--accent);
}
.enc-coding-suggest-chip:disabled,
.enc-coding-suggest-chip-added {
  opacity: .55;
  cursor: default;
  pointer-events: none;
}
.enc-coding-suggest-code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: .75rem;
  font-weight: 600;
  color: var(--accent);
}
.enc-coding-suggest-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 250px;
}
.enc-coding-condition .enc-coding-suggest-code { color: #1e40af; }
.enc-coding-procedure .enc-coding-suggest-code { color: #065f46; }

/* Tier 1 #9 — BT BP cuff capture button + flash animation. */
.vitals-bt-row { margin-top: .65rem; }
.bt-bp-wrap {
  display: inline-flex;
  align-items: center;
  gap: .65rem;
}
.bt-bp-caveat {
  font-size: .8rem;
  color: var(--text-mute);
  font-style: italic;
}
.bt-bp-status { font-size: .85rem; }
.bt-bp-ok { color: #065f46; font-weight: 600; }
.bt-bp-err { color: #991b1b; }
@keyframes vitalsBtFlash {
  0%   { background: #fef3c7; }
  100% { background: transparent; }
}
.vitals-bt-flash { animation: vitalsBtFlash 1.2s ease-out; }

/* Status badges — color-coded by ingestion-job state. */
.intake-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .02em;
}
.intake-badge-extracted, .intake-badge-completed {
  background: #d1fae5; color: #065f46;
}
.intake-badge-processing, .intake-badge-queued {
  background: #fef3c7; color: #92400e;
}
.intake-badge-failed, .intake-badge-error {
  background: #fee2e2; color: #991b1b;
}
.intake-badge-unknown {
  background: var(--bg); color: var(--text-mute);
}
:root[data-theme="dark"] .intake-badge-extracted,
:root[data-theme="dark"] .intake-badge-completed {
  background: #064e3b; color: #d1fae5;
}
:root[data-theme="dark"] .intake-badge-processing,
:root[data-theme="dark"] .intake-badge-queued {
  background: #78350f; color: #fef3c7;
}
:root[data-theme="dark"] .intake-badge-failed,
:root[data-theme="dark"] .intake-badge-error {
  background: #7f1d1d; color: #fee2e2;
}

/* ── Dashboard Grid ────────────────────────────────────────────── */

.dash-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.dash-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.dash-card h3 {
  font-size: .9rem;
  color: var(--text-sec);
  margin-bottom: .75rem;
  padding-bottom: .4rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
}

.dash-card-wide { grid-column: 1 / -1; }

.ai-legacy-summary { font-size: .85rem; cursor: pointer; }
.ai-legacy-panel { margin-top: .5rem; }
.ai-legacy-copy { font-size: .82rem; }
.del-error {
  color: var(--danger);
  font-size: .85rem;
  margin: .35rem 0 0;
}

/* Bar chart rows */
.bar-row { display: flex; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.bar-label { width: 120px; font-size: .82rem; color: var(--text-sec); white-space: nowrap; }
.bar-track { flex: 1; height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-hover)); border-radius: 4px; transition: width .4s ease; }
.bar-count { width: 30px; text-align: right; font-size: .82rem; color: var(--text-sec); font-weight: 600; }

/* Report items */
.report-item {
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem .5rem; border-radius: 8px; transition: background .15s;
  cursor: pointer;
}
.report-item:hover { background: var(--bg); }
.report-icon { font-size: 1.3rem; }
.report-info { flex: 1; min-width: 0; }
.report-name { display: block; font-size: .88rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.report-meta { font-size: .75rem; color: var(--text-mute); }

/* Category badge */
.cat-badge { font-size: .8rem; color: var(--text-sec); white-space: nowrap; }

/* ── Drop Zone ──────────────────────────────────────────────────── */

.drop-zone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 3rem 1.5rem; text-align: center;
  transition: all .2s; cursor: pointer;
  background: var(--surface);
}
.drop-zone.drag-over { border-color: var(--accent); background: var(--accent-light); }
.drop-icon { font-size: 3rem; margin-bottom: .5rem; opacity: .4; }
.drop-zone p { color: var(--text-mute); margin-bottom: 1rem; }
.drop-buttons { display: flex; gap: .75rem; justify-content: center; }

/* ── File Queue ─────────────────────────────────────────────────── */

.file-queue { margin-top: 1.25rem; }
.file-queue h3 { font-size: .95rem; color: var(--text-sec); margin-bottom: .75rem; }
.file-queue ul { list-style: none; margin-bottom: 1rem; max-height: 320px; overflow-y: auto; }
.file-queue li {
  display: flex; align-items: center; gap: .75rem;
  padding: .5rem .75rem; background: var(--surface); border-radius: 8px;
  margin-bottom: .35rem; font-size: .88rem; border: 1px solid var(--border);
}
.fq-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fq-size { color: var(--text-mute); font-size: .8rem; white-space: nowrap; }
.fq-cat {
  padding: .15rem .5rem; border-radius: 4px; font-size: .75rem; font-weight: 600;
  background: var(--bg); color: var(--text-sec); white-space: nowrap;
}
.fq-cat.cat-dicom { background: var(--danger-light); color: var(--danger); }
.fq-remove { background: none; border: none; color: var(--text-mute); font-size: 1.1rem; cursor: pointer; padding: 0 .25rem; line-height: 1; }
.fq-remove:hover { color: var(--danger); }

/* ── Upload Progress ────────────────────────────────────────────── */

.upload-progress { margin-top: 1.25rem; text-align: center; }
.progress-bar { width: 100%; height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; margin-bottom: .75rem; }
.progress-fill { width: 0%; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-hover)); border-radius: 3px; transition: width .3s ease; }
.progress-fill.indeterminate { width: 30%; animation: progress-slide 1.2s ease-in-out infinite; }
@keyframes progress-slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(400%); } }
#progress-text { color: var(--text-sec); font-size: .9rem; }

/* ── Upload Results ─────────────────────────────────────────────── */

.upload-results { margin-top: 1.25rem; background: var(--surface); border-radius: var(--radius); padding: 1.25rem; border: 1px solid var(--border); }
.upload-results h3 { color: var(--success); margin-bottom: 1rem; }
.results-section { margin-bottom: 1.25rem; }
.results-actions { display: flex; gap: .75rem; margin-top: 1.25rem; }

/* ── Files Tab ─────────────────────────────────────────────────── */

.files-total { color: var(--text-sec); font-size: .85rem; margin-bottom: 1rem; }
.files-category { margin-bottom: 1.25rem; }
.files-category h4 {
  color: var(--text); font-size: .9rem; margin-bottom: .5rem;
  padding-bottom: .3rem; border-bottom: 1px solid var(--border);
}
.files-count {
  background: var(--accent-light); color: var(--accent);
  padding: .1rem .45rem; border-radius: 10px; font-size: .75rem; margin-left: .3rem; font-weight: 600;
}
.files-list { list-style: none; padding: 0; }
.files-list li { display: flex; align-items: center; gap: .75rem; padding: .4rem .5rem; border-radius: 6px; font-size: .85rem; }
.files-list li:hover { background: var(--bg); }
.fl-name { flex: 1; color: var(--text-sec); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fl-report { color: var(--success); font-weight: 600; }
.fl-size { color: var(--text-mute); font-size: .8rem; white-space: nowrap; }
.btn-view {
  padding: .2rem .6rem; background: var(--accent-light); border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  border-radius: 6px; color: var(--accent); font-size: .8rem; cursor: pointer; font-weight: 500;
}
.btn-view:hover { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

/* ── File Viewer ───────────────────────────────────────────────── */

.file-viewer { margin-top: .5rem; }
.viewer-header { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.viewer-header span { color: var(--text-sec); font-family: monospace; font-size: .85rem; }

.viewer-body {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem; color: var(--text);
  font-size: .85rem; line-height: 1.7; max-height: 70vh;
  overflow-y: auto; white-space: pre-wrap; word-wrap: break-word;
}

/* ── Markdown rendered ──────────────────────────────────────────── */

.md-rendered { white-space: normal; font-family: var(--font); font-size: .9rem; line-height: 1.6; }
.md-rendered h1 { font-size: 1.4rem; border-bottom: 2px solid var(--accent); padding-bottom: .4rem; margin: 1.5rem 0 .8rem; color: var(--accent); }
.md-rendered h2 { font-size: 1.15rem; border-bottom: 1px solid var(--border); padding-bottom: .3rem; margin: 1.3rem 0 .6rem; color: var(--text); }
.md-rendered h3 { font-size: 1.02rem; margin: 1rem 0 .5rem; color: var(--text-sec); }
.md-rendered h4 { font-size: .95rem; margin: .8rem 0 .4rem; color: var(--text-sec); }
.md-rendered p { margin: .5rem 0; }
.md-rendered strong { color: var(--text); }
.md-rendered em { color: var(--accent); }
.md-rendered hr { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }

.md-rendered table { width: 100%; border-collapse: collapse; margin: .8rem 0; font-size: .82rem; }
.md-rendered th { background: var(--bg); text-align: left; padding: .5rem .6rem; border: 1px solid var(--border); color: var(--accent); font-weight: 600; white-space: nowrap; }
.md-rendered td { padding: .4rem .6rem; border: 1px solid var(--border); vertical-align: top; }
.md-rendered tr:hover td { background: var(--accent-light); }

.md-rendered ul, .md-rendered ol { margin: .5rem 0 .5rem 1.5rem; }
.md-rendered li { margin: .25rem 0; }
.md-rendered li::marker { color: var(--accent); }

.md-rendered blockquote { border-left: 3px solid var(--accent); padding: .5rem 1rem; margin: .8rem 0; background: var(--accent-light); border-radius: 0 var(--radius) var(--radius) 0; }
.md-rendered blockquote p { margin: .3rem 0; }

.md-rendered code { background: var(--bg); padding: .15rem .4rem; border-radius: 4px; font-family: "Cascadia Code", "Fira Code", monospace; font-size: .82rem; color: var(--accent-hover); }
.md-rendered pre { background: #1E293B; border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem; overflow-x: auto; color: #E2E8F0; }
.md-rendered pre code { background: none; padding: 0; color: inherit; }

/* ── AI Prompt Panel ────────────────────────────────────────────── */

.ai-panel {
  width: 100%;
}

.ai-header { margin-bottom: 1rem; }
.ai-header h3 { font-size: 1.1rem; margin-bottom: .3rem; }

.ai-actions { display: flex; gap: .75rem; margin-bottom: 1rem; }

.ai-output {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  max-width: 1100px;
  max-height: 50vh;
  overflow-y: auto;
  margin-bottom: 1.25rem;
  font-size: .85rem;
  line-height: 1.6;
  box-shadow: var(--shadow);
}

.ai-instructions {
  background: var(--success-light);
  border: 1px solid #A7F3D0;
  border-radius: var(--radius);
  padding: 1.25rem;
}
.ai-instructions h4 { color: var(--success); margin-bottom: .5rem; font-size: .95rem; }
.ai-instructions ol { padding-left: 1.5rem; color: var(--text-sec); line-height: 1.8; }
.ai-instructions li { margin: .3rem 0; }
.ai-instructions strong { color: var(--text); }
.ai-instructions a { color: var(--accent); }

.ai-privacy-note {
  margin-top: .75rem;
  padding: .5rem .75rem;
  background: var(--warning-light);
  border: 1px solid #FDE68A;
  border-radius: 6px;
  font-size: .82rem;
  color: #92400E;
}

/* ── Modal ──────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.45);
  backdrop-filter: blur(4px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 2rem 1rem;
  overflow-y: auto;
  z-index: 200; animation: fade-in .15s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  background: var(--surface); border-radius: 12px; padding: 1.5rem;
  width: 90%; max-width: 440px; position: relative; box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.modal-close { position: absolute; top: .75rem; right: .75rem; background: none; border: none; color: var(--text-mute); font-size: 1.4rem; cursor: pointer; line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-card h3 { margin-bottom: .75rem; color: var(--text); }
.modal-card p { color: var(--text-sec); font-size: .9rem; margin-bottom: .75rem; line-height: 1.5; }
.modal-card .form-row {
  margin-bottom: 1rem;
  /* Anchor for absolutely-positioned typeahead dropdowns (.appt-patient-results,
   * etc.) so they pin under the input field instead of escaping the modal-card.
   * Without this they fell back to .modal-card as the nearest positioned ancestor
   * and rendered at the bottom of the modal, scrolling under the page. */
  position: relative;
}
/* Every input/select/textarea inside a modal (both .modal-card AND .modal-panel
 * variants) gets unified field styling regardless of which wrapper class the
 * JS component used (.form-row, .scoring-field, .form-group, or none at all).
 * Checkbox/radio/file/range/color are excluded because full-width padding+border
 * breaks their native shape. */
.modal-card input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="color"]),
.modal-card select,
.modal-card textarea,
.modal-panel input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="color"]),
.modal-panel select,
.modal-panel textarea {
  width: 100%; padding: .55rem .75rem; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface); color: var(--text);
  font-family: var(--font); font-size: .95rem; outline: none;
  box-sizing: border-box;
}
.modal-card select,
.modal-panel select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='none' stroke='%2352627A' stroke-width='1.5' d='M1 1l4 4 4-4'/></svg>");
  background-repeat: no-repeat; background-position: right .75rem center;
  padding-right: 2rem;
}
.modal-card input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="color"]):focus,
.modal-card select:focus,
.modal-card textarea:focus,
.modal-panel input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="color"]):focus,
.modal-panel select:focus,
.modal-panel textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(8,145,178,.1);
}
.modal-card .form-row label { display: block; margin-bottom: .3rem; font-size: .85rem; color: var(--text-sec); }
.modal-actions { display: flex; gap: .75rem; justify-content: flex-end; }

/* Shared modal layout helpers (me-preferences, admin-overrides,
 * doc-editor). Keeps the new modals on the same visual rails as the
 * existing .modal-card surfaces — header, tab strip, scrollable body,
 * footer actions. The two new wide variants extend .modal-card with
 * their own max-width because the personalization modals need more
 * horizontal room than the default 440px confirm/prompt cards. */
.mv-modal-wide  { max-width: 720px; }
.mv-modal-xwide { max-width: 900px; }
.mv-modal-tall  { max-height: 80vh; display: flex; flex-direction: column; padding: 0; }
.mv-modal-tall .mv-modal-header,
.mv-modal-tall .mv-modal-tabs,
.mv-modal-tall .mv-modal-footer { padding: .75rem 1rem; }
.mv-modal-tall .mv-modal-header {
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: .75rem;
}
.mv-modal-tall .mv-modal-header h3 { margin: 0; flex: 1; font-size: 1.05rem; }
.mv-modal-tall .mv-modal-tabs {
  border-bottom: 1px solid var(--border);
  display: flex; gap: .35rem;
  background: var(--bg);
}
.mv-modal-tall .mv-modal-tabs .btn { border-radius: 6px; }
.mv-modal-tall .mv-modal-tab-active { background: var(--surface-alt, var(--bg)); font-weight: 600; }
.mv-modal-tall .mv-modal-body { flex: 1; overflow: auto; padding: 1rem; }
.mv-modal-tall .mv-modal-footer {
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: .5rem;
  background: var(--bg);
}
.mv-modal-tall .mv-modal-footer .mv-flex-spacer { flex: 1; }
.mv-row { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .75rem; }
.mv-row > label { font-size: .82rem; color: var(--text-sec); font-weight: 600; }
.mv-list-item {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: .5rem .6rem; margin-bottom: .4rem;
  display: flex; align-items: flex-start; gap: .5rem;
}
.mv-list-item-main { flex: 1; min-width: 0; }
.mv-list-item-sub  { font-size: .8rem; color: var(--text-sec); margin-top: .15rem; }
.mv-chip { font-size: .7rem; padding: .12rem .4rem; border-radius: 10px;
            background: var(--bg); color: var(--text-sec); }
.mv-empty { padding: .75rem; color: var(--text-sec); font-size: .9rem; font-style: italic; }

/* doc-editor: side-by-side textarea + preview pane. The body slot is a
 * flex row; the textarea and preview each flex:1. .mv-doc-editor-body
 * replaces what the .mv-modal-tall .mv-modal-body slot would normally
 * be — the editor needs no inner scroll because the textarea owns it. */
.mv-doc-editor-body { flex: 1; display: flex; min-height: 0; }
.mv-doc-editor-edit { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.mv-doc-editor-meta { font-size: .72rem; color: var(--text-sec);
                       padding: .25rem .75rem;
                       border-bottom: 1px solid var(--border);
                       background: var(--bg); }
.mv-doc-editor-textarea {
  flex: 1; width: 100%; border: 0; resize: none;
  padding: .75rem;
  font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
  font-size: .86rem; line-height: 1.45; outline: none;
  background: var(--surface); color: var(--text); tab-size: 2;
}
.mv-doc-editor-preview {
  flex: 1; display: none; overflow: auto; padding: 1rem;
  border-left: 1px solid var(--border); background: var(--surface);
}
.mv-doc-editor-preview-open { display: block; }
.mv-doc-editor-status { flex: 1; font-size: .85rem; min-height: 1.2em; }
.mv-doc-editor-status[data-severity="error"]   { color: var(--danger); }
.mv-doc-editor-status[data-severity="success"] { color: var(--success, #1ca150); }
.mv-doc-editor-status:not([data-severity])     { color: var(--text-sec); }

/* Scoring modal layout — vertical centering for short content + wider card.
 * Default modal-overlay anchors content to flex-start; override here so the
 * scoring calculator (short, fixed-shape) sits in the optical center. The form
 * area defaults to max-height:350px (.mv-scroll-350); bump to 65vh so the
 * "Compute Score" button stays visible on most screens without inner scroll. */
#scoring-modal { align-items: center; }
#scoring-modal .modal-card { max-width: 560px; }
#scoring-modal #scoring-form { max-height: 65vh; }
#scoring-modal .scoring-compute-btn { margin-top: 0.75rem; }

.del-code { font-family: "Cascadia Code", "Fira Code", monospace; font-size: 2rem; font-weight: 700; text-align: center; padding: .75rem; background: var(--danger-light); border-radius: 8px; letter-spacing: .4rem; margin-bottom: .5rem; color: var(--danger); }
.del-timer { text-align: center; font-size: .8rem; color: var(--text-mute); margin-bottom: .75rem; }
.del-success { text-align: center; padding: 1.5rem 0; }
.del-check { display: inline-flex; align-items: center; justify-content: center; width: 56px; height: 56px; border-radius: 50%; background: var(--success-light); color: var(--success); font-size: 2rem; margin-bottom: .75rem; }
.del-success h3 { color: var(--success); }
.del-success p { color: var(--text-sec); }

/* ── Help Panel ────────────────────────────────────────────────── */

.help-panel {
  position: fixed; inset: 0; background: rgba(15,23,42,.45); backdrop-filter: blur(4px); z-index: 500;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 2rem 1rem; overflow-y: auto;
}
.help-card {
  background: var(--surface); border-radius: 12px;
  padding: 2rem 2.5rem; max-width: 700px; width: 100%;
  position: relative; box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.help-card h2 { color: var(--accent); margin-bottom: .25rem; }
.help-subtitle { color: var(--text-sec); margin-bottom: 1.5rem; }
.help-section { margin-bottom: 1.5rem; }
.help-section h3 { color: var(--text); font-size: 1rem; margin-bottom: .5rem; padding-bottom: .3rem; border-bottom: 1px solid var(--border); }
.help-section ol, .help-section ul { padding-left: 1.5rem; color: var(--text-sec); line-height: 1.8; }
.help-section li strong { color: var(--text); }
.help-section p { color: var(--text-sec); line-height: 1.6; }
.help-section pre { background: #1E293B; padding: .5rem .75rem; border-radius: 6px; font-size: .85rem; color: #8FE0CC; margin: .5rem 0; overflow-x: auto; }
.help-section code { background: var(--bg); padding: .15rem .4rem; border-radius: 4px; font-size: .85rem; }
.help-table { width: 100%; border-collapse: collapse; }
.help-table td { padding: .35rem .5rem; border-bottom: 1px solid var(--border); color: var(--text-sec); font-size: .9rem; }
.help-table td:first-child { color: var(--text); white-space: nowrap; width: 130px; font-weight: 500; }
.help-footer { padding-top: .5rem; border-top: 1px solid var(--border); }
.help-footer p { font-size: .85rem; }

/* ── Responsive ─────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .dash-grid { grid-template-columns: minmax(0, 1fr); }
  .dash-grid > * { min-width: 0; }
  .summary-section > div:first-child { flex-wrap: wrap; }
  .preop-header > .preop-header-actions {
    display: flex;
    flex-wrap: wrap;
    max-width: 100%;
  }
  .pc-main { flex-wrap: wrap; }
  .pc-stats { width: 100%; justify-content: center; margin-top: .75rem; }
  .list-toolbar { flex-direction: column; }
  .form-row-half { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .topbar {
    position: static;
    flex-wrap: wrap;
    gap: .5rem;
    padding: .6rem .75rem;
  }
  .topbar-right {
    flex-basis: 100%;
    flex-wrap: wrap;
    gap: .4rem;
    min-width: 0;
  }
  .topbar-status { margin-left: auto; }
  .patient-banner { position: static; }
  .screen { padding: 1rem .75rem; }
  .tab { padding: .5rem .75rem; font-size: .85rem; }
  .data-table { font-size: .82rem; }
  .data-table th, .data-table td { padding: .45rem .4rem; }
  .audit-row {
    grid-template-columns:
      minmax(80px, 1.2fr) minmax(45px, .6fr) minmax(0, 1.3fr) auto;
  }
  .audit-row > * { min-width: 0; overflow-wrap: anywhere; }
}

/* ── Scrollbar ──────────────────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-mute); }

/* ── Patient Banner (sticky) ──────────────────────────────────── */

.patient-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  position: sticky;
  top: 3rem;
  z-index: 50;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
}
.banner-back {
  color: var(--text-mute);
  text-decoration: none;
  font-size: 1.1rem;
  padding: 0.2rem;
}
.banner-back:hover { color: var(--accent); }
.pb-avatar {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: var(--on-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.pb-info { flex: 1; min-width: 0; }
.pb-name-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.pb-name-row h2 {
  font-size: 1rem;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.pb-uuid { font-size: 1rem; font-weight: 600; color: var(--text-sec); font-family: "Cascadia Code", "Fira Code", monospace; }
.pb-meta { font-size: 0.75rem; color: var(--text-sec); }
.pb-clinic {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  background: var(--accent-light);
  border-radius: 4px;
  color: var(--accent);
  font-weight: 500;
}
.pb-alerts-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem; margin-top: 0.15rem; }
.pb-allergy {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  background: var(--danger-light);
  color: var(--danger);
  border-radius: 4px;
  font-weight: 600;
}
.pb-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 0.3rem; flex-shrink: 0; }
.pb-upload-btn { cursor: pointer; }
.pb-stats { display: flex; gap: 0.75rem; font-size: 0.75rem; color: var(--text-sec); }

/* ── Branch Headers ────────────────────────────────────────────── */

.branch-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.branch-header h3 { font-size: 1rem; margin: 0; color: var(--text); }
.branch-actions { display: flex; gap: 0.3rem; flex-wrap: wrap; }

/* ── Visit Notes List ──────────────────────────────────────────── */

.visit-notes-list .note-card {
  background: var(--surface);
  border-radius: 8px;
  padding: 0.6rem 0.85rem;
  margin-bottom: 0.4rem;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  border: 1px solid var(--border);
}
.visit-notes-list .note-card:hover { background: var(--bg); border-color: var(--border-hover); }
.note-date { font-size: 0.78rem; color: var(--text-sec); min-width: 6rem; font-variant-numeric: tabular-nums; }
.note-type-badge {
  font-size: 0.65rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  font-weight: 600;
}
.note-type-badge.medical { background: #DBEAFE; color: #1D4ED8; }
.note-type-badge.aesthetic { background: #FCE7F3; color: #BE185D; }
.note-type-badge.procedure { background: #EDE9FE; color: #7C3AED; }
.note-detail { flex: 1; font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.note-card .note-chevron {
  color: var(--text-mute); transition: transform 0.2s; flex-shrink: 0;
}
.note-card.expanded .note-chevron { transform: rotate(90deg); }
.note-card.expanded { border-color: var(--accent); background: var(--accent-light); border-bottom-left-radius: 0; border-bottom-right-radius: 0; margin-bottom: 0; }

/* ── Inline Note Viewer ────────────────────────────────────────── */
.note-inline-viewer {
  background: var(--surface);
  border: 1px solid var(--accent);
  border-top: none;
  border-radius: 0 0 8px 8px;
  padding: 1rem;
  margin-bottom: 0.4rem;
  max-height: 50vh;
  overflow-y: auto;
  animation: slideDown 0.15s ease;
}
@keyframes slideDown { from { opacity: 0; max-height: 0; } to { opacity: 1; max-height: 50vh; } }
.note-inline-viewer .nv-toolbar {
  display: flex; align-items: center; gap: 0.5rem;
  margin-bottom: 0.6rem; padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem; color: var(--text-mute);
}
.note-inline-viewer .nv-toolbar .nv-filename { flex: 1; font-family: "Cascadia Code", "Fira Code", monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-inline-viewer .nv-body { font-size: 0.85rem; line-height: 1.6; }
.note-inline-viewer .nv-body .md-rendered { font-size: 0.85rem; }
.note-inline-viewer .nv-body pre { font-size: 0.8rem; line-height: 1.5; max-height: 40vh; overflow: auto; background: #1E293B; color: #E2E8F0; padding: 0.8rem; border-radius: 6px; white-space: pre-wrap; word-wrap: break-word; }
.note-inline-viewer .nv-body table.csv-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.note-inline-viewer .nv-body table.csv-table th { background: var(--bg); font-weight: 600; text-align: left; padding: 0.35rem 0.5rem; border: 1px solid var(--border); color: var(--accent); font-size: 0.75rem; text-transform: uppercase; }
.note-inline-viewer .nv-body table.csv-table td { padding: 0.3rem 0.5rem; border: 1px solid var(--border); }
.note-inline-viewer .nv-body table.csv-table tr:hover td { background: var(--accent-light); }
.note-inline-viewer .nv-body img.nv-image { max-width: 100%; max-height: 40vh; border-radius: 6px; box-shadow: var(--shadow); }

/* ── Rich JSON Viewer ──────────────────────────────────────────── */
.json-viewer { font-size: 0.85rem; }
.jv-section { }
.jv-nested { padding-left: 0.75rem; border-left: 2px solid var(--border); margin-left: 0.25rem; }
.jv-row {
  display: flex; gap: 0.75rem; padding: 0.3rem 0;
  border-bottom: 1px solid var(--border);
  align-items: baseline;
}
.jv-row:last-child { border-bottom: none; }
.jv-key {
  min-width: 140px; max-width: 200px; font-size: 0.78rem;
  color: var(--text-mute); font-weight: 500;
  flex-shrink: 0;
}
.jv-val { flex: 1; color: var(--text); word-break: break-word; }
.jv-str { color: var(--text); }
.jv-num { color: var(--accent); font-weight: 600; font-variant-numeric: tabular-nums; }
.jv-bool { color: var(--success); font-weight: 600; }
.jv-null { color: var(--text-mute); font-style: italic; }
.jv-group { margin: 0.6rem 0; }
.jv-group-title {
  font-size: 0.8rem; font-weight: 600; color: var(--accent);
  text-transform: uppercase; letter-spacing: 0.03em;
  padding: 0.3rem 0; margin-bottom: 0.2rem;
  border-bottom: 1px solid var(--accent);
  display: flex; align-items: center; gap: 0.3rem;
}
.jv-array-item {
  background: var(--bg); border-radius: 6px;
  padding: 0.5rem 0.75rem; margin-bottom: 0.35rem;
  border: 1px solid var(--border);
}

/* ── Photo Grid ────────────────────────────────────────────────── */

.photo-sessions h4 { font-size: 0.9rem; margin-bottom: 0.5rem; }
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.5rem;
}
.photo-session-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 0.5rem;
  cursor: pointer;
  transition: all 0.15s;
  border: 1px solid var(--border);
}
.photo-session-card:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.photo-session-card .ps-date { font-size: 0.78rem; color: var(--text-sec); }
.photo-session-card .ps-type { font-size: 0.7rem; color: var(--accent); text-transform: uppercase; font-weight: 600; }
.photo-session-card .ps-count { font-size: 0.75rem; color: var(--text-mute); }
.photo-session-card .ps-thumb {
  width: 100%;
  height: 120px;
  object-fit: cover;
  border-radius: 6px;
  margin-top: 0.3rem;
  background: var(--bg);
}

/* ── Upload Overlay ────────────────────────────────────────────── */

.upload-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15,23,42,0.45);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
.upload-overlay-content {
  background: var(--surface);
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
}

/* ── Trends ────────────────────────────────────────────────────── */

.trends-container { padding: 0.5rem 0; }
.trend-category { margin-bottom: 1rem; }
.trend-category-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-mute);
  margin-bottom: 0.3rem;
  padding-bottom: 0.2rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.trend-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}
.trend-row:hover { background: var(--accent-light); }
.trend-name { flex: 1; font-size: 0.82rem; color: var(--text); }
.trend-value { font-size: 0.85rem; font-weight: 600; min-width: 5rem; text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }
.trend-unit { font-size: 0.7rem; color: var(--text-mute); min-width: 3rem; }
.trend-sparkline { min-width: 80px; height: 20px; }
.trend-status {
  font-size: 0.65rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-weight: 600;
  min-width: 4rem;
  text-align: center;
}
.trend-status.normal { background: var(--success-light); color: var(--success); }
.trend-status.altered { background: var(--danger-light); color: var(--danger); }
.trend-status.borderline { background: var(--warning-light); color: var(--warning); }
.trend-chart {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 0.3rem 0 0.5rem 0;
  border: 1px solid var(--border);
}

/* ── Summary Profile Card ──────────────────────────────────────── */

.summary-metrics .sm-row {
  display: flex;
  justify-content: space-between;
  padding: 0.25rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.summary-metrics .sm-row:last-child { border-bottom: none; }
.sm-label { color: var(--text-sec); }
.sm-value { font-weight: 600; color: var(--text); }
.summary-profile .sp-row {
  display: flex;
  justify-content: space-between;
  padding: 0.2rem 0;
  font-size: 0.82rem;
}
.sp-label { color: var(--text-mute); }

/* ── Timeline ──────────────────────────────────────────────────── */

.timeline-container { padding: 0.5rem 0; }
.timeline-year { color: var(--accent); font-size: 1.1rem; font-weight: 700; margin: 1.2rem 0 0.5rem 0; }
.timeline-line {
  position: relative;
  margin-left: 1.5rem;
  padding-left: 1.5rem;
  border-left: 2px solid var(--border);
}
.tl-event {
  position: relative;
  padding: 0.5rem 0;
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}
.tl-event::before {
  content: "";
  position: absolute;
  left: -1.65rem;
  top: 0.75rem;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border);
  border: 2px solid var(--bg);
}
.tl-event.tl-visit::before { background: var(--accent); }
.tl-event.tl-lab::before { background: var(--success); }
.tl-event.tl-imaging::before { background: #3B82F6; }
.tl-event.tl-consent::before { background: var(--warning); }
.tl-event.tl-photo::before { background: #EC4899; }
.tl-event.tl-discharge::before { background: var(--text-mute); }
.tl-date {
  font-size: 0.78rem;
  color: var(--text-sec);
  min-width: 5.5rem;
  font-variant-numeric: tabular-nums;
}
.tl-icon { font-size: 0.9rem; min-width: 1.5rem; text-align: center; }
.tl-body { flex: 1; }
.tl-type {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-mute);
  font-weight: 600;
}
.tl-detail { font-size: 0.85rem; color: var(--text); }
.tl-empty { color: var(--text-mute); padding: 2rem; text-align: center; }

/* ── History Tree ──────────────────────────────────────────────── */

.history-tree { padding: 0.5rem 0; }
.ht-summary { font-size: 0.8rem; color: var(--text-mute); margin-bottom: 0.75rem; }
.ht-year {
  color: var(--accent); font-size: 1rem; font-weight: 700;
  margin: 1rem 0 0.4rem 0; padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}
.ht-year:first-of-type { border-top: none; padding-top: 0; }

/* Group (collapsible) */
.ht-group { margin-bottom: 0.3rem; }
.ht-group-header {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 0.75rem; cursor: pointer;
  border-radius: 8px; transition: background 0.15s;
}
.ht-group-header:hover { background: var(--accent-light); }
.ht-arrow {
  font-size: 0.65rem; color: var(--text-mute);
  transition: transform 0.2s; display: inline-block;
}
.ht-group.open > .ht-group-header .ht-arrow { transform: rotate(90deg); }
.ht-date { font-weight: 600; font-size: 0.85rem; min-width: 6rem; font-variant-numeric: tabular-nums; color: var(--text); }
.ht-badges { font-size: 0.75rem; color: var(--text-sec); }
.ht-preview { font-size: 0.78rem; color: var(--text-mute); margin-left: auto; max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Group body (hidden by default) */
.ht-group-body {
  display: none; padding: 0.25rem 0 0.5rem 1.8rem;
  border-left: 2px solid var(--border); margin-left: 0.9rem;
}
.ht-group.open > .ht-group-body { display: block; }

/* Events */
.ht-event { display: flex; align-items: center; gap: 0.5rem; padding: 0.25rem 0; font-size: 0.85rem; }
.ht-ev-icon { font-size: 0.8rem; min-width: 1.2rem; text-align: center; }
.ht-ev-type { font-size: 0.7rem; text-transform: uppercase; color: var(--text-mute); min-width: 5rem; }
.ht-ev-detail { color: var(--text); }
.ht-event-notes { font-size: 0.78rem; color: var(--text-sec); padding-left: 1.7rem; margin-bottom: 0.25rem; }

/* Files in group */
.ht-files { margin-top: 0.3rem; }
.ht-file {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.35rem 0.5rem; border-radius: 6px;
  font-size: 0.82rem; transition: background 0.15s;
}
.ht-file:hover { background: var(--accent-light); }
.ht-file-icon { font-size: 0.85rem; min-width: 1.2rem; text-align: center; }
.ht-file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.ht-file-cat { font-size: 0.7rem; color: var(--text-mute); min-width: 4rem; }
.ht-file-size { font-size: 0.7rem; color: var(--text-mute); min-width: 3.5rem; text-align: right; font-variant-numeric: tabular-nums; }
.ht-file-view { font-size: 0.85rem; opacity: 0.3; }
.ht-file:hover .ht-file-view { opacity: 1; color: var(--accent); }
.ht-file-dl {
  font-size: 0.85rem; text-decoration: none; color: var(--text-mute);
  opacity: 0.3; transition: opacity 0.15s;
}
.ht-file:hover .ht-file-dl { opacity: 1; color: var(--accent); }
.ht-report-badge {
  font-size: 0.6rem; background: var(--accent); color: var(--on-accent);
  padding: 0.1rem 0.35rem; border-radius: 4px; margin-left: 0.3rem;
  vertical-align: middle; font-weight: 600;
}

/* ── History Viewer ────────────────────────────────────────────── */

.hv-viewer { height: 100%; display: flex; flex-direction: column; }
.hv-header {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.5rem 0; border-bottom: 1px solid var(--border);
  margin-bottom: 0.5rem;
}
.hv-filename { flex: 1; font-size: 0.85rem; color: var(--text-sec); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hv-body { flex: 1; overflow: auto; }
.hv-image-wrap { text-align: center; padding: 1rem 0; }
.hv-image { max-width: 100%; max-height: 80vh; border-radius: var(--radius); box-shadow: var(--shadow-md); }
.hv-pdf-frame { width: 100%; height: 80vh; border: none; border-radius: var(--radius); }
.hv-markdown { padding: 1rem; line-height: 1.6; }
.hv-markdown h1, .hv-markdown h2, .hv-markdown h3 { margin-top: 1rem; color: var(--text); }
.hv-markdown table { border-collapse: collapse; width: 100%; margin: 0.5rem 0; }
.hv-markdown th, .hv-markdown td { border: 1px solid var(--border); padding: 0.3rem 0.6rem; font-size: 0.85rem; }
.hv-markdown th { background: var(--bg); font-weight: 600; }
.hv-code { background: #1E293B; color: #E2E8F0; padding: 1rem; border-radius: var(--radius); overflow-x: auto; font-size: 0.82rem; line-height: 1.5; white-space: pre-wrap; }

/* ── Follow-up Panels ──────────────────────────────────────────── */

.followup-container { padding: 0.5rem 0; }
.fu-section { margin-bottom: 1.5rem; }
.fu-section-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.fu-section-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
}
.fu-section-title.urgent { background: var(--danger-light); color: var(--danger); }
.fu-section-title.recommended { background: var(--warning-light); color: #92400E; }
.fu-section-title.screening { background: var(--success-light); color: var(--success); }
.fu-section-title.procedure { background: #EDE9FE; color: #7C3AED; }
.fu-section-title.monitoring { background: #DBEAFE; color: #1D4ED8; }

.fu-badge {
  font-size: 0.7rem;
  background: var(--bg);
  padding: 0.1rem 0.4rem;
  border-radius: 10px;
  color: var(--text-sec);
}

.fu-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  margin-bottom: 0.4rem;
  border-left: 3px solid var(--border);
}
.fu-panel.urgent { border-left-color: var(--danger); }
.fu-panel.recommended { border-left-color: var(--warning); }
.fu-panel.screening { border-left-color: var(--success); }
.fu-panel.procedure { border-left-color: #7C3AED; }

.fu-panel-name { font-weight: 600; font-size: 0.85rem; margin-bottom: 0.2rem; color: var(--text); }
.fu-panel-reason { font-size: 0.75rem; color: var(--text-sec); margin-bottom: 0.4rem; }

.fu-panel-tests { display: flex; flex-wrap: wrap; gap: 0.25rem; }

.fu-test-chip {
  font-size: 0.68rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  background: var(--bg);
  color: var(--text-sec);
}
.fu-test-chip.imaging { background: #DBEAFE; color: #1D4ED8; }
.fu-test-chip.functional { background: #EDE9FE; color: #7C3AED; }

.fu-monitoring-item {
  display: flex;
  justify-content: space-between;
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
  color: var(--text-sec);
  border-bottom: 1px solid var(--border);
}

.fu-monitoring-date { font-size: 0.72rem; color: var(--text-mute); }

.fu-empty {
  padding: 1rem;
  text-align: center;
  color: var(--text-mute);
  font-size: 0.85rem;
}

/* ── Physiologic State Selector ────────────────────────────────── */

.state-selector {
  margin: 0.5rem 0;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  border: 1px solid var(--border);
}
.state-label {
  font-size: 0.8rem;
  color: var(--text-sec);
  white-space: nowrap;
  font-weight: 500;
}
.state-options {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}
.state-chip {
  padding: 0.25rem 0.65rem;
  font-size: 0.78rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-sec);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  font-family: var(--font);
}
.state-chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }
.state-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.state-chip.active:hover { opacity: 0.9; }
.state-group-label {
  font-size: 0.7rem;
  color: var(--text-mute);
  padding: 0.2rem 0.4rem;
  align-self: center;
}
.state-divider {
  width: 1px;
  height: 1.2rem;
  background: var(--border);
  align-self: center;
  margin: 0 0.15rem;
}

/* ── Login Screen ──────────────────────────────────────────────── */

.login-container {
  max-width: 340px;
  margin: 15vh auto 0;
  text-align: center;
  padding: 2.5rem 2rem;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.login-icon { font-size: 3rem; margin-bottom: 0.5rem; }
.login-container h2 { margin-bottom: 0.25rem; color: var(--text); }
.login-container input {
  /* Was: only input[type="password"] got styled, so the email field
   * fell through to browser-native chrome and looked unfinished next
   * to the rounded password box. Broadened to all inputs in the login
   * container so every field shares the same shape. */
  width: 100%;
  padding: 0.6rem;
  margin-top: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  text-align: center;
  font-family: var(--font);
  /* Belt-and-braces — strip Webkit's auto-generated input chrome
   * (rounded outline, inset shadow on autofill) so the box looks
   * the same in Chromium, Firefox, and Safari. */
  -webkit-appearance: none;
  appearance: none;
  box-sizing: border-box;
}
.login-container input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(8,145,178,.1);
}
.login-container input::placeholder {
  color: var(--text-mute);
}

/* ── Clinical Timeline (vis-timeline) ─────────────────────────── */

.medical-timeline-wrap {
  margin-bottom: 1.2rem;
}

.tl-legend {
  display: flex;
  gap: 1rem;
  padding: 0.4rem 0;
  font-size: 0.75rem;
  color: var(--text-sec);
  flex-wrap: wrap;
}

.tl-legend-item { display: flex; align-items: center; gap: 0.3rem; }

.tl-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.medical-timeline {
  min-height: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

/* Override vis-timeline styles for light theme */
.vis-timeline {
  background: var(--surface) !important;
  border: none !important;
  font-family: var(--font) !important;
  color: var(--text) !important;
}
.vis-panel.vis-bottom, .vis-panel.vis-top,
.vis-panel.vis-left, .vis-panel.vis-right {
  border-color: var(--border) !important;
}
.vis-time-axis .vis-text { color: var(--text-sec) !important; font-size: 0.75rem !important; }
.vis-time-axis .vis-grid.vis-minor { border-color: rgba(0,0,0,.04) !important; }
.vis-time-axis .vis-grid.vis-major { border-color: rgba(0,0,0,.08) !important; }
.vis-item { color: var(--text) !important; font-size: 0.75rem !important; border-radius: 6px !important; }
.vis-item.vis-selected { border-color: var(--accent) !important; box-shadow: 0 0 0 2px rgba(8,145,178,.25) !important; }
.vis-item .vis-item-content { padding: 2px 6px !important; }
.vis-labelset .vis-label { color: var(--text-sec) !important; }
.vis-foreground .vis-group { border-bottom: 1px solid rgba(0,0,0,.04) !important; }
.vis-panel.vis-left { background: var(--bg) !important; }
.vis-current-time { background-color: var(--accent) !important; }
.vis-custom-time { background-color: var(--success) !important; }

.tl-report { font-weight: bold !important; }

/* ── Follow-up Recommendations Panel ─────────────────────────── */

.medical-followup {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.medical-followup h4 {
  font-size: 0.95rem;
  margin-bottom: 0.8rem;
  color: var(--text);
}

/* ── Clinical Form Modal ──────────────────────────────────────── */

.modal-card-full {
  width: 95vw;
  max-width: 900px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
}

.form-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 10;
}

.form-modal-header h3 { flex: 1; text-align: center; font-size: 1rem; }

.form-modal-body {
  padding: 1rem;
  overflow-y: auto;
  flex: 1;
}

/* json-editor overrides for light theme */
.form-modal-body .je-object__container { margin: 0; padding: 0; border: none; }
.form-modal-body .je-child-editor-holder { margin-left: 0; }
.form-modal-body .je-header { display: none; }

.form-modal-body div[data-schematype="object"] > h3,
.form-modal-body fieldset > legend,
.form-modal-body .je-object__title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
  margin: 1rem 0 0.4rem;
  padding-bottom: 0.2rem;
  border-bottom: 1px solid var(--border);
}

.form-modal-body label {
  display: block;
  font-size: 0.78rem;
  color: var(--text-sec);
  margin: 0.4rem 0 0.15rem;
  font-weight: 500;
}

.form-modal-body input[type="text"],
.form-modal-body input[type="number"],
.form-modal-body input[type="integer"],
.form-modal-body textarea,
.form-modal-body select {
  width: 100%;
  padding: 0.45rem 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.85rem;
  font-family: var(--font);
}

.form-modal-body textarea { min-height: 60px; resize: vertical; }

.form-modal-body input:focus, .form-modal-body textarea:focus,
.form-modal-body select:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(8,145,178,.1);
}

.form-modal-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.3rem 0;
}

.form-modal-body table th {
  font-size: 0.72rem;
  text-transform: uppercase;
  color: var(--text-sec);
  padding: 0.3rem 0.4rem;
  text-align: left;
  border-bottom: 2px solid var(--border);
  font-weight: 600;
}

.form-modal-body table td {
  padding: 0.2rem 0.3rem;
  border-bottom: 1px solid var(--border);
}

.form-modal-body table td input {
  background: var(--surface);
  border: 1px solid transparent;
  color: var(--text);
  padding: 0.3rem;
  width: 100%;
  font-size: 0.8rem;
  border-radius: 4px;
}

.form-modal-body table td input:focus {
  border-color: var(--accent);
  outline: none;
}

.form-modal-body button {
  background: var(--bg);
  color: var(--text-sec);
  border: 1px solid var(--border);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
  margin: 0.2rem;
  font-family: var(--font);
}

.form-modal-body button:hover { background: var(--border); }

/* Grid format for json-editor */
.form-modal-body div[data-schemaformat="grid"] > div {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.4rem;
}

/* ── Edit Modal ───────────────────────────────────────────────── */
.edit-form .form-row { margin-bottom: 0.5rem; }
.edit-form label { display: block; font-size: 0.78rem; color: var(--text-sec); margin-bottom: 0.15rem; font-weight: 500; }
.edit-form input, .edit-form select, .edit-form textarea {
  width: 100%; padding: 0.45rem 0.6rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; color: var(--text);
  font-size: 0.85rem; font-family: var(--font);
}
.edit-form input:focus, .edit-form select:focus, .edit-form textarea:focus {
  border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(8,145,178,.1);
}
.edit-form textarea { resize: vertical; min-height: 50px; }

/* ── Trend Charts ─────────────────────────────────────────────── */
.tc-info { display: flex; align-items: center; gap: 0.8rem; margin-bottom: 0.4rem; font-size: 0.8rem; }
.tc-label { color: var(--text-sec); }
.tc-status { font-size: 0.7rem; padding: 0.1rem 0.4rem; border-radius: 4px; }
.tc-normal { background: var(--success-light); color: var(--success); }
.tc-altered { background: var(--danger-light); color: var(--danger); }
.tc-count { color: var(--text-mute); font-size: 0.72rem; }
.tc-svg { width: 100%; max-width: 500px; height: auto; }

/* ── Before/After Comparison ──────────────────────────────────── */
.compare-header { display: flex; align-items: center; gap: 1rem; padding: 0.8rem 1rem; border-bottom: 1px solid var(--border); }
.compare-header h3 { flex: 1; }
.compare-body { display: flex; gap: 0; flex: 1; min-height: 300px; }
.compare-side { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 0.8rem; }
.compare-side h4 { font-size: 0.85rem; color: var(--text-sec); margin-bottom: 0.4rem; text-transform: uppercase; letter-spacing: 0.05em; }
.compare-slot { width: 100%; flex: 1; display: flex; align-items: center; justify-content: center; background: var(--bg); border: 1px dashed var(--border); border-radius: var(--radius); overflow: hidden; min-height: 250px; }
.compare-img { max-width: 100%; max-height: 400px; object-fit: contain; }
.compare-info { font-size: 0.75rem; color: var(--text-sec); margin-top: 0.3rem; }
.compare-divider { width: 2px; background: var(--accent); margin: 1rem 0; }
.compare-picker { padding: 0.8rem; border-top: 1px solid var(--border); max-height: 180px; overflow-y: auto; }
.compare-thumbs { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.compare-thumb { width: 80px; height: 80px; border-radius: 6px; overflow: hidden; cursor: pointer; position: relative; border: 2px solid var(--border); transition: border-color 0.2s; }
.compare-thumb:hover { border-color: var(--accent); }
.compare-thumb img { width: 100%; height: 100%; object-fit: cover; }
.ct-date { position: absolute; bottom: 0; left: 0; right: 0; background: rgba(0,0,0,0.6); color: #fff; font-size: 0.6rem; text-align: center; padding: 1px; }

/* ── Quick Vitals ─────────────────────────────────────────────── */
.quick-vitals { margin: 0.8rem 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.quick-vitals summary { cursor: pointer; padding: 0.5rem 0.8rem; font-size: 0.85rem; color: var(--text-sec); user-select: none; font-weight: 500; }
.quick-vitals summary:hover { color: var(--accent); }
.quick-vitals[open] summary { border-bottom: 1px solid var(--border); }
.qv-form { padding: 0.6rem 0.8rem; }
.qv-row { display: flex; gap: 0.4rem; margin-bottom: 0.4rem; flex-wrap: wrap; }
.qv-row label { font-size: 0.72rem; color: var(--text-sec); display: flex; flex-direction: column; gap: 0.15rem; flex: 1; min-width: 80px; font-weight: 500; }
.qv-row input { padding: 0.35rem 0.5rem; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 0.82rem; width: 100%; }
.qv-row input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 2px rgba(8,145,178,.1); }
.qv-row input[readonly] { opacity: 0.5; background: var(--bg); }
.qv-status { font-size: 0.78rem; margin-left: 0.5rem; }

/* ── Print Styles ─────────────────────────────────────────────── */
/* 2026-05-18 UX-RESID-5 — redefine the design tokens for print
   instead of overriding every component with hardcoded #fff / #000.
   When the user prints from dark mode, the tokens now cascade to
   white-on-black correctly without per-rule !important fights.
   Existing per-component hardcoded colors below stay as belt-and-
   braces for any element whose color isn't bound to a token. */
@media print {
  :root,
  :root[data-theme="dark"] {
    --bg: #fff;
    --surface: #fff;
    --surface-muted: #f5f5f5;
    --text: #000;
    --text-mute: #333;
    --text-sec: #444;
    --border: #ccc;
    --input: #fff;
    --on-dark: #000;
    --text-on-dark: #000;
  }
  body { background: #fff !important; color: #000 !important; }
  .topbar, .tab-bar, .patient-banner, .state-selector,
  .btn, button, .help-panel, .modal-overlay,
  .upload-overlay, .tl-legend, #medical-timeline-wrap,
  #aesthetic-timeline-wrap, .quick-vitals,
  .medical-followup, .branch-header { display: none !important; }

  .screen { display: block !important; }
  .tab-content { display: block !important; border: none !important; }
  .tab-content.hidden { display: none !important; }

  /* Show only the active tab content */
  #screen-patient { padding: 0 !important; }

  /* History viewer */
  .hv-viewer { background: #fff !important; }
  .hv-body, .hv-markdown { color: #000 !important; }
  .hv-markdown table { border-collapse: collapse; }
  .hv-markdown td, .hv-markdown th { border: 1px solid #ccc; padding: 4px 8px; }

  /* AI output (Phase I tightening) */
  .ai-actions { display: none !important; }
  .ai-header .text-muted { display: none !important; }

  /* EMR-DOCS Commit 5: patient contact print mode — hide everything
     except the now-collapsed sidebar drawer's body when
     body.patient-card-print-only is set. (Phase C originally printed
     the top-wide patient-card banner; the banner was deleted with
     Commit 5 in favour of the drawer.) */
  body.patient-card-print-only > :not(#screen-patient) { display: none !important; }
  body.patient-card-print-only #screen-patient .tab-content,
  body.patient-card-print-only #screen-patient .patient-tabs,
  body.patient-card-print-only #screen-patient .specialty-sidebar-compact-mount {
    display: none !important;
  }
  body.patient-card-print-only #sidebar-contact-drawer-body {
    display: block !important;  /* force-show even if currently collapsed */
  }
  body.patient-card-print-only .sidebar-contact-actions { display: none !important; }
  .ai-output { color: #000 !important; background: #fff !important; border: none !important; }
  .md-rendered { color: #000 !important; }
  .md-rendered table { border-collapse: collapse; }
  .md-rendered td, .md-rendered th { border: 1px solid #ccc; padding: 4px 8px; }

  /* Trend rows */
  .trend-row { color: #000 !important; }
  .trend-chart { background: #fff !important; border: 1px solid #ccc !important; }

  /* Note cards */
  .note-card { color: #000 !important; background: #f5f5f5 !important; }
}

/* ── Generic .form-control ─────────────────────────────────────────
   Themed input/select/textarea baseline. Several components (preop-tab,
   etc) use `<select class="form-control">` without local styling and
   previously fell back to white-on-black system widgets. */
.form-control,
select.form-control,
input.form-control,
textarea.form-control {
  background: var(--input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.55rem;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.3;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.form-control:focus,
select.form-control:focus,
input.form-control:focus,
textarea.form-control:focus {
  outline: none;
  border-color: var(--accent, #2563eb);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent, #2563eb) 25%, transparent);
}
select.form-control {
  /* Native select arrow respects color-scheme; both modes look right. */
  appearance: auto;
}
:root[data-theme="dark"] select.form-control option {
  background: var(--surface);
  color: var(--text);
}

/* ── Toast Notifications ──────────────────────────────────────── */
.toast-container {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  /* Above every modal-overlay (default 200 + any inline 9000) so a
     toast spawned while a modal is open is still visible. */
  z-index: 20000; display: flex; flex-direction: column-reverse; gap: 0.5rem;
  pointer-events: none;
}
.toast {
  padding: 0.65rem 1rem; border-radius: 8px;
  font-size: 0.85rem; font-weight: 500; font-family: var(--font);
  box-shadow: var(--shadow-lg); pointer-events: auto;
  display: flex; align-items: center; gap: 0.5rem;
  animation: toastIn 0.25s ease;
  max-width: 360px;
}
.toast.toast-success { background: var(--success); color: var(--on-status); }
.toast.toast-error { background: var(--danger); color: var(--on-status); }
.toast.toast-info { background: var(--accent); color: var(--on-accent); }
.toast.toast-warn { background: var(--warning); color: var(--on-status); }
.toast.toast-out { animation: toastOut 0.2s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(10px); } }

/* ── Focus states (accessibility) ─────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none; /* handled by box-shadow */
}

/* ── Reduced motion ───────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
.state-chip.pending-deselect { animation: pulse-warn 0.5s ease; border-color: #ef4444; }
@keyframes pulse-warn { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }

/* ── Encounter Form ─────────────────────────────────────────────── */
.encounter-panel {
  background: var(--bg); border-radius: 12px;
  width: min(900px, 95vw); max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.encounter-panel .modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.8rem 1rem; border-bottom: 1px solid var(--border);
}
.encounter-panel .modal-header h3 { font-size: 1rem; margin: 0; }
.encounter-body { padding: 0; overflow-y: auto; flex: 1; }

.enc-template-chip {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.6rem; padding: 0.45rem 1rem;
  background: var(--bg-mute, rgba(8,145,178,.06));
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem; color: var(--text-sec);
}
.enc-template-chip-name { font-weight: 600; color: var(--text); }
.enc-template-chip-blank {
  border: none; background: none; padding: 0;
  color: var(--accent); font-size: 0.78rem; cursor: pointer;
  text-decoration: underline;
}
.enc-template-chip-blank:hover { opacity: 0.8; }

.enc-tabs {
  display: flex; gap: 0; border-bottom: 2px solid var(--border);
  padding: 0 1rem; background: var(--surface);
}
.enc-tab {
  padding: 0.6rem 1rem; border: none; background: none;
  color: var(--text-sec); font-size: 0.82rem; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
}
.enc-tab:hover { color: var(--text); }
.enc-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.enc-content { padding: 1rem 1.2rem; min-height: 300px; }
.enc-section { margin-bottom: 1rem; }
.enc-label { display: block; font-weight: 600; font-size: 0.85rem; color: var(--text); margin-bottom: 0.5rem; }
.enc-textarea {
  width: 100%; padding: 0.5rem 0.7rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; color: var(--text);
  font-family: inherit; font-size: 0.85rem; resize: vertical;
}
.enc-textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(8,145,178,.1); }
.enc-input {
  padding: 0.4rem 0.6rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; color: var(--text);
  font-size: 0.85rem; width: 100%;
}
.enc-input:focus { border-color: var(--accent); outline: none; }

.vitals-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0.6rem; }
.vitals-field { display: flex; flex-direction: column; gap: 0.2rem; }
.vitals-field label { font-size: 0.78rem; color: var(--text-sec); font-weight: 500; }
.vitals-flag { font-size: 0.72rem; font-weight: 700; min-height: 1em; }
.flag-low { color: var(--severity-low, #3b82f6); }
.flag-high { color: var(--severity-high, #ef4444); }
.flag-normal { color: var(--severity-normal, #22c55e); }

.enc-status {
  padding: 0.5rem 1rem; font-size: 0.75rem; color: var(--text-sec);
  border-top: 1px solid var(--border); background: var(--surface);
}
.enc-summary { padding: 0.8rem; background: var(--surface); border-radius: 8px; margin-bottom: 1rem; font-size: 0.85rem; line-height: 1.5; }
.enc-summary-row { margin-bottom: 0.3rem; }
.enc-btn-row { display: flex; gap: 0.8rem; justify-content: flex-end; }
.enc-sign-section { padding-top: 0.5rem; }

/* Smart Note Recall */
.enc-recall-box {
  margin-top: 0.5rem; padding: 0.6rem; background: var(--surface);
  border: 1px solid var(--accent); border-radius: 8px;
}
.enc-recall-box.hidden { display: none; }
.recall-title { font-size: 0.75rem; color: var(--text-sec); margin-bottom: 0.4rem; font-weight: 600; }
.recall-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.3rem 0; border-bottom: 1px solid var(--border);
}
.recall-item:last-child { border-bottom: none; }
.recall-text { font-size: 0.82rem; color: var(--text); flex: 1; margin-right: 0.5rem; }
.btn-xs { padding: 0.15rem 0.5rem; font-size: 0.72rem; }

/* ── Rx Tab ──────────────────────────────────────────────────────── */
.rx-list { margin: 1rem 0; }
.rx-list h4 { font-size: 0.9rem; margin-bottom: 0.5rem; color: var(--text); }
.rx-card {
  padding: 0.6rem 0.8rem; background: var(--surface); border-radius: 8px;
  margin-bottom: 0.5rem; border: 1px solid var(--border);
}
.rx-card-header { display: flex; justify-content: space-between; align-items: center; }
.rx-uuid { font-size: 0.78rem; color: var(--text-sec); font-family: monospace; }
.rx-date { font-size: 0.75rem; color: var(--text-sec); margin-top: 0.2rem; }

/* ── Billing Tab ─────────────────────────────────────────────────── */
.billing-balance-card {
  padding: 1rem; background: var(--surface); border-radius: 10px;
  margin: 1rem 0; border: 1px solid var(--border);
}
.balance-row { display: flex; gap: 2rem; }
.balance-stat { flex: 1; text-align: center; }
.balance-label { font-size: 0.75rem; color: var(--text-sec); margin-bottom: 0.3rem; }
.balance-value { font-size: 1.3rem; font-weight: 700; color: var(--text); }
.balance-outstanding .balance-value { color: var(--severity-high, #ef4444); }
.balance-clear .balance-value { color: var(--severity-normal, #22c55e); }

.invoice-list { margin: 1rem 0; }
.invoice-list h4 { font-size: 0.9rem; margin-bottom: 0.5rem; }
.invoice-row {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.5rem 0.8rem; background: var(--surface); border-radius: 6px;
  margin-bottom: 0.4rem; border: 1px solid var(--border); font-size: 0.85rem;
}
.invoice-num { font-family: monospace; font-weight: 600; min-width: 90px; }
.invoice-date { color: var(--text-sec); min-width: 90px; }
.invoice-total { font-weight: 600; min-width: 80px; text-align: right; }

.packages-section { margin: 1rem 0; }
.packages-section h4 { font-size: 0.9rem; margin-bottom: 0.5rem; }
.pkg-card {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.5rem 0.8rem; background: var(--surface); border-radius: 6px;
  margin-bottom: 0.4rem; border: 1px solid var(--border);
}
.pkg-name { font-weight: 600; font-size: 0.85rem; }
.pkg-progress { font-size: 0.78rem; color: var(--text-sec); }
.membership-card {
  padding: 0.6rem 1rem; background: var(--accent); color: var(--on-accent);
  border-radius: 8px; font-size: 0.85rem; font-weight: 600; margin: 1rem 0;
}

/* ── Voice Dictation ─────────────────────────────────────────────── */
.voice-btn {
  position: absolute; top: 6px; right: 6px; width: 28px; height: 28px;
  border: none; border-radius: 50%; background: var(--surface);
  cursor: pointer; font-size: 14px; display: flex; align-items: center;
  justify-content: center; opacity: 0.6; transition: opacity 0.2s;
}
.voice-btn:hover { opacity: 1; }
.voice-btn.voice-active { background: #ef4444; opacity: 1; animation: pulse-voice 1s infinite; }
.dictating { border-color: #ef4444 !important; box-shadow: 0 0 0 3px rgba(239,68,68,.15) !important; }
@keyframes pulse-voice { 0%,100% { transform: scale(1); } 50% { transform: scale(1.1); } }

/* ── Analytics Dashboard ─────────────────────────────────────────── */
.analytics-kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.8rem; margin-bottom: 1rem; }
.kpi-card {
  padding: 0.8rem; background: var(--surface); border-radius: 8px;
  border: 1px solid var(--border); text-align: center;
}
.kpi-value { font-size: 1.4rem; font-weight: 700; color: var(--text); }
.kpi-label { font-size: 0.75rem; color: var(--text-sec); margin-top: 0.2rem; }
.kpi-warn .kpi-value { color: var(--severity-high, #ef4444); }
.analytics-section { margin-top: 1rem; }
.analytics-section h4 { font-size: 0.9rem; margin-bottom: 0.5rem; }
.analytics-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.analytics-table th { background: var(--surface); padding: 0.5rem; text-align: left;
  font-size: 0.78rem; color: var(--text-sec); border-bottom: 2px solid var(--border); }
.analytics-table td { padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--border); }
@media (max-width: 768px) { .analytics-kpi-row { grid-template-columns: repeat(2, 1fr); } }

/* ── Face Diagram ────────────────────────────────────────────────── */
.face-diagram-section { margin: 0.8rem 0; }
.face-diagram-section summary { font-weight: 600; font-size: 0.9rem; cursor: pointer; padding: 0.5rem; }
.face-svg { display: block; margin: 0 auto; }
.face-outline { fill: none; stroke: var(--text-sec); stroke-width: 1.5; }
.face-feature { fill: none; stroke: var(--text-sec); stroke-width: 1; }
.zone-area { fill: rgba(8,145,178,0.08); stroke: rgba(8,145,178,0.3); stroke-width: 1;
  transition: fill 0.15s, stroke 0.15s; }
.zone-area:hover { fill: rgba(8,145,178,0.2); stroke: var(--accent); }
.zone-area.zone-selected { fill: rgba(8,145,178,0.3); stroke: var(--accent); stroke-width: 2; }
.zone-label { font-size: 6px; text-anchor: middle; fill: var(--text-sec); pointer-events: none; }
.injection-marker { fill: #ef4444; stroke: white; stroke-width: 1.5; }
.face-info-panel { padding: 0.8rem; margin-top: 0.5rem; background: var(--surface);
  border-radius: 8px; font-size: 0.85rem; }
.injection-form { display: grid; grid-template-columns: auto 1fr; gap: 0.4rem; align-items: center; margin-top: 0.5rem; }
.injection-form label { font-size: 0.8rem; font-weight: 500; }
.injection-form .btn { grid-column: span 2; justify-self: end; margin-top: 0.3rem; }

/* ── Messaging ───────────────────────────────────────────────────── */
.msg-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.8rem; }
.msg-header h3 { margin: 0; font-size: 1rem; }
.msg-badge { background: var(--danger); color: var(--on-status); font-size: 0.7rem; padding: 0.1rem 0.45rem;
  border-radius: 10px; margin-left: 0.5rem; font-weight: 700; }
.msg-list { display: flex; flex-direction: column; gap: 0.3rem; }
.msg-row { display: grid; grid-template-columns: 120px 1fr 130px; gap: 0.5rem; padding: 0.5rem 0.7rem;
  background: var(--surface); border-radius: 6px; border: 1px solid var(--border);
  cursor: pointer; font-size: 0.85rem; transition: background 0.15s; }
.msg-row:hover { background: var(--bg); }
.msg-row.msg-unread { border-left: 3px solid var(--accent); font-weight: 600; }
.msg-sender { font-weight: 600; color: var(--text); }
.msg-subject { color: var(--text-sec); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-date { font-size: 0.75rem; color: var(--text-sec); text-align: right; }
.msg-detail { padding: 0.5rem; }
.msg-from { font-weight: 600; margin: 0.5rem 0; }
.msg-subj { font-size: 1.1rem; font-weight: 600; margin-bottom: 0.5rem; }
.msg-body { background: var(--surface); padding: 1rem; border-radius: 8px; font-size: 0.9rem; line-height: 1.5; white-space: pre-wrap; }
.msg-compose { display: flex; flex-direction: column; gap: 0.5rem; }
.msg-compose label { font-size: 0.82rem; font-weight: 500; }

/* ── Patient Summary Widget ──────────────────────────────────────── */
.summary-section { margin-bottom: 1rem; }
.summary-section h4 { font-size: 0.85rem; font-weight: 600; color: var(--text); margin-bottom: 0.4rem; }
.summary-action { padding: 0.4rem 0.6rem; background: var(--surface); border-radius: 6px;
  border-left: 3px solid var(--accent); margin-bottom: 0.3rem; font-size: 0.82rem; }
.summary-action.priority-high { border-left-color: #ef4444; }
.summary-action.priority-medium { border-left-color: #f59e0b; }
.summary-action.priority-low { border-left-color: #22c55e; }
.summary-plan-card { display: flex; align-items: center; gap: 0.8rem; padding: 0.5rem 0.6rem;
  background: var(--surface); border-radius: 6px; margin-bottom: 0.3rem; }
.plan-name { font-weight: 600; font-size: 0.85rem; min-width: 150px; }
.progress-bar { flex: 1; height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 4px; transition: width 0.3s; }
.progress-text { font-size: 0.75rem; color: var(--text-sec); min-width: 80px; text-align: right; }

/* ── Scheduler Calendar ────────────────────────────────────────────── */
.sched-toolbar { display: flex; align-items: center; gap: .5rem; padding: .75rem 0; flex-wrap: wrap; }
.sched-month-label { font-size: 1.1rem; font-weight: 700; flex: 1; text-align: center; }

.sched-calendar {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px;
  background: var(--border); border-radius: var(--radius); overflow: hidden;
  margin-bottom: 1rem;
}
.sched-day-header {
  background: var(--accent); color: var(--on-accent); text-align: center;
  padding: .4rem; font-size: .75rem; font-weight: 600; text-transform: uppercase;
}
.sched-cell {
  background: var(--surface); padding: .5rem; min-height: 60px; cursor: pointer;
  transition: background .15s; position: relative;
}
.sched-cell:hover { background: var(--accent-light); }
.sched-cell-muted { background: var(--bg); color: var(--text-mute); cursor: default; }
.sched-cell-today { background: #FFFBEB; }
/* axe color-contrast (sweep 2026-05-09): amber-600 var(--warning) #D97706
 * on #FFFBEB is 3.07:1; WCAG AA at this size needs 4.5:1. amber-800
 * #92400E gives ~7:1. Local override only — --warning unchanged elsewhere. */
.sched-cell-today .sched-cell-num { color: #92400E; font-weight: 700; }
.sched-cell-selected { outline: 2px solid var(--accent); outline-offset: -2px; z-index: 1; }
.sched-cell-num { font-size: .85rem; font-weight: 500; }
.sched-cell-dots { display: flex; gap: 3px; margin-top: 4px; flex-wrap: wrap; }
.sched-dot { width: 6px; height: 6px; border-radius: 50%; }

.sched-day-panel { background: var(--surface); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.sched-day-header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: .75rem; }
.sched-day-header-row h4 { font-size: 1rem; font-weight: 600; }

.sched-appt-card {
  display: grid; grid-template-columns: 80px 1fr auto auto;
  align-items: center; gap: .75rem; padding: .65rem .75rem;
  border-bottom: 1px solid var(--border); font-size: .85rem;
}
.sched-appt-card:last-child { border-bottom: none; }
.sched-appt-time { font-weight: 600; color: var(--accent); font-size: .82rem; }
.sched-appt-notes { font-size: .75rem; margin-top: 2px; }
.sched-status-badge {
  font-size: .7rem; padding: .15rem .45rem; border-radius: 4px;
  color: var(--on-status); text-transform: capitalize; white-space: nowrap;
}
.sched-appt-actions { display: flex; gap: .3rem; }
.summary-rx-row { font-size: 0.82rem; padding: 0.3rem 0; color: var(--text-sec); }
.summary-balance-warn { padding: 0.6rem; background: rgba(239,68,68,0.1); border-radius: 6px;
  color: #ef4444; font-weight: 600; font-size: 0.85rem; }

/* ── Patient Sidebar Layout (Epic Storyboard) ──────────────────────── */

.patient-layout {
  display: flex;
  gap: 0;
  min-height: calc(100vh - var(--mv-topbar-height, 52px));
}

.patient-sidebar {
  width: var(--mv-sidebar-width, 260px);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1rem 0.75rem;
  overflow-y: auto;
  position: sticky;
  top: var(--mv-topbar-height, 52px);
  height: calc(100vh - var(--mv-topbar-height, 52px));
}

.patient-content {
  flex: 1;
  min-width: 0;
  padding: 0;
}

/* Sidebar sections */
.sidebar-section {
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-section:last-child { border-bottom: none; }

/* Identity */
.sidebar-identity { text-align: center; }
.sidebar-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 700;
  margin: 0 auto 0.4rem;
  border: 2px solid var(--accent);
}
.sidebar-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.15rem;
  word-break: break-word;
}
.sidebar-uuid {
  font-size: 0.72rem;
  font-family: var(--mv-font-mono, monospace);
  color: var(--text-mute);
  cursor: pointer;
}
.sidebar-uuid:hover { color: var(--accent); }
.sidebar-meta {
  font-size: 0.82rem;
  color: var(--text-sec);
  margin-top: 0.2rem;
}
.sidebar-clinic {
  font-size: 0.78rem;
  color: var(--text-mute);
  margin-top: 0.1rem;
}

/* Alerts */
.sidebar-alerts { display: flex; flex-direction: column; gap: 0.3rem; }
.sidebar-alerts .alert-badge { font-size: 0.75rem; }
.sidebar-section-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-mute);
  margin-bottom: 0.35rem;
}

/* MRI-safety banner — Unification Slice 3 implants panel. Surfaced
   when any active device is mri_unsafe or mri_conditional. */
.sidebar-mri-banner {
  font-size: 0.72rem;
  font-weight: 600;
  color: #92400e;
  background: #fef3c7;
  border-left: 3px solid #f59e0b;
  padding: 0.35rem 0.5rem;
  border-radius: 3px;
  margin-bottom: 0.4rem;
}

/* Inline checkbox+label rows in modals. Without this the form-row's
   `label { display: block }` rule stacks the checkbox above the
   text. Used by the family-history "Deceased" toggle. */
.form-row label.mv-checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  cursor: pointer;
}
.form-row label.mv-checkbox-label input[type="checkbox"] {
  margin: 0;
  width: auto;
}

/* Active Meds mini list */
.sidebar-meds-list { display: flex; flex-direction: column; gap: 0.2rem; }
.sidebar-med-item {
  font-size: 0.8rem;
  color: var(--text-sec);
  padding: 0.15rem 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-med-item::before {
  content: "\2022";
  color: var(--accent);
  margin-right: 0.35rem;
  font-weight: 700;
}

/* Next appointment */
.sidebar-next-appt {
  font-size: 0.82rem;
  color: var(--text-sec);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.sidebar-appt-date { font-weight: 600; color: var(--text); }
.sidebar-appt-type { font-size: 0.75rem; color: var(--text-mute); }

/* Quick actions */
.sidebar-quick-actions { display: flex; flex-direction: column; gap: 0.3rem; }
.sidebar-action-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.6rem;
  font-size: 0.82rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-sec);
  cursor: pointer;
  transition: all var(--mv-transition-fast, 150ms ease);
}
.sidebar-action-btn:hover {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

/* Stats row */
.sidebar-stats { display: flex; flex-direction: column; gap: 0.25rem; }
.sidebar-stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-sec);
}
.sidebar-stat-row strong { color: var(--text); }

/* Back link in sidebar */
.sidebar-back {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.82rem;
  color: var(--text-mute);
  margin-bottom: 0.5rem;
  cursor: pointer;
}
.sidebar-back:hover { color: var(--accent); text-decoration: none; }

/* ── Mobile Patient Banner ──────────────────────────────────────────── */

.patient-banner-mobile {
  display: none;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.patient-banner-mobile .mob-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  font-weight: 700;
  flex-shrink: 0;
}
.patient-banner-mobile .mob-info { flex: 1; min-width: 0; }
.patient-banner-mobile .mob-name {
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.patient-banner-mobile .mob-meta {
  font-size: 0.75rem;
  color: var(--text-mute);
}
.patient-banner-mobile .mob-alerts {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
}
.patient-banner-mobile .mob-back {
  font-size: 1.1rem;
  color: var(--text-mute);
  cursor: pointer;
  flex-shrink: 0;
}

/* ── Command Palette ───────────────────────────────────────────────── */

.command-palette-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: var(--mv-z-modal, 200);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
}
.command-palette-card {
  width: 520px;
  max-width: 90vw;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.command-palette-card input {
  width: 100%;
  padding: 0.85rem 1rem;
  font-size: 1rem;
  border: none;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  outline: none;
}
.command-palette-card input::placeholder { color: var(--text-mute); }
.cmd-results {
  max-height: 320px;
  overflow-y: auto;
}
.cmd-result-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 1rem;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
  transition: background var(--mv-transition-fast, 150ms ease);
}
.cmd-result-item:hover, .cmd-result-item.active {
  background: var(--accent-light);
}
.cmd-result-item .cmd-icon {
  width: 18px;
  height: 18px;
  color: var(--text-mute);
  flex-shrink: 0;
}
.cmd-result-item .cmd-label { flex: 1; }
.cmd-result-item .cmd-shortcut {
  font-size: 0.72rem;
  color: var(--text-mute);
  font-family: var(--mv-font-mono, monospace);
}
.cmd-empty {
  padding: 1.5rem;
  text-align: center;
  color: var(--text-mute);
  font-size: 0.85rem;
}

/* ── Responsive: Sidebar collapse & hide ───────────────────────────── */

@media (max-width: 1024px) {
  .patient-sidebar {
    width: var(--mv-sidebar-collapsed, 60px);
    padding: 0.5rem 0.3rem;
    overflow: hidden;
  }
  .patient-sidebar .sidebar-section-title,
  .patient-sidebar .sidebar-name,
  .patient-sidebar .sidebar-uuid,
  .patient-sidebar .sidebar-meta,
  .patient-sidebar .sidebar-clinic,
  .patient-sidebar .sidebar-meds-list,
  .patient-sidebar .sidebar-next-appt,
  .patient-sidebar .sidebar-stat-row,
  .patient-sidebar .sidebar-back,
  .patient-sidebar .alert-badge { display: none; }
  .patient-sidebar .sidebar-avatar {
    width: 40px;
    height: 40px;
    font-size: 1rem;
    margin: 0 auto 0.3rem;
  }
  .patient-sidebar .sidebar-action-btn {
    padding: 0.4rem;
    justify-content: center;
  }
  .patient-sidebar .sidebar-action-btn span { display: none; }
}

@media (max-width: 768px) {
  .patient-sidebar { display: none; }
  .patient-banner-mobile { display: flex; }
  .patient-layout { flex-direction: column; }
}

/* ── Rx Tab ─────────────────────────────────────────────────────────── */

.rx-card {
  padding: 0.6rem 0.8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.4rem;
}
.rx-card-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.rx-uuid { font-size: 0.8rem; font-family: var(--mv-font-mono, monospace); color: var(--text-mute); }
.rx-date { font-size: 0.8rem; color: var(--text-sec); }
.rx-items-list { margin-top: 0.4rem; padding-top: 0.4rem; border-top: 1px solid var(--border); }
.rx-item-display {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.2rem 0;
  font-size: 0.82rem;
}
.rx-item-name { font-weight: 600; color: var(--text); }
.rx-item-detail { color: var(--text-sec); font-size: 0.78rem; }
.rx-actions {
  display: flex;
  gap: 0.3rem;
  margin-top: 0.4rem;
  flex-wrap: wrap;
}
.rx-action-btn { font-size: 0.75rem; padding: 0.2rem 0.5rem; }
.rx-form-item-row {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
}
.rx-form-item-row input, .rx-form-item-row select {
  font-size: 0.85rem;
  padding: 0.35rem 0.5rem;
}
.rx-search-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow-md);
  z-index: var(--mv-z-dropdown, 100);
  max-height: 200px;
  overflow-y: auto;
}
.rx-search-option {
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
  cursor: pointer;
}
.rx-search-option:hover { background: var(--accent-light); }
.rx-interaction-alert {
  padding: 0.4rem 0.6rem;
  margin: 0.3rem 0;
  border-radius: var(--radius);
  font-size: 0.82rem;
}
.rx-interaction-warning { background: var(--warning-light); color: var(--warning); }
.rx-interaction-critical { background: var(--danger-light); color: var(--danger); }
.rx-interaction-ok { padding: 0.4rem; font-size: 0.82rem; color: var(--success); }

/* ── Billing Tab (expanded) ────────────────────────────────────────── */

.invoice-detail {
  padding: 0.6rem 0.8rem;
  background: var(--bg);
  border-radius: 0 0 var(--radius) var(--radius);
  border: 1px solid var(--border);
  border-top: none;
  margin-bottom: 0.4rem;
}
.invoice-items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  margin-bottom: 0.5rem;
}
.invoice-items-table th {
  text-align: left;
  padding: 0.3rem 0.4rem;
  border-bottom: 2px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-sec);
  font-weight: 600;
}
.invoice-items-table td {
  padding: 0.25rem 0.4rem;
  border-bottom: 1px solid var(--border);
}
.payment-form {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}
.payment-form input, .payment-form select {
  font-size: 0.85rem;
  padding: 0.35rem 0.5rem;
}
.payment-row {
  display: flex;
  gap: 0.5rem;
  font-size: 0.8rem;
  padding: 0.2rem 0;
  color: var(--text-sec);
}
.invoice-row { cursor: pointer; transition: background var(--mv-transition-fast, 150ms ease); }
.invoice-row:hover { background: var(--accent-light); }

/* ── Consent Component ─────────────────────────────────────────────── */

.consent-card {
  padding: 0.5rem 0.7rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.3rem;
}

/* ── Encounter Enhancements ────────────────────────────────────────── */

.enc-macro-dropdown {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  /* Must sit ABOVE .modal-overlay (z-index 200) — the macro dropdown is
   * appended to document.body from inside the encounter modal, so the
   * default --mv-z-dropdown (100) renders it behind the modal's
   * backdrop-filter blur. Use --mv-z-tooltip (400) which is the right
   * tier for modal-spawned popups. */
  z-index: var(--mv-z-tooltip, 400);
  max-height: 180px;
  overflow-y: auto;
  min-width: 200px;
}
.enc-macro-item {
  padding: 0.35rem 0.6rem;
  font-size: 0.82rem;
  cursor: pointer;
}
.enc-macro-item:hover, .enc-macro-item.active { background: var(--accent-light); }
.enc-macro-item .enc-macro-key {
  font-weight: 600;
  color: var(--accent);
  margin-right: 0.4rem;
}
.enc-amend-form {
  padding: 0.6rem;
  background: var(--warning-light);
  border-radius: var(--radius);
  margin-top: 0.5rem;
}
.enc-amend-badge {
  font-size: 0.72rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  background: var(--warning-light);
  color: var(--warning);
  font-weight: 600;
}
.enc-unsigned-banner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--warning-light);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
  color: var(--warning);
}

/* ── Markdown body (Phase B — Knowledge Base cheatsheets) ─────────── */
.markdown-body {
  font-size: 0.88rem;
  line-height: 1.55;
}
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  margin: 1rem 0 0.5rem;
  font-weight: 600;
}
.markdown-body h1 { font-size: 1.4rem; border-bottom: 1px solid var(--border); padding-bottom: 0.3rem; }
.markdown-body h2 { font-size: 1.15rem; }
.markdown-body h3 { font-size: 1rem; }
.markdown-body h4 { font-size: 0.92rem; }
.markdown-body p { margin: 0.5rem 0; }
.markdown-body ul,
.markdown-body ol { margin: 0.5rem 0 0.5rem 1.3rem; padding: 0; }
.markdown-body li { margin: 0.2rem 0; }
.markdown-body table {
  border-collapse: collapse;
  margin: 0.6rem 0;
  font-size: 0.82rem;
  width: 100%;
}
.markdown-body th,
.markdown-body td {
  border: 1px solid var(--border);
  padding: 0.35rem 0.55rem;
  text-align: left;
  vertical-align: top;
}
.markdown-body th { background: var(--input); font-weight: 600; color: var(--text); }
.markdown-body td { color: var(--text); }
.markdown-body blockquote {
  border-left: 3px solid var(--accent);
  padding: 0.2rem 0.7rem;
  margin: 0.5rem 0;
  color: var(--text-sec);
}
.markdown-body pre,
.markdown-body code {
  background: var(--input);
  color: var(--text);
  border-radius: 3px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.82rem;
}
.markdown-body code { padding: 0.05rem 0.3rem; }
.markdown-body pre { padding: 0.5rem 0.7rem; overflow-x: auto; }
.markdown-body pre code { background: transparent; padding: 0; }
.markdown-body hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }
.markdown-body a { color: var(--accent); text-decoration: none; }
.markdown-body a:hover { text-decoration: underline; }

/* Phase E: Workflow + pill nav */
.workflow-root { padding: 1rem 1.5rem; max-width: 1200px; margin: 0 auto; }
.workflow-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.workflow-header h1 { margin: 0; font-size: 1.25rem; }
.workflow-body { min-height: 60vh; }

.pill-nav { display: flex; gap: 0.35rem; flex-wrap: wrap; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; margin-bottom: 1rem; }
.pill {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.35rem 0.85rem; border-radius: 6px;
  background: transparent; color: var(--text); border: 1px solid var(--border);
  font-size: 0.85rem; cursor: pointer;
}
.pill:hover { background: var(--bg-mute); }
.pill.active { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.pill .pill-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; margin-left: 0.35rem;
  background: rgba(0,0,0,0.15); border-radius: 999px; font-size: 0.7rem;
}

.muted { color: var(--text-mute, #888); font-style: italic; }

.card-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem; margin-top: 0.75rem;
}

.status-badge { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 6px; font-size: 0.7rem; font-weight: 600; }
.status-badge-gray { background: var(--bg-mute); color: var(--text-mute); }
.status-badge-green { background: rgba(34,197,94,0.15); color: rgb(21,128,61); }
.status-badge-amber { background: rgba(245,158,11,0.15); color: rgb(180,83,9); }
.status-badge-red { background: rgba(239,68,68,0.15); color: rgb(185,28,28); }

/* T3-47 voice dictation — wraps the textarea + microphone button */
.voice-host { position: relative; }

/* ── Clinic contact cards (Admin → Operations) ───────────────── */

.clinic-cards-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 1rem;
}
.clinic-cards-title {
  margin: 0;
  font-size: 1.1rem;
}
.clinic-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.75rem;
}
.clinic-card {
  text-align: left;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease, border-color 0.08s ease;
  font: inherit;
  color: inherit;
  overflow: hidden;
}
.clinic-card:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
}
.clinic-card-name {
  margin: 0 0 0.15rem;
  font-size: 1rem;
}
.clinic-card-legal {
  margin: 0 0 0.4rem;
  font-size: 0.78rem;
  color: var(--text-mute);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.clinic-card-line {
  margin: 0.1rem 0;
  font-size: 0.82rem;
  color: var(--text-sec);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.clinic-edit-card { max-width: 640px; width: 90vw; }
.clinic-edit-form { padding: 0 1.25rem 1rem; }
.clinic-edit-footer { display: flex; align-items: center; }
.clinic-edit-spacer { flex: 1; }
.clinic-delete-card { max-width: 480px; width: 90vw; }
.clinic-delete-card p { padding: 0 1.25rem; margin: 0.5rem 0; }
.clinic-delete-card #cdc-confirm-input {
  display: block;
  width: calc(100% - 2.5rem);
  margin: 0.5rem 1.25rem 1rem;
}

/* ── Generic tabular list card (Phase B.1 / B.4) ─────────────────── */
.tab-list-card,
.task-list-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.85rem;
  box-shadow: var(--shadow);
  margin-top: 0.5rem;
}
.tab-list-card .data-table tbody tr:hover,
.task-list-card .data-table tbody tr:hover {
  background: var(--bg-mute, rgba(0, 0, 0, 0.03));
}
.tab-list-card .data-table th,
.task-list-card .data-table th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-mute);
  font-weight: 600;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
}
.tab-list-card .data-table td,
.task-list-card .data-table td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.task-priority-high,
.task-priority-normal,
.task-priority-low {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.task-priority-high   { background: rgba(220, 38, 38, 0.12); color: #b91c1c; }
.task-priority-normal { background: rgba(59, 130, 246, 0.12); color: #1d4ed8; }
.task-priority-low    { background: rgba(107, 114, 128, 0.12); color: #4b5563; }
.task-due-overdue { color: #b91c1c; font-weight: 600; }
.task-due-today   { color: #d97706; font-weight: 600; }

/* ── Audit trail (Phase B.3) ─────────────────────────────────────── */
.audit-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}
.audit-filter-bar {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}
.audit-filter-bar select,
.audit-filter-bar input {
  font-size: 0.82rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.3rem 0.5rem;
}
.audit-filter-bar select:focus,
.audit-filter-bar input:focus {
  outline: none;
  border-color: var(--accent);
}
.audit-filter-bar input { flex: 1; }
.audit-filter-bar input::placeholder { color: var(--text-mute); }
.audit-empty { padding: 1rem; }
.audit-load-more {
  margin-top: 0.5rem;
  display: none;  /* JS toggles to inline-block when more pages exist */
}
.audit-row {
  display: grid;
  grid-template-columns: 140px 60px 1fr auto;
  gap: 0.4rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  align-items: center;
}
.audit-row-time {
  color: var(--text-mute);
  font-family: var(--mv-font-mono, monospace);
  font-size: 0.72rem;
}
.audit-row-provider { color: var(--text-sec); }
.audit-row-detail {
  font-size: 0.72rem;
  color: var(--text-mute);
  cursor: pointer;
}
.audit-chain-status {
  font-size: 0.82rem;
  padding: 0.3rem 0;
  color: var(--text-sec);
}
.audit-chain-status.is-ok    { color: var(--success); }
.audit-chain-status.is-error { color: var(--danger); }

/* ── Knowledge tree (Phase H) ──────────────────────────────────────── */
.kb-tree { padding: 0.5rem 0; }
.kb-tree-node { display: block; margin-bottom: 0.25rem; }
.kb-tree-toggle {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.45rem 0.6rem; cursor: pointer; user-select: none;
  border-radius: var(--radius); font-weight: 600;
}
.kb-tree-toggle:hover { background: var(--bg-mute, rgba(0,0,0,0.03)); }
.kb-tree-chevron {
  display: inline-block; transition: transform 0.15s; font-size: 0.7rem;
  color: var(--text-mute); width: 0.8rem;
}
.kb-tree-node.is-expanded > .kb-tree-toggle > .kb-tree-chevron {
  transform: rotate(90deg);
}
.kb-tree-children {
  display: none; padding: 0.25rem 0 0.5rem 1.5rem;
}
.kb-tree-node.is-expanded > .kb-tree-children { display: block; }
.kb-tree-leaf {
  padding: 0.35rem 0.6rem; cursor: pointer; border-radius: var(--radius);
  font-size: 0.86rem; color: var(--text-sec);
}
.kb-tree-leaf:hover { background: var(--bg-mute, rgba(0,0,0,0.03)); color: var(--text); }

/* ── Patient contact card (Phase C) ──────────────────────────────── */
#patient-contact-card-mount { padding: 0.5rem 0 0; }

.patient-card {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(0, 2fr) auto;
  gap: 1rem;
  align-items: start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  box-shadow: var(--shadow);
  margin: 0 0 0.75rem;
}

.patient-card-identity { min-width: 0; }
.patient-card-name-row {
  display: flex;
  gap: 0.6rem;
  align-items: baseline;
  flex-wrap: wrap;
}
.patient-card-name { margin: 0; font-size: 1.05rem; }
.patient-card-docid {
  font-family: var(--mv-font-mono, monospace);
  font-size: 0.78rem;
  color: var(--text-mute);
}
.patient-card-meta,
.patient-card-contact {
  font-size: 0.82rem;
  color: var(--text-sec);
  margin-top: 0.2rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.patient-card-contact { color: var(--text-mute); }

.patient-card-alerts {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}
.patient-card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  align-items: center;
}
.patient-card-badges-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-mute);
  margin-right: 0.2rem;
}
.patient-card-badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}
.patient-card-badge-allergy    { background: rgba(220, 38, 38, 0.14); color: #b91c1c; }
.patient-card-badge-condition  { background: rgba(245, 158, 11, 0.16); color: #b45309; }
.patient-card-badge-medication { background: rgba(59, 130, 246, 0.14); color: #1d4ed8; }
.patient-card-badge-more {
  background: rgba(107, 114, 128, 0.14);
  color: #4b5563;
  font-style: italic;
}

.patient-card-actions {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
}

@media (max-width: 768px) {
  .patient-card { grid-template-columns: 1fr; }
  .patient-card-actions { justify-content: flex-start; }
}

/* ── EMR-DOCS Commit 5: sidebar contact drawer ──────────────────── */

.sidebar-contact-drawer {
  margin-top: 8px;
}

.sidebar-contact-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 6px 8px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-mute);
  cursor: pointer;
  text-align: left;
}

.sidebar-contact-toggle:hover {
  background: var(--bg);
  border-color: var(--border);
}

.sidebar-contact-toggle[aria-expanded="true"] {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border);
}

.sidebar-contact-caret {
  font-size: 0.85rem;
  width: 12px;
  text-align: center;
}

.sidebar-contact-body {
  margin-top: 6px;
  padding: 8px 10px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-contact-body.hidden {
  display: none;
}

.sidebar-contact-line {
  word-break: break-word;
  color: var(--text);
}

.sidebar-contact-line strong {
  color: var(--text-sec);
}

.sidebar-contact-empty {
  color: var(--text-mute);
  font-style: italic;
  font-size: 0.8rem;
}

.sidebar-contact-section-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-mute);
  margin-top: 8px;
  margin-bottom: 2px;
}

.sidebar-contact-acompanante {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}

.sidebar-contact-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}


/* ── AI Workshop ─────────────────────────────────────────────────── */
.ai-workshop {
  margin-bottom: 1rem;
}

.ai-workshop-grid > div {
  /* Make sure flex children can shrink properly inside grid cells. */
  min-width: 0;
}

.ai-workshop-plantilla-row:hover {
  border-color: var(--accent, #2563eb) !important;
  background: var(--bg-soft, #f5f5f7) !important;
}

/* Output pane: render rich markdown the same way the informe preview does */
#ai-workshop-output-md h1,
#ai-workshop-output-md h2,
#ai-workshop-output-md h3 {
  margin: 0.6em 0 0.3em;
  color: var(--text);
}
#ai-workshop-output-md h1 { font-size: 1.15rem; border-bottom: 1px solid var(--border); padding-bottom: 0.2em; }
#ai-workshop-output-md h2 { font-size: 1.05rem; }
#ai-workshop-output-md h3 { font-size: 0.95rem; }
#ai-workshop-output-md ul,
#ai-workshop-output-md ol { padding-left: 1.4em; margin: 0.4em 0; }
#ai-workshop-output-md code { background: var(--bg-soft, #f5f5f7); padding: 1px 4px; border-radius: 3px; font-size: 0.88em; }
#ai-workshop-output-md pre { background: var(--bg-soft, #f5f5f7); padding: 0.5em 0.7em; border-radius: 4px; overflow-x: auto; }
#ai-workshop-output-md blockquote {
  border-left: 3px solid var(--accent-light, #cde);
  margin: 0.4em 0;
  padding: 0.2em 0.7em;
  color: var(--text-mute, #666);
}

/* Responsive collapse: stack panes vertically when narrow. */
@media (max-width: 980px) {
  .ai-workshop-grid {
    grid-template-columns: 1fr !important;
  }
}

/* Risk approval queue (Task 10) — Summary-tab card listing
   longevity_scores rows whose worsening transition needs staff sign-off
   before the patient sees the new tile. Hidden via [hidden] when empty. */
.risk-approval-card {
  background: var(--surface, #fff);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 8px;
  padding: 12px 14px;
  margin: 12px 0;
}
.risk-approval-heading {
  margin: 0 0 8px;
  font-size: 0.95rem;
  font-weight: 600;
}
.risk-approval-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border, #e5e7eb);
}
.risk-approval-row:last-child { border-bottom: none; }
.risk-approval-row-watch {
  border-left: 3px solid #d97706;
  padding-left: 8px;
}
.risk-approval-row-elevated {
  border-left: 3px solid var(--danger, #b91c1c);
  padding-left: 8px;
}
.risk-approval-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.risk-approval-kind { font-weight: 600; }
.risk-approval-transition {
  font-family: monospace;
  color: var(--text-muted, #6b7280);
  font-size: 0.85rem;
}
.risk-approval-time {
  font-size: 0.78rem;
  color: var(--text-muted, #6b7280);
}
.risk-approval-actions {
  display: flex;
  gap: 6px;
}
