/* Patient Management System — design system --------------------------------------------------------------
   Functional patterns: role-aware shell, patient identity band, queue boards, encounter workspace, ledgers.
   Perceptual patterns: calm clinical neutrals (slate), ONE accent (teal-700) for actions and focus, status tones
   reserved for state, a deep ink-teal sidebar to anchor the workspace. Tailwind scale throughout: 4px spacing,
   rounded-lg/xl, shadow-sm on surfaces, text-sm body, tabular numbers everywhere a value is compared.        */
@font-face { font-family: "Inter"; src: url("../fonts/inter-latin-wght.woff2") format("woff2"); font-weight: 100 900; font-style: normal; font-display: swap; }

:root {
  --bg: #f6f8fa; --surface: #ffffff; --surface-2: #f1f5f9; --surface-3: #e2e8f0;
  --border: #e5e9f0; --border-strong: #cbd5e1;
  --text: #0f172a; --text-2: #475569; --text-3: #64748b; --text-inv: #ffffff;
  --accent: #0f766e; --accent-hover: #115e59; --accent-soft: #f0fdfa; --accent-softer: #f7fefc; --accent-ring: rgba(15,118,110,.24); --accent-ink: #134e4a;
  --blue: #1d4ed8; --blue-soft: #eff6ff; --emerald: #047857; --emerald-soft: #ecfdf5; --amber: #b45309; --amber-soft: #fffbeb;
  --rose: #be123c; --rose-soft: #fff1f2; --violet: #6d28d9; --violet-soft: #f5f3ff; --gray-soft: #f1f5f9;
  --side-bg: #0c2624; --side-bg-2: #12312e; --side-text: #b6cbc8; --side-text-strong: #f1f5f4; --side-muted: #6f8b87; --side-active: #164e48;
  --shadow-sm: 0 1px 2px rgba(15,23,42,.04), 0 1px 3px rgba(15,23,42,.06);
  --shadow-md: 0 4px 12px -2px rgba(15,23,42,.08), 0 2px 4px -2px rgba(15,23,42,.05);
  --shadow-lg: 0 12px 32px -8px rgba(15,23,42,.18);
  --r-sm: 6px; --r: 8px; --r-lg: 12px; --r-xl: 16px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sidebar: 256px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a1120; --surface: #0f172a; --surface-2: #131d31; --surface-3: #1e293b; --border: #1e293b; --border-strong: #334155;
    --text: #e2e8f0; --text-2: #a3b1c4; --text-3: #8391a7; --accent: #2dd4bf; --accent-hover: #5eead4; --accent-soft: #0d2a2a; --accent-softer: #0b2121; --accent-ring: rgba(45,212,191,.3); --accent-ink: #99f6e4;
    --blue: #93c5fd; --blue-soft: #172554; --emerald: #6ee7b7; --emerald-soft: #052e22; --amber: #fcd34d; --amber-soft: #2b1d05; --rose: #fda4af; --rose-soft: #3a0a16;
    --violet: #c4b5fd; --violet-soft: #23123f; --gray-soft: #1e293b; --text-inv: #0b1220;
    --side-bg: #07131a; --side-bg-2: #0c1c24; --side-active: #11343a;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3); --shadow-md: 0 4px 12px rgba(0,0,0,.35); color-scheme: dark;
  }
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.55 var(--font); font-feature-settings: "cv11", "ss01"; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -0.011em; }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -0.02em; } h2 { font-size: 15px; font-weight: 600; } h3 { font-size: 14px; font-weight: 600; }
p { margin: 0 0 8px; }
.muted { color: var(--text-3); } .small { font-size: 12.5px; } .num, .tabular { font-variant-numeric: tabular-nums; } .mono { font-family: var(--mono); font-size: 12.5px; }
.icon { width: 18px; height: 18px; flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: var(--r); z-index: 99; }
.skip:focus { left: 8px; }

/* Shell ------------------------------------------------------------------------------------------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { background: linear-gradient(180deg, var(--side-bg) 0%, var(--side-bg-2) 100%); color: var(--side-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; scrollbar-width: thin; scrollbar-color: #2c4a46 transparent; }
.brand { display: flex; align-items: center; gap: 11px; padding: 20px 18px 16px; }
.brand-mark { width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, #14b8a6, #0f766e); color: #fff; display: grid; place-items: center; box-shadow: 0 6px 16px -6px rgba(20,184,166,.6), inset 0 1px 0 rgba(255,255,255,.25); flex: none; overflow: hidden; }
.brand-mark img { width: 100%; height: 100%; object-fit: cover; }
.brand-mark svg { width: 20px; height: 20px; }
.brand-name { font-weight: 650; font-size: 14px; line-height: 1.25; color: var(--side-text-strong); letter-spacing: -0.01em; }
.brand-sub { font-size: 11.5px; color: var(--side-muted); }
.nav { padding: 4px 10px 16px; display: flex; flex-direction: column; gap: 1px; }
.nav-group { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--side-muted); padding: 16px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--r); color: var(--side-text); font-weight: 500; transition: background .15s, color .15s; }
.nav a .icon { width: 17px; height: 17px; opacity: .8; }
.nav a:hover { background: rgba(255,255,255,.05); color: var(--side-text-strong); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--side-active); color: #fff; box-shadow: inset 2px 0 0 #2dd4bf; }
.nav a[aria-current="page"] .icon { color: #5eead4; opacity: 1; }
.nav .count { margin-left: auto; font-size: 11px; background: rgba(255,255,255,.08); color: var(--side-text-strong); border-radius: 999px; padding: 0 7px; line-height: 18px; font-variant-numeric: tabular-nums; }
.nav .count.hot { background: #be123c; color: #fff; }
.sidebar-foot { margin-top: auto; padding: 14px 18px 18px; border-top: 1px solid rgba(255,255,255,.06); font-size: 11.5px; color: var(--side-muted); line-height: 1.5; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 28px; background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: saturate(180%) blur(10px); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; min-height: 60px; }
.search { flex: 1; max-width: 560px; position: relative; }
.search .icon { position: absolute; left: 11px; top: 10px; color: var(--text-3); }
.search input[type=search] { width: 100%; padding: 9px 44px 9px 36px; border: 1px solid var(--border); background: var(--surface-2); border-radius: var(--r-lg); font: inherit; color: var(--text); transition: background .15s, border-color .15s, box-shadow .15s; }
.search input[type=search]:focus { background: var(--surface); border-color: var(--accent); outline: none; box-shadow: 0 0 0 4px var(--accent-ring); }
.search kbd { position: absolute; right: 9px; top: 8px; font: 11px var(--mono); color: var(--text-3); border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; background: var(--surface); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.role-switch select { padding: 6px 28px 6px 10px; font-size: 13px; min-height: 34px; }
.bell { position: relative; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; color: var(--text-2); border: 1px solid transparent; }
.bell:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.bell .dot { position: absolute; top: 3px; right: 2px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 999px; background: var(--rose); color: #fff; font-size: 10.5px; font-weight: 700; display: grid; place-items: center; border: 2px solid var(--surface); font-variant-numeric: tabular-nums; }
.avatar { width: 34px; height: 34px; border-radius: 999px; background: linear-gradient(135deg, var(--accent-soft), var(--surface-3)); color: var(--accent-ink); display: grid; place-items: center; font-size: 12px; font-weight: 650; }
.user-chip { display: flex; align-items: center; gap: 9px; line-height: 1.2; color: var(--text); padding: 3px 8px 3px 3px; border-radius: 999px; }
.user-chip:hover { background: var(--surface-2); text-decoration: none; }
.user-chip small { display: block; color: var(--text-3); font-size: 11.5px; }
.env-banner { background: repeating-linear-gradient(135deg, #fef3c7 0 12px, #fde68a 12px 24px); color: #78350f; text-align: center; font-weight: 600; font-size: 12px; padding: 4px; letter-spacing: .02em; }
.content { padding: 28px 32px 48px; max-width: 1440px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--text-3); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.crumbs { font-size: 12.5px; color: var(--text-3); margin-bottom: 8px; } .crumbs a { color: var(--text-3); } .crumbs a:hover { color: var(--accent); }
.section-title { font-size: 17px; font-weight: 650; margin: 4px 0 14px; letter-spacing: -0.015em; }
.generated { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-3); background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 4px 11px; }
.generated .icon { width: 14px; height: 14px; }

/* Flash ------------------------------------------------------------------------------------------- */
.flash { display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border-radius: var(--r-lg); margin-bottom: 16px; border: 1px solid; font-weight: 500; box-shadow: var(--shadow-sm); }
.flash .icon { margin-top: 1px; }
.flash-success { background: var(--emerald-soft); border-color: color-mix(in srgb, var(--emerald) 25%, transparent); color: var(--emerald); }
.flash-error { background: var(--rose-soft); border-color: color-mix(in srgb, var(--rose) 25%, transparent); color: var(--rose); }
.flash-warning { background: var(--amber-soft); border-color: color-mix(in srgb, var(--amber) 25%, transparent); color: var(--amber); }
.flash-info { background: var(--blue-soft); border-color: color-mix(in srgb, var(--blue) 20%, transparent); color: var(--blue); }

/* Cards & layout ---------------------------------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); box-shadow: var(--shadow-sm); }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 20px; border-bottom: 1px solid var(--border); }
.card-head p { margin: 2px 0 0; font-size: 12.5px; color: var(--text-3); }
.card-head h2 { display: flex; align-items: center; gap: 8px; }
.card-body { padding: 18px 20px; } .card-body.tight { padding: 0; }
.card-foot { padding: 12px 20px; border-top: 1px solid var(--border); background: var(--accent-softer); border-radius: 0 0 var(--r-xl) var(--r-xl); }
.grid { display: grid; gap: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 16px; }
.grid-5 { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px 16px; }
.cols { display: grid; grid-template-columns: minmax(0, 2fr) minmax(310px, 1fr); gap: 18px; align-items: start; }
.cols-even { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.stack > * + * { margin-top: 18px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.divider { height: 1px; background: var(--border); margin: 16px 0; border: 0; }

/* KPI tiles --------------------------------------------------------------------------------------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); padding: 15px 18px; box-shadow: var(--shadow-sm); display: block; color: inherit; position: relative; transition: border-color .15s, box-shadow .15s, transform .15s; }
a.kpi:hover { border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); text-decoration: none; box-shadow: var(--shadow-md); transform: translateY(-1px); }
.kpi-label { font-size: 12.5px; color: var(--text-3); font-weight: 550; display: flex; align-items: center; gap: 7px; }
.kpi-label .icon { width: 16px; height: 16px; color: var(--accent); }
.kpi-value { font-size: 28px; font-weight: 650; letter-spacing: -0.025em; font-variant-numeric: tabular-nums; margin-top: 6px; line-height: 1.15; }
.kpi-value-sm { font-size: 21px; }
.kpi-sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.kpi.attn .kpi-value { color: var(--rose); }
.kpi-accent { background: linear-gradient(135deg, var(--accent) 0%, #115e59 100%); border-color: transparent; color: #fff; }
.kpi-accent .kpi-label, .kpi-accent .kpi-sub { color: #ccfbf1; } .kpi-accent .kpi-label .icon { color: #99f6e4; }

/* Tables ------------------------------------------------------------------------------------------ */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.table td { padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover td { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
.table .r, .table th.r { text-align: right; font-variant-numeric: tabular-nums; }
.table .nowrap { white-space: nowrap; }
.table tfoot td { font-weight: 600; background: var(--surface-2); }
.table .muted-row td { color: var(--text-3); }
.table .muted-row td s, .table s { text-decoration-color: var(--text-3); }
.empty { padding: 36px 18px; text-align: center; color: var(--text-3); }
.empty .icon { width: 30px; height: 30px; margin-bottom: 6px; color: var(--border-strong); }

/* Badges ------------------------------------------------------------------------------------------ */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; line-height: 20px; white-space: nowrap; border: 1px solid transparent; }
.badge .icon { width: 13px; height: 13px; }
.badge-gray { background: var(--gray-soft); color: var(--text-2); } .badge-teal { background: var(--accent-soft); color: var(--accent-ink); }
.badge-blue { background: var(--blue-soft); color: var(--blue); } .badge-emerald { background: var(--emerald-soft); color: var(--emerald); }
.badge-amber { background: var(--amber-soft); color: var(--amber); } .badge-rose { background: var(--rose-soft); color: var(--rose); }
.badge-violet { background: var(--violet-soft); color: var(--violet); }
.badge-outline { background: transparent; border-color: var(--border-strong); color: var(--text-2); }
.pill-dot { width: 8px; height: 8px; border-radius: 999px; display: inline-block; }

/* Forms ------------------------------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 13px; min-width: 0; }
.field label, .label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.req { color: var(--rose); }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=datetime-local], input[type=time], input[type=number], input[type=tel], input[type=search], input[type=color], input[type=file], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r); padding: 8px 11px; min-height: 38px;
  transition: border-color .15s, box-shadow .15s; }
input[type=file] { padding: 6px; }
input[type=color] { padding: 3px; height: 38px; }
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--text-3) 75%, transparent); }
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 4px var(--accent-ring); }
input[readonly] { background: var(--surface-2); }
[aria-invalid=true] { border-color: var(--rose) !important; }
.field-error { color: var(--rose); font-size: 12px; margin: 0; } .hint { color: var(--text-3); font-size: 12px; margin: 0; }
.check { display: flex; align-items: flex-start; gap: 9px; margin-bottom: 8px; cursor: pointer; } .check input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--accent); flex: none; }
fieldset { border: 1px solid var(--border); border-radius: var(--r-lg); padding: 14px 16px 4px; margin: 0 0 16px; background: var(--surface); } legend { font-weight: 650; font-size: 12.5px; padding: 0 6px; color: var(--text); letter-spacing: .01em; }
fieldset .legend-sub { font-weight: 400; color: var(--text-3); }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; padding-top: 8px; flex-wrap: wrap; }
form.inline { display: inline; }
.stepup { background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: var(--r); padding: 12px 14px 2px; margin: 8px 0 12px; }
.stepup-title { font-weight: 600; font-size: 12.5px; display: flex; align-items: center; gap: 6px; color: var(--text-2); }
.stepup-title .icon { width: 15px; height: 15px; }
.pair { display: flex; gap: 6px; } .pair > * { min-width: 0; }
.with-unit { position: relative; } .with-unit input { padding-right: 52px; }
.with-unit .unit { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-size: 12px; color: var(--text-3); pointer-events: none; }
output.conv { display: block; font-size: 12.5px; font-weight: 600; color: var(--accent-ink); min-height: 18px; font-variant-numeric: tabular-nums; }

/* Buttons ----------------------------------------------------------------------------------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; font: inherit; font-weight: 600; font-size: 13px; padding: 8px 15px; min-height: 38px; border-radius: var(--r);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, box-shadow .15s, transform .05s; box-shadow: 0 1px 1px rgba(15,23,42,.03); }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn .icon { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--text-inv); box-shadow: 0 1px 2px rgba(15,118,110,.25), inset 0 1px 0 rgba(255,255,255,.12); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--rose); border-color: color-mix(in srgb, var(--rose) 35%, var(--border)); }
.btn-danger:hover { background: var(--rose-soft); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); box-shadow: none; }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 4px 11px; min-height: 30px; font-size: 12.5px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; font-weight: 600; }
.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 3px; gap: 2px; }
.segmented a, .segmented button { padding: 5px 12px; border-radius: var(--r); color: var(--text-2); font-weight: 600; font-size: 13px; border: 0; background: transparent; cursor: pointer; font-family: inherit; }
.segmented a:hover { text-decoration: none; color: var(--text); }
.segmented [aria-current="true"], .segmented .on { background: var(--surface); color: var(--accent-ink); box-shadow: var(--shadow-sm); }
.filterbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); padding: 10px 12px; box-shadow: var(--shadow-sm); }

/* Patient identity band (spec §7.1) --------------------------------------------------------------- */
.patient-band { display: flex; gap: 16px; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); padding: 16px 20px; margin-bottom: 16px; box-shadow: var(--shadow-sm); flex-wrap: wrap; position: relative; overflow: hidden; }
.patient-band::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: linear-gradient(180deg, #14b8a6, var(--accent)); }
.patient-avatar { width: 48px; height: 48px; border-radius: 14px; background: linear-gradient(135deg, var(--accent-soft), #ccfbf1); color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; font-size: 15px; flex: none; }
.patient-name { font-size: 18px; font-weight: 650; letter-spacing: -0.015em; }
.patient-meta { display: flex; gap: 6px 16px; flex-wrap: wrap; color: var(--text-2); font-size: 13px; margin-top: 3px; align-items: center; }
.patient-meta b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.patient-flags { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.allergy-banner { display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-radius: var(--r-lg); margin-bottom: 16px; font-weight: 600; border: 1px solid transparent; }
.allergy-banner.has { background: var(--rose-soft); color: var(--rose); border-color: color-mix(in srgb, var(--rose) 22%, transparent); } .allergy-banner.unknown { background: var(--amber-soft); color: var(--amber); } .allergy-banner.nka { background: var(--emerald-soft); color: var(--emerald); }
.record-state { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }

/* Tabs -------------------------------------------------------------------------------------------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 10px 14px; color: var(--text-3); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a[aria-current="page"] { color: var(--accent-ink); border-bottom-color: var(--accent); }
.tabs .count { font-size: 11px; background: var(--surface-3); color: var(--text-2); border-radius: 999px; padding: 0 6px; line-height: 17px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { padding: 3px 11px; border-radius: 999px; border: 1px solid var(--border-strong); color: var(--text-2); font-size: 12.5px; font-weight: 500; background: var(--surface); }
.chip[aria-pressed="true"], .chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }
.chip:hover { text-decoration: none; border-color: var(--accent); }

/* Quick actions (patient page) ------------------------------------------------------------------- */
.quick { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; margin-bottom: 18px; }
.quick a, .quick button { display: flex; align-items: center; gap: 11px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); color: var(--text); font: inherit; font-weight: 600; text-align: left; cursor: pointer; box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s, transform .15s; width: 100%; }
.quick a:hover, .quick button:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); box-shadow: var(--shadow-md); text-decoration: none; transform: translateY(-1px); }
.quick .qi { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.quick small { display: block; font-weight: 400; color: var(--text-3); font-size: 12px; line-height: 1.3; }
.quick .primary .qi { background: var(--accent); color: #fff; }

/* Queue board ------------------------------------------------------------------------------------- */
.board { display: grid; grid-template-columns: repeat(5, minmax(200px, 1fr)); gap: 12px; overflow-x: auto; }
.lane { background: var(--surface-2); border-radius: var(--r-xl); padding: 10px; min-height: 120px; border: 1px solid var(--border); }
.lane-head { display: flex; justify-content: space-between; font-size: 11.5px; font-weight: 700; color: var(--text-2); padding: 3px 5px 10px; text-transform: uppercase; letter-spacing: .06em; }
.ticket { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 10px 12px; margin-bottom: 8px; box-shadow: var(--shadow-sm); border-left: 3px solid var(--accent); }
.ticket.urgent { border-left-color: var(--rose); } .ticket.priority { border-left-color: var(--amber); }
.ticket-name { font-weight: 600; } .ticket-meta { font-size: 12px; color: var(--text-3); display: flex; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.ticket .wait { font-variant-numeric: tabular-nums; font-weight: 600; }
.ticket .wait.long { color: var(--rose); }

/* Calendar ---------------------------------------------------------------------------------------- */
.cal { display: grid; border: 1px solid var(--border); border-radius: var(--r-xl); overflow: hidden; background: var(--surface); box-shadow: var(--shadow-sm); }
.cal-head { display: contents; } .cal-head > div { background: var(--surface-2); padding: 9px 10px; font-weight: 600; font-size: 12.5px; border-bottom: 1px solid var(--border); border-left: 1px solid var(--border); }
.cal-time { font-size: 11px; color: var(--text-3); padding: 4px 8px; border-top: 1px solid var(--border); text-align: right; font-variant-numeric: tabular-nums; }
.cal-cell { border-top: 1px solid var(--border); border-left: 1px solid var(--border); min-height: 34px; padding: 2px 4px; position: relative; }
.cal-cell.off { background: repeating-linear-gradient(135deg, var(--surface-2) 0 6px, transparent 6px 12px); }
.appt { display: block; border-radius: 7px; padding: 3px 8px; margin: 1px 0; font-size: 12px; line-height: 1.35; background: var(--accent-soft); border-left: 3px solid var(--accent); color: var(--text); overflow: hidden; }
.appt:hover { text-decoration: none; filter: brightness(.97); }
.appt small { color: var(--text-3); display: block; }
.appt.s-cancelled, .appt.s-no_show { opacity: .55; text-decoration: line-through; }
.week { display: grid; grid-template-columns: repeat(7, minmax(120px, 1fr)); gap: 8px; }
.week-day { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 9px; min-height: 160px; }
.week-day.today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.week-day h3 { font-size: 12.5px; margin-bottom: 6px; display: flex; justify-content: space-between; }
.slots { display: flex; flex-wrap: wrap; gap: 6px; }
.slot { padding: 6px 11px; border: 1px solid var(--border-strong); border-radius: var(--r); background: var(--surface); cursor: pointer; font: 600 13px var(--font); font-variant-numeric: tabular-nums; color: var(--text); }
.slot:hover { border-color: var(--accent); } .slot.on { background: var(--accent); color: var(--text-inv); border-color: var(--accent); }

/* Timeline ---------------------------------------------------------------------------------------- */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before { content: ""; position: absolute; left: 7px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.timeline li { position: relative; padding: 0 0 15px 28px; }
.timeline li::before { content: ""; position: absolute; left: 2px; top: 5px; width: 12px; height: 12px; border-radius: 999px; background: var(--surface); border: 2px solid var(--accent); }
.timeline li.k-payments::before { border-color: var(--emerald); } .timeline li.k-vitals::before { border-color: var(--blue); } .timeline li.k-documents::before { border-color: var(--text-3); }
.timeline .t-when { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.timeline .t-title { font-weight: 600; }

/* Clinical note ----------------------------------------------------------------------------------- */
.note { border: 1px solid var(--border); border-radius: var(--r-xl); background: var(--surface); box-shadow: var(--shadow-sm); }
.note-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 11px 18px; border-bottom: 1px solid var(--border); background: var(--surface-2); border-radius: var(--r-xl) var(--r-xl) 0 0; flex-wrap: wrap; }
.note.signed .note-head { background: var(--accent-soft); }
.note.draft { border-style: dashed; border-color: var(--border-strong); }
.note-body { padding: 16px 18px; }
.note-section + .note-section { margin-top: 12px; }
.note-section h4 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); margin-bottom: 3px; }
.note-section p { white-space: pre-wrap; margin: 0; }
.addendum { border-left: 3px solid var(--violet); background: var(--violet-soft); padding: 10px 14px; border-radius: 0 var(--r) var(--r) 0; margin-top: 10px; }
.autosave { font-size: 12px; color: var(--text-3); }
.checklist { list-style: none; padding: 0; margin: 0; } .checklist li { padding: 6px 0; border-bottom: 1px solid var(--border); } .checklist li:last-child { border: 0; }

/* Measurements (visit intake) -------------------------------------------------------------------- */
.measures { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px; }
.measure { border: 1px solid var(--border); background: var(--accent-softer); border-radius: var(--r-lg); padding: 9px 12px; }
.measure span { display: block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); }
.measure b { display: block; font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; margin-top: 2px; }
.measure small { display: block; font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.measure.hi b { color: var(--rose); } .measure.hi { border-color: color-mix(in srgb, var(--rose) 30%, var(--border)); background: var(--rose-soft); }
.bp-grid { width: 100%; border-collapse: separate; border-spacing: 8px 6px; margin: -6px -8px 6px; }
.bp-grid th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); font-weight: 600; text-align: left; padding: 0 2px; }
.bp-grid td:first-child { font-weight: 600; font-size: 13px; color: var(--text-2); width: 150px; }
.intake-box { background: var(--accent-softer); border: 1px solid color-mix(in srgb, var(--accent) 18%, var(--border)); border-radius: var(--r-lg); padding: 14px 16px; }
.intake-box h3 { display: flex; align-items: center; gap: 7px; color: var(--accent-ink); margin-bottom: 10px; }

/* Repeatable rows (prescriptions, medication administered, vaccinations) ------------------------- */
.repeat { margin: 4px 0 12px; }
.rrow { display: grid; gap: 8px 10px; align-items: end; padding: 12px; border: 1px solid var(--border); border-radius: var(--r-lg); margin-bottom: 10px; background: var(--surface-2); }
.rrow .field { margin-bottom: 0; } .rrow label { font-size: 11.5px; }
.rrow-med { grid-template-columns: 2fr 1fr 1.5fr 1.2fr .9fr 1.6fr auto; }
.rrow-vacc { grid-template-columns: 2fr 1fr .9fr 1.4fr 1.2fr auto; }
.rrow-vacc > .span2 { grid-column: span 2; }

/* Selection lists (print / email several documents) --------------------------------------------- */
.select-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 20px; border-bottom: 1px solid var(--border); background: var(--accent-softer); }
.select-bar .hint { margin-right: auto; }
td.pick, th.pick { width: 40px; } td.pick input, th.pick input { width: 16px; height: 16px; accent-color: var(--accent); }
.doc-list { list-style: none; margin: 0; padding: 0; }
.doc-list li { display: flex; gap: 14px; align-items: flex-start; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.doc-list li:last-child { border-bottom: 0; }
.doc-list .title { font-weight: 600; font-size: 14.5px; }
.doc-list .meta { font-size: 12.5px; color: var(--text-3); }

/* Notifications ---------------------------------------------------------------------------------- */
.notif-list { list-style: none; margin: 0; padding: 0; }
.notif-list li { display: flex; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--border); align-items: flex-start; }
.notif-list li:last-child { border-bottom: 0; }
.notif-list li.unread { background: var(--accent-softer); }
.notif-list li.unread .n-msg { font-weight: 600; }
.notif-list .n-icon { width: 32px; height: 32px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.notif-list .n-when { font-size: 12px; color: var(--text-3); }

/* Charts ------------------------------------------------------------------------------------------ */
.trend { width: 100%; height: 96px; display: block; overflow: visible; }
.trend-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.trend-band { fill: var(--accent); opacity: .07; }
.trend-ref { stroke: var(--text-3); stroke-dasharray: 3 3; stroke-width: 1; vector-effect: non-scaling-stroke; }
.trend .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; vector-effect: non-scaling-stroke; }
.trend .dot.out { fill: var(--rose); }
.trend .hit, .bars .hit { fill: transparent; }
.trend-pt:hover .dot { r: 5.5; }
.bars { width: 100%; height: 160px; display: block; }
.bars path { fill: var(--accent); }
.bars .bar:hover path { fill: var(--accent-hover); }
.bars .baseline { stroke: var(--border-strong); stroke-width: 1; }
.bars .tick { font-size: 10px; fill: var(--text-3); font-family: var(--font); }
.vital-tile { border: 1px solid var(--border); border-radius: var(--r-lg); padding: 11px 13px; }
.vital-tile .v { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.hbar { display: grid; grid-template-columns: 140px 1fr 110px; gap: 10px; align-items: center; font-size: 13px; padding: 5px 0; }
.hbar .track { background: var(--surface-2); border-radius: 999px; height: 8px; overflow: hidden; }
.hbar .fill { background: var(--accent); height: 100%; border-radius: 999px; }

/* Body map (dermatology) -------------------------------------------------------------------------- */
.bodymap { position: relative; width: 180px; margin: 0 auto; cursor: crosshair; }
.bodymap svg { width: 100%; height: auto; display: block; }
.bodymap .silhouette { fill: var(--surface-2); stroke: var(--border-strong); stroke-width: 1.5; }
.bodymap .pin { position: absolute; width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 999px; background: var(--rose); color: #fff; font-size: 9px; font-weight: 700; display: grid; place-items: center; border: 2px solid var(--surface); }
.bodymap .pin.new { background: var(--accent); }

/* Auth pages -------------------------------------------------------------------------------------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.auth-aside { background: radial-gradient(1200px 600px at -10% -10%, #14b8a6 0%, transparent 55%), radial-gradient(900px 500px at 120% 110%, #0d9488 0%, transparent 50%), linear-gradient(160deg, #0c2624, #0f3b37 55%, #134e4a);
  color: #ecfeff; padding: 52px 56px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-aside::after { content: ""; position: absolute; inset: 0; background-image: radial-gradient(rgba(255,255,255,.07) 1px, transparent 1px); background-size: 22px 22px; pointer-events: none; }
.auth-aside > * { position: relative; z-index: 1; }
.auth-aside h2 { font-size: 32px; font-weight: 650; letter-spacing: -0.025em; line-height: 1.15; max-width: 460px; }
.auth-aside p { color: #ccfbf1; max-width: 440px; }
.auth-main { display: grid; place-items: center; padding: 32px; background: var(--surface); }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h1 { margin-bottom: 6px; font-size: 24px; }
.auth-points { list-style: none; padding: 0; margin: 26px 0 0; display: grid; gap: 12px; color: #ccfbf1; font-size: 13.5px; }
.auth-points li { display: flex; gap: 10px; } .auth-points .icon { color: #5eead4; }

/* Utility ----------------------------------------------------------------------------------------- */
.mt-0 { margin-top: 0 !important; } .mt-2 { margin-top: 8px; } .mt-4 { margin-top: 16px; } .mb-0 { margin-bottom: 0 !important; } .mb-4 { margin-bottom: 18px; }
.w-full { width: 100%; } .right { text-align: right; } .center { text-align: center; }
details.disclosure { border: 1px solid var(--border); border-radius: var(--r-lg); padding: 0 14px; background: var(--surface); }
details.disclosure + details.disclosure { margin-top: 8px; }
details.disclosure summary { cursor: pointer; padding: 11px 0; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 8px; }
details.disclosure summary::-webkit-details-marker { display: none; }
details.disclosure summary::before { content: "+"; width: 20px; height: 20px; border-radius: 6px; background: var(--surface-2); display: grid; place-items: center; font-weight: 700; color: var(--text-2); flex: none; }
details.disclosure[open] summary::before { content: "–"; }
details.disclosure[open] { padding-bottom: 12px; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 7px 14px; font-size: 13.5px; margin: 0; }
.kv dt { color: var(--text-3); } .kv dd { margin: 0; }
.idle-warn { position: fixed; right: 16px; bottom: 16px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg); border-radius: var(--r-xl); padding: 14px 16px; z-index: 50; max-width: 320px; }
.portal-top { background: var(--surface); border-bottom: 1px solid var(--border); padding: 14px 24px; display: flex; align-items: center; gap: 12px; }
.portal-wrap { max-width: 960px; margin: 0 auto; padding: 24px 16px; }
.callout { display: flex; gap: 12px; align-items: flex-start; padding: 13px 15px; border-radius: var(--r-lg); background: var(--surface-2); border: 1px solid var(--border); font-size: 13px; color: var(--text-2); }
.callout .icon { color: var(--accent); margin-top: 1px; }

.cols > *, .cols-even > *, .grid-2 > *, .grid-3 > *, .grid-4 > *, .grid-5 > * { min-width: 0; } /* let tables scroll inside their card instead of widening the page */
@media (max-width: 1100px) { .cols { grid-template-columns: minmax(0, 1fr); } .board { grid-template-columns: repeat(5, 240px); } .grid-4, .grid-5 { grid-template-columns: repeat(2, 1fr); } .rrow-med, .rrow-vacc { grid-template-columns: repeat(2, 1fr); } .rrow-vacc > .span2 { grid-column: auto; } }
@media (max-width: 820px) {
  /* Phone/tablet: sidebar becomes a compact top bar with one swipeable row of destinations */
  .shell { grid-template-columns: minmax(0, 1fr); } .sidebar { position: static; height: auto; overflow: visible; } .brand { padding: 12px 16px 8px; }
  .nav { flex-direction: row; flex-wrap: nowrap; overflow-x: auto; gap: 4px; padding: 2px 12px 12px; scrollbar-width: none; } .nav::-webkit-scrollbar { display: none; }
  .nav a { flex: none; white-space: nowrap; } .nav a[aria-current="page"] { box-shadow: inset 0 -2px 0 #2dd4bf; } .nav-group, .sidebar-foot { display: none; }
  .topbar { padding: 10px 16px; flex-wrap: wrap; } .content { padding: 18px 16px 40px; } .grid-2, .grid-3, .cols-even, .auth { grid-template-columns: minmax(0, 1fr); } .auth-aside { display: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } .kpi { padding: 12px 14px; } .kpi-value { font-size: 24px; }
  .week { grid-template-columns: 1fr; } .kv { grid-template-columns: 1fr; } .hbar { grid-template-columns: 90px 1fr 80px; } .rrow-med, .rrow-vacc { grid-template-columns: 1fr; }
}

/* Print: A4 prescriptions/invoices/receipts, CR80 ID card (3.37in x 2.125in) ------------------------ */
.print-page { max-width: 794px; margin: 24px auto; background: #fff; color: #0f172a; padding: 40px 48px; border: 1px solid #e2e8f0; }
.print-head { display: flex; justify-content: space-between; border-bottom: 2px solid #0f766e; padding-bottom: 12px; margin-bottom: 18px; }
.print-head h1 { font-size: 20px; } .print-foot { margin-top: 32px; font-size: 11px; color: #64748b; border-top: 1px solid #e2e8f0; padding-top: 8px; }
.print-page table { width: 100%; border-collapse: collapse; } .print-page th, .print-page td { padding: 6px 8px; border-bottom: 1px solid #e2e8f0; text-align: left; font-size: 13px; }
.print-page .r { text-align: right; font-variant-numeric: tabular-nums; }
.rx-mark { font: italic 700 32px Georgia, serif; color: #0f766e; }
.signature-line { margin-top: 48px; border-top: 1px solid #0f172a; width: 260px; padding-top: 4px; font-size: 12px; }
.idcard { width: 3.37in; height: 2.125in; border-radius: 10px; overflow: hidden; border: 1px solid #cbd5e1; background: #fff; color: #0f172a; display: grid; grid-template-rows: 32% 1fr; margin: 24px auto; font-size: 10px; }
.idcard-top { background: linear-gradient(135deg, #0f766e, #134e4a); color: #fff; padding: 8px 12px; display: flex; align-items: center; justify-content: space-between; }
.idcard-body { display: grid; grid-template-columns: 1fr 0.9in; gap: 8px; padding: 8px 12px; align-items: center; }
.idcard-body .nm { font-size: 13px; font-weight: 700; } .idcard-body img { width: 0.9in; height: 0.9in; }
.no-print { }
@media print {
  /* App pages printed from the browser: our own footer replaces the browser header/footer (which carries the URL). */
  @page { size: A4; margin: 14mm; @top-left { content: ""; } @top-right { content: ""; } @bottom-right { content: "Page " counter(page) " of " counter(pages); font-size: 8pt; color: #64748b; } }
  body { background: #fff; } .no-print, .sidebar, .topbar, .env-banner, .flash, .tabs, .filterbar, .btn { display: none !important; }
  .print-page { border: 0; margin: 0; padding: 0; max-width: none; } .shell { display: block; } .content { padding: 0; }
  .card, .kpi { box-shadow: none; break-inside: avoid; }
  .idcard { margin: 0; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
@media (forced-colors: active) { .trend-line, .bars path { forced-color-adjust: auto; } .badge { border: 1px solid CanvasText; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
