/* Shearwave Reporting — shared styles.
 *
 * Single source of truth for design tokens, which were previously duplicated
 * verbatim in index.html and reports.html.
 *
 * Breakpoints: 1200px (desktop two-pane), 900px (tablet), 600px (phone).
 * Below 900px the layout goes single-column and html/body MUST scroll — the
 * desktop view sets overflow:hidden for its locked two-pane layout, and if that
 * leaks through, a phone page becomes unscrollable. See CLAUDE.md section 9.
 */

:root {
  --ink: #0f1923;
  --ink-soft: #48555f;
  --paper: #f7f5f0;
  --paper-2: #eeeae2;
  --paper-3: #e4dfd5;
  --teal: #007b8a;
  --teal-dark: #005f6b;
  --red: #b83232;
  --amber: #a9640a;
  --green: #1a7a4a;
  --border: #d6d0c4;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(15, 25, 35, 0.08);
  /* 44px is the accessible minimum touch target; the old buttons were ~40px. */
  --touch: 44px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

html {
  overflow-x: hidden;
}

body {
  font-family: var(--font);
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

/* Every page that extends base.html (metrics capture, reports, admin) scrolls
 * normally. index.html uses app-shell too but keeps its own two-pane lock on
 * wide viewports via inline styles in index.html. */
body.app-shell {
  min-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 1200px) {
  html,
  body.report-page {
    height: auto !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }

  body.report-page .layout {
    overflow: visible !important;
    height: auto !important;
    flex: none !important;
  }

  body.report-page .panel {
    max-height: none !important;
    overflow: visible !important;
  }
}

/* ── App chrome ──────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  background: var(--ink);
  color: #fff;
  position: relative;
  z-index: 20;
}

.topbar-menu-btn {
  display: none;
}

.topbar .brand {
  --brand-title-size: 22px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  margin-right: auto;
  line-height: 1;
  flex-shrink: 0;
}

.brand-app-name,
.brand-sep {
  font-size: var(--brand-title-size);
  line-height: 1.15;
  color: #fff;
}

.brand-app-name {
  font-weight: 700;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.brand-sep {
  font-weight: 300;
  opacity: 0.45;
}

.brand-user-stack {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  height: calc(var(--brand-title-size) * 1.15);
  min-width: 0;
  padding-left: 6px;
}

.brand-user-name {
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  color: rgba(255, 255, 255, 0.88);
  white-space: nowrap;
  text-align: center;
}

.brand-badge {
  margin-top: 0;
  display: inline-block;
  align-self: center;
  padding: 1px 7px;
  font-size: 10px;
  line-height: 1.35;
}

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

.topbar-nav a {
  color: #dfe6ea;
  text-decoration: none;
  padding: 8px 12px;
  border-radius: var(--radius);
  min-height: var(--touch);
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
}

.topbar-nav a:hover,
.topbar-nav a:focus-visible {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.topbar-nav a.active {
  background: var(--teal);
  color: #fff;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.identity {
  font-size: 13px;
  color: #b9c4cb;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.25;
  text-align: right;
}

.identity strong {
  color: #fff;
  font-weight: 600;
}

.identity-badge {
  display: inline-block;
  margin-top: 2px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: #9a5b00;
  background: #ffe8c8;
}

.identity-badge--superadmin {
  color: #5b2d82;
  background: #ede4f7;
}

.identity-badge--clinic_admin {
  color: #9a5b00;
  background: #ffe8c8;
}

.identity-badge--clinician {
  color: #0d5c6d;
  background: #dff3f6;
}

.identity-meta {
  color: #b9c4cb;
  font-size: 12px;
}

/* Desktop / tablet wide: name lives in the left brand; right side is sign-out only. */
@media (min-width: 901px) {
  .topbar-actions .identity {
    display: none;
  }
}

.identity--compact {
  flex-direction: row;
  align-items: center;
}

.topbar-signout-btn {
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--border);
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 8px;
  min-height: var(--touch);
  display: inline-flex;
  align-items: center;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

.topbar-signout-btn:hover,
.topbar-signout-btn:focus-visible {
  background: var(--paper-2);
}

/* Mobile / tablet side drawer (hidden on desktop). */
.nav-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(15, 25, 35, 0.45);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

body.nav-open .nav-backdrop {
  opacity: 1;
  pointer-events: auto;
}

.nav-backdrop[hidden] {
  display: block;
  visibility: hidden;
}

body.nav-open .nav-backdrop[hidden] {
  visibility: visible;
}

.nav-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 1001;
  width: min(300px, 82vw);
  background: #fff;
  color: var(--ink);
  box-shadow: 4px 0 24px rgba(15, 25, 35, 0.18);
  transform: translateX(-105%);
  transition: transform 0.24s ease;
  display: flex;
  flex-direction: column;
  padding: 0;
}

body.nav-open .nav-drawer {
  transform: translateX(0);
}

body.nav-open {
  overflow: hidden;
}

.nav-drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
}

.nav-drawer-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--teal);
  line-height: 1.2;
}

.nav-drawer-sub {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--ink-soft);
}

.nav-drawer-close {
  width: var(--touch);
  height: var(--touch);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

.nav-drawer-links {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  flex: 1;
  overflow-y: auto;
}

.nav-drawer-links a {
  color: var(--ink);
  text-decoration: none;
  padding: 12px 14px;
  border-radius: 8px;
  font-weight: 500;
  min-height: var(--touch);
  display: flex;
  align-items: center;
}

.nav-drawer-links a:hover,
.nav-drawer-links a:focus-visible {
  background: var(--paper-2);
}

.nav-drawer-links a.active {
  background: rgba(0, 123, 138, 0.12);
  color: var(--teal);
  font-weight: 600;
}

.nav-drawer-foot {
  margin: 0;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}

.topbar-menu-btn {
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: var(--touch);
  height: var(--touch);
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  background: transparent;
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
}

.topbar-menu-icon {
  display: block;
  width: 18px;
  height: 2px;
  margin: 0 auto;
  border-radius: 1px;
  background: currentColor;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

body.nav-open .topbar-menu-icon:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

body.nav-open .topbar-menu-icon:nth-child(2) {
  opacity: 0;
}

body.nav-open .topbar-menu-icon:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

@media (min-width: 901px) {
  .nav-drawer,
  .nav-backdrop {
    display: none !important;
  }

  .topbar-signout-btn {
    background: transparent;
    border-color: transparent;
    color: #dfe6ea;
    font-weight: 500;
    padding: 8px 12px;
    border-radius: var(--radius);
  }

  .topbar-signout-btn:hover,
  .topbar-signout-btn:focus-visible {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
  }
}

/* ── Layout ──────────────────────────────────────────────────────────────── */

.page {
  padding: 18px;
  max-width: 1400px;
  margin: 0 auto;
  padding-bottom: max(24px, env(safe-area-inset-bottom, 0px));
}

.page-narrow {
  max-width: 860px;
}

.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}

.card h1,
.card h2 {
  margin-top: 0;
}

h1 {
  font-size: 22px;
}

h2 {
  font-size: 17px;
}

.muted {
  color: var(--ink-soft);
  font-size: 13px;
}

.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

/* ── Forms ───────────────────────────────────────────────────────────────── */

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.password-field .password-input-wrap {
  position: relative;
}

.password-field .password-input-wrap input {
  padding-right: 44px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.password-toggle:hover {
  color: var(--ink);
  background: rgba(41, 70, 93, 0.08);
}

.password-toggle svg {
  width: 20px;
  height: 20px;
  pointer-events: none;
}

.password-toggle .icon-eye-off {
  display: none;
}

.password-toggle.is-visible .icon-eye {
  display: none;
}

.password-toggle.is-visible .icon-eye-off {
  display: block;
}

.login-links {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: -4px 0 14px;
  font-size: 14px;
}

.login-links a {
  color: var(--teal);
  text-decoration: none;
}

.login-links a:hover {
  text-decoration: underline;
}

label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

input,
select,
textarea {
  font-family: inherit;
  font-size: 15px; /* >=16px avoids iOS auto-zoom on focus; 15 is a compromise */
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 10px;
  min-height: var(--touch);
  width: 100%;
}

textarea {
  min-height: 90px;
  resize: vertical;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 1px;
}

.required::after {
  content: " *";
  color: var(--red);
}

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

button,
.btn {
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  min-height: var(--touch);
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
}

button:hover:not(:disabled),
.btn:hover {
  background: #1c2a36;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--teal);
  border-color: var(--teal);
}

.btn-primary:hover:not(:disabled) {
  background: var(--teal-dark);
}

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--paper-2);
}

.btn-danger {
  background: var(--red);
  border-color: var(--red);
}

.btn-sm {
  font-size: 13px;
  padding: 6px 12px;
  min-height: 36px;
}

/* ── Status and badges ───────────────────────────────────────────────────── */

.status {
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--paper-2);
  border: 1px solid var(--border);
}

.status.success {
  background: #e6f4ec;
  border-color: #b6ddc6;
  color: var(--green);
}

.status.error {
  background: #fbeaea;
  border-color: #e5bcbc;
  color: var(--red);
}

.status.warn {
  background: #fdf3e3;
  border-color: #ecd6ac;
  color: var(--amber);
}

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--paper-3);
  color: var(--ink-soft);
  white-space: nowrap;
}

.badge-image {
  background: #d7edf1;
  color: var(--teal-dark);
}

.badge-document {
  background: var(--paper-3);
  color: var(--ink-soft);
}

.badge-ok {
  background: #d9f0e3;
  color: var(--green);
}

.badge-bad {
  background: #f7d9d9;
  color: var(--red);
}

.badge-role {
  background: #dfe6ea;
  color: var(--ink);
}

/* ── Tables ──────────────────────────────────────────────────────────────── */

.table-wrap {
  overflow-x: auto; /* wide tables scroll themselves, never the page body */
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  text-align: left;
  padding: 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--ink-soft);
  background: var(--paper-2);
  white-space: nowrap;
}

tbody tr:hover {
  background: #fafaf7;
}

/* My Reports / Admin report rows — 2×2 action grid (never 3+1 orphan). */
.report-row-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
  max-width: 17.5rem;
  margin-left: auto;
}

.report-row-actions button,
.report-row-actions .btn {
  min-width: 0;
  width: 100%;
  min-height: 36px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
}

/* Three visible actions (History hidden on phone): one full-width row. */
.report-row-actions > :last-child:nth-child(3) {
  grid-column: 1 / -1;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.stat {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.stat .value {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.1;
}

.stat .label {
  font-size: 12px;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* ── Metrics matrix ──────────────────────────────────────────────────────── */
/* Mirrors the device's table: 4 metric columns x 3 value rows (Med/IQR/IQR%).
 * Kept as a table on phones inside .table-wrap rather than stacked into 12
 * labelled rows, which loses the row/column relationship the clinician reads. */

.metrics-matrix {
  min-width: 620px;
}

.metrics-matrix th {
  background: var(--paper-2);
}

.metrics-matrix td {
  padding: 6px;
}

.metrics-matrix .rowhead {
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
  background: var(--paper);
  text-transform: none;
  letter-spacing: 0;
}

.metrics-matrix input {
  min-height: 40px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Source badging so a clinician can see which cells came from the photo. */
.metrics-matrix input.from-image {
  border-color: var(--teal);
  background: #f2fafb;
}

.metrics-matrix input.from-document {
  border-color: var(--border);
  background: var(--paper-2);
}

.field input.from-image {
  border-color: #2a7a4b;
  background: #f4fbf6;
}

.unit {
  font-size: 11px;
  color: var(--ink-soft);
  font-weight: 500;
  display: block;
  text-transform: none;
  letter-spacing: 0;
}

/* ── Capture ─────────────────────────────────────────────────────────────── */

.capture-drop {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px 18px;
  text-align: center;
  background: #fff;
}

.capture-preview-hint {
  margin: 12px 0 0;
  font-size: 13px;
}

.capture-preview-area {
  margin-top: 12px;
}

.capture-preview-area[hidden],
.capture-preview-hint[hidden],
[hidden] {
  display: none !important;
}

.capture-preview {
  max-width: 100%;
  max-height: 320px;
  border-radius: 6px;
  border: 1px solid var(--border);
  display: block;
  margin: 0 auto;
}

.capture-clear {
  margin-top: 8px;
}

.site-picker {
  margin-bottom: 12px;
  padding: 12px;
  background: var(--paper-2);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.site-picker label {
  display: block;
  margin-bottom: 4px;
}

.site-picker-help {
  margin: 0 0 8px;
  font-size: 13px;
  line-height: 1.4;
}

.site-picker select {
  max-width: 280px;
}

.quality-strip {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  font-size: 13px;
  padding: 10px 12px;
  background: var(--paper-2);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.quality-strip b {
  font-variant-numeric: tabular-nums;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
  vertical-align: middle;
}

.spinner-lg {
  width: 42px;
  height: 42px;
  border-width: 3px;
  border-color: rgba(0, 123, 138, 0.25);
  border-top-color: var(--teal);
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 25, 35, 0.55);
  padding: 20px;
}

.loading-overlay[hidden] {
  display: none !important;
}

.loading-overlay-card {
  background: #fff;
  border-radius: 12px;
  padding: 28px 32px;
  text-align: center;
  max-width: 360px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.loading-overlay-card p {
  margin: 14px 0 0;
  color: var(--ink-soft);
  font-size: 15px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  max-width: 720px;
  width: calc(100% - 32px);
  box-shadow: 0 12px 40px rgba(15, 25, 35, 0.25);
}

/* Once results (quality strip + 12-cell matrix) fill the dialog, its content
 * can run taller than a phone viewport. The whole dialog used to scroll as one
 * block, so the header/Close button scrolled away and Apply — at the very
 * bottom, past the matrix's own horizontal scroller — needed a long, easy-to-
 * miss scroll to reach. Reported as "no way to access other buttons" on
 * mobile. `dialog[open]` (not bare `dialog`) so this never fights the UA's
 * `dialog:not([open]) { display: none }` for a closed dialog. */
dialog[open] {
  display: flex;
  flex-direction: column;
  max-height: 85vh;
  overflow: hidden;
}

dialog::backdrop {
  background: rgba(15, 25, 35, 0.45);
}

/* Confirm/prompt modal (Api.confirmDialog / Api.promptDialog) is a short
 * question, not a form — the shared 720px dialog width leaves it looking
 * empty, so narrow it down. */
dialog.confirm-dialog {
  max-width: 420px;
}

dialog.confirm-dialog .dialog-body input {
  width: 100%;
  margin-top: 4px;
}

dialog.confirm-dialog .dialog-body p[data-role="message"] {
  margin: 0;
}

dialog.confirm-dialog .dialog-body p[data-role="hint"] {
  margin: 6px 0 0;
  font-size: 12px;
}

dialog.confirm-dialog form.dialog-form {
  margin: 0;
  border: 0;
  padding: 0;
}

dialog.confirm-dialog .dialog-actions {
  justify-content: flex-end;
  margin-top: 16px;
  flex-wrap: wrap;
  gap: 8px;
}

dialog.confirm-dialog .dialog-actions > button {
  min-height: 40px;
}

dialog.confirm-dialog .dialog-actions--choice {
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  margin-top: 16px;
  gap: 10px;
}

dialog.confirm-dialog .dialog-actions--choice > button {
  width: 100%;
  min-height: 44px;
  margin: 0;
}

@media (max-width: 900px) {
  dialog.confirm-dialog {
    width: min(420px, calc(100vw - 24px));
    max-width: none;
  }

  dialog.confirm-dialog .dialog-actions {
    flex-direction: column;
    align-items: stretch;
  }

  dialog.confirm-dialog .dialog-actions > button {
    width: 100%;
    min-height: 44px;
  }
}

.dialog-body {
  padding: 18px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1 1 auto;
  min-height: 0;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex: none;
}

.dialog-head h2 {
  margin: 0;
}

/* Keep the primary action reachable without scrolling past the metrics
 * matrix's own horizontal scroller first. */
.dialog-body [data-role="results"] > .row:last-child {
  position: sticky;
  bottom: 0;
  margin-top: 10px;
  padding: 10px 0;
  background: #fff;
  border-top: 1px solid var(--border);
}

/* ── Tablet ──────────────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  /* Belt-and-braces for any page that might inherit overflow:hidden from elsewhere. */
  html,
  body.app-shell {
    height: auto !important;
    overflow-y: auto !important;
  }

  .page {
    padding: 12px;
  }

  .grid,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }

  .card {
    padding: 14px;
  }

  /* Wide admin tables become cards on tablet and phone. */
  table.stack-on-phone thead {
    display: none;
  }

  table.stack-on-phone,
  table.stack-on-phone tbody,
  table.stack-on-phone tr,
  table.stack-on-phone td {
    display: block;
    width: 100%;
  }

  table.stack-on-phone tr {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 10px;
    padding: 6px 10px;
    background: #fff;
  }

  table.stack-on-phone td {
    border: none;
    padding: 5px 0;
    display: flex;
    justify-content: space-between;
    gap: 12px;
  }

  table.stack-on-phone td::before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--ink-soft);
    flex: 0 0 42%;
  }

  table.stack-on-phone td.table-actions-cell {
    justify-content: stretch;
    padding-top: 10px;
    margin-top: 4px;
    border-top: 1px solid var(--border);
  }

  table.stack-on-phone td.table-actions-cell .report-row-actions {
    max-width: none;
    margin-left: 0;
  }

  table.stack-on-phone td.table-actions-cell::before {
    display: none;
  }

  .table-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 8px;
    width: 100%;
  }

  .table-actions > button,
  .table-actions > .btn {
    width: auto;
    flex: 1 1 calc(50% - 8px);
    min-width: 6.5rem;
    max-width: 100%;
  }

  /* Compact top bar + left slide-out nav (not a dropdown). */
  .topbar {
    padding: 10px 12px;
    gap: 10px;
  }

  .topbar-menu-btn {
    display: inline-flex;
    order: -1;
  }

  .topbar .brand {
    display: none;
  }

  .topbar-nav {
    display: none;
  }

  .topbar-actions {
    margin-left: auto;
    gap: 10px;
  }

  .identity {
    align-items: flex-end;
  }

  .identity-meta {
    display: none;
  }

  .topbar-signout-btn {
    padding: 8px 12px;
    font-size: 13px;
  }
}

/* ── Phone ───────────────────────────────────────────────────────────────── */

@media (max-width: 600px) {
  body {
    font-size: 15px;
  }

  h1 {
    font-size: 19px;
  }

  .row:not(.table-actions) > button,
  .row:not(.table-actions) > .btn {
    width: 100%;
  }
}

@media print {
  .topbar,
  .no-print {
    display: none !important;
  }
}

/* ── Searchable combobox (admin clinic picker) ───────────────────────────── */

.combobox {
  position: relative;
}

.combobox-list {
  position: absolute;
  z-index: 20;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  margin: 0;
  padding: 4px 0;
  list-style: none;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: 220px;
  overflow-y: auto;
}

.combobox-list li {
  padding: 10px 12px;
  cursor: pointer;
}

.combobox-list li:hover,
.combobox-list li[aria-selected="true"] {
  background: var(--paper-2);
}

.combobox-list li.muted-option {
  color: var(--ink-soft);
  font-style: italic;
}

.combobox-list li.empty {
  color: var(--ink-soft);
  cursor: default;
}

.combobox-list li.combobox-create {
  border-top: 1px solid var(--border);
  color: var(--teal-dark);
  font-weight: 500;
}

.combobox-list li.combobox-create strong {
  font-weight: 700;
  color: var(--teal);
}

.combobox.is-obsolete {
  opacity: 0.55;
}

.combobox.is-obsolete input[type="text"] {
  pointer-events: none;
  background: var(--paper-2);
}
