/* =========================================================================
   Meridian HMS — design system

   Written as tokens first, components second. The palette is a clinical teal
   against warm greys: high contrast for dense tables, calm enough to sit in
   front of for a nine-hour shift. Light and dark are both first-class; dark is
   a token override, not a second stylesheet.

   Type is the system UI stack on purpose — a webfont would be another 90 KB on
   a connection that may be a rural 3G tether, and this system has to work
   there.
   ========================================================================= */

:root {
  /* Brand */
  --teal-50:  #eaf5f4;
  --teal-100: #cbe6e4;
  --teal-200: #9ccfcc;
  --teal-300: #66b2ae;
  --teal-400: #33928e;
  --teal-500: #0e6f6f;
  --teal-600: #0a5a5b;
  --teal-700: #084748;
  --teal-800: #063536;

  /* Neutrals — very slightly warm so white cards do not read as blue */
  --grey-0:   #ffffff;
  --grey-25:  #fbfcfc;
  --grey-50:  #f4f7f7;
  --grey-100: #e9eded;
  --grey-200: #d8dfdf;
  --grey-300: #bcc6c6;
  --grey-400: #93a0a1;
  --grey-500: #6c7a7b;
  --grey-600: #4e5a5b;
  --grey-700: #384243;
  --grey-800: #232b2c;
  --grey-900: #151b1c;

  /* Status */
  --red-50:   #fdeceb;  --red-100: #fbd5d2; --red-500: #c8372d; --red-600: #a52b23;
  --amber-50: #fdf3e2;  --amber-100: #f9e3bd; --amber-500: #b57614; --amber-600: #92600f;
  --green-50: #e8f5ec;  --green-100: #cbe8d5; --green-500: #1f7a45; --green-600: #176036;
  --blue-50:  #eaf1fb;  --blue-100: #cfdff5; --blue-500: #2c5aa8; --blue-600: #234785;
  --violet-50:#f1edfa; --violet-100:#ded5f3; --violet-500:#5b45a8;

  /* Semantic (light) */
  --bg:            var(--grey-50);
  --bg-raised:     var(--grey-0);
  --bg-sunken:     var(--grey-100);
  --bg-inset:      var(--grey-25);
  --sidebar-bg:    #0b3b3d;
  --sidebar-fg:    #cfe3e2;
  --sidebar-fg-dim:#8fb3b2;
  --sidebar-active:#12595a;
  --text:          var(--grey-900);
  --text-soft:     var(--grey-600);
  --text-dim:      var(--grey-500);
  --text-invert:   #ffffff;
  --line:          var(--grey-200);
  --line-soft:     var(--grey-100);
  --line-strong:   var(--grey-300);
  --accent:        var(--teal-500);
  --accent-hover:  var(--teal-600);
  --accent-soft:   var(--teal-50);
  --accent-border: var(--teal-200);
  --focus:         #1f8f8f;

  --danger: var(--red-500);       --danger-soft: var(--red-50);   --danger-border: var(--red-100);
  --warn: var(--amber-500);       --warn-soft: var(--amber-50);   --warn-border: var(--amber-100);
  --ok: var(--green-500);         --ok-soft: var(--green-50);     --ok-border: var(--green-100);
  --info: var(--blue-500);        --info-soft: var(--blue-50);    --info-border: var(--blue-100);

  /* Spacing (4px base) */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px;
  --s6: 24px; --s7: 32px; --s8: 40px; --s9: 56px; --s10: 72px;

  /* Radii */
  --r-sm: 5px; --r: 8px; --r-lg: 12px; --r-xl: 16px; --r-full: 999px;

  /* Elevation — soft and low; clinical software should feel flat and calm */
  --sh-1: 0 1px 2px rgba(21, 27, 28, .06), 0 1px 1px rgba(21, 27, 28, .04);
  --sh-2: 0 2px 6px rgba(21, 27, 28, .07), 0 1px 2px rgba(21, 27, 28, .05);
  --sh-3: 0 12px 28px rgba(21, 27, 28, .14), 0 3px 8px rgba(21, 27, 28, .08);

  /* Type */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --sidebar-w: 246px;
  --topbar-h: 60px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:           #101617;
    --bg-raised:    #182122;
    --bg-sunken:    #0b1112;
    --bg-inset:     #1d2728;
    --sidebar-bg:   #0a1516;
    --sidebar-fg:   #bdd3d2;
    --sidebar-fg-dim:#7e9695;
    --sidebar-active:#123a3b;
    --text:         #e8eeee;
    --text-soft:    #a9b7b7;
    --text-dim:     #8b9a9a;
    --line:         #2a3536;
    --line-soft:    #212b2c;
    --line-strong:  #3b4849;
    --accent:       #37a5a1;
    --accent-hover: #4fbdb8;
    --accent-soft:  #10302f;
    --accent-border:#1d4d4c;
    --focus:        #4fbdb8;

    --danger:#e8776c; --danger-soft:#2e1614; --danger-border:#4a201c;
    --warn:#dfa441;   --warn-soft:#2b2010;  --warn-border:#453218;
    --ok:#57b17c;     --ok-soft:#122619;    --ok-border:#1c3d28;
    --info:#7ba5e8;   --info-soft:#141d2e;  --info-border:#22304c;

    --sh-1: 0 1px 2px rgba(0,0,0,.4);
    --sh-2: 0 2px 8px rgba(0,0,0,.45);
    --sh-3: 0 14px 34px rgba(0,0,0,.6);
  }
}

[data-theme="dark"] {
  --bg:#101617; --bg-raised:#182122; --bg-sunken:#0b1112; --bg-inset:#1d2728;
  --sidebar-bg:#0a1516; --sidebar-fg:#bdd3d2; --sidebar-fg-dim:#7e9695; --sidebar-active:#123a3b;
  --text:#e8eeee; --text-soft:#a9b7b7; --text-dim:#8b9a9a;
  --line:#2a3536; --line-soft:#212b2c; --line-strong:#3b4849;
  --accent:#37a5a1; --accent-hover:#4fbdb8; --accent-soft:#10302f; --accent-border:#1d4d4c; --focus:#4fbdb8;
  --danger:#e8776c; --danger-soft:#2e1614; --danger-border:#4a201c;
  --warn:#dfa441; --warn-soft:#2b2010; --warn-border:#453218;
  --ok:#57b17c; --ok-soft:#122619; --ok-border:#1c3d28;
  --info:#7ba5e8; --info-soft:#141d2e; --info-border:#22304c;
  --sh-1: 0 1px 2px rgba(0,0,0,.4);
  --sh-2: 0 2px 8px rgba(0,0,0,.45);
  --sh-3: 0 14px 34px rgba(0,0,0,.6);
}

/* ---------------------------------------------------------------- base -- */

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

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-wrap: break-word;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.011em; line-height: 1.25; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
h4 { font-size: 13px; }
p { margin: 0 0 var(--s3); }
p:last-child { margin-bottom: 0; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

::selection { background: var(--accent-soft); color: var(--text); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* -------------------------------------------------------- boot screen -- */

.app-boot { min-height: 100vh; display: grid; place-items: center; }

.boot-screen { text-align: center; padding: var(--s8); }

.boot-mark {
  width: 44px; height: 44px; margin: 0 auto var(--s4);
  border-radius: var(--r-lg);
  background: var(--accent);
  position: relative;
  animation: boot-pulse 1.4s ease-in-out infinite;
}
.boot-mark::before, .boot-mark::after {
  content: ""; position: absolute; background: #fff; border-radius: 2px;
}
.boot-mark::before { left: 50%; top: 11px; bottom: 11px; width: 4px; transform: translateX(-50%); }
.boot-mark::after { top: 50%; left: 11px; right: 11px; height: 4px; transform: translateY(-50%); }

@keyframes boot-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }

.boot-text { color: var(--text-soft); font-size: 13px; }
.boot-note { color: var(--danger); font-size: 13px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ------------------------------------------------------------- shell -- */

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas: "sidebar topbar" "sidebar main";
}

.sidebar {
  grid-area: sidebar;
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.brand {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s4) var(--s5);
  border-bottom: 1px solid rgba(255,255,255,.08);
  min-height: var(--topbar-h);
}
.brand-mark {
  width: 32px; height: 32px; border-radius: var(--r); flex: none;
  background: var(--accent); position: relative;
}
.brand-mark::before, .brand-mark::after { content:""; position:absolute; background:#fff; border-radius:1.5px; }
.brand-mark::before { left:50%; top:8px; bottom:8px; width:3px; transform:translateX(-50%); }
.brand-mark::after { top:50%; left:8px; right:8px; height:3px; transform:translateY(-50%); }
.brand-text { min-width: 0; }
.brand-name {
  font-size: 14px; font-weight: 650; color: #fff; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-role { font-size: 11px; color: var(--sidebar-fg-dim); text-transform: uppercase; letter-spacing: .06em; }

.nav { padding: var(--s4) var(--s3); flex: 1; }
.nav-group + .nav-group { margin-top: var(--s5); }
.nav-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--sidebar-fg-dim); padding: 0 var(--s3) var(--s2);
}
.nav-item {
  display: flex; align-items: center; gap: var(--s3);
  padding: 9px var(--s3); border-radius: var(--r);
  color: var(--sidebar-fg); font-size: 13.5px; font-weight: 500;
  cursor: pointer; border: 0; background: none; width: 100%; text-align: left;
  transition: background .12s ease, color .12s ease;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav-item.is-active { background: var(--sidebar-active); color: #fff; }
.nav-item svg { flex: none; opacity: .85; }
.nav-item.is-active svg { opacity: 1; }
.nav-count {
  margin-left: auto; font-size: 11px; font-weight: 600;
  background: rgba(255,255,255,.14); color: #fff;
  padding: 1px 7px; border-radius: var(--r-full);
}
.nav-count.is-urgent { background: var(--red-500); }

.sidebar-foot {
  padding: var(--s3) var(--s4) var(--s5);
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: 11.5px; color: var(--sidebar-fg-dim);
}
.sidebar-foot strong { color: var(--sidebar-fg); font-weight: 600; }

.topbar {
  grid-area: topbar;
  height: var(--topbar-h);
  background: var(--bg-raised);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: var(--s3);
  padding: 0 var(--s6);
  position: sticky; top: 0; z-index: 30;
}
.topbar-title { font-size: 15px; font-weight: 600; }
.topbar-sub { font-size: 12px; color: var(--text-dim); }
.topbar-spacer { flex: 1; }

.main { grid-area: main; padding: var(--s6); max-width: 1440px; width: 100%; }

/* Wins over the .btn display rule that follows it. */
.topbar .burger { display: none; }

/* --------------------------------------------------------- page bits -- */

.page-head {
  display: flex; align-items: flex-start; gap: var(--s4);
  margin-bottom: var(--s5); flex-wrap: wrap;
}
.page-head .spacer { flex: 1; }
.page-title { font-size: 20px; font-weight: 650; letter-spacing: -.015em; }
.page-sub { font-size: 13px; color: var(--text-soft); margin-top: 2px; }

.section { margin-bottom: var(--s6); }
.section-head {
  display: flex; align-items: center; gap: var(--s3);
  margin-bottom: var(--s3);
}
.section-head h2 { flex: 1; }

.grid { display: grid; gap: var(--s4); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-side { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
.grid-side-l { grid-template-columns: 300px minmax(0, 1fr); align-items: start; }

.row { display: flex; gap: var(--s3); align-items: center; flex-wrap: wrap; }
.row-tight { gap: var(--s2); }
.stack { display: flex; flex-direction: column; gap: var(--s4); }
.stack-tight { display: flex; flex-direction: column; gap: var(--s2); }

/* ------------------------------------------------------------- card -- */

.card {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
}
.card-head {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s4) var(--s5);
  border-bottom: 1px solid var(--line-soft);
}
.card-head h2, .card-head h3 { flex: 1; min-width: 0; }
.card-body { padding: var(--s5); }
.card-body.tight { padding: var(--s4); }
.card-foot {
  padding: var(--s3) var(--s5);
  border-top: 1px solid var(--line-soft);
  background: var(--bg-inset);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
  font-size: 12.5px; color: var(--text-soft);
}
.card-flat { box-shadow: none; }

/* A card that is itself a control — used for picking a doctor, a slot, a test */
button.card {
  width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer;
  transition: border-color .12s ease, box-shadow .12s ease;
}
button.card:hover { border-color: var(--line-strong); }
.card.is-selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

/* -------------------------------------------------------- stat tiles -- */

.stats { display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

.stat {
  background: var(--bg-raised); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: var(--s4) var(--s5);
  box-shadow: var(--sh-1); position: relative; overflow: hidden;
}
.stat-label {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-dim); font-weight: 600; display: flex; align-items: center; gap: 6px;
}
.stat-value {
  font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 6px;
  font-variant-numeric: tabular-nums;
}
.stat-meta { font-size: 12px; color: var(--text-soft); margin-top: 2px; }
.stat-accent { color: var(--accent); }
.stat-danger .stat-value { color: var(--danger); }
.stat-warn .stat-value { color: var(--warn); }
.stat-ok .stat-value { color: var(--ok); }

/* ---------------------------------------------------------- buttons -- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px; border-radius: var(--r);
  border: 1px solid var(--line-strong); background: var(--bg-raised); color: var(--text);
  font-size: 13.5px; font-weight: 550; cursor: pointer;
  transition: background .12s ease, border-color .12s ease, color .12s ease, transform .06s ease;
  white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--bg-sunken); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn.is-busy { opacity: .55; cursor: not-allowed; pointer-events: none; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.94); background: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--bg-sunken); }
.btn-soft { background: var(--accent-soft); border-color: var(--accent-border); color: var(--accent); }
.btn-soft:hover { background: var(--accent-soft); border-color: var(--accent); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: var(--r-sm); }
.btn-lg { padding: 11px 20px; font-size: 15px; }
.btn-block { width: 100%; }
.btn-icon { padding: 7px; }

.btn .spin { animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--r) 0 0 var(--r); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--r) var(--r) 0; }

/* --------------------------------------------------------- segmented -- */

.segmented {
  display: inline-flex; background: var(--bg-sunken);
  border: 1px solid var(--line); border-radius: var(--r); padding: 2px; gap: 2px;
}
.segmented button {
  border: 0; background: none; padding: 5px 12px; border-radius: var(--r-sm);
  font-size: 12.5px; font-weight: 550; color: var(--text-soft); cursor: pointer;
}
.segmented button.is-active { background: var(--bg-raised); color: var(--text); box-shadow: var(--sh-1); }

/* ------------------------------------------------------------ forms -- */

.field { display: block; margin-bottom: var(--s4); }
.field:last-child { margin-bottom: 0; }
.field-label {
  display: block; font-size: 12.5px; font-weight: 600; color: var(--text-soft);
  margin-bottom: 5px;
}
.field-label .req { color: var(--danger); margin-left: 2px; }
.field-hint { font-size: 12px; color: var(--text-dim); margin-top: 5px; }
.field-error { font-size: 12px; color: var(--danger); margin-top: 5px; font-weight: 500; }

.input, .select, .textarea {
  width: 100%; padding: 9px 11px;
  background: var(--bg-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--r); font-size: 14px;
  transition: border-color .12s ease, box-shadow .12s ease;
  -webkit-appearance: none; appearance: none;
}
.input:hover, .select:hover, .textarea:hover { border-color: var(--grey-400); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input::placeholder, .textarea::placeholder { color: var(--text-dim); }
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger); }
.textarea { min-height: 84px; resize: vertical; line-height: 1.55; }
.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236c7a7b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; padding-right: 32px;
}
.input-sm { padding: 6px 9px; font-size: 13px; }

.field-row { display: grid; gap: var(--s4); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field-row-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.check {
  display: flex; align-items: flex-start; gap: var(--s3); cursor: pointer;
  font-size: 13.5px; padding: 2px 0;
}
.check input { width: 16px; height: 16px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }

.search {
  position: relative; display: flex; align-items: center;
}
.search svg { position: absolute; left: 10px; color: var(--text-dim); pointer-events: none; }
.search .input { padding-left: 34px; }

/* ------------------------------------------------------------ table -- */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Above the stacked-card breakpoint a dense table scrolls rather than
   squeezing columns into unreadable slivers. */
@media (min-width: 641px) {
  .table-wrap > table.data { min-width: 660px; }
}

table.data {
  width: 100%; border-collapse: collapse; font-size: 13.5px;
}
table.data th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .045em;
  color: var(--text-dim); font-weight: 650; padding: 10px var(--s4);
  border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--bg-raised);
}
table.data td {
  padding: 11px var(--s4); border-bottom: 1px solid var(--line-soft); vertical-align: middle;
}
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr { transition: background .1s ease; }
table.data tbody tr:hover { background: var(--bg-inset); }
table.data tr.is-clickable { cursor: pointer; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .nowrap { white-space: nowrap; }
table.data .shrink { width: 1%; white-space: nowrap; }

.cell-main { font-weight: 550; }
.cell-sub { font-size: 12px; color: var(--text-dim); margin-top: 1px; }

/* ------------------------------------------------------------ badge -- */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: var(--r-full);
  font-size: 11.5px; font-weight: 600; line-height: 1.6;
  background: var(--bg-sunken); color: var(--text-soft);
  border: 1px solid transparent; white-space: nowrap;
}
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; flex: none; }
.badge-plain::before { display: none; }
.badge-ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok-border); }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-border); }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-border); }
.badge-info { background: var(--info-soft); color: var(--info); border-color: var(--info-border); }
.badge-accent { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-border); }
.badge-lg { font-size: 12.5px; padding: 4px 11px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: var(--r-full); font-size: 12.5px;
  background: var(--bg-sunken); border: 1px solid var(--line); color: var(--text-soft);
}
.chip button { border: 0; background: none; padding: 0; cursor: pointer; color: var(--text-dim); display: flex; }
.chip button:hover { color: var(--danger); }

/* ------------------------------------------------------------- tabs -- */

.tabs {
  display: flex; gap: var(--s1); border-bottom: 1px solid var(--line);
  margin-bottom: var(--s5); overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 0; background: none; padding: 9px 14px; cursor: pointer;
  font-size: 13.5px; font-weight: 550; color: var(--text-soft);
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }
.tab .count {
  font-size: 11px; background: var(--bg-sunken); padding: 1px 6px;
  border-radius: var(--r-full); margin-left: 6px; color: var(--text-dim);
}

/* ------------------------------------------------------------ alert -- */

.alert {
  display: flex; gap: var(--s3); padding: var(--s3) var(--s4);
  border-radius: var(--r); border: 1px solid var(--line);
  background: var(--bg-inset); font-size: 13px; align-items: flex-start;
}
.alert svg { flex: none; margin-top: 1px; }
.alert-title { font-weight: 600; margin-bottom: 2px; }
.alert-danger { background: var(--danger-soft); border-color: var(--danger-border); color: var(--danger); }
.alert-warn { background: var(--warn-soft); border-color: var(--warn-border); color: var(--warn); }
.alert-ok { background: var(--ok-soft); border-color: var(--ok-border); color: var(--ok); }
.alert-info { background: var(--info-soft); border-color: var(--info-border); color: var(--info); }
.alert .alert-body { color: var(--text); }
.alert-danger .alert-body, .alert-warn .alert-body, .alert-ok .alert-body, .alert-info .alert-body { color: inherit; }

/* ------------------------------------------------------- empty state -- */

.empty {
  text-align: center; padding: var(--s8) var(--s5); color: var(--text-soft);
}
.empty-mark {
  width: 44px; height: 44px; border-radius: var(--r-lg); margin: 0 auto var(--s3);
  background: var(--bg-sunken); display: grid; place-items: center; color: var(--text-dim);
}
.empty h3 { font-size: 14.5px; margin-bottom: 4px; color: var(--text); }
.empty p { font-size: 13px; max-width: 380px; margin: 0 auto; }
.empty .btn { margin-top: var(--s4); }

/* --------------------------------------------------------- skeleton -- */

.skel {
  background: linear-gradient(90deg, var(--bg-sunken) 25%, var(--line-soft) 37%, var(--bg-sunken) 63%);
  background-size: 400% 100%;
  animation: skel 1.3s ease infinite;
  border-radius: var(--r-sm);
}
@keyframes skel { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.skel-line { height: 12px; margin-bottom: 9px; }
.skel-line.w-40 { width: 40%; } .skel-line.w-60 { width: 60%; } .skel-line.w-80 { width: 80%; }
.skel-title { height: 20px; width: 45%; margin-bottom: var(--s4); }
.skel-tile { height: 92px; border-radius: var(--r-lg); }
.skel-row { height: 44px; margin-bottom: 2px; border-radius: var(--r-sm); }

/* ------------------------------------------------------------ modal -- */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(12, 20, 20, .5);
  backdrop-filter: blur(2px); z-index: 100;
  display: grid; place-items: center; padding: var(--s4);
  animation: fade .14s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--bg-raised); border-radius: var(--r-xl);
  box-shadow: var(--sh-3); width: min(560px, 100%);
  max-height: min(86vh, 900px); display: flex; flex-direction: column;
  animation: rise .16s cubic-bezier(.2, .8, .3, 1);
}
.modal-lg { width: min(860px, 100%); }
.modal-xl { width: min(1100px, 100%); }
@keyframes rise { from { transform: translateY(10px) scale(.99); opacity: 0; } }
.modal-head {
  display: flex; align-items: flex-start; gap: var(--s3);
  padding: var(--s5) var(--s5) var(--s4);
  border-bottom: 1px solid var(--line-soft);
}
.modal-head h2 { flex: 1; font-size: 16px; }
.modal-head .sub { font-size: 12.5px; color: var(--text-dim); margin-top: 2px; }
.modal-body { padding: var(--s5); overflow-y: auto; flex: 1; }
.modal-foot {
  display: flex; gap: var(--s3); justify-content: flex-end;
  padding: var(--s4) var(--s5); border-top: 1px solid var(--line-soft);
  background: var(--bg-inset); border-radius: 0 0 var(--r-xl) var(--r-xl);
}
.modal-foot .spacer { flex: 1; }

/* ----------------------------------------------------------- toasts -- */

.toasts {
  position: fixed; bottom: var(--s5); right: var(--s5); z-index: 200;
  display: flex; flex-direction: column; gap: var(--s2); max-width: 380px;
}
.toast {
  display: flex; gap: var(--s3); align-items: flex-start;
  background: var(--grey-900); color: #fff;
  padding: 11px var(--s4); border-radius: var(--r);
  box-shadow: var(--sh-3); font-size: 13.5px;
  animation: toast-in .2s cubic-bezier(.2,.8,.3,1);
}
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }
.toast svg { flex: none; margin-top: 1px; }
.toast-ok svg { color: #6ede9d; }
.toast-error { background: var(--red-600); }
.toast-warn { background: var(--amber-600); }
.toast button { border: 0; background: none; color: rgba(255,255,255,.7); cursor: pointer; padding: 0; margin-left: auto; }

/* -------------------------------------------------- connection state -- */

.netbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 300;
  padding: 7px var(--s5); text-align: center;
  font-size: 12.5px; font-weight: 600;
  background: var(--amber-500); color: #fff;
  animation: slide-down .2s ease;
}
@keyframes slide-down { from { transform: translateY(-100%); } }
.netbar-offline { background: var(--grey-800); }
.netbar-slow { background: var(--amber-600); }

/* -------------------------------------------------- patient banner -- */

.patient-banner {
  display: flex; gap: var(--s4); align-items: center; flex-wrap: wrap;
  padding: var(--s4) var(--s5);
  background: var(--bg-raised); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--sh-1);
}
.avatar {
  width: 46px; height: 46px; border-radius: var(--r-full); flex: none;
  display: grid; place-items: center; font-weight: 650; font-size: 16px;
  background: var(--accent-soft); color: var(--accent); letter-spacing: -.02em;
}
.avatar-sm { width: 32px; height: 32px; font-size: 12.5px; }
.avatar-lg { width: 60px; height: 60px; font-size: 21px; }
.patient-id { display: flex; align-items: baseline; gap: var(--s3); flex-wrap: wrap; }
.patient-name { font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.mrn {
  font-family: var(--mono); font-size: 12px; color: var(--text-dim);
  background: var(--bg-sunken); padding: 1px 7px; border-radius: var(--r-sm);
}
.patient-facts { display: flex; gap: var(--s4); flex-wrap: wrap; font-size: 12.5px; color: var(--text-soft); margin-top: 3px; }
.patient-facts b { color: var(--text); font-weight: 600; }

.allergy-flag {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--danger-soft); color: var(--danger);
  border: 1px solid var(--danger-border);
  padding: 4px 10px; border-radius: var(--r); font-size: 12.5px; font-weight: 600;
}

/* ----------------------------------------------------------- queue -- */

.queue { display: flex; flex-direction: column; }
.queue-item {
  display: flex; align-items: center; gap: var(--s4);
  padding: var(--s4) var(--s5); border-bottom: 1px solid var(--line-soft);
  cursor: pointer; transition: background .1s ease;
}
.queue-item:last-child { border-bottom: 0; }
.queue-item:hover { background: var(--bg-inset); }
.queue-item.is-current { background: var(--accent-soft); }
.queue-token {
  width: 40px; height: 40px; border-radius: var(--r); flex: none;
  display: grid; place-items: center; font-weight: 650; font-size: 15px;
  background: var(--bg-sunken); color: var(--text-soft);
  font-variant-numeric: tabular-nums;
}
.queue-item.is-current .queue-token { background: var(--accent); color: #fff; }
.queue-main { flex: 1; min-width: 0; }
.queue-name { font-weight: 600; font-size: 14px; }
.queue-meta { font-size: 12.5px; color: var(--text-dim); margin-top: 1px; }
.queue-time { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------- timeline -- */

.timeline { position: relative; padding-left: var(--s6); }
.timeline::before {
  content: ""; position: absolute; left: 7px; top: 6px; bottom: 6px;
  width: 2px; background: var(--line);
}
.tl-item { position: relative; padding-bottom: var(--s5); }
.tl-item:last-child { padding-bottom: 0; }
.tl-item::before {
  content: ""; position: absolute; left: calc(var(--s6) * -1 + 3px); top: 5px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--bg-raised); border: 2px solid var(--accent);
}
.tl-date { font-size: 12px; color: var(--text-dim); font-weight: 600; }
.tl-title { font-weight: 600; font-size: 14px; margin-top: 2px; }
.tl-body { font-size: 13px; color: var(--text-soft); margin-top: 3px; }

/* ------------------------------------------------------ lab results -- */

table.results td.value { font-variant-numeric: tabular-nums; font-weight: 600; }
.flag-high { color: var(--danger); }
.flag-low { color: var(--info); }
.flag-abnormal { color: var(--danger); }
.flag-normal { color: var(--text); }
.flag-mark { font-size: 11px; font-weight: 700; margin-left: 4px; }
tr.is-abnormal { background: var(--danger-soft); }
tr.is-abnormal:hover { background: var(--danger-soft); }

.ref-range { font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------- charting -- */

/* Bar heights come from JS as pixels on a 100px track — see applyBarHeights. */
.bars { display: flex; align-items: flex-end; gap: 3px; min-height: 140px; }
.bar-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 5px; min-width: 0; }
.bar {
  width: 100%; max-width: 46px; background: var(--accent); border-radius: 3px 3px 0 0;
  min-height: 2px; height: var(--h, 2px); transition: height .3s ease;
}
.bar-col.is-muted .bar { background: var(--line-strong); }
.bar-label { font-size: 10px; color: var(--text-dim); white-space: nowrap; }

.spark { display: flex; align-items: flex-end; gap: 2px; height: 34px; }
.spark span { flex: 1; background: var(--accent-border); border-radius: 2px 2px 0 0; height: var(--h, 2px); }
.spark span.is-high { background: var(--danger); }
.spark span.is-low { background: var(--info); }

.meter { height: 6px; background: var(--bg-sunken); border-radius: var(--r-full); overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--accent); border-radius: var(--r-full); width: var(--w, 0%); }
.meter.is-danger span { background: var(--danger); }
.meter.is-warn span { background: var(--warn); }

/* ------------------------------------------------------------ auth -- */

.auth {
  min-height: 100vh; display: grid; grid-template-columns: 1fr 480px;
}
.auth-art {
  background: linear-gradient(150deg, var(--teal-700), var(--teal-500) 55%, var(--teal-400));
  color: #fff; padding: var(--s10) var(--s9);
  display: flex; flex-direction: column; justify-content: space-between;
  position: relative; overflow: hidden;
}
.auth-art::after {
  content: ""; position: absolute; right: -140px; bottom: -140px;
  width: 460px; height: 460px; border-radius: 50%;
  background: rgba(255,255,255,.06);
}
.auth-art-brand { display: flex; align-items: center; gap: var(--s3); position: relative; z-index: 1; }
.auth-art-brand .brand-mark { width: 38px; height: 38px; background: rgba(255,255,255,.16); }
.auth-art-brand .brand-mark::before, .auth-art-brand .brand-mark::after { background: #fff; }
.auth-art h1 {
  font-size: 34px; line-height: 1.15; letter-spacing: -.025em;
  max-width: 12em; position: relative; z-index: 1;
}
.auth-art p { font-size: 15px; color: rgba(255,255,255,.85); max-width: 34em; position: relative; z-index: 1; }
.auth-points { display: flex; flex-direction: column; gap: var(--s3); position: relative; z-index: 1; }
.auth-point { display: flex; gap: var(--s3); align-items: flex-start; font-size: 13.5px; color: rgba(255,255,255,.9); }
.auth-point svg { flex: none; margin-top: 1px; opacity: .9; }
.auth-foot { font-size: 12.5px; color: rgba(255,255,255,.6); position: relative; z-index: 1; }

.auth-panel {
  background: var(--bg-raised); padding: var(--s9) var(--s8);
  display: flex; flex-direction: column; justify-content: center;
  overflow-y: auto;
}
.auth-box { width: 100%; max-width: 360px; margin: 0 auto; }
.auth-box h2 { font-size: 21px; margin-bottom: 4px; letter-spacing: -.02em; }
.auth-box .lead { color: var(--text-soft); font-size: 13.5px; margin-bottom: var(--s6); }
.auth-switch { margin-top: var(--s5); font-size: 13px; color: var(--text-soft); text-align: center; }
.auth-mobile-brand { display: none; }

.pw-meter { display: flex; gap: 3px; margin-top: 6px; }
.pw-meter i { flex: 1; height: 3px; border-radius: 2px; background: var(--line); }
.pw-meter i.on-weak { background: var(--danger); }
.pw-meter i.on-ok { background: var(--warn); }
.pw-meter i.on-good { background: var(--ok); }

/* ------------------------------------------------------ prescription -- */

.rx-item {
  border: 1px solid var(--line); border-radius: var(--r);
  padding: var(--s3) var(--s4); margin-bottom: var(--s3); background: var(--bg-inset);
}
.rx-item-head { display: flex; align-items: center; gap: var(--s3); }
.rx-drug { font-weight: 600; flex: 1; }
.rx-sig { font-size: 12.5px; color: var(--text-soft); margin-top: 3px; }
.rx-sig b { color: var(--text); font-weight: 600; }

.dose-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s2); margin-top: var(--s3); }

/* ------------------------------------------------------- print doc -- */

.doc {
  background: #fff; color: #151b1c; padding: var(--s7);
  border-radius: var(--r); border: 1px solid var(--line);
}
.doc-head { display: flex; justify-content: space-between; gap: var(--s5); border-bottom: 2px solid #151b1c; padding-bottom: var(--s4); }
.doc-hospital { font-size: 19px; font-weight: 700; letter-spacing: -.02em; }
.doc-meta { font-size: 12px; color: #4e5a5b; margin-top: 3px; line-height: 1.5; }
.doc-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; text-align: right; }
.doc-section { margin-top: var(--s5); }
.doc-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em; color: #6c7a7b; font-weight: 700; }
.doc table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: var(--s2); }
.doc table th { text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: #4e5a5b; border-bottom: 1px solid #bcc6c6; padding: 6px 8px; }
.doc table td { padding: 7px 8px; border-bottom: 1px solid #e9eded; }
.doc-total { display: flex; justify-content: flex-end; margin-top: var(--s4); }
.doc-total table { width: auto; min-width: 260px; }
.doc-total td { border: 0; padding: 3px 8px; }
.doc-total .grand td { border-top: 2px solid #151b1c; font-weight: 700; font-size: 15px; padding-top: 8px; }
.doc-sign { margin-top: var(--s9); display: flex; justify-content: space-between; align-items: flex-end; }
.doc-sign-line { border-top: 1px solid #151b1c; padding-top: 5px; font-size: 12px; min-width: 200px; text-align: center; }
.doc-foot { margin-top: var(--s6); padding-top: var(--s3); border-top: 1px solid #e9eded; font-size: 11px; color: #6c7a7b; text-align: center; }

/* --------------------------------------------------------- utilities -- */

.left { text-align: left; }
.muted { color: var(--text-soft); }
.dim { color: var(--text-dim); }
.small { font-size: 12.5px; }
.tiny { font-size: 11.5px; }
.strong { font-weight: 600; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.tabular { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.center { text-align: center; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hide { display: none !important; }
.divider { height: 1px; background: var(--line-soft); margin: var(--s4) 0; }
.mt-0 { margin-top: 0; } .mt-2 { margin-top: var(--s2); } .mt-3 { margin-top: var(--s3); }
.mt-4 { margin-top: var(--s4); } .mt-5 { margin-top: var(--s5); } .mt-6 { margin-top: var(--s6); }
.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: var(--s2); } .mb-3 { margin-bottom: var(--s3); }
.mb-4 { margin-bottom: var(--s4); } .mb-5 { margin-bottom: var(--s5); }
.gap-2 { gap: var(--s2); } .gap-3 { gap: var(--s3); } .gap-4 { gap: var(--s4); }
.flex-1 { flex: 1; min-width: 0; }
.w-full { width: 100%; }

/* ------------------------------------------------------- responsive -- */

@media (max-width: 1180px) {
  .grid-side { grid-template-columns: minmax(0, 1fr); }
  .grid-side-l { grid-template-columns: minmax(0, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 1024px) {
  .auth { grid-template-columns: 1fr; }
  .auth-art { display: none; }
  .auth-panel { padding: var(--s6) var(--s5); justify-content: flex-start; }
  .auth-mobile-brand {
    display: flex; align-items: center; gap: var(--s3);
    margin: 0 auto var(--s6); max-width: 360px; width: 100%;
  }
  .auth-mobile-brand .brand-name { color: var(--text); font-size: 15px; }
  .auth-mobile-brand .brand-role { color: var(--text-dim); }
}

@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-areas: "topbar" "main";
  }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 90;
    transform: translateX(-100%); transition: transform .2s cubic-bezier(.2,.8,.3,1);
    box-shadow: var(--sh-3);
  }
  .sidebar.is-open { transform: translateX(0); }
  .scrim {
    position: fixed; inset: 0; background: rgba(12,20,20,.45); z-index: 80;
    animation: fade .14s ease;
  }
  .topbar .burger { display: inline-flex; }
  .topbar { padding: 0 var(--s4); }
  .main { padding: var(--s4); }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .field-row, .field-row-3 { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--s3); }
  .dose-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  body { font-size: 14px; }
  .page-title { font-size: 18px; }
  .card-body { padding: var(--s4); }
  .card-head { padding: var(--s3) var(--s4); }
  .stat { padding: var(--s3) var(--s4); }
  .stat-value { font-size: 22px; }
  .modal { max-height: 92vh; width: 100%; }
  .modal-foot { flex-wrap: wrap; }
  .modal-foot .btn { flex: 1; }
  .toasts { left: var(--s3); right: var(--s3); bottom: var(--s3); max-width: none; }
  .hide-sm { display: none; }

  /* A queue row has four zones; on a phone they wrap onto two lines instead of
     squeezing the patient's name into a one-letter-per-line column. */
  .queue-item { padding: var(--s3) var(--s4); gap: var(--s2) var(--s3); flex-wrap: wrap; align-items: flex-start; }
  .queue-main { flex: 1 1 55%; }
  .queue-item > .right { margin-left: auto; text-align: right; }
  .queue-item > .row { flex: 1 0 100%; }

  /* Page actions become full-width targets rather than ragged inline buttons. */
  .page-head { flex-direction: column; align-items: stretch; }
  .page-head .btn { width: 100%; justify-content: center; }
  .page-head .spacer { display: none; }
  .patient-banner { padding: var(--s4); }
  .doc { padding: var(--s4); }
  /* Dense tables become readable stacks on a phone */
  table.data.stack-mobile thead { display: none; }
  table.data.stack-mobile tr {
    display: block; border: 1px solid var(--line); border-radius: var(--r);
    margin-bottom: var(--s3); padding: var(--s2) var(--s3);
  }
  table.data.stack-mobile td {
    display: flex; justify-content: space-between; gap: var(--s4);
    padding: 5px 0; border: 0; text-align: right;
  }
  table.data.stack-mobile td::before {
    content: attr(data-label); font-size: 11.5px; text-transform: uppercase;
    letter-spacing: .04em; color: var(--text-dim); font-weight: 650; text-align: left;
  }
  table.data.stack-mobile td:empty { display: none; }
}

/* ------------------------------------------------------------ print -- */

@media print {
  body { background: #fff; }
  .sidebar, .topbar, .toasts, .netbar, .no-print, .modal-foot, .tabs { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; max-width: none; }
  .modal-backdrop { position: static; background: none; padding: 0; display: block; }
  .modal { box-shadow: none; max-height: none; width: 100%; animation: none; }
  .modal-head { display: none; }
  .modal-body { overflow: visible; padding: 0; }
  .card, .doc { box-shadow: none; border: 0; }
  .doc { padding: 0; }
  a[href]::after { content: ""; }
  @page { margin: 14mm; }
}
