/* Clinic OS components. Uses tokens.css only. Mobile first is not used here:
   desktop density is the reference, and each component states how it
   changes at 1279, 1023 and 767 px (see R5). */

@font-face { font-family: "Inter"; font-weight: 400; font-display: swap; src: url("../fonts/inter-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-weight: 500; font-display: swap; src: url("../fonts/inter-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-weight: 600; font-display: swap; src: url("../fonts/inter-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-weight: 700; font-display: swap; src: url("../fonts/inter-latin-700-normal.woff2") format("woff2"); }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: var(--fs-base); line-height: var(--lh); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img, svg { display: block; max-width: 100%; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; text-wrap: balance; }
p { margin: 0; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }
.num { font-variant-numeric: tabular-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.xs { font-size: var(--fs-xs); }
.strong { font-weight: 600; color: var(--text); }
.link { color: var(--primary-ink); font-weight: 600; }
.link:hover { text-decoration: underline; }
.icon { width: 18px; height: 18px; flex-shrink: 0; }
.icon.sm { width: 15px; height: 15px; }
.icon.lg { width: 22px; height: 22px; }

/* ---------- Layout utilities ---------- */
.row { display: flex; gap: var(--s3); align-items: center; flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; }
.row.between { justify-content: space-between; }
.row.top { align-items: flex-start; }
.stack { display: grid; gap: var(--s4); min-width: 0; }
.stack.tight { gap: var(--s2); }
.stack.loose { gap: var(--s6); }
.grow { flex: 1; min-width: 0; }
.grid { display: grid; gap: var(--s4); grid-template-columns: repeat(12, minmax(0, 1fr)); }
.grid > * { min-width: 0; }
.c12 { grid-column: span 12; } .c9 { grid-column: span 9; } .c8 { grid-column: span 8; } .c7 { grid-column: span 7; }
.c6 { grid-column: span 6; } .c5 { grid-column: span 5; } .c4 { grid-column: span 4; } .c3 { grid-column: span 3; }
@media (max-width: 1279px) {
  .c9, .c8, .c7 { grid-column: span 12; } .c6, .c5, .c4 { grid-column: span 6; } .c3 { grid-column: span 6; }
  .c4.keep, .c3.keep { grid-column: span 4; }
}
@media (max-width: 1023px) { .c4.keep, .c3.keep { grid-column: span 6; } .c6.l-full, .c5.l-full, .c4.l-full { grid-column: span 12; } }
@media (max-width: 767px) { .grid > * { grid-column: span 12 !important; } }
.split { display: grid; grid-template-columns: minmax(0, 1fr) var(--drawer-w); gap: var(--s4); align-items: start; }
@media (max-width: 1279px) { .split { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; min-height: 100dvh; }
.side { width: var(--side-w); flex-shrink: 0; background: linear-gradient(160deg, #051021, var(--nav-bg-2)); color: var(--nav-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; height: 100dvh; overflow-y: auto; z-index: 30; padding: 22px 12px 14px; scrollbar-width: thin; scrollbar-color: #24405f transparent; }
.brand { display: flex; align-items: baseline; font-size: 24px; font-weight: 700; letter-spacing: -0.8px; color: #fff; padding: 0 10px; white-space: nowrap; }
.brand em { color: var(--brand-slash); font-style: normal; }
.brand b { color: var(--brand-os); font-weight: 700; }
.brand-tag { font-size: 9px; letter-spacing: 2px; color: #8EA3BE; margin: 6px 10px 14px; white-space: nowrap; }
.side-label { font-size: 10px; letter-spacing: 1.3px; color: var(--nav-muted); margin: 16px 12px 6px; text-transform: uppercase; white-space: nowrap; }
.nav { display: flex; align-items: center; gap: 11px; min-height: 38px; padding: 7px 10px; border-radius: var(--r); font-size: 13.5px; color: var(--nav-text); margin: 1px 0; white-space: nowrap; }
.nav span.t { min-width: 0; white-space: normal; line-height: 1.25; }   /* long module names (Joint Pain and Regenerative) wrap instead of overflowing */
.nav:hover { background: var(--nav-hover); }
.nav.on { background: linear-gradient(90deg, #18355A, var(--nav-active)); color: #fff; font-weight: 600; }
.nav .badge { margin-left: auto; font-size: 10.5px; font-weight: 700; background: #E63256; color: #fff; border-radius: var(--r-pill); padding: 1px 7px; }
.nav .badge.soft { background: #23406a; color: #CFDEFF; }
.nav .chev { margin-left: auto; color: #8EA3BE; }
.mi { width: 26px; height: 26px; border-radius: 7px; display: inline-flex; align-items: center; justify-content: center; background: var(--c); color: #fff; flex-shrink: 0; }
.mi .icon { width: 16px; height: 16px; }
.mi.sm { width: 20px; height: 20px; border-radius: 6px; } .mi.sm .icon { width: 13px; height: 13px; }
.subnav { display: grid; gap: 1px; margin: 2px 0 6px 36px; }
.subnav a { font-size: 12.5px; color: #A9B9CE; padding: 6px 10px; border-radius: 6px; white-space: nowrap; }
.subnav a.on { color: #fff; background: #13294A; }
.side-add { display: flex; align-items: center; justify-content: center; gap: 6px; margin: 12px 4px 4px; padding: 9px; border: 1px dashed #8B75EF; color: #CABEFF; border-radius: var(--r); font-size: 12.5px; white-space: nowrap; }
.side-foot { margin-top: auto; padding-top: 12px; }
.clinic-switch { display: flex; align-items: center; gap: 10px; background: #102740; border: 1px solid #223953; border-radius: 10px; padding: 9px; margin-top: 8px; width: 100%; text-align: left; }
.clinic-switch strong { display: block; font-size: 12px; color: #fff; }
.clinic-switch small { display: block; font-size: 11px; color: #A9B9CE; }
.side-label, .nav span.t, .subnav, .brand-tag, .clinic-switch .t { transition: opacity var(--dur); }

.frame { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; height: var(--topbar-h); background: rgba(255,255,255,.92); backdrop-filter: saturate(1.4) blur(8px); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: var(--s3); padding: 0 max(var(--s6), env(safe-area-inset-right)) 0 max(var(--s6), env(safe-area-inset-left)); }
.topbar .menu-btn { display: none; }
.topbar .mobile-brand { display: none; }
.search { display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); color: var(--muted); font-size: 13px; width: min(420px, 40vw); }
.search kbd { margin-left: auto; font-size: 11px; border: 1px solid var(--border-strong); border-radius: 4px; padding: 0 5px; color: var(--muted); background: #fff; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.iconbtn { position: relative; width: 38px; height: 38px; display: inline-flex; align-items: center; justify-content: center; border-radius: var(--r); border: 0; background: transparent; color: var(--text-2); }
.iconbtn:hover { background: var(--surface-sunk); }
.iconbtn .dot { position: absolute; top: 4px; right: 4px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: #E63256; color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; border: 2px solid #fff; }
.loc-switch { display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--r); background: #fff; font-size: 13px; white-space: nowrap; }
.me { display: flex; align-items: center; gap: 9px; padding: 3px 6px 3px 3px; border-radius: var(--r-pill); border: 0; background: transparent; }
.me .t strong { display: block; font-size: 12.5px; line-height: 1.2; }
.me .t small { display: block; font-size: 11px; color: var(--muted); }

.main { width: 100%; max-width: var(--content-max); margin: 0 auto; padding: var(--s6) max(var(--s6), env(safe-area-inset-right)) var(--s10) max(var(--s6), env(safe-area-inset-left)); flex: 1; }
.page-head { display: flex; gap: var(--s4); align-items: flex-end; justify-content: space-between; flex-wrap: wrap; margin-bottom: var(--s5); }
.page-head h1 { font-size: var(--fs-2xl); letter-spacing: -0.5px; }
.page-head .sub { color: var(--muted); margin-top: 6px; max-width: 72ch; }
/* A page whose only action is Help keeps the Help button top right instead of on a row of its own */
.page-head { position: relative; }
@media (max-width: 1023px) { .page-head:has(> .actions > .page-help:only-child) { padding-right: 52px; } .page-head > .actions:has(> .page-help:only-child) { position: absolute; top: 0; right: 0; width: auto; margin: 0; } }
.page-head .actions { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; }
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--primary-ink); text-decoration: underline; }
.crumbs .sep { color: var(--border-strong); }

.bottombar { display: none; }

/* 1024 to 1279: icon sidebar */
@media (max-width: 1279px) and (min-width: 1024px) {
  .side { width: var(--side-w-mini); padding: 18px 10px 12px; overflow-x: hidden; }
  .brand { font-size: 0; padding: 0; justify-content: center; }
  .brand::before { content: "C/"; font-size: 20px; color: #fff; }
  .brand-tag, .side-label, .nav span.t, .nav .chev, .subnav, .clinic-switch .t, .side-add span { display: none; }
  .side-label { display: block; height: 1px; background: var(--nav-line); margin: 12px 6px; font-size: 0; }
  .nav { justify-content: center; padding: 8px 0; }
  .nav .badge { position: absolute; margin: -22px 0 0 26px; padding: 0 5px; font-size: 9.5px; }
  .side-add { padding: 9px 0; }
  .clinic-switch { justify-content: center; padding: 8px 0; }
}
/* under 1024: drawer sidebar */
@media (max-width: 1023px) {
  .side { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-105%); transition: transform var(--dur); box-shadow: var(--shadow-pop); width: min(300px, 86vw); padding-top: max(22px, env(safe-area-inset-top)); }
  .shell.nav-open .side { transform: none; }
  .shell.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(6, 16, 34, .45); z-index: 25; }
  .topbar .menu-btn { display: inline-flex; }
  .search { width: auto; flex: 1; max-width: 360px; }
  .loc-switch .t, .me .t { display: none; }
  .main { padding-top: var(--s5); }
}
/* under 768: phone */
@media (max-width: 767px) {
  .topbar { height: calc(52px + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top); padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); gap: 6px; }
  .topbar .mobile-brand { display: flex; font-size: 18px; color: var(--text); }
  .topbar .mobile-brand em { color: var(--info); } .topbar .mobile-brand b { color: var(--brand-os); }
  .search { display: none; }
  .loc-switch { display: none; }
  .iconbtn.hide-phone { display: none; }
  .main { padding: var(--s4) max(var(--s4), env(safe-area-inset-right)) calc(var(--bottombar-h) + var(--s8) + env(safe-area-inset-bottom)) max(var(--s4), env(safe-area-inset-left)); }
  .page-head { align-items: stretch; flex-direction: column; margin-bottom: var(--s4); }
  .page-head h1 { font-size: 22px; }
  .page-head .actions { width: 100%; }
  .page-head .actions .btn { flex: 1 1 auto; justify-content: center; }
  .bottombar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; height: calc(var(--bottombar-h) + env(safe-area-inset-bottom)); padding: 4px max(6px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(6px, env(safe-area-inset-left)); background: #fff; border-top: 1px solid var(--border); }
  .bottombar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; color: var(--muted); border-radius: var(--r); position: relative; }
  .bottombar a.on { color: var(--primary-ink); font-weight: 600; }
  .bottombar .dot { position: absolute; top: 4px; left: 54%; min-width: 16px; height: 16px; border-radius: 8px; background: #E63256; color: #fff; font-size: 9.5px; font-weight: 700; display: grid; place-items: center; padding: 0 4px; }
}

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 38px; padding: 8px 15px; border-radius: var(--r); border: 1px solid transparent; font-size: 13.5px; font-weight: 600; white-space: nowrap; background: var(--primary); color: var(--on-primary); box-shadow: 0 4px 10px rgba(104, 76, 230, .14); transition: background var(--dur); }
.btn:hover { background: var(--primary-hover); }
.btn.secondary { background: #fff; color: var(--text-2); border-color: var(--border-strong); box-shadow: none; }
.btn.secondary:hover { background: var(--surface-2); }
.btn.ghost { background: transparent; color: var(--primary-ink); box-shadow: none; }
.btn.ghost:hover { background: var(--primary-tint); }
.btn.danger { background: #fff; color: var(--bad-ink); border-color: var(--bad-line); box-shadow: none; }
.btn.danger.solid { background: var(--bad-ink); color: #fff; border-color: var(--bad-ink); }
.btn.sm { min-height: 32px; padding: 5px 11px; font-size: 12.5px; }
.btn.icon-only { width: 38px; padding: 0; }
.btn[disabled], .btn.is-disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
@media (max-width: 1023px) { .btn { min-height: var(--tap); } .btn.sm { min-height: 38px; } }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); box-shadow: var(--shadow-card); min-width: 0; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: 15px 18px 0; flex-wrap: wrap; }
.card-h h2, .card-h h3 { font-size: 15px; font-weight: 700; }
.card-h .sub { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.card-b { padding: 14px 18px 18px; }
.card-b.flush { padding: 0; }
.card-f { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: var(--s2); justify-content: space-between; align-items: center; flex-wrap: wrap; background: var(--surface-2); border-radius: 0 0 var(--r-card) var(--r-card); }
.card.pad { padding: 18px; }
.card.tint { background: var(--primary-tint); border-color: var(--primary-tint-2); }
@media (max-width: 767px) { .card-h { padding: 14px 14px 0; } .card-b { padding: 12px 14px 14px; } .card-f { padding: 10px 14px; } }

/* ---------- KPI cards ---------- */
.kpis { display: grid; grid-template-columns: repeat(var(--n, 4), minmax(0, 1fr)); gap: var(--s4); }
.kpi { display: flex; gap: 12px; align-items: flex-start; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); box-shadow: var(--shadow-card); min-width: 0; position: relative; }
a.kpi:hover { border-color: var(--primary-tint-2); box-shadow: 0 0 0 3px var(--primary-tint); }
.kpi .bi { width: 36px; height: 36px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; background: color-mix(in srgb, var(--c, var(--primary)) 12%, #fff); color: var(--c, var(--primary)); flex-shrink: 0; }
.kpi .lbl { font-size: 12.5px; color: var(--muted); }
.kpi .val { font-size: var(--fs-kpi); font-weight: 700; letter-spacing: -0.6px; line-height: 1.15; margin-top: 4px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.kpi .delta { font-size: 12px; margin-top: 6px; color: var(--muted); }
.kpi .delta .up { color: var(--ok-ink); font-weight: 600; } .kpi .delta .down { color: var(--bad-ink); font-weight: 600; } .kpi .delta .warn { color: var(--warn-ink); font-weight: 600; }
.kpi .spark { margin-top: 8px; width: 100%; height: 30px; }
.kpi .body { min-width: 0; flex: 1; }
@media (max-width: 1279px) { .kpis { grid-template-columns: repeat(min(var(--n, 4), 3), minmax(0, 1fr)); } }
@media (max-width: 1023px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 767px) { .kpis { gap: 10px; } .kpi { padding: 12px; flex-direction: column; gap: 8px; } .kpi .bi { width: 30px; height: 30px; } .kpi .val { font-size: 21px; } .kpi .spark { display: none; } }
@media (max-width: 380px) { .kpis.wide { grid-template-columns: 1fr; } }

/* ---------- Pills, chips, avatars ---------- */
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: var(--r-pill); white-space: nowrap; line-height: 1.4; }
.pill.ok { background: var(--ok-tint); color: var(--ok-ink); }
.pill.warn { background: var(--warn-tint); color: var(--warn-ink); }
.pill.bad { background: var(--bad-tint); color: var(--bad-ink); }
.pill.info { background: var(--info-tint); color: var(--info-ink); }
.pill.purple { background: var(--primary-tint); color: var(--primary-ink); }
.pill.grey { background: var(--grey-tint); color: var(--grey-ink); }
.pill.outline { background: #fff; border: 1px solid var(--border-strong); color: var(--text-2); }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; padding: 3px 9px 3px 7px; border-radius: var(--r-pill); background: color-mix(in srgb, var(--c) 11%, #fff); color: var(--ci, var(--text)); white-space: nowrap; }
.chip i { width: 7px; height: 7px; border-radius: 50%; background: var(--c); flex-shrink: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.av { width: 34px; height: 34px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; flex-shrink: 0; overflow: hidden; background: var(--avbg, #DDD7FF); color: var(--avfg, #4B37B8); position: relative; }
.av img, .av svg { width: 100%; height: 100%; object-fit: cover; }
.av.xs { width: 22px; height: 22px; font-size: 9.5px; } .av.sm { width: 28px; height: 28px; font-size: 10.5px; } .av.lg { width: 52px; height: 52px; font-size: 17px; } .av.xl { width: 88px; height: 88px; font-size: 28px; }
.av .online { position: absolute; right: 0; bottom: 0; width: 28%; height: 28%; border-radius: 50%; background: var(--ok); border: 2px solid #fff; }
.avstack { display: flex; } .avstack .av { border: 2px solid #fff; margin-left: -8px; } .avstack .av:first-child { margin-left: 0; }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who .t { min-width: 0; }
.who strong { display: block; font-size: 13.5px; font-weight: 600; color: var(--text); }
.who small { display: block; font-size: 12px; color: var(--muted); }
a.who:hover strong { color: var(--primary-ink); text-decoration: underline; }

/* ---------- Tables (desktop) and their phone cards ---------- */
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { font-size: 11px; letter-spacing: .5px; text-transform: uppercase; color: var(--muted-2); text-align: left; font-weight: 600; padding: 10px 12px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0; }
.tbl th.r, .tbl td.r { text-align: right; }
.tbl td { padding: 11px 12px; border-bottom: 1px solid var(--line); color: var(--text-2); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr.click { cursor: pointer; }
.tbl tbody tr.click:hover td { background: #FAFBFE; }
.tbl tbody tr.sel td { background: #F6F3FF; }
.tbl tbody tr.sel td:first-child { box-shadow: inset 3px 0 0 var(--primary); }
.tbl tfoot td { font-weight: 700; color: var(--text); background: var(--surface-2); border-top: 1px solid var(--border); padding: 10px 12px; }
.tbl .void td { color: var(--muted-2); text-decoration: line-through; }
@media (max-width: 1439px) { .tbl .p3 { display: none; } }
@media (max-width: 1279px) { .tbl .p2 { display: none; } }
.mlist { display: none; }
@media (max-width: 767px) {
  .tbl-wrap.cards { display: none; }
  .mlist { display: block; }
}
.mitem { display: flex; gap: 12px; align-items: flex-start; padding: 13px 14px; border-bottom: 1px solid var(--line); min-height: var(--tap); }
.mitem:last-child { border-bottom: 0; }
.mitem .body { flex: 1; min-width: 0; display: grid; gap: 5px; }
.mitem .l1 { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.mitem .l1 strong { font-size: 14px; }
.mitem .meta { font-size: 12.5px; color: var(--muted); }
.mitem .val { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Tabs, filters, segmented ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: var(--s4); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { padding: 10px 14px; font-size: 13.5px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; font-weight: 500; display: inline-flex; gap: 6px; align-items: center; }
.tab.on { color: var(--primary-ink); border-color: var(--primary); font-weight: 700; }
.tab .n { font-size: 11.5px; color: var(--muted-2); background: var(--surface-sunk); border-radius: var(--r-pill); padding: 0 7px; }
.tab.on .n { background: var(--primary-tint); color: var(--primary-ink); }
.filters { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; margin-bottom: var(--s4); }
.filter { display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--r); background: #fff; font-size: 13px; white-space: nowrap; }
.filter.on { border-color: var(--primary); background: var(--primary-tint); color: var(--primary-ink); font-weight: 600; }
.filter .x { margin-left: 2px; }
.filters .search-in { flex: 1 1 240px; max-width: 360px; display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--r); background: #fff; color: var(--muted); font-size: 13px; }
@media (max-width: 767px) { .filters { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-right: calc(-1 * var(--s4)); padding-right: var(--s4); } .filters .search-in { flex: 0 0 100%; max-width: none; } .filters.has-search { flex-wrap: wrap; } .filter { height: 40px; } }
.seg { display: inline-flex; background: var(--surface-sunk); border-radius: var(--r); padding: 3px; gap: 2px; }
.seg a, .seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 6px; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.seg .on { background: #fff; color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(17, 34, 68, .08); }

/* ---------- Forms ---------- */
.form { display: grid; gap: var(--s4); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s4) var(--s5); }
.form-grid .full { grid-column: 1 / -1; }
.form-grid > .field { align-content: start; }
@media (max-width: 1023px) { .form-grid { grid-template-columns: minmax(0, 1fr); } }
.field { display: grid; gap: 6px; min-width: 0; }
.field label, .field .label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field .req { color: var(--bad-ink); }
.input, .select, .textarea { width: 100%; min-height: 40px; padding: 9px 12px; border: 1px solid var(--border-strong); border-radius: var(--r); background: #fff; font-size: 14px; color: var(--text); }
.select { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.input.ph, .select.ph, .textarea.ph { color: var(--muted-2); }
.textarea { min-height: 88px; }
.input.err, .select.err { border-color: var(--bad); box-shadow: 0 0 0 3px var(--bad-tint); }
.hint { font-size: 12px; color: var(--muted); }
.errmsg { font-size: 12px; color: var(--bad-ink); font-weight: 600; display: flex; gap: 6px; align-items: center; }
.input-group { display: flex; }
.input-group .input { border-radius: var(--r) 0 0 var(--r); }
.input-group .addon { display: flex; align-items: center; padding: 0 12px; border: 1px solid var(--border-strong); border-left: 0; border-radius: 0 var(--r) var(--r) 0; background: var(--surface-2); font-size: 13px; color: var(--muted); white-space: nowrap; }
@media (max-width: 767px) { .input, .select, .textarea { font-size: 16px; min-height: var(--tap); } }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 13.5px; }
.check .box { width: 18px; height: 18px; border: 1.5px solid var(--border-strong); border-radius: 5px; flex-shrink: 0; margin-top: 2px; display: grid; place-items: center; background: #fff; }
.check .box.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.check .box.radio { border-radius: 50%; } .check .box.radio.on { background: #fff; box-shadow: inset 0 0 0 4px var(--primary); }
.switch { width: 38px; height: 22px; border-radius: 11px; background: var(--border-strong); position: relative; flex-shrink: 0; border: 0; padding: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: left var(--dur); }
.switch.on { background: var(--primary); } .switch.on::after { left: 19px; }
.switch.locked { background: #C9C2F5; cursor: not-allowed; }
.upload { border: 1.5px dashed var(--border-strong); border-radius: var(--r-card); padding: 26px; text-align: center; background: var(--surface-2); display: grid; gap: 8px; justify-items: center; }
.upload.drag { border-color: var(--primary); background: var(--primary-tint); }

/* ---------- Alerts and banners ---------- */
.alert { display: flex; gap: 12px; align-items: flex-start; padding: 12px 15px; border-radius: 10px; border: 1px solid; font-size: 13.5px; line-height: 1.5; }
.alert .grow { min-width: 0; }
.alert.warn { background: var(--warn-tint); border-color: var(--warn-line); color: #6E420B; }
.alert.info { background: var(--info-tint); border-color: var(--info-line); color: #0F5A59; }
.alert.bad { background: var(--bad-tint); border-color: var(--bad-line); color: #7E2443; }
.alert.ok { background: var(--ok-tint); border-color: #CBEBD8; color: #1B5E3B; }
.alert.purple { background: var(--primary-tint); border-color: var(--primary-tint-2); color: #3F2BA8; }
.alert .btn { flex-shrink: 0; }
@media (max-width: 767px) { .alert { flex-wrap: wrap; } .alert .btn { width: 100%; } }

/* ---------- Key-value lists ---------- */
.kv { display: grid; grid-template-columns: minmax(120px, 34%) 1fr; gap: 9px 14px; font-size: 13.5px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; color: var(--text); min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 380px) { .kv { grid-template-columns: 1fr; gap: 2px; } .kv dd { margin-bottom: 8px; } }
.section-label { font-size: 11px; font-weight: 700; letter-spacing: 1.1px; text-transform: uppercase; color: var(--muted-2); }

/* ---------- Drawer, dialog, sheet, menu, toast ---------- */
.drawer { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-drawer); box-shadow: var(--shadow-card); overflow: hidden; position: sticky; top: calc(var(--topbar-h) + 16px); max-height: calc(100vh - var(--topbar-h) - 32px); display: flex; flex-direction: column; }
.drawer-h { display: flex; gap: 12px; align-items: flex-start; padding: 18px; border-bottom: 1px solid var(--line); }
.drawer-h h2 { font-size: 18px; }
.drawer-b { overflow-y: auto; padding: 4px 18px 18px; display: grid; gap: 0; }
.drawer-b > section { padding: 14px 0; border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
.drawer-b > section:last-child { border-bottom: 0; }
.drawer-f { padding: 12px 18px; border-top: 1px solid var(--line); background: var(--surface-2); display: flex; gap: 8px; flex-wrap: wrap; }
@media (max-width: 1279px) {
  .drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(var(--drawer-w), 92vw); max-height: none; border-radius: var(--r-drawer) 0 0 var(--r-drawer); z-index: 40; box-shadow: var(--shadow-drawer); }
  .drawer-backdrop { position: fixed; inset: 0; background: rgba(6, 16, 34, .35); z-index: 39; }
}
@media (max-width: 767px) {
  .drawer { width: 100%; border-radius: 0; padding-top: env(safe-area-inset-top); }
  .drawer-f { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
}
.dialog-backdrop { position: fixed; inset: 0; background: rgba(6, 16, 34, .45); z-index: 50; display: grid; place-items: center; padding: 24px; }
.dialog { width: min(560px, 100%); max-height: calc(100vh - 48px); background: #fff; border-radius: 14px; box-shadow: var(--shadow-pop); display: flex; flex-direction: column; overflow: hidden; }
.dialog.wide { width: min(820px, 100%); }
.dialog-h { padding: 18px 20px 0; display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.dialog-h h2 { font-size: 18px; }
.dialog-b { padding: 14px 20px 20px; overflow-y: auto; display: grid; gap: var(--s4); }
.dialog-f { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; background: var(--surface-2); }
@media (max-width: 767px) {
  .dialog-backdrop { padding: 0; place-items: end stretch; }
  .dialog, .dialog.wide { width: 100%; max-height: 100vh; height: 100dvh; border-radius: 0; padding-top: env(safe-area-inset-top); }
  .dialog-b { flex: 1; }
  .dialog-f { padding-bottom: max(14px, env(safe-area-inset-bottom)); }
  .dialog-f .btn { flex: 1; }
}
.menu { position: absolute; min-width: 220px; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-pop); padding: 6px; z-index: 60; }
.menu a, .menu button { display: flex; gap: 10px; align-items: center; width: 100%; padding: 9px 10px; border-radius: 7px; font-size: 13.5px; border: 0; background: transparent; text-align: left; }
.menu a:hover, .menu button:hover { background: var(--surface-sunk); }
.menu .sep { height: 1px; background: var(--line); margin: 5px 0; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 70; display: flex; gap: 12px; align-items: center; background: var(--text); color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow-pop); font-size: 13.5px; max-width: calc(100vw - 32px); }
.toast a { color: #C7B9FF; font-weight: 700; }
@media (max-width: 767px) { .toast { bottom: calc(var(--bottombar-h) + 14px + env(safe-area-inset-bottom)); } }

/* ---------- Empty, loading, no access ---------- */
.empty { display: grid; gap: 10px; justify-items: center; text-align: center; padding: 36px 20px; }
.empty .ico { width: 52px; height: 52px; border-radius: 14px; background: var(--primary-tint); color: var(--primary-ink); display: grid; place-items: center; }
.empty h3 { font-size: 17px; }
.empty p { color: var(--muted); max-width: 52ch; }
.sk { display: block; border-radius: 6px; background: linear-gradient(90deg, #EEF2F7 25%, #F7F9FC 50%, #EEF2F7 75%); background-size: 200% 100%; animation: sk 1.3s linear infinite; }
@keyframes sk { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .sk { animation: none; } }
.blocked { max-width: 560px; margin: 48px auto; text-align: center; display: grid; gap: 12px; justify-items: center; padding: 32px 26px; }
.blocked .ico { width: 56px; height: 56px; border-radius: 16px; background: var(--grey-tint); color: var(--grey-ink); display: grid; place-items: center; }
.blocked h2 { font-size: 20px; }
.blocked p { color: var(--muted); }

/* ---------- Progress, bars, charts ---------- */
.bar { height: 8px; border-radius: 4px; background: var(--surface-sunk); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 4px; background: var(--c, var(--primary)); }
.hbars { display: grid; gap: 9px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 30%) 1fr auto; gap: 10px; align-items: center; font-size: 13px; }
.hbar .v { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 48px; text-align: right; }
@media (max-width: 767px) { .hbar { grid-template-columns: 1fr auto; } .hbar .bar { grid-column: 1 / -1; order: 3; } }
.chart { width: 100%; height: auto; }
.chart text { font-family: var(--font); font-size: 11px; fill: var(--muted); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; gap: 6px; align-items: center; }
.legend i { width: 10px; height: 10px; border-radius: 3px; background: var(--c); }

/* ---------- Stepper (wizards) ---------- */
.stepper { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: var(--s5); }
.step { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); padding: 6px 10px 6px 6px; border-radius: var(--r-pill); background: var(--surface-sunk); white-space: nowrap; }
.step b { width: 22px; height: 22px; border-radius: 50%; background: #fff; display: grid; place-items: center; font-size: 11px; border: 1px solid var(--border-strong); }
.step.done { color: var(--ok-ink); background: var(--ok-tint); } .step.done b { background: var(--ok); color: #fff; border-color: var(--ok); }
.step.on { color: var(--primary-ink); background: var(--primary-tint); font-weight: 700; } .step.on b { background: var(--primary); color: #fff; border-color: var(--primary); }
@media (max-width: 767px) { .stepper .step:not(.on) span { display: none; } .stepper .step:not(.on) { padding: 6px; } }

/* ---------- Timeline ---------- */
.timeline { display: grid; gap: 0; }
.tl { display: grid; grid-template-columns: 34px 1fr; gap: 12px; position: relative; padding-bottom: 16px; }
.tl::before { content: ""; position: absolute; left: 16px; top: 34px; bottom: 0; width: 2px; background: var(--line); }
.tl:last-child::before { display: none; }
.tl .dot { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: color-mix(in srgb, var(--c, var(--primary)) 12%, #fff); color: var(--c, var(--primary)); }
.tl .when { font-size: 12px; color: var(--muted); }

/* ---------- Mockup chrome (not part of the product) ---------- */
.mock-bar { position: fixed; z-index: 1000; right: 12px; bottom: 12px; display: flex; gap: 8px; align-items: center; background: #0B1426; color: #D6DEEA; border-radius: 10px; padding: 7px 10px; font-size: 12px; box-shadow: var(--shadow-pop); max-width: calc(100vw - 24px); flex-wrap: wrap; }
.mock-bar select { background: #17243a; color: #fff; border: 1px solid #2b3d58; border-radius: 6px; padding: 3px 6px; font-size: 12px; }
.mock-bar a { color: #C7B9FF; }
html.shot .mock-bar { display: none; }
@media (max-width: 767px) { .mock-bar { bottom: calc(var(--bottombar-h) + 10px); } }
.state { display: none; }
.state.on { display: contents; }

/* top bar touch sizes and phone search button */
.iconbtn.sbtn { display: none; }
@media (max-width: 1023px) { .iconbtn { width: var(--tap); height: var(--tap); } .me { min-height: var(--tap); } }
@media (max-width: 767px) { .iconbtn.sbtn { display: inline-flex; } }
[hidden] { display: none !important; }
.dialog-b { align-content: start; }
.tbl .who strong, .tbl .who small { white-space: nowrap; }
@media (max-width: 767px) { .chart .xl.odd { display: none; } }
.funnel { display: grid; gap: 10px; }
.fstep { display: grid; grid-template-columns: minmax(110px, 26%) 1fr 60px minmax(110px, auto); gap: 10px; align-items: center; font-size: 13px; padding: 4px 6px; border-radius: 8px; }
a .fstep:hover { background: var(--surface-2); }
.fstep .v { text-align: right; font-weight: 700; }
@media (max-width: 767px) { .fstep { grid-template-columns: 1fr auto; } .fstep .bar { grid-column: 1 / -1; order: 3; } .fstep .muted { grid-column: 1 / -1; order: 4; } }
/* switches: full tap area on touch widths (the visual stays 38 x 22) */
@media (max-width: 1023px) { .switch { position: relative; } .switch::before { content: ""; position: absolute; inset: -11px -3px; } }

/* Support session bar (CON-06): shown above the top bar on every clinic page while Clinic OS support works inside a grant */
.support-bar { position: sticky; top: 0; z-index: 21; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding: 8px max(var(--s6), env(safe-area-inset-right)) 8px max(var(--s6), env(safe-area-inset-left)); background: var(--primary-ink); color: var(--on-primary); font-size: var(--fs-sm); }
.support-bar .grow { flex: 1 1 220px; min-width: 0; }
.support-bar a { color: var(--on-primary); font-weight: 600; text-decoration: underline; min-height: 32px; display: inline-flex; align-items: center; }
.support-bar + .topbar { top: 0; position: relative; }
@media (max-width: 767px) { .support-bar { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); } .support-bar a { min-height: 44px; } }

/* ---------- Narrowest phones (320 to 359): nothing may push the page wider (R5 V00 sweep) ---------- */
.chips { min-width: 0; max-width: 100%; }
.chip { max-width: 100%; }
@media (max-width: 359px) {
  .chip { white-space: normal; line-height: 1.3; }
  .mitem .l1 { flex-wrap: wrap; }
}
