:root, [data-theme="light"] {
  --bg: #f5f4ef;
  --surface: #ffffff;
  --surface-2: #fbfaf6;
  --surface-3: #eeebe4;
  --sidebar: #1d1e1b;
  --sidebar-text: #cac9c2;
  --sidebar-text-muted: #8d8c86;
  --sidebar-active-bg: #2b2c28;
  --sidebar-active-text: #f4f1e9;
  --border: #d6d3cb;
  --divider: #e7e4dc;
  --text: #25231b;
  --text-muted: #6b6961;
  --text-faint: #9b9991;
  --primary: #016870;
  --primary-hover: #0a4e54;
  --primary-soft: #cddcd8;
  --success: #437a22;
  --success-soft: #dbe8ce;
  --warning: #964118;
  --warning-soft: #efd9c7;
  --error: #a12b7b;
  --error-soft: #efd0e2;
  --radius-sm: .375rem;
  --radius-md: .625rem;
  --radius-lg: .875rem;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 18px rgba(0,0,0,.07);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, Segoe UI, sans-serif;
  --sidebar-w: 244px;
}
[data-theme="dark"] {
  --bg: #141311;
  --surface: #1a1a18;
  --surface-2: #1f1e1c;
  --surface-3: #26251f;
  --sidebar: #0c0c0a;
  --sidebar-text: #b4b3ad;
  --sidebar-text-muted: #6b6a64;
  --sidebar-active-bg: #1a1a18;
  --sidebar-active-text: #f4f1e9;
  --border: #353431;
  --divider: #252422;
  --text: #e0dfdc;
  --text-muted: #adaba6;
  --text-faint: #7c7a75;
  --primary: #4f98a3;
  --primary-hover: #6cb1bb;
  --primary-soft: #1f3a3d;
  --success-soft: #1f3322;
  --warning-soft: #3a2a1d;
  --error-soft: #3a1f30;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow-md: 0 4px 18px rgba(0,0,0,.4);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
/* Force the HTML `hidden` attribute to win over author `display:` rules.
   Without this, selectors like `.btn { display: inline-flex }` keep elements
   visible even when JS sets `el.hidden = true`. */
[hidden] { display: none !important; }
html { -webkit-font-smoothing: antialiased; }
body {
  min-height: 100dvh;
  font: 14px/1.5 var(--font);
  color: var(--text);
  background: var(--bg);
  display: flex;
}
button, input, textarea, select { font: inherit; color: inherit; outline: none; }
button { cursor: pointer; border: 0; background: none; }
table { border-collapse: collapse; width: 100%; }
.hidden { display: none !important; }

/* ---------- sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100dvh;
  padding: 20px 0;
}
.sidebar {
  transition: width .18s ease;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  margin-bottom: 16px;
}
.brand-text { flex: 1; min-width: 0; }
/* Collapse / expand affordance in the brand row. */
.sidebar-toggle {
  width: 28px; height: 28px;
  flex-shrink: 0;
  border-radius: 6px;
  color: var(--sidebar-text-muted);
  display: grid; place-items: center;
  transition: background .12s, color .12s, transform .18s ease;
}
.sidebar-toggle svg { width: 18px; height: 18px; }
.sidebar-toggle:hover {
  background: rgba(255,255,255,.08);
  color: var(--sidebar-active-text);
}
.brand-mark {
  width: 38px; height: 38px;
  padding: 8px;
  border-radius: 9px;
  background: var(--primary);
  color: #fff;
  display: grid; place-items: center;
}
.brand-mark svg { width: 100%; height: 100%; }
.brand h1 {
  font-size: 15px;
  font-weight: 600;
  color: var(--sidebar-active-text);
  line-height: 1.2;
}
.brand-subtitle {
  font-size: 11px;
  color: var(--sidebar-text-muted);
  margin-top: 2px;
}
.nav-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--sidebar-text-muted);
  padding: 14px 20px 6px;
  font-weight: 600;
}
/* Turn the nav-label into a full-width clickable header when it has the
   toggle affordance. Keeps the visual styling identical to the static
   label variant, just adds the caret + hover. */
button.nav-label {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  cursor: pointer;
  background: transparent;
}
button.nav-label:hover { color: var(--sidebar-text); }
.nav-caret {
  display: inline-block;
  width: 0; height: 0;
  border-left: 4px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transform: rotate(90deg);
  transition: transform .15s ease;
  opacity: .7;
}
.nav-group.is-collapsed .nav-caret { transform: rotate(0deg); }
.nav-group.is-collapsed .nav { display: none; }

.nav { display: flex; flex-direction: column; gap: 2px; padding: 0 8px; }
/* Sub-heading inside a nav group (e.g. "EDI Analyzer" under Reports). */
.nav-subhead {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--sidebar-text-muted);
  font-weight: 700;
  padding: 10px 12px 3px;
  opacity: .75;
}
.sidebar.collapsed .nav-subhead { display: none; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 7px;
  color: var(--sidebar-text);
  font-size: 13.5px;
  font-weight: 500;
  transition: background .12s, color .12s;
  width: 100%;
  text-align: left;
}
.nav-item:hover {
  background: rgba(255,255,255,.05);
  color: var(--sidebar-active-text);
}
.nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
}
.nav-item.disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.nav-item.disabled:hover {
  background: transparent;
  color: var(--sidebar-text);
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-item .badge {
  margin-left: auto;
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
  min-width: 20px;
  text-align: center;
}
/* Signed-in account + logout — always visible above the footer. */
.sidebar-account {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-top: 1px solid rgba(255,255,255,.06);
}
.sidebar-account .account-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}
.account-avatar {
  width: 30px; height: 30px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700;
}
.account-text { min-width: 0; }
.account-name {
  font-size: 12.5px; font-weight: 600;
  color: var(--sidebar-active-text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.account-role {
  font-size: 10.5px;
  color: var(--sidebar-text-muted);
  text-transform: capitalize;
}
.account-action {
  width: 30px; height: 30px;
  flex-shrink: 0;
  border-radius: 6px;
  color: var(--sidebar-text-muted);
  display: grid; place-items: center;
  transition: background .12s, color .12s;
}
.account-action svg { width: 17px; height: 17px; }
.account-action:hover {
  background: rgba(255,255,255,.08);
  color: var(--sidebar-active-text);
}
/* Collapsed rail: show just the avatar (which doubles as the logout button). */
.sidebar.collapsed .sidebar-account {
  flex-direction: column;
  gap: 8px;
  padding: 10px 0;
}
.sidebar.collapsed .account-text { display: none; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,.06);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--sidebar-text-muted);
}
.theme-toggle {
  width: 32px; height: 32px;
  border-radius: 6px;
  color: var(--sidebar-text);
  display: grid; place-items: center;
  transition: .12s;
}
.theme-toggle:hover {
  background: rgba(255,255,255,.08);
  color: var(--sidebar-active-text);
}

/* ---------- collapsed (icon-rail) sidebar ---------- */
.sidebar.collapsed { width: 68px; }
.sidebar.collapsed .brand {
  flex-direction: column;
  gap: 10px;
  padding: 0 0 16px;
  justify-content: center;
}
.sidebar.collapsed .brand-text { display: none; }
.sidebar.collapsed .sidebar-toggle svg { transform: rotate(180deg); }
/* Icon rail: drop the accordion headers, show every item's icon. */
.sidebar.collapsed .nav-label { display: none; }
.sidebar.collapsed .nav-group + .nav-group { border-top: 1px solid rgba(255,255,255,.05); }
.sidebar.collapsed .nav-group .nav { display: flex !important; padding: 6px; }
.sidebar.collapsed .nav-item {
  justify-content: center;
  gap: 0;
  padding: 10px 0;
}
.sidebar.collapsed .nav-item > span { display: none; }
.sidebar.collapsed .sidebar-footer {
  flex-direction: column;
  gap: 8px;
  justify-content: center;
  padding: 12px 0;
}
.sidebar.collapsed .footer-copy { display: none; }

/* ---------- layout ---------- */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar {
  padding: 18px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--divider);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
}
.topbar h2 { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.topbar-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 3px; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.content { padding: 24px 28px; flex: 1; }
.view { display: none; flex-direction: column; min-height: 0; }
.view.active { display: flex; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: background .12s, border-color .12s, color .12s, opacity .12s;
  border: 1px solid transparent;
  line-height: 1;
}
.btn svg { width: 14px; height: 14px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-3); }
.btn-danger {
  background: var(--surface);
  border-color: var(--border);
  color: var(--error);
}
.btn-danger:hover:not(:disabled) {
  background: var(--error-soft);
  border-color: var(--error);
}
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-icon {
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  display: grid; place-items: center;
  color: var(--text-muted);
}
.btn-icon:hover { background: var(--surface-3); color: var(--text); }

/* ---------- banner ---------- */
.banner {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
  border: 1px solid transparent;
}
.banner.info {
  background: var(--primary-soft);
  color: var(--primary-hover);
  border-color: var(--primary-soft);
}
.banner.success {
  background: var(--success-soft);
  color: var(--success);
  border-color: var(--success-soft);
}
.banner.error {
  background: var(--error-soft);
  color: var(--error);
  border-color: var(--error-soft);
}

/* ---------- dropzone ---------- */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  padding: 40px 24px;
  text-align: center;
  transition: background .15s, border-color .15s;
}
.dropzone.drag {
  background: var(--primary-soft);
  border-color: var(--primary);
}
.dz-icon {
  width: 48px; height: 48px;
  color: var(--text-faint);
  margin: 0 auto 12px;
}
.dropzone h3 { font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.dropzone-actions {
  display: flex; justify-content: center; gap: 10px;
  margin-top: 14px;
}
.dz-hint {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 14px;
}

/* ---------- progress ---------- */
.progress {
  height: 4px;
  background: var(--divider);
  margin-top: 16px;
  border-radius: 999px;
  overflow: hidden;
  opacity: 0;
  transition: opacity .2s;
}
.progress.active { opacity: 1; }
.progress-bar {
  height: 100%;
  background: var(--primary);
  width: 0;
  transition: width .3s;
}

/* ---------- file table ---------- */
.file-table-wrap {
  margin-top: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.file-table-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--divider);
}
.file-table-head h3 { font-size: 14px; font-weight: 600; }
.file-table-head .meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.file-table-actions { display: flex; gap: 6px; }
.maint-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 24px;
  padding: 12px 16px;
  border: 1px dashed var(--divider);
  border-radius: 6px;
  opacity: 0.85;
}
.maint-label { display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.maint-label .meta { font-size: 12px; color: var(--text-muted); }
.maint-actions { display: flex; gap: 6px; }
.table-scroll { overflow-x: auto; }
.file-table { font-size: 13px; }
.file-table th, .file-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--divider);
}
.file-table th {
  background: var(--surface-2);
  font-weight: 600;
  color: var(--text-muted);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.file-table tr:last-child td { border-bottom: 0; }
.c-check { width: 36px; }
.c-size, .c-status, .c-rows { width: 100px; }
.c-actions { width: 170px; text-align: right; }
.name-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.file-icon { width: 18px; height: 18px; color: var(--text-faint); flex-shrink: 0; }
.name-cell .name {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 520px;
}
.actions-cell { display: flex; gap: 6px; justify-content: flex-end; }

/* ---------- pill ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
}
.pill .dot { width: 6px; height: 6px; border-radius: 999px; background: currentColor; }
.pill-pending { background: var(--surface-3); color: var(--text-muted); }
.pill-processing { background: var(--primary-soft); color: var(--primary-hover); }
.pill-done { background: var(--success-soft); color: var(--success); }
.pill-error { background: var(--error-soft); color: var(--error); }

/* ---------- empty state ---------- */
.empty-state {
  padding: 40px 24px;
  text-align: center;
  color: var(--text-muted);
}
.empty-state svg {
  width: 42px; height: 42px;
  color: var(--text-faint);
  margin-bottom: 12px;
}
.empty-state h4 { font-size: 14px; font-weight: 600; margin-bottom: 4px; color: var(--text); }
.empty-state p { font-size: 13px; }

/* ---------- stats ---------- */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}
.stat-card .label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 4px;
}
.stat-card .value {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.stat-card .delta { font-size: 11.5px; color: var(--text-faint); margin-top: 2px; }

/* ---------- results toolbar ---------- */
.results-toolbar {
  display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap;
}
.search-box {
  position: relative;
  flex: 1; min-width: 240px;
}
.search-box svg {
  position: absolute; left: 10px; top: 50%;
  transform: translateY(-50%);
  width: 14px; height: 14px;
  color: var(--text-faint);
}
.search-box input {
  width: 100%;
  padding: 8px 10px 8px 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.search-box input:focus { border-color: var(--primary); }
#file-filter {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  min-width: 200px;
}

/* ---------- results table ---------- */
.results-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}
.results-table { font-size: 13px; min-width: 900px; }
.results-table th, .results-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--divider);
  white-space: nowrap;
}
.results-table th {
  background: var(--surface-2);
  font-weight: 600;
  color: var(--text-muted);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .04em;
  position: sticky;
  top: 0;
  cursor: pointer;
}
.results-table th.sorted-asc, .results-table th.sorted-desc { color: var(--primary); }
.results-table td.empty-cell { color: var(--text-faint); }
.results-table tr.others-row { background: var(--surface-3); }
.results-table tr.others-row td { font-style: italic; color: var(--text-muted); }
.sort-arrow { font-size: 10px; margin-left: 4px; opacity: .6; }
.page-range {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--primary-soft);
  color: var(--primary-hover);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 500;
}
.page-range svg { width: 12px; height: 12px; }
.source-tag {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11.5px;
  color: var(--text-muted);
}
.view-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--primary);
  border: 1px solid var(--border);
}
.view-btn svg { width: 12px; height: 12px; }
.view-btn:hover { background: var(--primary-soft); }

.idx { color: var(--text-faint); font-size: 11.5px; width: 40px; }

/* ---------- rules ---------- */
.rules-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.rules-card label { display: block; font-weight: 600; margin-bottom: 6px; }
.rules-card .hint { font-size: 12.5px; color: var(--text-muted); margin-bottom: 14px; }
.rules-card code {
  background: var(--surface-3);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12px;
}
#rules-textarea {
  width: 100%;
  min-height: 440px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font: 12.5px/1.5 ui-monospace, Menlo, monospace;
  resize: vertical;
}
#rules-textarea:focus { border-color: var(--primary); }
.rules-actions { margin-top: 14px; }
.rules-actions .banner { margin: 0; padding: 6px 12px; display: inline-block; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal-backdrop.active { display: flex; }
/* Gate mode — the app is fully hidden until the user signs in. There is no
   "skip": the login is mandatory. Using display:none (not visibility) so no
   content flashes or is reachable behind the opaque login overlay. */
.modal-backdrop.gate { background: var(--bg); z-index: 5000; }
body.app-gated { overflow: hidden; }
body.app-gated .sidebar,
body.app-gated .main { display: none !important; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 96%;
  max-width: 1180px;
  height: 92%;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 48px rgba(0,0,0,.25);
  overflow: hidden;
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--divider);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
}
.modal-header h3 { font-size: 15px; font-weight: 600; }
.modal-header .meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; display: flex; gap: 14px; flex-wrap: wrap; }
.modal-actions { display: flex; gap: 8px; align-items: center; }
.modal-close {
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  display: grid; place-items: center;
  color: var(--text-muted);
}
.modal-close:hover { background: var(--surface-3); color: var(--text); }
.modal-toolbar {
  padding: 10px 20px;
  border-bottom: 1px solid var(--divider);
  background: var(--surface-2);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.page-jump {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: var(--text-muted);
}
.page-jump select {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 12.5px;
}
.modal-toolbar .hint { font-size: 11.5px; color: var(--text-muted); }
.modal-body {
  flex: 1;
  background: #2a2a28;
  overflow: hidden;
  display: flex;
}
.pdf-iframe { border: 0; width: 100%; height: 100%; }
.pdf-page-loading {
  flex: 1;
  display: grid;
  place-items: center;
  color: #fff;
  text-align: center;
  gap: 12px;
}
.spinner {
  width: 28px; height: 28px;
  border: 3px solid rgba(255,255,255,.15);
  border-top-color: #fff;
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Settings view ---------- */
.settings-card {
  background: var(--surface);
  border: 1px solid var(--divider);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.settings-card h3 { font-size: 14px; font-weight: 600; margin-bottom: 10px; }
.settings-card-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px;
}
.settings-card .hint { font-size: 12px; color: var(--text-muted); margin-top: 8px; }
.toggle { display: inline-flex; gap: 8px; align-items: center; cursor: pointer; font-size: 13px; }
.toggle input { width: 16px; height: 16px; }

.sftp-list { display: flex; flex-direction: column; gap: 8px; }
.sftp-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto auto auto;
  gap: 10px; align-items: center;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--divider);
  border-radius: 6px;
}
.sftp-row .sftp-name { font-weight: 600; font-size: 13px; }
.sftp-row .sftp-host { font-size: 12px; color: var(--text-muted); }
.sftp-row .sftp-enabled-badge { font-size: 11px; padding: 2px 8px; border-radius: 10px; }
.sftp-row .sftp-enabled-badge.on { background: #234a2f; color: #9ee2b4; }
.sftp-row .sftp-enabled-badge.off { background: #4a2323; color: #e29e9e; }

/* ---------- Help modal variant (About / scrub help on Upload screen) ---------- */
.modal-help { max-width: 760px; height: auto; max-height: 86vh; }
.modal-help .modal-body { padding: 20px 24px 28px; overflow: auto; display: block; }

/* ---------- Small modal variant (for login / sftp form) ---------- */
.modal-sm { max-width: 460px; height: auto; }
.modal-sm .modal-body {
  background: var(--surface);
  padding: 20px; overflow: auto; display: block;
}
.modal-sm label {
  display: block; font-size: 12px; color: var(--text-muted);
  margin-bottom: 12px;
}
.modal-sm label input[type="text"],
.modal-sm label input[type="email"],
.modal-sm label input[type="password"],
.modal-sm label input[type="number"] {
  width: 100%; margin-top: 4px;
  padding: 8px 10px;
  background: var(--surface-2); border: 1px solid var(--divider);
  color: var(--text); border-radius: 4px; font-size: 13px;
}
.modal-sm .two-col {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.modal-sm .modal-actions { margin-top: 16px; justify-content: flex-end; }

/* Generic modal form (reuses modal-sm layout) */
#sftp-backdrop .modal { max-width: 520px; height: auto; }
#sftp-backdrop .modal-body {
  background: var(--surface); padding: 20px; overflow: auto; display: block;
}
#sftp-backdrop label {
  display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 12px;
}
#sftp-backdrop label input[type="text"],
#sftp-backdrop label input[type="password"],
#sftp-backdrop label input[type="number"],
#sftp-backdrop label select {
  width: 100%; margin-top: 4px;
  padding: 8px 10px;
  background: var(--surface-2); border: 1px solid var(--divider);
  color: var(--text); border-radius: 4px; font-size: 13px;
}
#sftp-backdrop .two-col {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
#sftp-backdrop .modal-actions { margin-top: 16px; justify-content: flex-end; }
.toggle-stack {
  display: flex !important; align-items: flex-end !important;
  padding-bottom: 8px;
}
.duplicate-list {
  max-height: 180px; overflow-y: auto;
  margin-bottom: 14px;
  font-size: 13px;
}
.duplicate-list .dup-row {
  padding: 8px 0; border-bottom: 1px solid var(--divider);
}
.duplicate-list .dup-row:last-child { border-bottom: 0; }
.duplicate-list .dup-file { font-weight: 600; }
.duplicate-list .dup-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.archive-hits {
  margin-top: 24px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--divider);
  border-radius: var(--radius);
}
.archive-hits-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 12px;
}
.archive-hits-head h4 { font-size: 13px; font-weight: 600; }
.archive-hits-head .meta { font-size: 11px; color: var(--text-muted); }
.archive-hits-list { display: flex; flex-direction: column; gap: 6px; }
.archive-hit {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 10px; align-items: center;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--divider);
  border-radius: 6px;
  font-size: 13px;
}
.archive-hit .ah-name { font-weight: 600; }
.archive-hit .ah-meta { font-size: 11px; color: var(--text-muted); }
.archive-hit .ah-pages { font-size: 11px; color: var(--text-muted); }

.scan-progress { margin-top: 10px; }
.scan-bar {
  height: 6px; width: 100%; background: var(--surface-3);
  border-radius: 3px; overflow: hidden;
}
.scan-bar-fill {
  height: 100%; width: 0%; background: var(--accent, #5fa8ff);
  transition: width 0.2s;
}
.scan-status { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.sftp-row .sftp-direction-badge {
  font-size: 11px; padding: 2px 8px; border-radius: 10px;
  background: var(--surface-3); color: var(--text-muted);
}


/* ---------- HTML view ---------- */
.html-view-content {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.html-view-header-info {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  box-shadow: var(--shadow-sm);
  font-size: 13px;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}
.html-view-header-info strong {
  color: var(--text-muted);
  font-weight: 600;
  margin-right: 4px;
}
.html-view-pages {
  background: var(--surface-3);
  border-radius: var(--radius-md);
  padding: 24px;
  overflow: auto;
  max-height: calc(100dvh - 220px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}
.html-view-pages:empty { display: none; }

.pdf-page-html {
  position: relative;
  background: #ffffff;
  box-shadow: 0 2px 12px rgba(0,0,0,.16);
  border-radius: 4px;
  overflow: hidden;
  flex-shrink: 0;
}
.pdf-page-html canvas {
  display: block;
  width: 100%;
  height: auto;
}
.pdf-page-html .page-label {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 2px 8px;
  background: rgba(0, 0, 0, 0.58);
  color: #fff;
  font-size: 11px;
  font-weight: 500;
  border-radius: 4px;
  z-index: 10;
  pointer-events: none;
}

/* Text overlay: transparent spans positioned over the canvas;
   backgrounds are applied via highlight classes for color coding. */
.pdf-page-html .text-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  line-height: 1.0;
  user-select: text;
  z-index: 2;
}
.pdf-page-html .text-layer span {
  position: absolute;
  white-space: pre;
  color: transparent;
  cursor: text;
  transform-origin: 0 0;
  padding: 0 1px;
  border-radius: 2px;
  pointer-events: auto;
}
.pdf-page-html .text-layer span::selection {
  background: rgba(0, 100, 255, 0.28);
  color: transparent;
}

/* --- Highlight classes (color coding) --- */
.pdf-page-html .text-layer span.hl-name     { background: rgba(255, 210, 50, 0.38); }
.pdf-page-html .text-layer span.hl-id       { background: rgba(70, 130, 255, 0.32); }
.pdf-page-html .text-layer span.hl-date     { background: rgba(80, 200, 120, 0.32); }
.pdf-page-html .text-layer span.hl-label    { background: rgba(180, 80, 200, 0.28); }
.pdf-page-html .text-layer span.hl-section  { background: rgba(255, 140, 40, 0.32); }
.pdf-page-html .text-layer span.hl-allergy  { background: rgba(255, 70, 70, 0.36); }

/* Legend (topbar) */
.hl-legend {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  color: var(--text-muted);
}
.hl-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
}
.hl-chip.hl-name    { background: rgba(255, 210, 50, 0.38); }
.hl-chip.hl-id      { background: rgba(70, 130, 255, 0.32); }
.hl-chip.hl-date    { background: rgba(80, 200, 120, 0.32); }
.hl-chip.hl-label   { background: rgba(180, 80, 200, 0.28); }
.hl-chip.hl-section { background: rgba(255, 140, 40, 0.32); }
.hl-chip.hl-allergy { background: rgba(255, 70, 70, 0.36); }

.html-view-loading {
  padding: 60px 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}
.html-view-loading .spinner {
  border-color: rgba(0,0,0,.12);
  border-top-color: var(--primary);
}

/* ---------- JSON view ---------- */
.json-view-content {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.json-view-header-info {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  box-shadow: var(--shadow-sm);
  font-size: 13px;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}
.json-view-header-info strong {
  color: var(--text-muted);
  font-weight: 600;
  margin-right: 4px;
}
.json-view-body {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  font: 12.5px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text);
  white-space: pre;
  overflow: auto;
  max-height: calc(100dvh - 220px);
  tab-size: 2;
}
.json-view-body .j-key   { color: var(--primary);   font-weight: 600; }
.json-view-body .j-str   { color: #437a22; }
.json-view-body .j-num   { color: #964118; }
.json-view-body .j-bool  { color: #a12b7b; font-weight: 600; }
.json-view-body .j-null  { color: var(--text-faint); font-style: italic; }
[data-theme="dark"] .json-view-body .j-str   { color: #9ec780; }
[data-theme="dark"] .json-view-body .j-num   { color: #e2a479; }
[data-theme="dark"] .json-view-body .j-bool  { color: #d97aaf; }

/* ---------- Consolidated Views panel ---------- */
.views-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
  flex: 1;
}
.views-shell {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  gap: 12px;
}
.views-meta {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  box-shadow: var(--shadow-sm);
  font-size: 12.5px;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  color: var(--text);
}
.views-meta strong {
  color: var(--text-muted);
  font-weight: 600;
  margin-right: 4px;
}
.views-tabs {
  display: flex;
  gap: 2px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}
.views-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  transition: background .12s, color .12s;
  white-space: nowrap;
}
.views-tab svg { width: 14px; height: 14px; }
.views-tab:hover {
  background: var(--surface);
  color: var(--text);
}
.views-tab.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 4px rgba(1, 104, 112, 0.25);
}
.views-tab.active:hover { background: var(--primary-hover); }
.views-panes {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
}
.views-pane {
  display: none;
  width: 100%;
  flex-direction: column;
  min-height: 0;
}
.views-pane.active { display: flex; }

/* Form pane */
.form-view-body {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  max-width: 1180px;
  margin: 0 auto;
  width: 100%;
  padding: 0 0 20px;
}

/* JSON pane (previously standalone — now lives inside Views) */
#views-pane-json {
  overflow: hidden;
}

/* Inline PDF pane (previously the modal) */
#views-pane-pdf {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.pdf-inline-toolbar {
  padding: 10px 16px;
  border-bottom: 1px solid var(--divider);
  background: var(--surface-2);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.pdf-inline-toolbar .hint { font-size: 11.5px; color: var(--text-muted); }
.pdf-inline-body {
  flex: 1;
  min-height: 520px;
  background: #2a2a28;
  display: flex;
}
.pdf-inline-body .pdf-iframe {
  border: 0;
  width: 100%;
  height: 100%;
  min-height: 520px;
}

/* HTML pane (topbar legend moved inline) */
#views-pane-html .hl-legend {
  margin-bottom: 10px;
}

/* Patient header strip — accent gradient */
.fv-patient-strip {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 20px;
  box-shadow: var(--shadow-md);
}
.fv-avatar {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: rgba(255,255,255,.18);
  display: grid; place-items: center;
  font-size: 20px; font-weight: 700;
  color: #fff;
  letter-spacing: 0.02em;
  border: 2px solid rgba(255,255,255,.25);
}
.fv-patient-main h2 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 6px;
  color: #fff;
}
.fv-patient-meta {
  display: flex; flex-wrap: wrap; gap: 10px 18px;
  font-size: 12.5px;
  color: rgba(255,255,255,.85);
}
.fv-patient-meta strong {
  color: #fff;
  font-weight: 500;
  margin-right: 5px;
  opacity: .75;
}
.fv-patient-ids {
  display: flex; flex-direction: column; gap: 6px;
  align-items: flex-end;
}
.fv-id-chip {
  background: rgba(255,255,255,.2);
  color: #fff;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  font-family: ui-monospace, Menlo, monospace;
  letter-spacing: 0.02em;
}
.fv-photo-chip {
  background: rgba(255,255,255,.14);
  color: rgba(255,255,255,.9);
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 999px;
}

/* Generic card */
.fv-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.fv-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--divider);
  background: var(--surface-2);
}
.fv-card-head h3 {
  font-size: 12.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text);
}
.fv-card-head .fv-accent {
  display: inline-block;
  width: 4px; height: 14px;
  border-radius: 2px;
  margin-right: 10px;
  vertical-align: middle;
  background: var(--primary);
}
.fv-card-head .fv-accent.fv-accent-facility { background: #016870; }
.fv-card-head .fv-accent.fv-accent-clinical { background: #a12b7b; }
.fv-card-head .fv-accent.fv-accent-schedule { background: #437a22; }
.fv-card-head .fv-accent.fv-accent-treatments { background: #964118; }
.fv-card-head .fv-accent.fv-accent-staff    { background: #4a5a8a; }
.fv-card-head .fv-accent.fv-accent-codes    { background: #6b6961; }
.fv-card-head .fv-accent.fv-accent-meta     { background: #8d8c86; }
.fv-card-head .fv-count {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 2px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.fv-card-body { padding: 14px 18px; font-size: 13px; }
.fv-card-body.fv-body-dense { padding: 0; }

/* Two-column grids */
.fv-row-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

/* Definition-list style field rows */
.fv-fields {
  display: grid;
  grid-template-columns: 140px 1fr;
  row-gap: 8px;
  column-gap: 12px;
}
.fv-fields dt {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding-top: 2px;
}
.fv-fields dd {
  font-size: 13px;
  color: var(--text);
  word-break: break-word;
}
.fv-fields dd.fv-muted { color: var(--text-faint); font-style: italic; }

/* Chips for allergies, initials, codes */
.fv-chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.fv-chip {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border);
}
.fv-chip-allergy {
  background: #fce8dc;
  color: #964118;
  border-color: #f0c8aa;
}
[data-theme="dark"] .fv-chip-allergy { background: #3a2a1d; color: #e2a479; border-color: #4a3a2d; }
.fv-chip-directive {
  background: #d4e8d4;
  color: #437a22;
  border-color: #b5d5b5;
}
[data-theme="dark"] .fv-chip-directive { background: #1f3322; color: #9ec780; border-color: #2f4432; }
.fv-chip-initial {
  background: var(--primary-soft);
  color: var(--primary-hover);
  border-color: var(--primary-soft);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
}

/* Long-paragraph block (medical conditions) */
.fv-paragraph {
  background: var(--surface-2);
  padding: 12px 14px;
  border-left: 3px solid var(--primary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
}

/* ---------- RCM Inferences (Form View) ---------- */
.fv-rcm-btn { white-space: nowrap; }
.fv-rcm-card .fv-card-head { cursor: pointer; }
.fv-rcm-card .fv-card-body { display: flex; flex-direction: column; gap: 12px; }
.fv-rcm-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.fv-rcm-status {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.fv-rcm-meta {
  font-size: 11.5px;
  color: var(--text-faint);
  font-style: italic;
}

/* Caret for collapsible sections (RCM card + RCM sub-sections).
   Rotates when the host gets .is-collapsed. */
.fv-caret {
  display: inline-block;
  width: 0; height: 0;
  border-left: 5px solid currentColor;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  margin-right: 8px;
  transform: rotate(90deg);
  transition: transform .15s ease;
  opacity: .55;
  vertical-align: middle;
}
.is-collapsed > .fv-card-head .fv-caret,
.is-collapsed > .fv-collapse-head .fv-caret { transform: rotate(0deg); }
.is-collapsed > .fv-card-body,
.is-collapsed > .fv-collapse-body { display: none; }

.fv-collapse-head {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  padding: 2px 0 6px;
  border: 0;
  background: transparent;
  cursor: pointer;
  text-align: left;
  color: inherit;
}
.fv-collapse-head h4 { margin: 0; }
.fv-rcm-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px;
  color: var(--text-muted);
  font-size: 13px;
}
.fv-rcm-loading .spinner {
  width: 18px; height: 18px;
  border-width: 2px;
  margin: 0;
}
.fv-rcm-error {
  background: var(--error-soft);
  color: var(--error);
  border: 1px solid var(--error);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.5;
}
.fv-rcm-error .meta { color: var(--text-muted); font-size: 12px; margin-top: 4px; }
.fv-rcm-section h4 {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.fv-rcm-table {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  font-size: 13px;
}
.fv-rcm-table th,
.fv-rcm-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--divider);
  text-align: left;
  vertical-align: top;
}
.fv-rcm-table tr:last-child th,
.fv-rcm-table tr:last-child td { border-bottom: 0; }
.fv-rcm-table th {
  width: 160px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-2);
  font-size: 12px;
}
.fv-rcm-rationale {
  background: var(--surface-2);
  padding: 10px 14px;
  border-left: 3px solid var(--success);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
}

/* Colored pills for billable outcomes in the Claim Routing & Bundling table. */
.fv-pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
  text-transform: uppercase;
}
.fv-pill-yes     { background: var(--success-soft); color: var(--success);  border-color: var(--success); }
.fv-pill-no      { background: var(--error-soft);   color: var(--error);    border-color: var(--error); }
.fv-pill-cond    { background: var(--warning-soft); color: var(--warning);  border-color: var(--warning); }
.fv-pill-bundled { background: var(--primary-soft); color: var(--primary);  border-color: var(--primary); }
.fv-pill-na      { background: var(--surface-3);    color: var(--text-muted); border-color: var(--border); }
.fv-pill-default { background: var(--surface-3);    color: var(--text);      border-color: var(--border); }
.fv-pill-rest { color: var(--text-muted); font-size: 12.5px; }

/* Inline code highlights inside rationales. Subtle pill-style chips that
   don't overwhelm the sentence flow. */
.fv-code {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
  font-size: 12px;
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.fv-code-lcd   { background: #fbeed6; color: #8a5a00; border-color: #e7d09a; }
.fv-code-hcpcs { background: #d9e7f7; color: #2a4d82; border-color: #a9c3e6; }
.fv-code-icd   { background: #efdcea; color: #86255e; border-color: #d3adc4; }
.fv-code-cpt   { background: #d9ecd6; color: #2f6320; border-color: #a5cd9c; }
.fv-code-rev   { background: #f0eaf7; color: #5b3f85; border-color: #c9bbe0; }
.fv-code-cfr   { background: var(--surface-3); color: var(--text); border-color: var(--border); font-style: italic; }

[data-theme="dark"] .fv-code-lcd   { background: #3a2e18; color: #e6bb6e; border-color: #4f3f22; }
[data-theme="dark"] .fv-code-hcpcs { background: #1d2e42; color: #86abd9; border-color: #2c435f; }
[data-theme="dark"] .fv-code-icd   { background: #3a1e32; color: #d49ac2; border-color: #4f2a44; }
[data-theme="dark"] .fv-code-cpt   { background: #1f3322; color: #9ec780; border-color: #2f4432; }
[data-theme="dark"] .fv-code-rev   { background: #2b223a; color: #b4a0d4; border-color: #3f3050; }
[data-theme="dark"] .fv-code-cfr   { background: var(--surface-3); color: var(--text); border-color: var(--border); }

/* Domain keyword chips — categories (wound/ostomy/enteral/...) + their
   supply items. Subtle backgrounds so a paragraph stays readable. */
.fv-kw {
  padding: 1px 5px;
  border-radius: 3px;
  border: 1px solid transparent;
  font-weight: 500;
}
.fv-kw-wound   { background: #fce8dc; color: #964118; border-color: #f0c8aa; }
.fv-kw-urology { background: #d6ecec; color: #1a5e66; border-color: #a8d3d5; }
.fv-kw-enteral { background: #f3e7c8; color: #8a6a1a; border-color: #ddc88c; }
.fv-kw-ostomy  { background: #ead7c3; color: #6b4a20; border-color: #d5b78f; }
.fv-kw-bladder { background: #dce6f3; color: #2a4d82; border-color: #b3c7e3; }
.fv-kw-billing { background: var(--surface-3); color: var(--text-muted); border-color: var(--border); font-variant: small-caps; font-weight: 600; }

[data-theme="dark"] .fv-kw-wound   { background: #3a2a1d; color: #e2a479; border-color: #4a3a2d; }
[data-theme="dark"] .fv-kw-urology { background: #1d3234; color: #8bc3c8; border-color: #2a4346; }
[data-theme="dark"] .fv-kw-enteral { background: #342a15; color: #d7ae5a; border-color: #4a3d20; }
[data-theme="dark"] .fv-kw-ostomy  { background: #2e241a; color: #c9a476; border-color: #453526; }
[data-theme="dark"] .fv-kw-bladder { background: #1f2c42; color: #94b6e2; border-color: #2f415e; }
[data-theme="dark"] .fv-kw-billing { background: var(--surface-3); color: var(--text); border-color: var(--border); }

/* ---------- RCM Settings (Settings view card) ---------- */
.rcm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px 16px;
  margin-top: 4px;
}
.rcm-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.rcm-grid .rcm-full { grid-column: 1 / -1; }
.rcm-grid input[type="text"],
.rcm-grid input[type="password"],
.rcm-grid input[type="number"],
.rcm-grid select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
  font-family: inherit;
}
.rcm-key-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}
.rcm-grid .meta {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-faint);
  text-transform: none;
  letter-spacing: normal;
}
.rcm-test-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 14px;
}
.rcm-test-result {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}
.rcm-test-result.ok { background: var(--success-soft); color: var(--success); }
.rcm-test-result.bad { background: var(--error-soft); color: var(--error); }
.rcm-prompt-label { margin-top: 16px; }
.rcm-prompt-label textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: 12px/1.55 'JetBrains Mono', ui-monospace, monospace;
  resize: vertical;
  min-height: 240px;
  text-transform: none;
  letter-spacing: normal;
}

/* Schedule summary strip */
.fv-schedule-strip {
  display: flex; flex-wrap: wrap; gap: 18px;
  padding: 14px 18px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--divider);
  font-size: 13px;
}
.fv-schedule-strip .fv-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 500;
}
.fv-schedule-strip .fv-pill strong {
  color: var(--text-muted);
  font-weight: 500;
  margin-right: 2px;
}

/* Treatment list */
.fv-treatments { display: flex; flex-direction: column; gap: 10px; padding: 14px 18px; }
.fv-treatment {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  overflow: hidden;
  transition: box-shadow .15s;
}
.fv-treatment:hover { box-shadow: 0 2px 10px rgba(0,0,0,.06); }
.fv-treatment-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--divider);
}
.fv-treatment-index {
  display: grid; place-items: center;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}
.fv-treatment-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
}
.fv-treatment-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.fv-badge {
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.fv-badge-slot  { background: var(--primary-soft); color: var(--primary-hover); }
.fv-badge-prn   { background: #efd9c7; color: #964118; }
[data-theme="dark"] .fv-badge-prn { background: #3a2a1d; color: #e2a479; }

.fv-treatment-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.fv-treatment-meta {
  display: flex; flex-wrap: wrap; gap: 6px 16px;
  font-size: 12px; color: var(--text-muted);
}
.fv-treatment-meta strong {
  color: var(--text);
  font-weight: 500;
  margin-right: 3px;
}

/* 31-day heatmap */
.fv-heatmap {
  display: grid;
  grid-template-columns: repeat(31, 1fr);
  gap: 3px;
  padding: 4px 0;
}
.fv-heatmap-day {
  aspect-ratio: 1;
  min-width: 0;
  border-radius: 3px;
  display: grid; place-items: center;
  font-size: 10px;
  font-weight: 600;
  cursor: default;
  transition: transform .1s;
  background: var(--surface-3);
  color: var(--text-faint);
  border: 1px solid var(--divider);
}
.fv-heatmap-day:hover { transform: scale(1.18); z-index: 5; position: relative; }
.fv-heatmap-day.fv-status-scheduled   { background: #e6ecf2; color: #4a6380; border-color: #c6d4e2; }
.fv-heatmap-day.fv-status-administered { background: #437a22; color: #fff; border-color: #2f5618; }
.fv-heatmap-day.fv-status-code        { background: #964118; color: #fff; border-color: #6b2e10; }
.fv-heatmap-day.fv-status-blank       { background: var(--surface-3); color: var(--text-faint); }
.fv-heatmap-day.fv-status-unknown     { background: #a12b7b; color: #fff; border-color: #741e58; }
[data-theme="dark"] .fv-heatmap-day.fv-status-scheduled { background: #26323f; color: #8ea4bd; border-color: #2f3d4c; }

.fv-heatmap-legend {
  display: flex; flex-wrap: wrap; gap: 10px;
  font-size: 11px;
  color: var(--text-muted);
  padding-top: 4px;
}
.fv-heatmap-legend .fv-legend-dot {
  display: inline-block; width: 10px; height: 10px;
  border-radius: 2px; margin-right: 4px;
  vertical-align: -1px;
}

/* Summary bar of counts */
.fv-summary-row {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.fv-stat-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.fv-stat-pill b { color: var(--text); font-weight: 700; }
.fv-stat-pill.fv-stat-admin   { background: #dbe8ce; color: #2f5618; border-color: #b5d5b5; }
.fv-stat-pill.fv-stat-admin b { color: #2f5618; }
[data-theme="dark"] .fv-stat-pill.fv-stat-admin { background: #1f3322; color: #9ec780; border-color: #2f4432; }

.fv-rollup-row { display: flex; flex-wrap: wrap; gap: 6px; }

/* Staff legend table inside Form view */
.fv-staff-table { width: 100%; font-size: 12.5px; }
.fv-staff-table th, .fv-staff-table td {
  padding: 8px 14px; text-align: left;
  border-bottom: 1px solid var(--divider);
}
.fv-staff-table tr:last-child td { border-bottom: 0; }
.fv-staff-table th {
  background: var(--surface-2);
  font-weight: 600;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.fv-staff-table td.fv-mono {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11.5px;
  color: var(--text-muted);
}

/* Chart code grid — compact */
.fv-codes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 6px 12px;
  padding: 12px 18px;
}
.fv-code-row {
  display: flex; gap: 10px;
  font-size: 12px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.fv-code-row b {
  font-family: ui-monospace, Menlo, monospace;
  color: var(--primary);
  min-width: 26px;
}

/* Extraction meta footer */
.fv-meta-footer {
  display: flex; flex-wrap: wrap; gap: 12px;
  padding: 10px 16px;
  font-size: 11.5px;
  color: var(--text-muted);
  border-top: 1px solid var(--divider);
  background: var(--surface-2);
}
.fv-meta-footer span { display: inline-flex; gap: 5px; }
.fv-meta-footer strong { color: var(--text); font-weight: 500; }

.fv-warning-list {
  padding: 10px 16px;
  color: var(--warning);
  background: var(--warning-soft);
  font-size: 12px;
  border-top: 1px solid var(--border);
}
.fv-warning-list ul { padding-left: 18px; margin-top: 4px; }

@media print {
  .sidebar, .topbar-actions { display: none; }
  .fv-patient-strip { page-break-after: avoid; }
  .fv-treatment, .fv-sched-section { page-break-inside: avoid; }
}

/* ---------- Schedule sub-sections (collapsible) ---------- */
.fv-sched-sections {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 14px;
}
.fv-sched-section {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  overflow: hidden;
}
.fv-sched-section + .fv-sched-section { margin-top: 0; }
.fv-sched-section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  background: var(--surface-2);
  user-select: none;
  list-style: none;
  transition: background .12s;
}
.fv-sched-section-head::-webkit-details-marker { display: none; }
.fv-sched-section-head:hover { background: var(--surface-3); }
.fv-sched-caret {
  display: inline-block;
  width: 0; height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--text-muted);
  transform: rotate(-90deg);
  transition: transform .15s;
}
.fv-sched-section[open] .fv-sched-caret { transform: rotate(0deg); }
.fv-sched-cat-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--primary);
}
.fv-cat-shift-coverage .fv-sched-cat-dot   { background: #4a5a8a; }
.fv-cat-vitals        .fv-sched-cat-dot   { background: #a12b7b; }
.fv-cat-treatments    .fv-sched-cat-dot   { background: #964118; }
.fv-cat-adl-care      .fv-sched-cat-dot,
.fv-cat-adl           .fv-sched-cat-dot   { background: #437a22; }
.fv-cat-other         .fv-sched-cat-dot   { background: #8d8c86; }
.fv-sched-cat-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.fv-sched-totals {
  margin-left: auto;
  font-size: 11.5px;
  color: var(--text-muted);
}
.fv-sched-totals b { color: var(--text); font-weight: 700; }
.fv-sched-body {
  border-top: 1px solid var(--divider);
  background: var(--surface);
}
.fv-sched-scroll {
  overflow-x: auto;
  max-width: 100%;
}

/* ---------- The daily grid ---------- */
.fv-sched-grid {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 11.5px;
  width: max-content;
  min-width: 100%;
}
.fv-sched-grid th, .fv-sched-grid td {
  border-bottom: 1px solid var(--divider);
  border-right: 1px solid var(--divider);
  padding: 4px 6px;
  vertical-align: top;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.fv-sched-grid thead th {
  background: var(--surface-2);
  font-weight: 600;
  color: var(--text-muted);
  position: sticky;
  top: 0;
  z-index: 2;
}
.fv-sched-label-col {
  min-width: 200px;
  max-width: 280px;
  text-align: left;
  position: sticky;
  left: 0;
  background: var(--surface-2);
  z-index: 3;
}
.fv-sched-slot-col { min-width: 56px; text-align: center; }
.fv-sched-day {
  text-align: center;
  padding: 3px 4px;
  min-width: 26px;
}
.fv-sched-wd {
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-faint);
  font-weight: 500;
}
.fv-sched-dn {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
}

.fv-sched-row td { background: var(--surface); }
.fv-sched-row:hover td { background: var(--surface-2); }
.fv-sched-label {
  min-width: 200px;
  max-width: 280px;
  position: sticky;
  left: 0;
  background: var(--surface);
  z-index: 1;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.fv-sched-row:hover .fv-sched-label { background: var(--surface-2); }
.fv-sched-label-main {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}
.fv-sched-label-meta {
  margin-top: 3px;
  font-size: 10.5px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
}
.fv-sched-label-meta strong { color: var(--text); font-weight: 500; margin-right: 2px; }
.fv-sched-label-summary {
  margin-top: 5px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}
.fv-sched-rollup { display: inline-flex; gap: 3px; flex-wrap: wrap; }
.fv-sched-slot {
  text-align: center;
  white-space: nowrap;
  padding: 4px 6px;
}

/* Cell coloring — mirrors the heatmap legend */
.fv-sched-cell {
  text-align: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10.5px;
  min-width: 34px;
  max-width: 110px;
  padding: 3px 4px;
  vertical-align: top;
  line-height: 1.15;
}
.fv-sched-cell-mark {
  font-size: 11.5px;
  font-weight: inherit;
}
.fv-sched-cell-init {
  font-size: 9.5px;
  margin-top: 1px;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.02em;
}
.fv-sched-cell.fv-status-administered .fv-sched-cell-init,
.fv-sched-cell.fv-status-recorded .fv-sched-cell-init,
.fv-sched-cell.fv-status-code .fv-sched-cell-init {
  color: inherit;
  opacity: 0.78;
}
.fv-sched-cell.fv-status-scheduled    { background: #e6ecf2; color: #4a6380; }
.fv-sched-cell.fv-status-administered { background: #dbe8ce; color: #2f5618; font-weight: 700; }
.fv-sched-cell.fv-status-recorded     { background: #cddcd8; color: #014a52; font-weight: 600; }
.fv-sched-cell.fv-status-code         { background: #efd9c7; color: #7a3410; font-weight: 700; }
.fv-sched-cell.fv-status-blank        { background: var(--surface); color: var(--text-faint); }
.fv-sched-cell.fv-status-unknown      { background: #efd0e2; color: #741e58; }

[data-theme="dark"] .fv-sched-cell.fv-status-scheduled    { background: #26323f; color: #8ea4bd; }
[data-theme="dark"] .fv-sched-cell.fv-status-administered { background: #1f3322; color: #9ec780; }
[data-theme="dark"] .fv-sched-cell.fv-status-recorded     { background: #1f3a3d; color: #6cb1bb; }
[data-theme="dark"] .fv-sched-cell.fv-status-code         { background: #3a2a1d; color: #e2a479; }

/* ---------- mobile ---------- */
@media (max-width: 860px) {
  :root { --sidebar-w: 64px; }
  .brand h1, .brand-subtitle, .nav-label, .nav-item span, .footer-copy { display: none; }
  .nav-item { justify-content: center; padding: 11px; }
  .nav-item .badge { display: none; }
  .brand { padding: 0 0 16px; justify-content: center; }
  .brand-mark { margin: 0 auto; }
  .topbar { flex-direction: column; }
  .content { padding: 18px; }
}
