:root {
  --bg: #f7f5f0;
  --card: #ffffff;
  --ink: #23241f;
  --muted: #6b6a63;
  --line: #e4e0d5;
  --accent: #a6704a;
  --accent-dark: #7d4f30;
  --calico-cream: #f1e4c8;
  --calico-orange: #d98a4a;
  --calico-black: #2c2a26;
  --open: #b3441e;
  --pending: #a3791f;
  --resolved: #3c7a4b;
  --ruled-out: #4a6d8c;
  --critical-bg: #fbe7de;
  --high-bg: #fbf0de;
  --moderate-bg: #f2f0e6;
  --radius: 10px;
  font-family: "Georgia", "Iowan Old Style", "Palatino Linotype", serif;
}

* { box-sizing: border-box; }

html {
  /* Prevent a single too-wide descendant (a big table, a long unbroken
     string, etc.) from ever forcing the WHOLE page to scroll sideways.
     Any content that genuinely needs horizontal scroll gets its own
     .table-scroll wrapper (overflow-x: auto) instead — see below. */
  overflow-x: hidden;
  width: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  font-size: 16px;
  overflow-x: hidden;
  width: 100%;
}

a { color: var(--accent-dark); }

.wrap {
  max-width: 880px;
  margin: 0 auto;
  padding: 0 20px 80px;
}

/* ---------- Top bar ---------- */
header.top {
  position: relative; /* anchors .nav-toggle to this corner, not the flex row */
  background: linear-gradient(135deg, var(--calico-black), #3c3a34);
  color: #f5f1e6;
  padding: 18px 20px 14px;
  border-bottom: 4px solid var(--calico-orange);
}
header.top .inner {
  max-width: 880px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
header.top h1 {
  font-size: 1.35rem;
  margin: 0;
  letter-spacing: 0.02em;
}
header.top .tag {
  font-size: 0.8rem;
  color: #e7cfa0;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

nav.section-nav {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #fffdf8;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  white-space: nowrap;
  padding: 10px 20px;
}
nav.section-nav a {
  display: inline-block;
  margin-right: 18px;
  font-size: 0.85rem;
  text-decoration: none;
  color: var(--ink);
  border-bottom: 2px solid transparent;
  padding-bottom: 2px;
}
nav.section-nav a:hover { border-color: var(--accent); }

/* Hamburger button — hidden on desktop, shown only under the mobile
   breakpoint (see media query below) where the horizontal nav is hidden
   and this + the slide-out drawer take over. */
.nav-toggle {
  display: none;
  /* Fixed to the viewport (not the header) so it floats in place as the
     page scrolls — always reachable, never scrolls away with the header. */
  position: fixed;
  top: 14px;
  right: 16px;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 38px;
  height: 38px;
  padding: 8px 9px;
  background: linear-gradient(135deg, var(--calico-black), #3c3a34);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  box-shadow: 0 4px 14px rgba(35, 30, 20, 0.3);
  cursor: pointer;
  flex-shrink: 0;
  z-index: 45;
}
.nav-toggle span {
  display: block;
  height: 2px;
  width: 100%;
  background: #f5f1e6;
  border-radius: 1px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.nav-toggle.active span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.nav-toggle.active span:nth-child(2) { opacity: 0; }
.nav-toggle.active span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* Slide-out mobile nav drawer */
.nav-drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20, 18, 14, 0.45);
  z-index: 40;
}
.nav-drawer-overlay.open { display: block; }

.nav-drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: 80%;
  max-width: 300px;
  background: #fffdf8;
  z-index: 50;
  box-shadow: -8px 0 28px rgba(0, 0, 0, 0.22);
  transform: translateX(100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.nav-drawer.open { transform: translateX(0); }
.nav-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  font-weight: bold;
  color: var(--accent-dark);
  flex-shrink: 0;
}
.nav-drawer-close {
  background: none;
  border: none;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 8px 10px;
}
.nav-drawer-links { display: flex; flex-direction: column; padding: 6px 0; }
.nav-drawer-links a {
  padding: 15px 20px;
  text-decoration: none;
  color: var(--ink);
  font-size: 1rem;
  border-bottom: 1px dotted var(--line);
  float: none !important;
}
.nav-drawer-links a:active, .nav-drawer-links a:hover { background: #f4f1e8; }

/* Search box duplicated at the top of the drawer — same behaviour and
   results index as the main search box, so it's reachable without
   scrolling back to the top of the page. */
.nav-drawer-search {
  position: relative;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.nav-drawer-search input {
  width: 100%;
  padding: 11px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  font-size: 16px; /* keeps iOS Safari from zooming in on focus */
  min-height: 44px;
  font-family: inherit;
  background: #faf8f2;
}
.nav-drawer-search input:focus { outline: 2px solid var(--accent); }
.nav-drawer-search .search-count { font-size: 0.72rem; color: var(--muted); margin-top: 5px; }

/* Floating "back to top" button */
.back-to-top {
  display: none;
  position: fixed;
  bottom: 22px;
  right: 16px;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--accent-dark);
  color: #fff;
  border: none;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(35, 30, 20, 0.3);
  z-index: 35;
}
.back-to-top.visible { display: flex; }
.back-to-top:active { background: var(--accent); }

/* ---------- Disclaimer ---------- */
.disclaimer {
  background: #fff7ea;
  border: 1px solid #e8d6a8;
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 0.85rem;
  color: #5c4a1f;
  margin: 22px 0;
}
.disclaimer strong { color: #7d4f30; }

/* ---------- Search ---------- */
.search-box {
  margin: 20px 0;
  position: relative;
}
.search-box input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  font-size: 0.95rem;
  background: var(--card);
  font-family: inherit;
}
.search-box input:focus { outline: 2px solid var(--accent); }
.search-count {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 6px;
}

/* Global search results dropdown — a cross-section list of every matching
   record, distinct from the in-place dimming that also happens on every
   [data-search] node. Clicking a result scrolls to and flashes it. */
.search-results {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 6px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 28px rgba(35, 30, 20, 0.15);
  max-height: 60vh;
  overflow-y: auto;
  z-index: 30;
}
.search-results.open { display: block; }
.search-result {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.search-result:last-child { border-bottom: none; }
.search-result:hover, .search-result:active { background: #faf8f2; }
.search-result .sr-section {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent-dark);
  font-weight: 700;
  margin-bottom: 3px;
}
.search-result .sr-snippet { font-size: 0.86rem; color: var(--ink); line-height: 1.4; }
.search-result .sr-snippet mark { background: #ffe08a; padding: 0 2px; border-radius: 2px; }
.search-no-results, .search-more {
  padding: 12px 14px;
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
}

/* Flash highlight applied briefly to whatever record a search result links
   to, so it's obvious what scrolled into view — outline (not background)
   so it still shows correctly on table rows and colour-coded lab cells. */
.search-flash {
  outline: 3px solid var(--calico-orange);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- Cards / sections ---------- */
section.block {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin: 18px 0;
}
section.block h2 {
  margin-top: 0;
  font-size: 1.15rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}
section.block h2 .icon { margin-right: 6px; }

.hidden-by-search { display: none !important; }
mark { background: #ffe08a; padding: 0 2px; border-radius: 2px; }

/* ---------- Patient ID grid ---------- */
.id-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 24px;
}
.id-grid .field { border-bottom: 1px dotted var(--line); padding-bottom: 6px; }
.id-grid .field .k { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.id-grid .field .v { font-size: 0.95rem; }
@media (max-width: 560px) { .id-grid { grid-template-columns: 1fr; } }

/* ---------- Owner account ---------- */
.owner-account p {
  background: #f4f1e8;
  border-left: 4px solid var(--calico-orange);
  padding: 10px 14px;
  border-radius: 0 6px 6px 0;
  margin: 12px 0;
  font-size: 0.95rem;
}

/* ---------- Problem list ---------- */
.problem {
  border-radius: 8px;
  padding: 12px 14px;
  margin: 10px 0;
  border: 1px solid var(--line);
}
.problem.status-open { background: var(--critical-bg); }
.problem.severity-high { background: var(--high-bg); }
.problem.severity-moderate { background: var(--moderate-bg); }
.problem.status-pending { background: #eef1f3; }
.problem.status-resolved { background: #e7f3e9; opacity: 0.85; }
.problem.status-ruled-out { background: #eaf1f6; opacity: 0.85; }
.problem.status-presumed-resolved { background: #faf3e2; opacity: 0.9; }
.problem .ptitle { font-weight: bold; }
.problem .pbadge {
  display: inline-block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 20px;
  margin-left: 8px;
  vertical-align: middle;
}
.pbadge.open { background: var(--open); color: #fff; }
.pbadge.pending { background: var(--pending); color: #fff; }
.pbadge.resolved { background: var(--resolved); color: #fff; }
.pbadge.ruled-out { background: var(--ruled-out); color: #fff; }
/* Distinct from a plain "resolved" badge: the problem is being treated as
   closed based on completed treatment + no recurrence, but nothing on file
   (e.g. a repeat lab test) actually confirms it cleared. Amber, not green,
   so it reads as "probably fine, unverified" rather than "confirmed fine". */
.pbadge.presumed-resolved { background: var(--pending); color: #fff; }
.problem .pdetail { font-size: 0.88rem; color: #454439; margin-top: 4px; }
.problem .pdetail p { margin: 0 0 8px; }
.problem .pdetail p:last-child { margin-bottom: 0; }
.problem .pdetail ul { margin: 0 0 8px; padding-left: 20px; }
.problem .pdetail ul:last-child { margin-bottom: 0; }
.problem .pdetail li { margin-bottom: 4px; }
.problem .pdetail li:last-child { margin-bottom: 0; }

/* ---------- Timeline ---------- */
.timeline-item {
  position: relative;
  padding: 10px 0 10px 26px;
  border-left: 2px solid var(--line);
  margin-left: 6px;
}
.timeline-item::before {
  content: "";
  position: absolute;
  left: -7px;
  top: 16px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--card);
}
.timeline-item.category-major::before { background: var(--open); }
.timeline-item.category-upcoming::before { background: var(--pending); }
.timeline-item.timeline-item-grouped { padding-top: 4px; }
.timeline-item.timeline-item-grouped::before { top: 10px; width: 8px; height: 8px; opacity: 0.7; }
.timeline-item .tdate {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.timeline-item .ttitle { font-weight: bold; margin: 2px 0 4px; }
.timeline-item .tbody { font-size: 0.92rem; }
.timeline-item .tbody p { margin: 0 0 8px; }
.timeline-item .tbody p:last-child { margin-bottom: 0; }
.timeline-item .tbody ul { margin: 0 0 8px; padding-left: 20px; }
.timeline-item .tbody ul:last-child { margin-bottom: 0; }
.timeline-item .tbody li { margin-bottom: 4px; }
.timeline-item .tbody li:last-child { margin-bottom: 0; }
.timeline-item .tsource { font-size: 0.75rem; color: var(--muted); margin-top: 6px; font-style: italic; }
.timeline-item blockquote {
  margin: 6px 0;
  padding: 8px 12px;
  background: #f4f1e8;
  border-left: 3px solid var(--accent);
  font-style: italic;
}

/* ---------- Tables ---------- */
/* Any table wide enough to overflow a phone screen goes inside this wrapper
   so IT scrolls sideways in its own little box — never the whole page. */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 8px;
}
.table-scroll table.data {
  margin-top: 0;
  border: none;
  border-radius: 0;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  margin-top: 8px;
}
table.data th, table.data td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
table.data th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: #faf8f2;
}
table.data tr:hover td { background: #fbf9f3; }
.pending-flag { color: var(--pending); font-weight: bold; }

/* Small "swipe for more" hint — only shown on narrow screens, only for
   tables that actually need horizontal scrolling there. */
.scroll-hint {
  display: none;
  font-size: 0.74rem;
  color: var(--muted);
  text-align: center;
  padding: 4px 0 2px;
}

/* ---------- Lab Results master table ---------- */
.labresults-filter { margin: 12px 0; position: relative; }
.labresults-filter input {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  font-size: 0.9rem;
  background: var(--card);
  font-family: inherit;
}
.labresults-filter input:focus { outline: 2px solid var(--accent); }
.labresults-filter-count { font-size: 0.76rem; color: var(--muted); margin-top: 4px; }
.labresults-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 0.78rem;
  color: var(--muted);
  margin: 8px 0 4px;
}
.labresults-legend .swatch {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 2px;
  margin-right: 4px;
  vertical-align: middle;
  background: #f2f0e6;
  border: 1px solid var(--line);
}
.labresults-legend .swatch.high { background: #f6c9bb; border-color: #e0836a; }
.labresults-legend .swatch.low { background: #f7e2a6; border-color: #c9a23d; }
.labresults-legend .swatch.normal { background: #dcefe0; border-color: #8fbf9b; }
.labresults-table-wrap {
  overflow-x: auto;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
}
table.labresults-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.82rem;
  white-space: nowrap;
}
table.labresults-table th, table.labresults-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  text-align: center;
}
table.labresults-table thead th {
  background: #faf8f2;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  position: sticky;
  top: 0;
  z-index: 2;
}
table.labresults-table td.param-name, table.labresults-table th.param-name {
  text-align: left;
  position: sticky;
  left: 0;
  background: #fffdf8;
  z-index: 1;
  border-right: 1px solid var(--line);
  white-space: normal;
  min-width: 170px;
  font-weight: 600;
  color: var(--ink);
}
table.labresults-table thead th.param-name { z-index: 3; }
table.labresults-table td.cell-high { background: #fbe3d8; color: #8a3a1e; font-weight: 700; }
table.labresults-table td.cell-low { background: #fbeec2; color: #6b4f0f; font-weight: 700; }
table.labresults-table td.cell-normal { color: var(--ink); }
table.labresults-table td.cell-empty { color: #c9c5b8; }
table.labresults-table tr.hidden-by-search { display: none !important; }
table.labresults-table tr:hover td:not(.param-name) { filter: brightness(0.97); }
.labresults-notes { margin-top: 12px; font-size: 0.8rem; color: var(--muted); }
.labresults-notes .lr-note { margin: 4px 0; padding-left: 10px; border-left: 3px solid var(--line); }

/* ---------- Urinalysis ---------- */
.urine-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px 20px; margin: 10px 0; }
.urine-grid .field .k { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.urine-grid .field .v { font-size: 0.9rem; }
.susceptibility-note { font-size: 0.82rem; background: #fff7ea; border: 1px solid #e8d6a8; border-radius: 8px; padding: 10px 12px; margin-top: 10px; color: #5c4a1f; }

/* ---------- Imaging attached media (one card can hold several scans) ---------- */
.imaging-media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  margin-top: 10px;
}
.imaging-media-item {
  width: 100%;
  height: 150px;
  object-fit: cover;
  border-radius: 8px;
  background: #000;
  display: block;
}
img.imaging-media-item { cursor: pointer; }
.imaging-media-file {
  display: flex;
  align-items: center;
  height: 150px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.85rem;
  text-decoration: none;
  color: var(--accent-dark);
  background: #faf8f2;
}

/* ---------- Med lists ---------- */
.med-group h3 { font-size: 0.95rem; margin-bottom: 6px; color: var(--accent-dark); }
.med-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px dotted var(--line);
  font-size: 0.9rem;
}
.med-item .mname { font-weight: 600; }
.med-item .mmeta { color: var(--muted); font-size: 0.82rem; text-align: right; }

/* ---------- Weight chart ---------- */
.weight-chart {
  width: 100%;
  height: 180px;
  margin-top: 10px;
}

/* ---------- Financial ---------- */
.fin-total {
  display: flex;
  justify-content: space-between;
  font-weight: bold;
  padding-top: 10px;
  margin-top: 6px;
  border-top: 2px solid var(--ink);
}

/* ---------- Gallery ---------- */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 10px;
}
.gallery-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fafafa;
  cursor: pointer;
  text-align: center;
}
.gallery-item .thumb {
  width: 100%;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #eee;
  font-size: 1.6rem;
}
.gallery-item .cap { font-size: 0.72rem; padding: 6px; color: var(--muted); }
.gallery-item.missing .thumb { background: #f4e9e2; color: var(--open); font-size: 0.75rem; padding: 6px; }

/* ---------- Footer ---------- */
footer {
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted);
  padding: 30px 20px;
}
footer a { color: var(--muted); }

/* ---------- Admin ---------- */
.admin-box {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin: 20px 0;
}
.admin-box label { display: block; font-size: 0.82rem; margin: 10px 0 4px; color: var(--muted); }
.admin-box input, .admin-box select, .admin-box textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.9rem;
}
.admin-box textarea { min-height: 80px; }
.admin-box button {
  margin-top: 14px;
  background: var(--accent-dark);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
}
.admin-box button:hover { background: var(--accent); }
.status-msg { font-size: 0.85rem; margin-top: 8px; }
.status-msg.ok { color: var(--resolved); }
.status-msg.err { color: var(--open); }
.upload-list { margin-top: 16px; font-size: 0.85rem; }
.upload-list li { padding: 4px 0; border-bottom: 1px dotted var(--line); }

/* ---------- AI Review Queue ---------- */
.ai-queue-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  margin-top: 14px;
  background: rgba(255,255,255,0.5);
}
.ai-queue-card-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
}
.ai-queue-badge {
  display: inline-block;
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-dark);
  color: #fff;
}
.ai-queue-badge.failed { background: var(--open, #b3402f); }
.ai-queue-meta { font-size: 0.78rem; color: var(--muted); margin: 4px 0 10px; }
.ai-queue-notes {
  font-size: 0.8rem;
  color: var(--muted);
  background: rgba(0,0,0,0.03);
  border-radius: 6px;
  padding: 8px 10px;
  margin: 8px 0;
}
.ai-queue-fields { display: none; }
.ai-queue-fields.active { display: block; }
.ai-queue-actions { display: flex; gap: 10px; margin-top: 12px; }
.ai-queue-actions button { margin-top: 0; }
.ai-queue-actions .reject-btn { background: #6b6a63; }
.ai-queue-actions .reject-btn:hover { background: #55544e; }
.ai-queue-empty { font-size: 0.85rem; color: var(--muted); margin-top: 10px; }

/* =====================================================================
   MOBILE / NARROW VIEWPORT ADJUSTMENTS
   Phones are the primary way this record actually gets checked in the
   moment, so tables need to scroll WITHIN themselves (sticky first
   column), filter inputs need to be big enough to tap accurately, and
   nothing should ever force the whole page to scroll sideways.
   ===================================================================== */
@media (max-width: 640px) {
  .wrap { padding: 0 12px 60px; }
  section.block { padding: 16px 14px; margin: 14px 0; }
  header.top h1 { font-size: 1.1rem; }
  /* Reserve room on the right of the title/tag row so they never run
     underneath the absolutely-positioned hamburger button. */
  header.top .inner { padding-right: 52px; }

  /* Horizontal nav gives way to the hamburger + slide-out drawer below
     640px — scrolling a cramped single-line nav sideways on a phone was
     the reported problem, so this swaps the pattern entirely rather than
     just shrinking it. */
  nav.section-nav { display: none; }
  .nav-toggle { display: flex; }

  /* 16px stops iOS Safari auto-zooming the page when a text input is
     focused, and gives every filter/search box a comfortably tappable
     height. */
  .search-box input,
  .labresults-filter input {
    font-size: 16px;
    padding: 12px 14px;
    min-height: 46px;
  }

  /* Plain data tables (Labs & Tests, Financial, Urinalysis) — compact
     type, tighter padding, and they live inside .table-scroll so only
     the table itself scrolls sideways if it's still too wide. */
  table.data { font-size: 0.8rem; }
  table.data th, table.data td { padding: 7px 8px; }

  /* Master Lab Results matrix — shrink everything and narrow the sticky
     parameter column so more date columns are visible at once, then
     show the swipe hint since 5+ date columns essentially always need
     horizontal scroll on a phone. */
  .labresults-legend { font-size: 0.72rem; gap: 10px; }
  table.labresults-table { font-size: 0.74rem; }
  table.labresults-table th, table.labresults-table td { padding: 6px 8px; }
  table.labresults-table td.param-name, table.labresults-table th.param-name {
    min-width: 118px;
    max-width: 118px;
    font-size: 0.72rem;
    line-height: 1.25;
  }
  .scroll-hint { display: block; }

  /* Financial and urinalysis sub-tables sit inside prose sections without
     their own explicit width rule — keep their font compact too. */
  .urine-grid { grid-template-columns: repeat(2, 1fr); gap: 8px 12px; }

  /* Global search results — slightly taller tap targets on phones. */
  .search-results { max-height: 50vh; }
  .search-result { padding: 12px 14px; }
}

@media (max-width: 400px) {
  table.labresults-table td.param-name, table.labresults-table th.param-name {
    min-width: 100px;
    max-width: 100px;
  }
}
