/* PT Portal — no external CSS frameworks (strict CSP, works offline on the clinic LAN) */
:root {
  --brand: #01578c; --brand-dark: #013f66; --brand-soft: #e4eef6;
  --ink: #1d2a2a; --muted: #607070; --line: #d7e0e0; --bg: #f4f7fa; --card: #fff;
  --ok: #1f7a3d; --ok-bg: #e2f4e8; --warn: #8a5a00; --warn-bg: #fff3d6;
  --bad: #b3261e; --bad-bg: #fde7e5; --info: #1d5f9e; --info-bg: #e3eefa;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--brand); }
h1 { font-size: 1.55rem; margin: .2rem 0 .6rem; }
h2 { font-size: 1.12rem; margin: 0 0 .6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
code { background: #eef3f3; padding: 0 .3em; border-radius: 4px; }
.break { word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.pre { white-space: pre-line; }
.warn-text { color: var(--warn); } .bad-text { color: var(--bad); }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar { background: var(--brand); color: #fff; display: flex; align-items: center; gap: 1rem; padding: .5rem 1rem; flex-wrap: wrap; position: sticky; top: 0; z-index: 10; }
.brand { color: #fff; text-decoration: none; font-weight: 700; display: flex; gap: .5rem; align-items: center; }
.mainnav { display: flex; align-items: center; gap: .2rem; flex: 1; flex-wrap: wrap; }
.mainnav a { color: #e9f6f6; text-decoration: none; padding: .35rem .6rem; border-radius: 6px; }
.mainnav a:hover { background: rgba(255,255,255,.14); color: #fff; }
.nav-spacer { flex: 1; }
.whoami { font-size: .85rem; opacity: .92; margin-right: .4rem; }
.whoami small { opacity: .8; display: block; line-height: 1; }
.nav-toggle { display: none; background: none; border: 0; color: #fff; font-size: 1.4rem; margin-left: auto; }
@media (max-width: 860px) {
  .nav-toggle { display: block; }
  .mainnav { display: none; width: 100%; flex-direction: column; align-items: stretch; }
  .mainnav.open { display: flex; }
  .nav-spacer { display: none; }
}

/* ---------- layout ---------- */
.container { max-width: 1180px; margin: 0 auto; padding: 1rem; }
.container.narrow { max-width: 460px; padding-top: 3rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: .6rem; }
.page-head p { margin: 0; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin: .3rem 0; }
.grid.two { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 860px) { .grid.two { grid-template-columns: 1fr; } }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.auth-card h1 { margin-top: 0; }
.inline { display: inline; }

/* ---------- buttons ---------- */
.btn { display: inline-block; background: var(--brand); color: #fff; border: 1px solid var(--brand); padding: .5rem .95rem; border-radius: 8px; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; line-height: 1.2; }
.btn:hover { background: var(--brand-dark); }
.btn.ghost { background: #fff; color: var(--brand); }
.btn.ghost:hover { background: var(--brand-soft); }
.btn.ghost-light { background: transparent; color: #fff; border-color: rgba(255,255,255,.6); }
.btn.danger { color: var(--bad); border-color: #e3b3ae; }
.btn.small { padding: .28rem .6rem; font-size: .85rem; }
.btn.big { padding: .85rem 1.4rem; font-size: 1.08rem; }
.btn.block { display: block; width: 100%; text-align: center; }

/* ---------- forms ---------- */
label { display: block; margin-bottom: .7rem; font-weight: 600; font-size: .9rem; }
input, select, textarea { display: block; width: 100%; margin-top: .25rem; padding: .5rem .6rem; border: 1px solid #b8c7c7; border-radius: 7px; font: inherit; font-weight: 400; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: var(--brand); }
input[type=checkbox], input[type=radio] { display: inline-block; width: auto; margin: 0 .35rem 0 0; vertical-align: middle; }
label.check { font-weight: 400; display: flex; align-items: center; gap: .2rem; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: .8rem; margin: 0 0 1rem; }
legend { font-weight: 700; padding: 0 .3rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0 1rem; }
.form-grid fieldset { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 0 1rem; }
.form-grid .wide, .dosage-grid .wide { grid-column: 1 / -1; }
.form-actions { grid-column: 1 / -1; display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .4rem; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; margin-bottom: 1rem; }
.filters input, .filters select { width: auto; min-width: 150px; margin: 0; }
.filters label { margin: 0; display: flex; align-items: center; gap: .3rem; }
.filters label input { width: auto; }
input.short { width: 90px !important; min-width: 0 !important; display: inline-block; }
.checks { display: flex; flex-wrap: wrap; gap: .2rem 1rem; }
.dosage-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 0 .6rem; }
.carrier-row { display: grid; grid-template-columns: 1.2fr 1.4fr auto 2fr auto; gap: .5rem; align-items: center; margin-bottom: .4rem; }
.carrier-row input { margin: 0; }
.carrier-row label { margin: 0; }
@media (max-width: 760px) { .carrier-row { grid-template-columns: 1fr 1fr; } }

/* ---------- flash, badges ---------- */
.flash { padding: .65rem .9rem; border-radius: 8px; margin-bottom: .8rem; border: 1px solid; }
.flash.success { background: var(--ok-bg); border-color: #b5dfc3; color: var(--ok); }
.flash.error { background: var(--bad-bg); border-color: #f1bdb8; color: var(--bad); }
.flash.warning { background: var(--warn-bg); border-color: #f0d79a; color: var(--warn); }
.flash.info { background: var(--info-bg); border-color: #bcd5ef; color: var(--info); }
.flash.big { font-size: 1.05rem; }
.block-link { display: block; text-decoration: none; }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: .1rem .45rem; border-radius: 99px; background: #eaefef; color: #4b5b5b; vertical-align: middle; letter-spacing: .02em; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--info-bg); color: var(--info); }

/* ---------- tables, lists ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .5rem .55rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.table.small td { font-size: .82rem; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; justify-content: space-between; gap: .8rem; align-items: flex-start; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.list.compact > li { padding: .3rem 0; display: block; }
.list .resolved { opacity: .6; }
.note { white-space: pre-line; margin-top: .2rem; }
.dl { display: grid; grid-template-columns: 130px 1fr; gap: .35rem .8rem; margin: 0; }
.dl dt { color: var(--muted); font-size: .85rem; }
.dl dd { margin: 0; }
.precaution { color: var(--bad); font-weight: 600; }
.stats { display: flex; gap: 1.5rem; flex-wrap: wrap; margin: .4rem 0 .8rem; }
.stats > div { display: flex; flex-direction: column; }
.stat { font-size: 1.6rem; font-weight: 700; color: var(--brand); }

/* ---------- adherence ---------- */
.meter { display: inline-flex; align-items: center; gap: .4rem; font-weight: 700; }
.meter meter { width: 90px; height: 12px; }
.strip { display: flex; gap: 3px; flex-wrap: wrap; margin: .4rem 0; }
.strip .cell { width: 14px; height: 14px; border-radius: 3px; background: #e3e8e8; }
.strip .cell.part { background: #9fd0b0; }
.strip .cell.full { background: var(--ok); }
.pain-chip { display: inline-block; min-width: 1.7em; text-align: center; border-radius: 6px; font-weight: 700; color: #fff; padding: 0 .3em; }
.p0,.p1,.p2 { --pc: #2e8b57; } .p3,.p4 { --pc: #7fae2e; } .p5,.p6 { --pc: #d39b00; } .p7,.p8 { --pc: #e0661b; } .p9,.p10 { --pc: #c62828; }
.pain-chip { background: var(--pc); }

/* ---------- chart ---------- */
.chart { width: 100%; height: auto; max-height: 240px; }
.chart .grid { stroke: #e5ecec; stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke: var(--brand); stroke-width: 2.5; stroke-linejoin: round; }
.chart .dot { fill: #fff; stroke: var(--brand); stroke-width: 2; }
.chart .dot.hi { stroke: var(--bad); fill: var(--bad-bg); }

/* ---------- exercise library ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.ex-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; text-decoration: none; color: inherit; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.ex-card:hover { border-color: var(--brand); }
.ex-card img, .thumb-ph { width: 100%; aspect-ratio: 16/9; object-fit: cover; background: var(--brand-soft); display: flex; align-items: center; justify-content: center; color: var(--brand); font-weight: 700; }
.ex-body { padding: .6rem .75rem; display: flex; flex-direction: column; gap: .25rem; }
.exvideo { width: 100%; max-height: 70vh; background: #000; border-radius: 8px; }
.video-placeholder { aspect-ratio: 16/9; background: var(--brand-soft); border-radius: 8px; display: flex; align-items: center; justify-content: center; color: var(--muted); }

/* ---------- plan builder ---------- */
.builder { display: grid; grid-template-columns: 1fr 380px; gap: 1rem; align-items: start; }
@media (max-width: 1000px) { .builder { grid-template-columns: 1fr; } }
.builder-search { position: sticky; top: 4rem; max-height: calc(100vh - 5rem); overflow: auto; }
.builder-search .filters input, .builder-search .filters select { min-width: 0; width: 100%; }
.phase-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem; flex-wrap: wrap; }
.phase-edit summary { list-style: none; }
.phase-edit summary::-webkit-details-marker { display: none; }
.pe-list { list-style: none; margin: 0; padding: 0; }
.pe { display: flex; justify-content: space-between; gap: .8rem; padding: .65rem 0; border-top: 1px solid var(--line); }
.pe.inactive { opacity: .5; }
.pe-actions { display: flex; gap: .3rem; align-items: flex-start; flex-wrap: wrap; justify-content: flex-end; }
.cue { background: var(--brand-soft); border-left: 3px solid var(--brand); padding: .35rem .6rem; border-radius: 4px; margin: .35rem 0; font-size: .92rem; }
.cue p { margin: 0; }
.cue.big { font-size: 1.05rem; }
.add-ex { border-bottom: 1px solid var(--line); padding: .45rem 0; }
.add-ex summary { cursor: pointer; }
.add-ex form { margin-top: .5rem; }
.rich p { margin: .3rem 0; }
.msg-preview { background: #f1f5f5; border-radius: 8px; padding: .8rem; margin: 0 0 .5rem; border-left: 3px solid var(--brand); }
.checklist { margin: .4rem 0 1rem; }

/* ---------- floor mode (tablet) ---------- */
body.floor { font-size: 17px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .8rem; }
.tile { background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 1rem; text-decoration: none; color: inherit; display: flex; flex-direction: column; gap: .2rem; min-height: 110px; }
.tile:hover, .tile:focus { border-color: var(--brand); }
.floor-card.done { border-color: #b5dfc3; }
.floor-card.current-phase { border-left: 5px solid var(--brand); }
.floor-check { display: flex; gap: .9rem; align-items: flex-start; cursor: pointer; font-weight: 400; margin: 0; }
.floor-check input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.big-check { flex: 0 0 44px; height: 44px; border: 3px solid var(--brand); border-radius: 10px; display: flex; align-items: center; justify-content: center; }
.floor-check input:checked + .big-check { background: var(--brand); }
.floor-check input:checked + .big-check::after { content: "✓"; color: #fff; font-size: 1.7rem; font-weight: 700; }
.floor-check input:focus-visible + .big-check { outline: 3px solid #f0b400; }
.rx { display: block; color: var(--brand-dark); font-weight: 600; }
.rx.big { font-size: 1.1rem; }
.floor-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0 .7rem; margin-top: .8rem; }
.floor-fields .wide { grid-column: 1 / -1; }
.sticky-actions { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 35%); padding: 1rem 0; text-align: right; }

/* ---------- patient portal ---------- */
body.portal .container { max-width: 760px; }
.week { display: flex; gap: .4rem; margin: .5rem 0; }
.week .day { flex: 1; text-align: center; padding: .35rem 0; border-radius: 8px; background: #eef2f2; font-weight: 700; display: flex; flex-direction: column; }
.week .day small { font-weight: 400; font-size: .72rem; color: var(--muted); }
.week .day.yes { background: var(--ok-bg); color: var(--ok); }
.week .day.today { outline: 2px solid var(--brand); }
.portal-list { display: flex; flex-direction: column; gap: .6rem; margin-bottom: 1rem; }
.portal-ex { display: flex; gap: .8rem; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: .6rem; text-decoration: none; color: inherit; box-shadow: var(--shadow); }
.portal-ex img, .portal-ex .thumb-ph { width: 96px; flex: 0 0 96px; aspect-ratio: 16/10; object-fit: cover; border-radius: 8px; }
.portal-ex .body { flex: 1; display: flex; flex-direction: column; }
.portal-ex .count { font-weight: 700; font-size: 1.1rem; color: var(--muted); padding: 0 .4rem; }
.portal-ex.complete { border-color: #b5dfc3; background: #f6fcf8; }
.portal-ex.complete .count { color: var(--ok); }
.pain-picker { display: grid; grid-template-columns: repeat(11, 1fr); gap: 4px; }
.pain-picker label, .seg label { margin: 0; }
.pain-picker input, .seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.pain-picker span { display: block; text-align: center; padding: .6rem 0; border-radius: 8px; border: 2px solid var(--pc); color: var(--pc); font-weight: 700; cursor: pointer; }
.pain-picker input:checked + span { background: var(--pc); color: #fff; }
.pain-picker input:focus-visible + span, .seg input:focus-visible + span { outline: 3px solid #f0b400; }
.pain-legend { display: flex; justify-content: space-between; font-size: .75rem; color: var(--muted); margin-top: .2rem; }
.seg { display: flex; gap: .4rem; }
.seg.wrap { flex-wrap: wrap; }
.seg label { flex: 1; min-width: 110px; }
.seg span { display: block; text-align: center; padding: .6rem .4rem; border: 2px solid var(--brand); border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--brand); font-size: .9rem; }
.seg input:checked + span { background: var(--brand); color: #fff; }
.questionnaire .q legend { font-weight: 600; }

/* ---------- idle warning ---------- */
.idle-warning { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 100; }
.idle-warning .card { max-width: 360px; text-align: center; }

@media print { .topbar, .actions, .filters, .btn { display: none !important; } .card { box-shadow: none; } }

/* ---------- intake, forms & records ---------- */
.req { color: var(--bad); margin-left: .15rem; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.intake-wrap { max-width: 860px; margin: 0 auto; }
.stepper { display: flex; flex-wrap: wrap; gap: .3rem; list-style: none; padding: 0; margin: 0 0 .4rem; counter-reset: step; }
.stepper li { counter-increment: step; flex: 1 1 120px; font-size: .82rem; }
.stepper li > * { display: block; padding: .45rem .5rem; border-radius: 8px; background: #fff; border: 1px solid var(--line); color: var(--muted); text-decoration: none; }
.stepper li > *::before { content: counter(step) ". "; font-weight: 700; }
.stepper li.done > * { border-color: var(--ok); color: var(--ok); background: var(--ok-bg); }
.stepper li.current > * { border-color: var(--brand); color: #fff; background: var(--brand); }
.intake-exit { margin: 0 0 .8rem; }
.fields { margin-bottom: .4rem; }
.fields .field-heading { grid-column: 1 / -1; margin: .9rem 0 .3rem; padding-top: .6rem; border-top: 1px solid var(--line); color: var(--brand-dark); }
.fields fieldset.field { grid-column: auto; display: block; }
.fields fieldset.field.wide { grid-column: 1 / -1; }
.fields .seg label { min-width: 90px; flex: 0 1 auto; }
label.agree { align-items: flex-start; background: var(--brand-soft); border-radius: 8px; padding: .6rem .7rem; margin: .6rem 0; font-weight: 600; }
label.agree input { margin-top: .25rem; }
.doc-box { max-height: 340px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; padding: .4rem 1rem .8rem; background: #fbfdfd; font-size: .92rem; }
.doc-box:focus { outline: 2px solid var(--brand); }
.doc-title { position: sticky; top: -.4rem; background: #fbfdfd; padding: .5rem 0 .3rem; margin: 0; }
.doc-section { margin: 1rem 0 1.4rem; }
.signature { border-top: 2px solid var(--brand); margin-top: 1rem; padding-top: .6rem; }
.review-section { border-bottom: 1px solid var(--line); padding-bottom: .4rem; margin-bottom: .8rem; }
.review-section h2 a { font-weight: 400; margin-left: .4rem; }
.dl.summary dt.sum-head { grid-column: 1 / -1; color: var(--brand-dark); font-weight: 700; margin-top: .4rem; }
.dl.summary dd.sum-head { display: none; }
.tabs { display: flex; flex-wrap: wrap; gap: .2rem; border-bottom: 2px solid var(--line); margin: 0 0 1rem; }
.tabs a { padding: .45rem .8rem; text-decoration: none; border-radius: 8px 8px 0 0; color: var(--muted); font-weight: 600; margin-bottom: -2px; border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); }
.tabs a:hover { background: var(--brand-soft); }
.count-pill { display: inline-block; min-width: 1.3em; padding: 0 .35em; border-radius: 99px; background: #f0b400; color: #1d2a2a; font-size: .75rem; font-weight: 700; text-align: center; line-height: 1.45; }
.count-pill.warn { background: var(--warn-bg); color: var(--warn); }
.card.accent { border-left: 4px solid var(--brand); }
.stack { display: flex; flex-direction: column; gap: .3rem; min-width: 220px; }
.stack textarea, .stack select { margin: 0; }
.sig-record { border-top: 2px solid var(--brand); margin-top: 1rem; padding-top: .5rem; }
textarea.mono { font-family: ui-monospace, Consolas, monospace; font-size: .82rem; }
.clinic-logo { display: block; max-width: 220px; height: auto; margin: 0 0 .6rem; }
.clinic-footer { text-align: center; font-size: .82rem; color: var(--muted); margin: 1rem 0; line-height: 1.6; }
.clinic-lockup { display: flex; align-items: center; gap: .6rem; margin: 0 0 .8rem; color: #0d2a85; }
.clinic-lockup img { width: 64px; height: auto; }
.clinic-lockup span { display: flex; flex-direction: column; line-height: 1.05; }
.clinic-lockup strong { font-size: 1.55rem; letter-spacing: .04em; font-weight: 600; }
.clinic-lockup small { font-size: .78rem; letter-spacing: .12em; }
.role-switch { margin: 0 .4rem 0 0; }
.role-switch label { margin: 0; color: #1d2a2a; font-size: .8rem; font-weight: 700; display: flex; align-items: center; gap: .35rem; }
.role-switch select { margin: 0; width: auto; padding: .2rem .4rem; font-size: .85rem; border-color: #f0b400; }
.test-banner { background: #f0b400; color: #1d2a2a; font-size: .8rem; font-weight: 700; padding: .3rem 1rem; letter-spacing: .03em; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: .3rem 1.2rem; }
.type-pick { margin: 1rem 0; }
.type-option { display: flex; gap: .6rem; align-items: flex-start; border: 1px solid var(--line); border-radius: 8px; padding: .55rem .7rem; margin: 0 0 .4rem; font-weight: 400; cursor: pointer; }
.type-option:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.type-option span { display: flex; flex-direction: column; }
.type-option input { margin-top: .25rem; }
.intake-nav { justify-content: space-between; }
.autosave-status { color: var(--ok); }
.status-list li { display: flex; justify-content: space-between; align-items: center; gap: .6rem; }
.form-line { margin: .1rem 0; white-space: nowrap; }
progress.steps { width: 90px; height: .6rem; vertical-align: middle; accent-color: var(--brand); }
.legend summary { cursor: pointer; font-weight: 600; }
.legend .dl { grid-template-columns: 190px 1fr; margin-top: .6rem; }
.req-matrix th[scope=row] { min-width: 220px; }
.req-matrix th.inactive { opacity: .55; }
.req-matrix select { min-width: 110px; margin: 0; }
.req-matrix select.req-required { border-color: var(--warn); background: var(--warn-bg); }
.req-matrix select.req-offered { border-color: var(--info); background: var(--info-bg); }
.req-matrix .settings-row input { margin: 0; min-width: 140px; }
.req-matrix td, .req-matrix th { vertical-align: top; }
.type-inline { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .4rem; margin: 0 0 .6rem; }
.type-inline label { margin: 0; }
.type-inline select { margin-top: .15rem; min-width: 220px; width: auto; }
dd .type-inline { margin: 0; }
dd .type-inline .type-label { position: absolute; left: -9999px; }
.nowrap { white-space: nowrap; }
