/*
  Trident Lake Health EMR prototype: design system.
  Palette comes from the Trident Lake Health logo and Elementor kit (#103E68 navy, #73C505 green).
  Light mode only: staff use this at office desks and in cars between home visits in bright daylight.
  Elevation rule: panels use a 1px border and no shadow. Only overlays (drawer, dialog) get a shadow.
*/

/* ---------- Tokens ---------- */
:root {
  /* Brand */
  --navy-900: #0a2338;
  --navy-800: #0d3253;
  --navy-700: #103e68;   /* primary */
  --navy-600: #1d5486;
  --navy-200: #c9d6e3;
  --navy-100: #e3ecf5;
  --navy-50: #f0f5fa;
  --green-800: #2f5e00;
  --green-700: #3f7d00;  /* green text on white, 5.1:1 */
  --green-500: #73c505;  /* logo green, fills and marks only */
  --green-100: #e3f4cc;
  --green-50: #f2f9e8;

  /* Neutrals (tinted toward navy) */
  --ink: #12243a;
  --ink-2: #44546a;
  --ink-3: #5d6b7e;      /* smallest text that still clears 4.5:1 on white and on --bg */
  --line: #d9e2ec;
  --line-2: #e8eef4;
  --bg: #f5f8fb;
  --surface: #ffffff;

  /* Status */
  --ok: var(--green-700);
  --ok-bg: var(--green-50);
  --warn: #8a4b00;
  --warn-bg: #fff3dc;
  --warn-mark: #e19a1c;
  --danger: #b42318;
  --danger-bg: #fdeceb;
  --info: var(--navy-700);
  --info-bg: var(--navy-50);

  /* Divisions: TLAC pediatric, TLPT adult PT, TLHH home health */
  --tlac: #3f7d00;
  --tlac-bg: #eef7e3;
  --tlpt: #103e68;
  --tlpt-bg: #e3ecf5;
  --tlhh: #0b6e6a;
  --tlhh-bg: #e1f3f1;

  /* Type */
  --font-ui: "Atkinson Hyperlegible Next", "Segoe UI", system-ui, sans-serif;
  --font-head: "Montserrat", "Atkinson Hyperlegible Next", "Segoe UI", sans-serif;
  --text-xs: 0.75rem;    /* 12 */
  --text-sm: 0.875rem;   /* 14 */
  --text-md: 1rem;       /* 16 */
  --text-lg: 1.125rem;   /* 18 */
  --text-xl: 1.375rem;   /* 22 */
  --text-2xl: 1.75rem;   /* 28 */

  /* Space (4px base) */
  --s-1: 0.25rem;
  --s-2: 0.5rem;
  --s-3: 0.75rem;
  --s-4: 1rem;
  --s-5: 1.25rem;
  --s-6: 1.5rem;
  --s-8: 2rem;
  --s-10: 2.5rem;

  /* Radius and depth */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-pill: 999px;
  --shadow-overlay: 0 18px 40px -12px rgb(10 35 56 / 0.28), 0 4px 10px -4px rgb(10 35 56 / 0.12);
  --focus: 0 0 0 3px #fff, 0 0 0 5px var(--navy-600);

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --sidenav-w: 15.5rem;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--text-md);
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  font-variant-numeric: tabular-nums;
}
h1, h2, h3, h4 { font-family: var(--font-head); color: var(--navy-900); margin: 0; line-height: 1.2; letter-spacing: -0.01em; text-wrap: balance; }
h1 { font-size: var(--text-2xl); font-weight: 700; }
h2 { font-size: var(--text-lg); font-weight: 700; }
h3 { font-size: var(--text-md); font-weight: 600; }
p { margin: 0; }
a { color: var(--navy-600); text-underline-offset: 2px; }
a:hover { color: var(--navy-800); }
img { max-width: 100%; display: block; }
ul, ol { margin: 0; padding: 0; }
table { border-collapse: collapse; width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-sm); }
.icon { width: 1.25em; height: 1.25em; flex: none; fill: currentColor; }
.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; }
.skip { position: absolute; left: var(--s-4); top: -4rem; z-index: 100; background: var(--navy-700); color: #fff; padding: var(--s-2) var(--s-4); border-radius: var(--r-sm); }
.skip:focus { top: var(--s-2); color: #fff; }
.muted { color: var(--ink-3); }
.small { font-size: var(--text-sm); }
.id { font-variant-numeric: tabular-nums slashed-zero; letter-spacing: 0.01em; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.num { text-align: right; }

/* ---------- Top bar ---------- */
.app-top { position: sticky; top: 0; z-index: 30; }
.topbar {
  display: flex; align-items: center; gap: var(--s-5);
  height: 4rem; padding: 0 var(--s-5);
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand img { height: 3rem; width: auto; }
.brand:focus-visible { border-radius: var(--r-sm); }
.topbar .topbar__menu, .sidenav .sidenav__close { display: none; }
.topbar__search { position: relative; flex: 1; max-width: 30rem; }
.topbar__search .icon { position: absolute; left: var(--s-3); top: 50%; transform: translateY(-50%); color: var(--ink-3); }
.topbar__search input { width: 100%; height: 2.5rem; padding: 0 var(--s-3) 0 2.5rem; border: 1px solid var(--line); border-radius: var(--r-pill); background: var(--bg); }
.topbar__search input::placeholder { color: var(--ink-3); }
.topbar__end { display: flex; align-items: center; gap: var(--s-3); margin-left: auto; }
.clinic-chip { display: inline-flex; align-items: center; gap: var(--s-2); height: 2.25rem; padding: 0 var(--s-3); border-radius: var(--r-pill); background: var(--navy-50); color: var(--navy-700); font-size: var(--text-sm); font-weight: 600; }
.icon-btn {
  position: relative; display: inline-grid; place-items: center;
  width: 2.5rem; height: 2.5rem; border: 0; border-radius: var(--r-pill);
  background: transparent; color: var(--ink-2); cursor: pointer;
}
.icon-btn:hover { background: var(--navy-50); color: var(--navy-700); }
.icon-btn .dot { position: absolute; top: 0.55rem; right: 0.6rem; width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--danger); box-shadow: 0 0 0 2px #fff; }
.avatar {
  display: inline-grid; place-items: center; flex: none;
  width: 2.25rem; height: 2.25rem; border-radius: 50%;
  background: var(--green-100); color: var(--green-800);
  font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.02em;
}
.avatar--navy { background: var(--navy-100); color: var(--navy-700); }
.avatar--teal { background: var(--tlhh-bg); color: var(--tlhh); }
.avatar--lg { width: 3.5rem; height: 3.5rem; font-size: var(--text-lg); }
.avatar--sm { width: 2rem; height: 2rem; }
/* Photo avatars: cropped circles; the tint shows while the image loads */
img.avatar { object-fit: cover; background: var(--navy-100); box-shadow: 0 0 0 1px rgb(10 35 56 / 0.08); }
.patient-banner .avatar--lg, .page-head__who .avatar--lg { width: 4rem; height: 4rem; }
.page-head__who { display: flex; align-items: center; gap: var(--s-4); }
.stop-who { display: flex; align-items: center; gap: var(--s-3); }
.who-line { display: flex; align-items: center; gap: var(--s-3); }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: var(--sidenav-w) minmax(0, 1fr); min-height: calc(100vh - 4rem); }
.main { padding: var(--s-8) var(--s-8) var(--s-10); min-width: 0; }
.sidenav {
  position: sticky; top: 4rem; align-self: start;
  height: calc(100vh - 4rem);
  display: flex; flex-direction: column;
  padding: var(--s-5) var(--s-3);
  background: var(--surface); border-right: 1px solid var(--line);
}
.sidenav ul { list-style: none; display: grid; gap: 2px; }
.sidenav a {
  display: flex; align-items: center; gap: var(--s-3);
  padding: 0.6rem var(--s-3); border-radius: var(--r-md);
  color: var(--ink-2); text-decoration: none; font-weight: 500;
}
.sidenav a:hover { background: var(--navy-50); color: var(--navy-800); }
.sidenav a[aria-current="page"] { background: var(--navy-700); color: #fff; font-weight: 600; }
.sidenav a[aria-current="page"] .icon { color: var(--green-500); }
.sidenav__foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: var(--s-3); display: grid; gap: var(--s-1); }
.who { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2) var(--s-3); }
.who strong { display: block; font-size: var(--text-sm); }
.who small { display: block; color: var(--ink-3); font-size: var(--text-xs); }
.scrim { display: none; }

/* ---------- Page header ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s-4); margin-bottom: var(--s-6); }
.page-head p { color: var(--ink-2); margin-top: var(--s-1); }
.actions { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.crumbs { display: flex; align-items: center; gap: var(--s-1); font-size: var(--text-sm); color: var(--ink-3); margin-bottom: var(--s-2); }
.crumbs .icon { width: 1em; height: 1em; }

/* ---------- Panels and grids ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); min-width: 0; }
.panel__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-3); padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--line-2); }
.panel__head p { font-size: var(--text-sm); color: var(--ink-3); }
.panel__body { padding: var(--s-5); }
.panel__foot { padding: var(--s-3) var(--s-5); border-top: 1px solid var(--line-2); font-size: var(--text-sm); }
.stack { display: grid; gap: var(--s-6); }
.grid-main { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); gap: var(--s-6); align-items: start; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-6); align-items: start; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 2.5rem; padding: 0 var(--s-4);
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--surface); color: var(--navy-800);
  font-weight: 600; font-size: var(--text-sm); text-decoration: none; cursor: pointer;
  transition: background-color 160ms var(--ease-out), border-color 160ms var(--ease-out);
}
.btn:hover { background: var(--navy-50); border-color: var(--navy-200); color: var(--navy-900); }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--navy-700); border-color: var(--navy-700); color: #fff; }
.btn--primary:hover { background: var(--navy-800); border-color: var(--navy-800); color: #fff; }
.btn--sm { min-height: 2rem; padding: 0 var(--s-3); font-size: var(--text-xs); }
.btn--lg { min-height: 3rem; font-size: var(--text-md); }
.btn--block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.link-btn { border: 0; background: none; padding: 0; color: var(--navy-600); font-weight: 600; font-size: var(--text-sm); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }

/* ---------- Forms ---------- */
.field { display: grid; gap: var(--s-1); }
.field label, .label { font-size: var(--text-sm); font-weight: 600; color: var(--ink); }
.field .hint { font-size: var(--text-xs); color: var(--ink-3); }
.input, .select, .textarea {
  width: 100%; min-height: 2.5rem; padding: var(--s-2) var(--s-3);
  border: 1px solid #b9c7d6; border-radius: var(--r-md); background: var(--surface);
}
.select { appearance: none; padding-right: 2.25rem; background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 256 256'%3E%3Cpath fill='%2344546a' d='m213.66 101.66l-80 80a8 8 0 0 1-11.32 0l-80-80a8 8 0 0 1 11.32-11.32L128 164.69l74.34-74.35a8 8 0 0 1 11.32 11.32'/%3E%3C/svg%3E") no-repeat right 0.75rem center / 0.9rem; }
.textarea { min-height: 6rem; resize: vertical; line-height: 1.5; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--navy-600); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { border-color: var(--navy-600); border-radius: var(--r-md); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--bg); color: var(--ink-2); border-color: var(--line); }
.filters { display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: end; padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--line-2); }
.filters .field { min-width: 11rem; flex: 1; }
.filters .field--grow { flex: 2.2; min-width: 15rem; }
.input-icon { position: relative; }
.input-icon .icon { position: absolute; left: var(--s-3); top: 50%; transform: translateY(-50%); color: var(--ink-3); }
.input-icon .input { padding-left: 2.4rem; }
.check { display: flex; align-items: center; gap: var(--s-2); font-size: var(--text-sm); }
.check input { width: 1.1rem; height: 1.1rem; accent-color: var(--navy-700); }

/* ---------- Badges and tags ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.15rem 0.55rem; border-radius: var(--r-pill);
  font-size: var(--text-xs); font-weight: 600; line-height: 1.5; white-space: nowrap;
  background: var(--navy-50); color: var(--navy-700);
}
.badge::before { content: ""; width: 0.45rem; height: 0.45rem; border-radius: 50%; background: currentColor; }
.badge--ok { background: var(--ok-bg); color: var(--ok); }
.badge--warn { background: var(--warn-bg); color: var(--warn); }
.badge--danger { background: var(--danger-bg); color: var(--danger); }
.badge--muted { background: #eef1f5; color: var(--ink-2); }
.badge--plain::before { display: none; }

/* Division tag: three bars echo the logo's trident, the lit bar names the division */
.div-tag { display: inline-flex; align-items: center; gap: 0.4rem; font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.03em; color: var(--c); white-space: nowrap; }
.div-tag::before {
  content: ""; width: 0.8rem; height: 0.8rem; flex: none;
  background: linear-gradient(90deg, var(--c) 0 26%, transparent 26% 37%, var(--c) 37% 63%, transparent 63% 74%, var(--c) 74%);
  clip-path: polygon(0 25%, 13% 0, 26% 25%, 26% 100%, 37% 100%, 37% 12%, 50% -10%, 63% 12%, 63% 100%, 74% 100%, 74% 25%, 87% 0, 100% 25%, 100% 100%, 0 100%);
}
.div-tag--tlac { --c: var(--tlac); }
.div-tag--tlpt { --c: var(--tlpt); }
.div-tag--tlhh { --c: var(--tlhh); }
.setting { display: inline-flex; align-items: center; gap: 0.3rem; font-size: var(--text-xs); color: var(--ink-2); white-space: nowrap; }
.setting .icon { width: 1rem; height: 1rem; color: var(--ink-3); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; position: relative; } /* contains .sr-only labels so they cannot widen the page */
.table th, .table td { padding: var(--s-3) var(--s-4); text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line-2); }
.table th { font-size: var(--text-xs); font-weight: 700; color: var(--ink-3); letter-spacing: 0.02em; background: #fafcfd; white-space: nowrap; }
.table th:first-child, .table td:first-child { padding-left: var(--s-5); }
.table th:last-child, .table td:last-child { padding-right: var(--s-5); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #f8fafc; }
.table td { font-size: var(--text-sm); }
.table .num { text-align: right; }
.cell-main { display: flex; align-items: center; gap: var(--s-3); }
.cell-main a { font-weight: 600; color: var(--navy-800); text-decoration: none; }
.cell-main a:hover { text-decoration: underline; }
.cell-sub { display: block; font-size: var(--text-xs); color: var(--ink-3); }
.table-count { padding: var(--s-3) var(--s-5); font-size: var(--text-sm); color: var(--ink-3); border-top: 1px solid var(--line-2); }

/* ---------- Tabs and segmented controls ---------- */
.tabs { display: flex; gap: var(--s-1); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs [role="tab"] {
  position: relative; flex: none;
  padding: var(--s-3) var(--s-4); border: 0; background: none; cursor: pointer;
  color: var(--ink-2); font-weight: 600; font-size: var(--text-sm);
}
.tabs [role="tab"]:hover { color: var(--navy-800); }
.tabs [role="tab"][aria-selected="true"] { color: var(--navy-800); }
.tabs [role="tab"][aria-selected="true"]::after { content: ""; position: absolute; left: var(--s-3); right: var(--s-3); bottom: -1px; height: 3px; border-radius: 3px 3px 0 0; background: var(--navy-700); }
.tabpanel { padding-top: var(--s-6); }
.tabpanel[hidden] { display: none; }
.tabpanel:focus-visible { box-shadow: none; }
.seg { display: inline-flex; padding: 3px; gap: 2px; background: #e9eef4; border-radius: var(--r-md); flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 0.35rem 0.8rem; border-radius: 7px; font-size: var(--text-sm); font-weight: 600; color: var(--ink-2); cursor: pointer; }
.seg button:hover { color: var(--navy-900); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--navy-800); box-shadow: 0 1px 2px rgb(10 35 56 / 0.12); }

/* ---------- Meters and data ---------- */
.meter { height: 0.5rem; border-radius: var(--r-pill); background: #e4eaf1; overflow: hidden; }
.meter > span { display: block; height: 100%; width: var(--v); border-radius: inherit; background: var(--green-700); }
.meter--navy > span { background: var(--navy-700); }
.meter--warn > span { background: var(--warn-mark); }
.meter--danger > span { background: var(--danger); }
.meter-row { display: grid; gap: var(--s-2); }
.meter-row__top { display: flex; justify-content: space-between; gap: var(--s-3); font-size: var(--text-sm); }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { padding: var(--s-5); border-left: 1px solid var(--line-2); }
.stat:first-child { border-left: 0; }
.stat dt { font-size: var(--text-sm); color: var(--ink-2); }
.stat dd { margin: var(--s-1) 0 0; font-family: var(--font-head); font-size: var(--text-2xl); font-weight: 700; color: var(--navy-900); line-height: 1.1; }
.stat .delta { display: block; margin-top: var(--s-1); font-family: var(--font-ui); font-size: var(--text-xs); font-weight: 600; color: var(--ink-3); }
.delta--up { color: var(--ok) !important; }
.delta--down { color: var(--danger) !important; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: var(--s-2) var(--s-5); font-size: var(--text-sm); }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; font-weight: 500; }

/* ---------- Lists ---------- */
.rows { list-style: none; }
.rows > li { display: flex; align-items: center; gap: var(--s-4); padding: var(--s-3) var(--s-5); border-bottom: 1px solid var(--line-2); }
.rows > li:last-child { border-bottom: 0; }
.rows .grow { flex: 1; min-width: 0; }
.rows .title { font-weight: 600; font-size: var(--text-sm); }
.rows .title a { color: var(--navy-800); text-decoration: none; }
.rows .title a:hover { text-decoration: underline; }
.rows .meta { font-size: var(--text-xs); color: var(--ink-3); }
.time { width: 4.5rem; flex: none; font-weight: 700; font-size: var(--text-sm); color: var(--navy-800); }
.time small { display: block; font-weight: 500; color: var(--ink-3); font-size: var(--text-xs); }

.alert-ico { display: grid; place-items: center; width: 2.25rem; height: 2.25rem; border-radius: var(--r-md); flex: none; }
.alert-ico--warn { background: var(--warn-bg); color: var(--warn); }
.alert-ico--danger { background: var(--danger-bg); color: var(--danger); }
.alert-ico--info { background: var(--navy-50); color: var(--navy-700); }

/* Timeline (progress notes) */
.timeline { list-style: none; position: relative; padding-left: var(--s-6); }
.timeline::before { content: ""; position: absolute; left: 0.45rem; top: 0.5rem; bottom: 0.5rem; width: 2px; background: var(--line); }
.timeline > li { position: relative; padding-bottom: var(--s-6); }
.timeline > li:last-child { padding-bottom: 0; }
.timeline > li::before { content: ""; position: absolute; left: calc(-1 * var(--s-6) + 0.15rem); top: 0.35rem; width: 0.75rem; height: 0.75rem; border-radius: 50%; background: var(--surface); border: 2px solid var(--navy-700); }
.timeline .when { font-size: var(--text-xs); color: var(--ink-3); }
.timeline h3 { margin: 2px 0 var(--s-1); }
.timeline p { font-size: var(--text-sm); color: var(--ink-2); max-width: 70ch; }

/* Goals */
.goal { display: grid; gap: var(--s-2); padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--line-2); }
.goal:last-child { border-bottom: 0; }
.goal__top { display: flex; justify-content: space-between; align-items: start; gap: var(--s-4); }
.goal p { font-size: var(--text-sm); max-width: 72ch; }
.goal__meta { display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-4); font-size: var(--text-xs); color: var(--ink-3); }

/* ---------- Patient banner ---------- */
.patient-banner { display: flex; flex-wrap: wrap; gap: var(--s-5); align-items: center; padding: var(--s-5); }
.patient-banner h1 { font-size: var(--text-xl); }
.patient-banner__facts { display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-5); font-size: var(--text-sm); color: var(--ink-2); margin-top: var(--s-1); }
.patient-banner__facts b { color: var(--ink); font-weight: 600; }
.flags { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-left: auto; }

/* ---------- Scheduling ---------- */
.cal-wrap { overflow-x: auto; }
.cal { display: grid; grid-template-columns: 13rem repeat(5, minmax(9.5rem, 1fr)); min-width: 62rem; }
.cal__h { padding: var(--s-3) var(--s-3); font-size: var(--text-xs); font-weight: 700; color: var(--ink-3); border-bottom: 1px solid var(--line); background: #fafcfd; }
.cal__h strong { display: block; font-size: var(--text-sm); color: var(--navy-900); }
.cal__h--today { background: var(--navy-50); }
.cal__h--today strong { color: var(--navy-700); }
.cal__who { display: flex; gap: var(--s-3); align-items: center; padding: var(--s-3); border-bottom: 1px solid var(--line-2); font-size: var(--text-sm); }
.cal__who small { display: block; color: var(--ink-3); font-size: var(--text-xs); }
.cal__cell { display: grid; align-content: start; gap: var(--s-1); padding: var(--s-2); border-bottom: 1px solid var(--line-2); border-left: 1px solid var(--line-2); min-height: 6rem; }
.cal__cell--today { background: #f7fafd; }
.appt { display: block; padding: 0.35rem 0.5rem; border-radius: var(--r-sm); background: var(--bg-c); color: var(--ink); font-size: var(--text-xs); line-height: 1.35; text-decoration: none; }
.appt:hover { filter: brightness(0.97); color: var(--ink); }
.appt b { display: block; font-weight: 700; color: var(--c); }
.appt--tlac { --c: var(--tlac); --bg-c: var(--tlac-bg); }
.appt--tlpt { --c: var(--tlpt); --bg-c: var(--tlpt-bg); }
.appt--tlhh { --c: var(--tlhh); --bg-c: var(--tlhh-bg); }
.appt--tele { background: repeating-linear-gradient(135deg, var(--bg-c) 0 6px, #fff 6px 9px); }
.appt--missed { background: var(--danger-bg); }
.appt--missed b { color: var(--danger); }
.legend { display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-5); font-size: var(--text-xs); color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: var(--s-2); }
.legend i { width: 0.9rem; height: 0.9rem; border-radius: 3px; background: var(--bg-c); border: 1px solid var(--c); }

/* Route view: schematic map of the East Valley (not to scale) */
.route { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); }
.map { position: relative; min-height: 26rem; background: #eef3ee; border-right: 1px solid var(--line-2); overflow: hidden; border-radius: var(--r-lg) 0 0 var(--r-lg); }
.map svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.map__city { font: 600 11px var(--font-ui); fill: #5d6b7e; letter-spacing: 0.04em; }
.map__road { stroke: #fff; stroke-width: 7; fill: none; }
.map__road--minor { stroke: #fff; stroke-width: 3.5; fill: none; }
.map__path { stroke: var(--tlhh); stroke-width: 3; fill: none; stroke-dasharray: 7 6; }
.map__stop circle { fill: var(--tlhh); stroke: #fff; stroke-width: 3; }
.map__stop text { font: 700 11px var(--font-ui); fill: #fff; text-anchor: middle; dominant-baseline: central; }
.map__stop--done circle { fill: var(--green-700); }
.map__stop--home rect { fill: var(--navy-700); }
.map__note { position: absolute; left: var(--s-3); bottom: var(--s-3); padding: 0.2rem 0.5rem; border-radius: var(--r-sm); background: rgb(255 255 255 / 0.9); font-size: var(--text-xs); color: var(--ink-2); }
.stops { list-style: none; counter-reset: stop; }
.stops > li { display: grid; grid-template-columns: 2rem 1fr auto; gap: var(--s-3); padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--line-2); align-items: start; }
.stops > li:last-child { border-bottom: 0; }
.stop-n { display: grid; place-items: center; width: 1.75rem; height: 1.75rem; border-radius: 50%; background: var(--tlhh); color: #fff; font-weight: 700; font-size: var(--text-xs); }
.stop-n--done { background: var(--green-700); }
.drive { display: flex; align-items: center; gap: var(--s-2); padding: 0 var(--s-5) 0 3.75rem; font-size: var(--text-xs); color: var(--ink-3); }
.drive .icon { width: 1rem; height: 1rem; }

/* ---------- Notes ---------- */
.note-layout { display: grid; grid-template-columns: minmax(0, 1fr) 19rem; gap: var(--s-6); align-items: start; }
.soap { display: grid; gap: var(--s-5); }
.soap__sec { display: grid; gap: var(--s-2); }
.soap__sec h3 { display: flex; align-items: center; gap: var(--s-2); }
.soap__letter { display: inline-grid; place-items: center; width: 1.6rem; height: 1.6rem; border-radius: var(--r-sm); background: var(--navy-700); color: #fff; font-size: var(--text-sm); font-weight: 700; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-4); }
.form-grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.chips { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.chip { display: inline-flex; align-items: center; gap: var(--s-2); padding: 0.3rem 0.7rem; border: 1px solid var(--line); border-radius: var(--r-pill); font-size: var(--text-sm); background: var(--surface); }
.chip input { accent-color: var(--navy-700); }
.is-locked .textarea, .is-locked .input, .is-locked .select { background: var(--bg); }
.sign-box { display: grid; gap: var(--s-3); padding: var(--s-5); }
.callout { display: flex; gap: var(--s-3); padding: var(--s-3) var(--s-4); border-radius: var(--r-md); background: var(--info-bg); color: var(--navy-800); font-size: var(--text-sm); }
.callout--warn { background: var(--warn-bg); color: var(--warn); }
.callout .icon { margin-top: 2px; }

/* ---------- Staff matrix ---------- */
.matrix th, .matrix td { text-align: center; }
.matrix th:first-child, .matrix td:first-child { text-align: left; }
.perm { display: inline-grid; place-items: center; width: 1.75rem; height: 1.75rem; border-radius: 50%; }
.perm--full { background: var(--green-50); color: var(--green-700); }
.perm--view { background: var(--navy-50); color: var(--navy-700); }
.perm--none { color: #9aa6b4; }
.perm .icon { width: 1.05rem; height: 1.05rem; }

/* ---------- Bar charts (pure CSS) ---------- */
.bars { display: grid; grid-template-columns: repeat(var(--n, 6), minmax(0, 1fr)); gap: var(--s-3); align-items: end; height: 13rem; padding: var(--s-5) var(--s-5) 0; border-bottom: 1px solid var(--line); background: linear-gradient(to top, var(--line-2) 1px, transparent 1px) 0 0 / 100% 25%; }
.bar { display: flex; flex-direction: column; justify-content: flex-end; gap: var(--s-1); height: 100%; }
.bar__stack { display: flex; flex-direction: column-reverse; height: calc(var(--h) * 0.86); border-radius: 5px 5px 0 0; overflow: hidden; }
.bar__stack > i { display: block; flex: var(--f) 0 0; }
.bar__val { font-size: var(--text-xs); font-weight: 700; text-align: center; color: var(--navy-900); }
.bar-labels { display: grid; grid-template-columns: repeat(var(--n, 6), minmax(0, 1fr)); gap: var(--s-3); padding: var(--s-2) var(--s-5) var(--s-4); font-size: var(--text-xs); color: var(--ink-3); text-align: center; }
.fill-tlac { background: var(--tlac); }
.fill-tlpt { background: var(--tlpt); }
.fill-tlhh { background: var(--tlhh); }
.hbars { display: grid; gap: var(--s-4); padding: var(--s-5); }
.hbar { display: grid; grid-template-columns: 11rem minmax(0, 1fr) 3.5rem; gap: var(--s-3); align-items: center; font-size: var(--text-sm); }
.hbar__track { height: 0.9rem; border-radius: var(--r-pill); background: #e9eef4; position: relative; }
.hbar__track > span { position: absolute; inset: 0 auto 0 0; width: var(--v); border-radius: inherit; background: var(--navy-700); }
.hbar__track::after { content: ""; position: absolute; top: -4px; bottom: -4px; left: var(--goal, 85%); width: 2px; background: var(--navy-900); }
.hbar--below .hbar__track > span { background: var(--warn-mark); }

/* ---------- Dialog ---------- */
dialog { width: min(32rem, calc(100vw - 2rem)); padding: 0; border: 0; border-radius: var(--r-lg); box-shadow: var(--shadow-overlay); color: var(--ink); }
dialog::backdrop { background: rgb(10 35 56 / 0.45); }
dialog[open] { animation: rise 220ms var(--ease-out); }
.dialog__head { display: flex; justify-content: space-between; align-items: center; padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--line-2); }
.dialog__body { display: grid; gap: var(--s-4); padding: var(--s-5); }
.dialog__foot { display: flex; justify-content: flex-end; gap: var(--s-2); padding: var(--s-4) var(--s-5); border-top: 1px solid var(--line-2); background: #fafcfd; border-radius: 0 0 var(--r-lg) var(--r-lg); }
@keyframes rise { from { opacity: 0; transform: translateY(8px) scale(0.98); } }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); background: var(--surface); }
.login__brand { display: flex; flex-direction: column; gap: var(--s-8); padding: var(--s-10) clamp(1.5rem, 5vw, 4.5rem); background: var(--navy-50); position: relative; overflow: hidden; }
.login__brand > * { position: relative; z-index: 1; }
.login__logo { width: 13rem; height: auto; }
.login__wave { position: absolute !important; z-index: 0 !important; left: 0; right: 0; bottom: 0; width: 100%; height: 38%; }
.login__pitch { display: grid; gap: var(--s-4); max-width: 34rem; margin-top: auto; }
.login__pitch h1 { font-size: clamp(1.75rem, 3vw, 2.4rem); line-height: 1.15; }
.login__pitch p { color: var(--ink-2); font-size: var(--text-lg); }
.login__divs { list-style: none; display: grid; gap: var(--s-3); max-width: 34rem; margin-bottom: auto; }
.login__divs li { display: grid; grid-template-columns: auto 1fr; gap: var(--s-1) var(--s-3); align-items: baseline; padding: var(--s-3) 0; border-top: 1px solid var(--navy-200); font-size: var(--text-sm); color: var(--ink-2); }
.login__divs li .div-tag { grid-row: span 2; min-width: 4rem; }
.login__divs li b { color: var(--navy-900); font-size: var(--text-md); }
.login__form-side { display: grid; align-content: center; justify-items: center; padding: var(--s-10) var(--s-6); }
.login__form { width: min(25rem, 100%); display: grid; gap: var(--s-5); }
.login__form h2 { font-size: var(--text-xl); }
.role-hint { display: grid; gap: var(--s-1); padding: var(--s-3) var(--s-4); background: var(--bg); border-radius: var(--r-md); font-size: var(--text-sm); color: var(--ink-2); }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .grid-main, .note-layout { grid-template-columns: minmax(0, 1fr); }
  .route { grid-template-columns: minmax(0, 1fr); }
  .map { min-height: 20rem; border-right: 0; border-bottom: 1px solid var(--line-2); border-radius: var(--r-lg) var(--r-lg) 0 0; }
}
@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .topbar .topbar__menu { display: inline-grid; }
  .sidenav .sidenav__close { display: inline-grid; justify-self: end; margin: calc(-1 * var(--s-2)) 0 var(--s-2) auto; }
  .sidenav {
    position: fixed; z-index: 50; top: 0; left: 0; bottom: 0; height: 100%;
    width: min(18rem, 85vw);
    transform: translateX(-100%); visibility: hidden;
    transition: transform 240ms var(--ease-out), visibility 0s linear 240ms;
    box-shadow: var(--shadow-overlay);
  }
  .nav-open .sidenav { transform: none; visibility: visible; transition: transform 240ms var(--ease-out); }
  .nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 40; background: rgb(10 35 56 / 0.4); }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat:nth-child(3) { border-left: 0; }
  .stat:nth-child(n+3) { border-top: 1px solid var(--line-2); }
  .login { grid-template-columns: minmax(0, 1fr); }
  .login__brand { gap: var(--s-5); padding-bottom: var(--s-8); }
  .login__wave { display: none; }
  .login__divs, .login__pitch p { display: none; }
  .login__pitch { margin-top: 0; }
  .login__form-side { padding-top: var(--s-6); }
}
@media (max-width: 720px) {
  .main { padding: var(--s-5) var(--s-4) var(--s-8); }
  .topbar { gap: var(--s-2); padding: 0 var(--s-3); }
  .topbar__search, .clinic-chip { display: none; }
  .brand img { height: 2.1rem; }
  .page-head { align-items: start; }
  h1 { font-size: var(--text-xl); }
  .stat dd { font-size: var(--text-xl); }
  .form-grid, .form-grid--2 { grid-template-columns: minmax(0, 1fr); }
  .panel__head, .panel__body { padding-left: var(--s-4); padding-right: var(--s-4); }
  .rows > li { padding-left: var(--s-4); padding-right: var(--s-4); }
  .flags { margin-left: 0; }
  .hbar { grid-template-columns: minmax(0, 1fr) 3rem; }
  .hbar > :first-child { grid-column: 1 / -1; }
  .bars { gap: var(--s-2); padding-left: var(--s-3); padding-right: var(--s-3); }
  .bar-labels { gap: var(--s-2); padding-left: var(--s-3); padding-right: var(--s-3); }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .rows .avatar { width: 2rem; height: 2rem; }
  .rows > li { gap: var(--s-3); }
  .patient-banner .avatar--lg { width: 3.5rem; height: 3.5rem; }
  .cal { grid-template-columns: 8.5rem repeat(5, 9.5rem); min-width: 0; }
  .cal__who .avatar { display: none; }
  .time { width: 3.5rem; }
  .kv dd { margin-bottom: var(--s-3); }

  /* Stacked tables: each row becomes a labelled block */
  .table--stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table--stack, .table--stack tbody, .table--stack tr, .table--stack td { display: block; width: 100%; }
  .table--stack tr { padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--line-2); }
  .table--stack tbody tr:last-child { border-bottom: 0; }
  .table--stack td, .table--stack td:first-child, .table--stack td:last-child { display: flex; justify-content: space-between; gap: var(--s-4); padding: var(--s-1) 0; border: 0; text-align: right; }
  .table--stack td::before { content: attr(data-label); font-size: var(--text-xs); font-weight: 600; color: var(--ink-3); text-align: left; flex: none; }
  .table--stack td:first-child { padding-bottom: var(--s-2); text-align: left; }
  .table--stack td:first-child::before { display: none; }
  .table--stack .num { text-align: right; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------- Late additions ---------- */
[hidden] { display: none !important; }
.stops > li.drive { display: flex; padding: 0 var(--s-5) 0 3.75rem; border-bottom: 0; margin: calc(-1 * var(--s-2)) 0; }
.stops > li:has(+ .drive) { border-bottom: 0; }
.rows > li > .icon { color: var(--ink-3); }
.hbars--plain .hbar__track::after { display: none; }
.stops .title { font-size: var(--text-sm); }
