:root {
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.8125rem);
  --text-sm: clamp(0.875rem, 0.82rem + 0.2vw, 0.9375rem);
  --text-base: clamp(1rem, 0.96rem + 0.15vw, 1.0625rem);
  --text-lg: clamp(1.125rem, 1rem + 0.5vw, 1.375rem);
  --text-xl: clamp(1.5rem, 1.25rem + 1vw, 2rem);
  --space-1: .25rem; --space-2: .5rem; --space-3: .75rem; --space-4: 1rem; --space-5: 1.25rem;
  --space-6: 1.5rem; --space-8: 2rem; --space-10: 2.5rem; --space-12: 3rem; --space-16: 4rem;

  --bg: #f4f3ee;
  --surface: #fbfaf7;
  --surface-2: #ffffff;
  --surface-offset: #eceae3;
  --border: #d9d6cc;
  --divider: #e4e1d8;
  --ink: #1d2430;
  --ink-muted: #5c6370;
  --ink-faint: #9aa0a8;
  --primary: #1f4e79;
  --primary-hover: #173d60;
  --primary-tint: #dfe8f1;
  --meets: #2e7d4f;
  --meets-tint: #e1f0e6;
  --meets-box: rgba(46, 125, 79, 0.12);
  --below: #b5452b;
  --below-tint: #f6e3dd;
  --interim: #8a6a12;
  --interim-tint: #f4ecd6;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(29, 36, 48, .06), 0 2px 8px rgba(29, 36, 48, .05);
  --font-display: 'Zodiak', 'Georgia', serif;
  --font-body: 'General Sans', 'Segoe UI', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: var(--text-base); line-height: 1.5; font-variant-numeric: tabular-nums; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
p { margin: 0 0 var(--space-3); max-width: 75ch; }
a { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }

/* Header */
.app-header { background: var(--ink); color: #f4f3ee; }
.app-header .inner { max-width: 1320px; margin: 0 auto; padding: var(--space-4) var(--space-6); display: flex; align-items: center; gap: var(--space-6); flex-wrap: wrap; }
.brand { display: flex; flex-direction: column; }
.brand .title { font-family: var(--font-display); font-size: var(--text-lg); font-weight: 700; letter-spacing: .01em; }
.brand .sub { font-size: var(--text-xs); color: #b9bfc8; }
.std-pill { margin-left: auto; display: flex; align-items: center; gap: var(--space-3); background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.18); border-radius: 999px; padding: var(--space-2) var(--space-4); font-size: var(--text-sm); cursor: pointer; color: inherit; }
.std-pill:hover { background: rgba(255,255,255,.14); }
.std-pill b { white-space: nowrap;  font-size: var(--text-base); }
.std-pill .dot { width: 10px; height: 10px; border-radius: 2px; background: #7fc59a; }

nav.tabs { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
nav.tabs .inner { max-width: 1320px; margin: 0 auto; padding: 0 var(--space-6); display: flex; gap: var(--space-1); overflow-x: auto; scrollbar-width: none; }
nav.tabs button { border: 0; background: none; padding: var(--space-4) var(--space-4); font-size: var(--text-sm); font-weight: 500; color: var(--ink-muted); border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap; }
nav.tabs button:hover { color: var(--ink); }
nav.tabs button[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

main { max-width: 1320px; margin: 0 auto; padding: var(--space-8) var(--space-6) var(--space-16); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-6); }
.page-head h1 { font-family: var(--font-display); font-size: var(--text-xl); font-weight: 700; }
.page-head p { color: var(--ink-muted); margin: var(--space-2) 0 0; }

.card { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-6); box-shadow: var(--shadow); }
.card + .card { margin-top: var(--space-6); }
.grid > .card + .card { margin-top: 0; }
.grid + .card, .grid + .grid, .card + .grid { margin-top: var(--space-6); }
.card h2 { font-size: var(--text-lg); font-weight: 600; margin-bottom: var(--space-3); }
.card h3 { font-size: var(--text-base); font-weight: 600; margin-bottom: var(--space-2); }
.muted { color: var(--ink-muted); }
.small { font-size: var(--text-sm); }
.xs { font-size: var(--text-xs); }
.grid { display: grid; gap: var(--space-4); }
.grid.c2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid.c3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.c4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.stack > * + * { margin-top: var(--space-4); }
.row { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.divider { height: 1px; background: var(--divider); margin: var(--space-6) 0; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: var(--space-2); border: 1px solid var(--border); background: var(--surface-2); padding: var(--space-2) var(--space-4); border-radius: var(--radius-sm); font-size: var(--text-sm); font-weight: 500; cursor: pointer; transition: background .15s, border-color .15s; text-decoration: none; color: var(--ink); min-height: 38px; }
.btn:hover { background: var(--surface-offset); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--below); }
.btn.sm { padding: var(--space-1) var(--space-3); min-height: 30px; font-size: var(--text-xs); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }

/* Forms */
label.field { display: flex; flex-direction: column; gap: var(--space-1); font-size: var(--text-sm); font-weight: 500; }
label.field span.hint { font-weight: 400; color: var(--ink-muted); font-size: var(--text-xs); }
input[type=text], input[type=number], input[type=date], select, textarea { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); padding: var(--space-2) var(--space-3); min-height: 38px; font-size: var(--text-sm); width: 100%; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
input.num { width: 76px; text-align: right; }
input.invalid { border-color: var(--below); background: var(--below-tint); }
.check { display: flex; gap: var(--space-2); align-items: flex-start; font-size: var(--text-sm); }
.check input { margin-top: 4px; }

/* Option cards */
.options { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.opt { position: relative; text-align: left; border: 1.5px solid var(--border); border-radius: var(--radius); background: var(--surface-2); padding: var(--space-5); cursor: pointer; display: flex; flex-direction: column; gap: var(--space-2); transition: border-color .15s, box-shadow .15s; }
.opt:hover { border-color: var(--ink-faint); }
.opt[aria-pressed="true"] { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-tint); }
.opt .opt-k { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .08em; color: var(--ink-muted); font-weight: 600; }
.opt .opt-t { font-weight: 600; font-size: var(--text-base); }
.opt .opt-v { font-family: var(--font-display); font-size: var(--text-xl); font-weight: 700; color: var(--primary); line-height: 1; }
.opt .opt-v small { font-family: var(--font-body); font-size: var(--text-sm); color: var(--ink-muted); font-weight: 500; }
.opt .opt-d { font-size: var(--text-sm); color: var(--ink-muted); }
.opt .tag { align-self: flex-start; font-size: var(--text-xs); padding: 2px var(--space-2); border-radius: 6px; line-height: 1.45; background: var(--surface-offset); color: var(--ink-muted); font-weight: 600; }
.opt .tag.rec { background: var(--meets-tint); color: var(--meets); }

/* Callouts */
.note { border-left: 3px solid var(--primary); background: var(--primary-tint); padding: var(--space-3) var(--space-4); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; font-size: var(--text-sm); }
.note.warn { border-color: var(--interim); background: var(--interim-tint); }
.note.bad { border-color: var(--below); background: var(--below-tint); }
.note.good { border-color: var(--meets); background: var(--meets-tint); }
.note p:last-child { margin-bottom: 0; }

/* KPIs */
.kpis { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: var(--space-6); }
.kpi { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-4) var(--space-5); }
.kpi .k { font-size: var(--text-xs); color: var(--ink-muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.kpi .v { font-family: var(--font-display); font-size: var(--text-xl); font-weight: 700; margin-top: var(--space-1); }
.kpi.meets .v { color: var(--meets); }
.kpi.below .v { color: var(--below); }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
table { border-collapse: collapse; width: 100%; font-size: var(--text-sm); }
th, td { padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--divider); text-align: left; vertical-align: middle; }
th { background: var(--surface-offset); font-weight: 600; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .04em; color: var(--ink-muted); white-space: nowrap; }
td.n, th.n { text-align: right; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #faf9f5; }
.badge { display: inline-block; font-size: var(--text-xs); font-weight: 600; padding: 2px var(--space-2); border-radius: 4px; white-space: nowrap; }
.badge.meets { background: var(--meets-tint); color: var(--meets); }
.badge.below { background: var(--below-tint); color: var(--below); }
.badge.interim { background: var(--interim-tint); color: var(--interim); }
.badge.neutral { background: var(--surface-offset); color: var(--ink-muted); }
.badge.neutral { white-space: normal; max-width: 100%; }

/* Chart */
.chart-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-4); }
.chart-box svg { width: 100%; height: auto; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: var(--space-4); font-size: var(--text-xs); color: var(--ink-muted); margin-top: var(--space-3); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 2px; margin-right: var(--space-1); vertical-align: -2px; }
.legend i.dot { border-radius: 50%; }
.tooltip { position: fixed; pointer-events: none; background: var(--ink); color: #fff; font-size: var(--text-xs); padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); z-index: 50; max-width: 260px; box-shadow: var(--shadow); }

/* Decision */
.decision { border-radius: var(--radius); padding: var(--space-4) var(--space-5); border: 1px solid; }
.decision .dt { font-weight: 700; font-size: var(--text-base); }
.decision.meets { background: var(--meets-tint); border-color: #b5d9c2; color: #1f5a37; }
.decision.below { background: var(--below-tint); border-color: #e7bfb3; color: #7f2e1b; }
.decision.neutral { background: var(--surface-offset); border-color: var(--border); }
.decision.info { background: var(--primary-tint); border-color: #b9cde0; color: #173d60; }
.decision ul { margin: var(--space-2) 0 0; padding-left: var(--space-5); font-size: var(--text-sm); }

.list-item { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) 0; border-bottom: 1px solid var(--divider); flex-wrap: wrap; }
.list-item:last-child { border-bottom: 0; }
.list-item .li-main { flex: 1; min-width: 200px; }
.list-item .li-main b { display: block; }

.empty { text-align: center; padding: var(--space-10) var(--space-6); color: var(--ink-muted); border: 1.5px dashed var(--border); border-radius: var(--radius); }
.empty p { max-width: none; margin: 0 auto; }
.empty h3 { color: var(--ink); margin-bottom: var(--space-2); }

.steps { counter-reset: s; list-style: none; padding: 0; margin: 0; display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.steps li { counter-increment: s; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-5); }
.steps li::before { content: counter(s); display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: #fff; font-weight: 700; font-size: var(--text-sm); margin-bottom: var(--space-2); }
.steps li b { display: block; margin-bottom: var(--space-1); }
.steps li span { font-size: var(--text-sm); color: var(--ink-muted); }

.toast { position: fixed; bottom: var(--space-6); left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: var(--space-3) var(--space-5); border-radius: var(--radius-sm); font-size: var(--text-sm); z-index: 60; box-shadow: var(--shadow); }

.modal-back { position: fixed; inset: 0; background: rgba(29,36,48,.45); z-index: 70; display: grid; place-items: center; padding: var(--space-4); }
.modal { background: var(--surface-2); border-radius: var(--radius); max-width: 520px; width: 100%; padding: var(--space-6); box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal h3 { font-size: var(--text-lg); margin-bottom: var(--space-3); }

footer.app-foot { max-width: 1320px; margin: 0 auto; padding: var(--space-6); font-size: var(--text-xs); color: var(--ink-muted); border-top: 1px solid var(--border); }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.seg button { border: 0; background: var(--surface-2); padding: var(--space-2) var(--space-3); font-size: var(--text-sm); cursor: pointer; border-right: 1px solid var(--border); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--primary); color: #fff; }

@media (max-width: 640px) {
  main { padding: var(--space-6) var(--space-4) var(--space-12); }
  .app-header .inner, nav.tabs .inner { padding-left: var(--space-4); padding-right: var(--space-4); }
  .std-pill { margin-left: 0; width: 100%; justify-content: center; }
  .card { padding: var(--space-4); }
  .kpis, .grid.c4 { grid-template-columns: 1fr 1fr; gap: var(--space-3); }
  .kpi { padding: var(--space-3); }
  .std-pill { flex-wrap: wrap; gap: var(--space-1) var(--space-3); }
  .std-pill b { white-space: nowrap; }
}
@media print {
  .app-header, nav.tabs, .no-print, footer.app-foot { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: 0; padding: 0; }
}
.modal.wide { max-width: 680px; max-height: calc(100vh - 32px); overflow: auto; }
.modal.wide td, .modal.wide th { padding: var(--space-2) var(--space-3); }
.modal input[type="radio"] { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }
.linkish { background: none; border: 0; padding: 0; color: var(--primary); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; font: inherit; text-align: left; }
.linkish.muted { color: var(--ink-muted); }
@media print { .linkish { text-decoration: none; color: inherit; } }
@media (max-width: 520px) {
  .modal.wide th, .modal.wide td { padding: var(--space-2); }
  .modal.wide thead th { white-space: normal; font-size: 11px; }
}
td .badge { white-space: normal; min-width: 12.5em; }

.mtss-group { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2) var(--space-3); margin: 0 0 var(--space-3); padding-bottom: var(--space-3); border-bottom: 1px solid currentColor; border-bottom-color: rgba(0,0,0,.12); }
.mtss-group .mg-k { font-size: var(--text-xs); font-weight: 600; letter-spacing: .08em; text-transform: uppercase; opacity: .8; }
.mtss-group .mg-pill { font-size: var(--text-sm); font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: #fff; padding: 3px 12px; border-radius: 999px; }
.mtss-group.treatment .mg-pill { background: #b5452b; }
.mtss-group.supports .mg-pill { background: #2e7d4f; }
.mtss-group .mg-d { font-size: var(--text-xs); flex-basis: 100%; }

/* License gate (shared license.js markup) */
body.gated .app-header, body.gated .tabs, body.gated main, body.gated .app-foot { display: none !important; }
#gate { padding: 56px 20px 72px; font-family: var(--font-body); color: var(--ink); }
#gate .auth.gate { max-width: 640px; margin: 0 auto; }
#gate .brand { display: block; font-family: var(--font-display); font-size: var(--text-lg); font-weight: 700; color: var(--primary); }
#gate .brand small { display: block; font-family: var(--font-body); font-size: var(--text-xs); font-weight: 400; color: var(--ink-faint); margin-top: 2px; }
#gate .card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 28px; box-shadow: var(--shadow); }
#gate h1 { font-family: var(--font-display); font-size: var(--text-xl); line-height: 1.25; margin: 0 0 8px; }
#gate .muted { color: var(--ink-muted); }
#gate .small { font-size: var(--text-xs); }
#gate form { display: flex; flex-direction: column; gap: 12px; }
#gate .field { display: flex; flex-direction: column; gap: 4px; }
#gate .field label { font-size: var(--text-xs); font-weight: 600; color: var(--ink-muted); text-transform: uppercase; letter-spacing: .04em; }
#gate .field input { font: inherit; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 15px; background: #fff; }
#gate #gateBtn { align-self: flex-start; background: var(--primary); border: 1px solid var(--primary); color: #fff; padding: 10px 22px; font-weight: 600; border-radius: var(--radius-sm); cursor: pointer; font-family: inherit; font-size: var(--text-sm); }
#gate #gateBtn:hover { background: var(--primary-hover); }
#gate .btn.link { background: none; border: 0; padding: 0; color: var(--primary); text-decoration: underline; cursor: pointer; font: inherit; }
#gate .alert { border-radius: 6px; padding: 12px 14px; font-size: var(--text-sm); margin: 12px 0; border: 1px solid transparent; }
#gate .alert.ok { background: var(--meets-tint); color: var(--meets); border-color: #c4dcc7; }
#gate .alert.err { background: var(--below-tint); color: var(--below); border-color: #e7c3bb; }
#gate .alert.warn { background: var(--interim-tint); color: #5c4600; border-color: #ead7a8; }
#gate .alert.info { background: var(--primary-tint); color: var(--primary); border-color: #c4d4e4; }
.gate-tiers { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 20px; }
.tier { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; background: var(--surface-offset); color: inherit; text-decoration: none; display: flex; flex-direction: column; gap: 4px; }
.tier-link:hover { border-color: var(--primary); background: var(--primary-tint); }
.tier-name { font-weight: 700; font-size: var(--text-sm); line-height: 1.25; }
.tier-price { font-size: var(--text-xl); font-weight: 700; color: var(--primary); }
.tier-who { font-size: var(--text-xs); color: var(--ink-muted); }
.tier-buy { font-size: var(--text-xs); font-weight: 700; color: var(--primary); margin-top: auto; padding-top: 6px; }
.gate-foot { margin-top: 16px; font-size: var(--text-sm); color: var(--ink-faint); }
.gate-foot a { color: var(--primary); }
.lic-dialog { border: 1px solid var(--border); border-radius: 10px; padding: 22px; max-width: 520px; width: calc(100% - 32px); font-family: var(--font-body); color: var(--ink); }
.lic-dialog::backdrop { background: rgba(20, 25, 35, .4); }
.lic-dialog h2 { font-family: var(--font-display); }
.lic-dialog .muted { color: var(--ink-muted); } .lic-dialog .small { font-size: var(--text-xs); }
.lic-dialog .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.lic-dialog .btn { font: inherit; font-size: var(--text-sm); padding: 8px 16px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); cursor: pointer; }
.lic-dialog .btn:not(.secondary) { background: var(--primary); border-color: var(--primary); color: #fff; }
.lic-list { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; margin: 0 0 12px; font-size: var(--text-sm); }
.lic-list dt { color: var(--ink-faint); } .lic-list dd { margin: 0; }
.app-header .lic-btn { background: transparent; color: #f4f3ee; border: 1px solid rgba(255,255,255,.3); border-radius: 999px; padding: 6px 16px; font: inherit; font-size: var(--text-sm); cursor: pointer; }
.app-header .lic-btn:hover { background: rgba(255,255,255,.12); }
@media (max-width: 640px) { .gate-tiers { grid-template-columns: 1fr; } #gate { padding-top: 28px; } }
@media print { #gate { display: none; } }
