@font-face {
  font-family: 'Inter';
  src: url('/inter.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #f8f6f0;
  --surface: #ffffff;
  --surface-2: #f1eee6;
  --surface-3: #e8e4d9;
  --line: rgb(22 33 58 / 0.12);
  --line-strong: rgb(22 33 58 / 0.22);
  --text: #16213a;
  --muted: #4f5a70;
  --faint: #737c90;
  --primary: #1f4bb8;
  --primary-hover: #193d96;
  --primary-soft: #e3eafa;
  --on-primary: #ffffff;
  --focus: #3a64d0;
  --error: #a3291d;
  --error-soft: #fbe9e6;
  --info: #2a5683;
  --info-soft: #e5eef7;
  --warn: #87470c;
  --warn-soft: #fbefdc;
  --success: #1e3f8f;
  --success-soft: #e6ecfa;
  --shadow: 0 1px 2px rgb(22 33 58 / 0.06), 0 4px 16px rgb(22 33 58 / 0.05);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.9375rem;
  --text-md: 1.0625rem;
  --text-lg: 1.25rem;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px; --s10: 40px; --s12: 48px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1524;
    --surface: #161d2f;
    --surface-2: #1d2539;
    --surface-3: #263049;
    --line: rgb(220 228 245 / 0.10);
    --line-strong: rgb(220 228 245 / 0.20);
    --text: #e8ecf5;
    --muted: #a6b0c5;
    --faint: #8089a0;
    --primary: #8fa9f0;
    --primary-hover: #a9bef5;
    --primary-soft: #1c2a52;
    --on-primary: #0b1430;
    --focus: #a9bef5;
    --error: #f08a7e;
    --error-soft: #3a1f1c;
    --info: #8db8e6;
    --info-soft: #1c2a3a;
    --warn: #f0b36a;
    --warn-soft: #362717;
    --success: #9db4f2;
    --success-soft: #1c2a52;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 4px 16px rgb(0 0 0 / 0.25);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  font-feature-settings: 'cv11', 'ss01';
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: var(--text-lg); font-weight: 650; }
h2 { font-size: var(--text-md); font-weight: 620; }
h3 { font-size: var(--text-base); font-weight: 600; }
p { margin: 0; }
a { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: var(--radius-sm); z-index: 50; }
.skip:focus { left: 8px; }

/* ---------- top bar ---------- */
.dev-strip {
  background: var(--warn-soft); color: var(--warn);
  font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.02em;
  text-align: center; padding: 4px 12px; border-bottom: 1px solid var(--line);
}
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--s4);
  padding: 10px var(--s6);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.2) blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 650; letter-spacing: -0.01em; }
.brand img.logo { display: block; }
.brand small { font-weight: 500; color: var(--faint); }
.topbar .spacer { flex: 1; }
.clinic-chip { font-size: var(--text-sm); color: var(--muted); display: flex; align-items: center; gap: 8px; min-width: 0; }
.clinic-chip strong { color: var(--text); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clinic-chip select { padding: 6px 8px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong); background: var(--surface); max-width: 260px; }
.user-chip { display: flex; align-items: center; gap: 10px; font-size: var(--text-sm); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary);
  font-size: var(--text-xs); font-weight: 700;
}
.user-chip .who { display: flex; flex-direction: column; line-height: 1.2; }
.user-chip .who span { color: var(--faint); font-size: var(--text-xs); }

/* ---------- layout ---------- */
main { padding: var(--s8) var(--s6) var(--s12); max-width: 1180px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s4); margin-bottom: var(--s6); flex-wrap: wrap; }
.page-head .sub { color: var(--muted); font-size: var(--text-sm); margin-top: 4px; }
.crumbs { font-size: var(--text-sm); color: var(--faint); margin-bottom: var(--s3); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--text); text-decoration: underline; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.card-pad { padding: var(--s6); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 16px;
  border-radius: var(--radius-sm); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--text);
  font-size: var(--text-sm); font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { color: var(--error); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-sm { min-height: 32px; padding: 4px 10px; font-size: var(--text-xs); }
.icon-btn { min-height: 36px; min-width: 36px; padding: 6px; }
.btn svg { flex: none; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px; border-radius: 999px;
  font-size: var(--text-xs); font-weight: 600; white-space: nowrap;
  background: var(--surface-2); color: var(--muted);
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.8; }
.badge.neutral { background: var(--surface-3); color: var(--text); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.active { background: var(--primary); color: var(--on-primary); }
.badge.muted { background: var(--surface-2); color: var(--faint); }
.pill { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* ---------- client list ---------- */
.toolbar { display: flex; gap: var(--s3); align-items: center; padding: var(--s4); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.search { position: relative; flex: 1; min-width: 220px; max-width: 380px; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--faint); }
.search input { width: 100%; padding: 9px 12px 9px 34px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong); background: var(--surface); }
.count { font-size: var(--text-sm); color: var(--faint); margin-left: auto; }
table.clients { width: 100%; border-collapse: collapse; }
table.clients th {
  text-align: left; font-size: var(--text-xs); font-weight: 600; color: var(--faint);
  text-transform: uppercase; letter-spacing: 0.05em; padding: 10px var(--s4); border-bottom: 1px solid var(--line);
}
table.clients td { padding: 14px var(--s4); border-bottom: 1px solid var(--line); vertical-align: middle; font-size: var(--text-sm); }
table.clients tr:last-child td { border-bottom: 0; }
table.clients tbody tr { cursor: pointer; transition: background 100ms ease; }
table.clients tbody tr:hover { background: var(--surface-2); }
.client-name { font-weight: 600; font-size: var(--text-base); color: var(--text); text-decoration: none; }
.client-name:hover { text-decoration: underline; }
.code { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: var(--text-xs); color: var(--faint); }
.num { font-variant-numeric: tabular-nums; }
.dim { color: var(--faint); }

/* ---------- notices ---------- */
.notice { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius); font-size: var(--text-sm); background: var(--surface-2); color: var(--text); }
.notice svg { flex: none; margin-top: 2px; }
.notice.info { background: var(--info-soft); }
.notice.info svg { color: var(--info); }
.notice.warn { background: var(--warn-soft); }
.notice.warn svg { color: var(--warn); }
.notice.error { background: var(--error-soft); }
.notice.error svg { color: var(--error); }
.notice.success { background: var(--success-soft); }
.notice.success svg { color: var(--success); }
.notice strong { display: block; margin-bottom: 2px; }
.notice + .notice { margin-top: var(--s3); }
.stack > * + * { margin-top: var(--s4); }

/* ---------- empty / loading ---------- */
.empty { text-align: center; padding: var(--s12) var(--s6); color: var(--muted); }
.empty svg { color: var(--faint); margin-bottom: var(--s3); }
.empty h2 { color: var(--text); margin-bottom: 6px; }
.empty p { max-width: 44ch; margin: 0 auto var(--s5); }
@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }
.skel { display: block; height: 14px; border-radius: 4px; background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.4s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .skel { animation: none; } * { transition: none !important; } }

/* ---------- client detail ---------- */
.client-head { display: flex; gap: var(--s4); align-items: center; }
.client-head .avatar { width: 48px; height: 48px; font-size: var(--text-sm); }
.meta { display: flex; gap: var(--s4); flex-wrap: wrap; font-size: var(--text-sm); color: var(--muted); margin-top: 4px; }
.plan-card + .plan-card { margin-top: var(--s4); }
.plan-card header { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); padding: var(--s4) var(--s5); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.version-row { display: grid; grid-template-columns: 64px 160px 1fr auto; gap: var(--s4); align-items: center; padding: 12px var(--s5); border-bottom: 1px solid var(--line); font-size: var(--text-sm); }
.version-row:last-child { border-bottom: 0; }
.version-row .v { font-weight: 650; font-variant-numeric: tabular-nums; }
.inline-form { display: flex; gap: var(--s3); align-items: flex-end; flex-wrap: wrap; padding: var(--s5); }
.inline-form .field { flex: 1; min-width: 240px; margin: 0; }

/* ---------- builder ---------- */
.builder-head { display: grid; grid-template-columns: 1fr auto; gap: var(--s4) var(--s6); align-items: start; margin-bottom: var(--s5); }
.builder-head .title-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.builder-head .sub { color: var(--muted); font-size: var(--text-sm); margin-top: 4px; }
.head-actions { display: flex; gap: var(--s2); flex-wrap: wrap; justify-content: flex-end; }
.progress { margin-top: var(--s4); display: flex; align-items: center; gap: var(--s3); font-size: var(--text-sm); color: var(--muted); }
.progress .bar { flex: 1; max-width: 320px; height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress .bar span { display: block; height: 100%; background: var(--primary); border-radius: 999px; transition: width 300ms ease; }
.progress strong { color: var(--text); font-variant-numeric: tabular-nums; }

.builder { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: var(--s6); align-items: start; }
.steps { position: sticky; top: 76px; padding: var(--s3); max-height: calc(100vh - 96px); overflow: auto; }
.step + .step { margin-top: var(--s3); padding-top: var(--s3); border-top: 1px solid var(--line); }
.step-title { display: flex; justify-content: space-between; align-items: baseline; padding: 4px 8px 6px; font-size: var(--text-xs); font-weight: 650; color: var(--faint); text-transform: uppercase; letter-spacing: 0.05em; }
.step-title .n { font-variant-numeric: tabular-nums; text-transform: none; letter-spacing: 0; font-weight: 500; }
.sec-link {
  display: flex; gap: 10px; align-items: center; width: 100%;
  padding: 7px 8px; border-radius: var(--radius-sm); border: 0; background: none; text-align: left;
  font-size: var(--text-sm); color: var(--muted); cursor: pointer; line-height: 1.3;
}
.sec-link:hover { background: var(--surface-2); color: var(--text); }
.sec-link[aria-current='true'] { background: var(--primary-soft); color: var(--text); font-weight: 600; }
.sec-link .mark { flex: none; width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; border: 1.5px solid var(--line-strong); }
.sec-link .mark.req { border-color: var(--warn); }
.sec-link .mark.done { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.sec-link .label { flex: 1; }
.sec-link .opt { font-size: 11px; color: var(--faint); }
.sec-link .opt.ins { color: var(--info); font-weight: 600; }

.editor { padding: var(--s6) var(--s8) var(--s8); min-height: 420px; }
.editor-head { display: flex; justify-content: space-between; gap: var(--s4); align-items: flex-start; margin-bottom: var(--s5); }
.editor-head .eyebrow { font-size: var(--text-xs); color: var(--faint); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px; }
.editor-head h2 { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.save-state { font-size: var(--text-xs); color: var(--faint); display: flex; align-items: center; gap: 6px; white-space: nowrap; min-height: 24px; }
.save-state.saving { color: var(--muted); }
.save-state.saved { color: var(--success); }
.save-state.error { color: var(--error); }
.save-state.dirty { color: var(--warn); }
.editor-foot { display: flex; justify-content: space-between; gap: var(--s3); margin-top: var(--s8); padding-top: var(--s5); border-top: 1px solid var(--line); }
.updated-by { font-size: var(--text-xs); color: var(--faint); margin-top: var(--s3); }

/* ---------- form fields ---------- */
.field { margin-bottom: var(--s5); }
.field > label, .field > .label, fieldset.field > legend { display: block; font-size: var(--text-sm); font-weight: 600; margin-bottom: 6px; color: var(--text); padding: 0; }
.field .help { font-size: var(--text-xs); color: var(--muted); margin: -2px 0 8px; }
fieldset.field { border: 0; padding: 0; margin-left: 0; margin-right: 0; min-width: 0; }
.input, .field input[type='text'], .field input[type='email'], .field input[type='date'], .field select, .field textarea {
  width: 100%; padding: 9px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  font-size: var(--text-base); line-height: 1.45;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.field textarea { resize: vertical; min-height: 64px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
.field select { max-width: 320px; }
.field select.wide { max-width: 100%; }
.field-error { font-size: var(--text-xs); color: var(--error); margin-top: 6px; }
.checks { display: flex; flex-wrap: wrap; gap: var(--s2); }
.check { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); cursor: pointer; font-size: var(--text-sm); min-height: 40px; }
.check:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.check input { accent-color: var(--primary); width: 16px; height: 16px; }
.list-items { display: flex; flex-direction: column; gap: var(--s2); }
.list-item { display: flex; gap: var(--s2); align-items: center; }
.list-item .idx { flex: none; width: 22px; text-align: right; font-size: var(--text-xs); color: var(--faint); font-variant-numeric: tabular-nums; }
.list-item input { flex: 1; }
.add-btn { margin-top: var(--s2); }
.rows { display: flex; flex-direction: column; gap: var(--s3); }
.row-card { border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s4); background: var(--surface-2); }
.row-card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--s3); font-size: var(--text-xs); color: var(--faint); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.row-card .field:last-child { margin-bottom: 0; }
.row-card .field input, .row-card .field textarea { background: var(--surface); }
.row-card .row-card { background: var(--surface); }
.row-card .row-card .field input, .row-card .row-card .field textarea { background: var(--surface-2); }

/* read-only display */
.ro-field { margin-bottom: var(--s5); }
.ro-field .label { font-size: var(--text-xs); font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px; }
.ro-field .val { white-space: pre-wrap; }
.ro-field ul, .ro-field ol { margin: 0; padding-left: 20px; }
.ro-field .empty-val { color: var(--faint); font-style: normal; }

/* review history */
.history { margin-top: var(--s6); }
.history summary { cursor: pointer; font-weight: 600; font-size: var(--text-sm); padding: var(--s4) var(--s5); list-style: none; display: flex; justify-content: space-between; }
.history summary::-webkit-details-marker { display: none; }
.history ol { list-style: none; margin: 0; padding: 0 var(--s5) var(--s4); }
.history li { padding: 10px 0; border-top: 1px solid var(--line); font-size: var(--text-sm); }
.history li .when { color: var(--faint); font-size: var(--text-xs); }
.history blockquote { margin: 6px 0 0; padding: 8px 12px; background: var(--surface-2); border-radius: var(--radius-sm); white-space: pre-wrap; }

/* dialog */
dialog { border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 0; width: min(520px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgb(0 0 0 / 0.25); }
dialog::backdrop { background: rgb(15 20 22 / 0.45); }
dialog form { padding: var(--s6); }
dialog h2 { margin-bottom: var(--s2); }
dialog p.lede { color: var(--muted); font-size: var(--text-sm); margin-bottom: var(--s5); }
dialog .actions { display: flex; justify-content: flex-end; gap: var(--s2); margin-top: var(--s5); }

/* toast-like inline flash at top of builder */
.flash { margin-bottom: var(--s4); }

/* sign in */
.signin { max-width: 440px; margin: 10vh auto 0; padding: var(--s10) var(--s8); text-align: left; }
.signin img.logo { display: block; margin-bottom: var(--s5); }
.signin h1 { margin-bottom: var(--s2); }
.signin p { color: var(--muted); margin-bottom: var(--s6); }
.signin .btn { width: 100%; min-height: 44px; font-size: var(--text-base); }
.signin .fine { font-size: var(--text-xs); color: var(--faint); margin-top: var(--s5); margin-bottom: 0; }


/* ---------- details cards (client insurance, settings) ---------- */
.details-card { margin-top: var(--s6); }
.details-card > header { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s3); padding: var(--s4) var(--s5); border-bottom: 1px solid var(--line); }
.details-card > header .sub { color: var(--muted); font-size: var(--text-sm); margin-top: 2px; max-width: 70ch; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--s4) var(--s6); margin: 0; padding: var(--s5); }
.detail-grid > div { min-width: 0; }
.detail-grid .wide { grid-column: 1 / -1; }
.detail-grid dt { font-size: var(--text-xs); font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 2px; }
.detail-grid dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.details-form { padding: var(--s5); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 0 var(--s5); }
.form-grid .wide { grid-column: 1 / -1; }
.form-grid .field select { max-width: none; }
.form-actions { display: flex; gap: var(--s2); margin-top: var(--s2); }
.payer-view { padding: 0 var(--s5) var(--s5); }
.payer-view h3 { font-size: var(--text-sm); margin-bottom: var(--s2); }
.payer-view .detail-grid { padding: 0; }
.payer-rows { display: flex; flex-direction: column; gap: var(--s2); }
.payer-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: var(--s2); align-items: center; }
.payer-row input { width: 100%; padding: 9px 12px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); }
.settings-stack { margin-top: var(--s2); }

/* readiness dialog before PDF download */
dialog .gaps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s3); }
dialog .gaps li { padding: var(--s3) var(--s4); border-radius: var(--radius); background: var(--warn-soft); font-size: var(--text-sm); display: flex; flex-direction: column; gap: 2px; }
dialog .gaps .missing { color: var(--text); }
dialog .gaps .how { color: var(--muted); }

@media (max-width: 720px) {
  .payer-row { grid-template-columns: 1fr auto; }
  .payer-row input:nth-child(2) { grid-row: 2; }
  .details-card > header { flex-wrap: wrap; }
}

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .builder { grid-template-columns: minmax(0, 1fr); }
  .steps { position: static; max-height: none; }
  .editor { padding: var(--s5); }
  .builder-head { grid-template-columns: 1fr; }
  .head-actions { justify-content: flex-start; }
}
@media (max-width: 720px) {
  main { padding: var(--s5) var(--s4) var(--s10); }
  .topbar { padding: 10px var(--s4); gap: var(--s3); flex-wrap: wrap; }
  .brand small, .user-chip .who { display: none; }
  .clinic-chip { order: 3; width: 100%; }
  table.clients thead { display: none; }
  table.clients, table.clients tbody, table.clients tr, table.clients td { display: block; width: 100%; }
  table.clients tr { padding: 12px var(--s4); border-bottom: 1px solid var(--line); }
  table.clients td { border: 0; padding: 2px 0; }
  table.clients td.hide-sm { display: none; }
  .version-row { grid-template-columns: 48px 1fr auto; }
  .version-row .who { display: none; }
  .editor-foot { flex-direction: column-reverse; }
  .editor-foot .btn { width: 100%; }
}
main:focus { outline: none; }

/* ---------- assessment score cards */
.sc-list { display: flex; flex-direction: column; gap: var(--s4); }
.sc-empty { font-size: var(--text-sm); margin: var(--s2) 0 var(--s3); }
.sc-add { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; margin-top: var(--s4); }
.sc-add select { min-height: 36px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); padding: 4px 8px; font: inherit; font-size: var(--text-sm); max-width: 100%; }
.sc-card { border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s4); background: var(--surface-2); min-width: 0; }
.sc-head { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); margin-bottom: var(--s2); }
.sc-head h3 { font-size: var(--text-base); }
.sc-meta { display: flex; gap: var(--s3); flex-wrap: wrap; margin-bottom: var(--s3); }
.sc-meta-field { display: flex; flex-direction: column; gap: 4px; flex: 1 1 200px; min-width: 0; }
.sc-meta-field label { font-size: var(--text-xs); font-weight: 600; color: var(--muted); }
.sc-meta-field input, .sc-table input, .sc-table select, .sc-notes textarea {
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font: inherit; font-size: var(--text-sm); padding: 6px 8px; min-height: 34px; width: 100%;
}
.sc-table input:focus, .sc-table select:focus, .sc-meta-field input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
.sc-table input[aria-invalid="true"] { border-color: var(--error); background: var(--error-soft); }
.sc-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
.sc-scroll:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sc-table { border-collapse: collapse; width: 100%; font-size: var(--text-sm); font-variant-numeric: tabular-nums; }
.sc-table th, .sc-table td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: center; vertical-align: middle; }
.sc-table thead th { font-size: var(--text-xs); font-weight: 650; color: var(--muted); background: var(--surface-3); white-space: nowrap; }
.sc-table tbody th { text-align: left; font-weight: 500; min-width: 180px; }
.sc-table .sc-rowhead { text-align: left; }
.sc-table td { min-width: 76px; }
.sc-table .sc-in { max-width: 84px; text-align: center; }
.sc-table select { min-width: 140px; }
.sc-period { display: block; margin-bottom: 4px; }
.sc-table .sc-date { min-width: 132px; font-size: var(--text-xs); }
.sc-group th { background: var(--primary-soft); color: var(--text); font-size: var(--text-xs); font-weight: 650; text-transform: uppercase; letter-spacing: 0.05em; text-align: left; }
.sc-indent { padding-left: 24px !important; color: var(--muted); }
.sc-strong { font-weight: 650 !important; }
.sc-fixed, .sc-pct { color: var(--muted); }
.sc-total th, .sc-total td { font-weight: 700; border-bottom: none; background: var(--surface-3); }
.sc-label-in { min-width: 160px; }
.sc-bands { display: flex; gap: var(--s2); flex-wrap: wrap; margin-top: var(--s3); }
.sc-bands:empty { display: none; }
.sc-notes { margin: var(--s3) 0 0; }
.sc-ro-notes { margin-top: var(--s3); font-size: var(--text-sm); white-space: pre-wrap; }
@media (max-width: 640px) {
  .sc-card { padding: var(--s3); }
  .sc-table tbody th { min-width: 140px; }
}
.editor, .editor form, .sc-list, .sc-card { min-width: 0; max-width: 100%; }
.builder > * { min-width: 0; }

/* ---------- clinic standard text library */
.lib-bar { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; margin: 0 0 8px; font-size: var(--text-xs); color: var(--muted); }
.lib-bar a { color: var(--primary); }
.lib-status { color: var(--success); font-size: var(--text-xs); }
.lib-card .details-form > .notice { margin-bottom: var(--s5); }
.lib-card > .dim, .lib-card > .notice, .lib-card > .help { padding: 0 var(--s5) var(--s5); }
.lib-card > .dim { padding-top: var(--s5); }
.lib-field textarea { width: 100%; }
.lib-foot { display: flex; justify-content: space-between; gap: var(--s3); margin-top: 6px; font-size: var(--text-xs); color: var(--faint); font-variant-numeric: tabular-nums; }
.lib-ro { padding: var(--s4) var(--s5); border-bottom: 1px solid var(--line); }
.lib-ro h3 { margin-bottom: 6px; }
.lib-text { white-space: pre-wrap; font-size: var(--text-sm); }
.lib-actions { display: inline-flex; align-items: center; gap: var(--s2); }
.lib-del { color: var(--error); }

/* ----- diagnosis code search (combobox) */
.combo-wrap { position: relative; }
.combo-list { position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px); margin: 0; padding: 4px; list-style: none;
  max-height: 320px; overflow-y: auto; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14); }
.combo-list li[role='option'] { display: grid; grid-template-columns: 76px 1fr; gap: 10px; align-items: baseline; padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: var(--text-sm); }
.combo-list li[role='option']:hover, .combo-list li.active { background: var(--surface-3); }
.combo-code { font-weight: 600; font-variant-numeric: tabular-nums; }
.combo-name { color: var(--text); min-width: 0; overflow-wrap: anywhere; }
.combo-sub { display: block; color: var(--faint); font-size: var(--text-xs); margin-top: 2px; }
.combo-empty { padding: 10px; color: var(--faint); font-size: var(--text-sm); }
.combo-status { font-size: var(--text-xs); margin-top: 6px; color: var(--faint); min-height: 1em; }
.combo-status.ok { color: var(--success); }
.combo-status.bad { color: var(--error); }

/* ---------- team page ---------- */
.team-body { padding: var(--s4) var(--s5); display: grid; gap: var(--s3); }
.team-table td { vertical-align: top; }
.sec-group { display: block; width: 100%; text-align: left; background: none; border: 0; border-radius: 6px; cursor: pointer; font: inherit;
  margin-top: 6px; padding: 6px 8px 4px 34px; font-size: 12px; font-weight: 650; color: var(--primary); text-decoration: underline; text-underline-offset: 3px; }
.sec-group:hover { background: var(--surface-2); }
.sec-group:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.add-client { padding: var(--s5); margin-bottom: var(--s5); }
.add-client h2 { font-size: var(--text-lg); margin: 0 0 var(--s4); }
.add-client .notice { margin-bottom: var(--s4); }
.add-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 var(--s4); }
.add-actions { display: flex; gap: var(--s3); margin-top: var(--s2); }

/* v20: welcome pop-ups after buying */
dialog .welcome ul { margin: var(--s3) 0 0; padding-left: 1.2em; display: flex; flex-direction: column; gap: var(--s2); }
dialog .welcome .fine { color: var(--muted); font-size: var(--text-sm); }

/* v21: staff guides */
.guide-card > header { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s3); padding: var(--s4) var(--s5); border-bottom: 1px solid var(--line); }
.guide-card > header .sub { color: var(--muted); font-size: var(--text-sm); margin-top: 2px; max-width: 70ch; }
.guide-card + .guide-card { margin-top: var(--s4); }
.guide-body { padding: var(--s4) var(--s5); display: grid; gap: var(--s5); }
.guide-part h3 { font-size: var(--text-sm); text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: var(--s2); }
.guide-part ul { margin: 0; padding-left: 1.2em; display: grid; gap: 6px; }
.guide-part li { line-height: 1.5; }
.guide-card > footer { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; padding: var(--s4) var(--s5); border-top: 1px solid var(--line); }
.guide-card > footer .help { margin: 0; }
.guide-ack .badge { display: inline-flex; align-items: center; gap: 6px; }
.guide-row { border-bottom: 1px solid var(--line); }
.guide-row:last-child { border-bottom: 0; }
.guide-row-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s3); padding: 14px var(--s5) 6px; flex-wrap: wrap; }
.guide-row details { padding: 0 var(--s5) 8px; }
.guide-row details summary { cursor: pointer; font-size: var(--text-sm); color: var(--accent, var(--text)); }
.guide-row .guide-body { padding: var(--s3) 0 0; }
.guide-edit-parts { display: grid; gap: var(--s4); margin: var(--s4) 0; }
.guide-edit-part { border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s4); display: grid; gap: var(--s3); justify-items: start; }
.guide-edit-part .field { width: 100%; }
.guide-edit-part textarea { width: 100%; }
@media print {
  .topbar, .crumbs, .page-head .btn, .guide-card > header .btn, .guide-ack, .notice, .banner { display: none !important; }
  main { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 0; }
}

/* v21: invitation to another clinic */
.invite-banner { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; margin-bottom: var(--s4); }
.invite-banner .actions { display: flex; gap: var(--s2); }
.guide-readers { padding: 0 var(--s5) 14px; font-size: var(--text-sm); color: var(--muted); margin: 0; }

/* ---------- v22: locations ---------- */
.loc-filter { padding: 8px 10px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); font: inherit; font-size: var(--text-sm); }
.loc-chip { display: inline-flex; align-items: center; gap: 4px; }
.loc-card { padding: var(--s5); }
.loc-grid { margin-top: var(--s4); display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: var(--s4); }
.loc-card header { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s3); margin-bottom: var(--s3); }
.loc-card h2 { display: flex; align-items: center; gap: 6px; font-size: var(--text-md); margin: 0; }
.loc-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s2); }
.loc-stat { background: var(--surface-2); border-radius: var(--radius-sm); padding: var(--s2) var(--s3); display: flex; flex-direction: column; gap: 2px; }
.loc-stat strong { font-size: var(--text-lg); }
.loc-stat span { font-size: var(--text-xs); color: var(--muted); }
.loc-stat.warn { background: var(--warn-soft); }
.loc-stat.warn strong { color: var(--warn); }
.loc-stat.good strong { color: var(--success); }
@media (max-width: 520px) { .loc-stats { grid-template-columns: repeat(2, 1fr); } }

/* ---------- v23: parent training portal ---------- */
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.small { font-size: var(--text-sm); }
.pt-sub { font-size: var(--text-base); margin: var(--s5) 0 var(--s2); }
.pt-sub:first-child { margin-top: 0; }
.pt-people { list-style: none; margin: 0 0 var(--s3); padding: 0; display: grid; gap: var(--s2); }
.pt-people li { display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s3); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.pt-people li > div { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.pt-add { justify-self: start; }
.pt-form { display: grid; gap: var(--s3); margin-top: var(--s3); padding: var(--s4); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); }
.pt-item { border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s4); margin-bottom: var(--s3); }
.pt-item-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s3); }
.pt-item h3 { margin: 0 0 2px; font-size: var(--text-md); }
.pt-progress { margin: var(--s2) 0; padding-left: 18px; color: var(--muted); }
.pt-thread { margin-top: var(--s3); border-top: 1px solid var(--line); padding-top: var(--s2); }
.pt-thread summary { cursor: pointer; font-weight: 600; font-size: var(--text-sm); }
.pt-msgs { list-style: none; padding: 0; margin: var(--s2) 0; display: grid; gap: var(--s2); }
.pt-msgs li { padding: var(--s2) var(--s3); border-radius: var(--radius-sm); max-width: 640px; }
.pt-msgs li p { margin: 2px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.pt-msgs .from-cg { background: var(--info-soft); }
.pt-msgs .from-staff { background: var(--surface-2); margin-left: var(--s6); }
.pt-reply { display: flex; gap: var(--s2); align-items: flex-end; }
.pt-reply textarea { flex: 1; }
.pt-editor { display: grid; gap: var(--s3); }
.pt-editor h3 { margin: 0; }
.pt-lesson { border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s4); display: grid; gap: var(--s2); margin: 0 0 var(--s3); }
.pt-lesson legend { font-weight: 600; padding: 0 6px; }
.pt-family { padding: var(--s5); margin-bottom: var(--s5); }
.pt-family header h2 { margin: 0 0 4px; }
.pt-bar { height: 8px; background: var(--surface-3); border-radius: 99px; overflow: hidden; margin-top: var(--s3); }
.pt-bar span { display: block; height: 100%; background: var(--success); width: 0; transition: width .3s; }
.pt-lesson-list { display: grid; gap: var(--s2); margin-top: var(--s4); }
.pt-lesson-view { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.pt-lesson-view summary { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); cursor: pointer; font-weight: 600; list-style: none; }
.pt-lesson-view summary::-webkit-details-marker { display: none; }
.pt-check { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: var(--text-sm); background: var(--surface-2); color: var(--muted); }
.pt-check.on { background: var(--success); color: #fff; }
.pt-lesson-body { padding: 0 var(--s4) var(--s4) calc(var(--s4) + 26px + var(--s3)); }
.pt-lesson-body ol { padding-left: 20px; }
.pt-lesson-body li { margin-bottom: 4px; }
.pt-practice { background: var(--success-soft); border-radius: var(--radius-sm); padding: var(--s3); margin: var(--s3) 0; }
.pt-practice p { margin: 4px 0 0; }
.pt-ask { margin-top: var(--s5); border-top: 1px solid var(--line); padding-top: var(--s4); }
.pt-ask h3 { font-size: var(--text-base); margin: 0 0 var(--s2); }
.pt-ask textarea { width: 100%; }
.pt-child { font-size: var(--text-lg); margin: var(--s4) 0 var(--s3); }
@media (max-width: 520px) { .pt-lesson-body { padding-left: var(--s4); } .pt-reply { flex-direction: column; align-items: stretch; } .pt-msgs .from-staff { margin-left: var(--s3); } }

/* ---------- v24a: Business Associate Agreement ---------- */
.baa-banner { margin-bottom: var(--s4); align-items: center; }
.baa-banner > div { display: flex; flex-direction: column; gap: 2px; }
.baa-top { display: grid; gap: var(--s3); margin-bottom: var(--s4); }
.baa-card { padding: var(--s5) var(--s6, 28px); }
.baa-doc { max-width: 72ch; line-height: 1.6; }
.baa-doc h2 { margin: 0 0 4px; }
.baa-doc h3 { font-size: var(--text-md); margin: var(--s5) 0 var(--s2); }
.baa-doc p, .baa-doc li { font-size: var(--text-sm); }
.baa-doc ol { padding-left: 22px; display: grid; gap: 6px; }
.baa-sign { margin-top: var(--s4); padding: var(--s5); display: grid; gap: var(--s3); }
.baa-sign h2 { margin: 0; }
.baa-agree { align-items: flex-start; font-weight: 400; max-width: 72ch; }
.baa-agree input { margin-top: 3px; }
@media (max-width: 640px) { .baa-card { padding: var(--s4); } }
@media print { .baa-sign, .baa-banner, .page-head .btn { display: none !important; } .baa-card { padding: 0; } }
.baa-doc p { margin: 0 0 10px; }

/* v24c: the logo is navy and royal blue; in dark mode it sits on a small pearl-white tile. */
@media (prefers-color-scheme: dark) {
  img.logo { background: #f8f6f0; border-radius: 8px; padding: 3px; box-sizing: content-box; }
}
