:root {
  --brand: #0f6e6e;
  --brand-ink: #ffffff;
  --brand-soft: color-mix(in srgb, var(--brand) 10%, white);
  --ink: #1b2326;
  --muted: #5d6b70;
  --line: #e1e6e8;
  --bg: #f5f7f8;
  --card: #ffffff;
  --danger: #b42318;
  --ok: #1f7a3a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; font-size: 15px; line-height: 1.5; }
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

/* Layout */
.topbar { background: var(--brand); color: var(--brand-ink); position: sticky; top: 0; z-index: 20; }
.topbar .inner { max-width: 1180px; margin: 0 auto; display: flex; align-items: center; gap: 1rem; padding: .6rem 1rem; }
.brand { font-weight: 700; letter-spacing: .2px; text-decoration: none; color: inherit; white-space: nowrap; }
.brand span { opacity: .75; font-weight: 500; }
.nav { display: flex; gap: .25rem; flex: 1; overflow-x: auto; }
.nav a { color: inherit; text-decoration: none; padding: .4rem .7rem; border-radius: 8px; opacity: .85; white-space: nowrap; }
.nav a.active, .nav a:hover { background: rgba(255,255,255,.16); opacity: 1; }
.user { display: flex; gap: .5rem; align-items: center; white-space: nowrap; }
.user button { background: transparent; color: inherit; border: 1px solid rgba(255,255,255,.4); }
main { max-width: 1180px; margin: 0 auto; padding: 1.25rem 1rem 4rem; }

.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.grid { display: grid; gap: 1rem; }
.grid.cols-3 { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1rem; align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.card + .card { margin-top: 1rem; }
.grid > .card + .card { margin-top: 0; }
.stat { font-size: 1.9rem; font-weight: 700; }

/* Forms */
label { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: .25rem; }
input, textarea, select { width: 100%; font: inherit; color: inherit; padding: .5rem .65rem; border: 1px solid #cdd5d8; border-radius: 8px; background: #fff; }
input:focus, textarea:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--brand) 40%, transparent); border-color: var(--brand); }
textarea { min-height: 70px; resize: vertical; }
.field { margin-bottom: .8rem; }
.fields { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

button, .btn { font: inherit; font-weight: 600; cursor: pointer; border-radius: 8px; padding: .5rem .9rem; border: 1px solid var(--line); background: #fff; color: var(--ink); text-decoration: none; display: inline-flex; gap: .4rem; align-items: center; }
button:hover, .btn:hover { border-color: #b8c3c7; }
button.primary, .btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
button.primary:hover { filter: brightness(1.07); }
button.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, white); }
button.ghost { background: transparent; border-color: transparent; }
button.icon { padding: .3rem .5rem; }
button:disabled { opacity: .5; cursor: not-allowed; }

/* Lists & tables */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: .7rem .2rem; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list a { text-decoration: none; color: inherit; display: block; }
.list a:hover strong { color: var(--brand); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }

.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: .1rem .5rem; border-radius: 99px; background: var(--brand-soft); color: var(--brand); }
.badge.grey { background: #eef1f2; color: var(--muted); }
.badge.ok { background: #e6f4ea; color: var(--ok); }
.chips { display: flex; gap: .35rem; flex-wrap: wrap; }
.chip { font-size: .85rem; padding: .25rem .65rem; border-radius: 99px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-weight: 500; }
.chip.active { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

/* Exercise cards */
.ex-card { display: flex; flex-direction: column; gap: .5rem; cursor: pointer; }
.ex-card:hover { border-color: var(--brand); }
.thumb { aspect-ratio: 16 / 9; background: #e9eef0; border-radius: 8px; overflow: hidden; display: grid; place-items: center; color: var(--muted); font-size: .8rem; }
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Plan editor */
.item { border: 1px solid var(--line); border-radius: 10px; padding: .75rem; background: #fff; margin-bottom: .6rem; }
.item-head { display: flex; gap: .5rem; align-items: center; }
.item-head .num { width: 1.8rem; height: 1.8rem; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; font-size: .85rem; flex: none; }
.item .fields { grid-template-columns: repeat(auto-fit, minmax(105px, 1fr)); margin-top: .6rem; }
.item .fields input { padding: .4rem .5rem; }
.block-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; margin: 1rem 0 .4rem; }
.dirty { color: #b54708; font-weight: 600; font-size: .85rem; }
.share-link { font-family: ui-monospace, Menlo, monospace; font-size: .8rem; word-break: break-all; background: var(--bg); padding: .5rem; border-radius: 8px; }
.qr { width: 160px; height: 160px; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); display: grid; place-items: center; z-index: 50; padding: 1rem; }
.modal { background: #fff; border-radius: 14px; width: min(720px, 100%); max-height: 90vh; overflow: auto; padding: 1.25rem; box-shadow: 0 20px 50px rgba(0,0,0,.2); }
.modal.wide { width: min(980px, 100%); }
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }

.toast { position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: .6rem 1rem; border-radius: 10px; z-index: 100; box-shadow: var(--shadow); }
.toast.error { background: var(--danger); }

.auth { max-width: 380px; margin: 10vh auto; }
.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }

/* Patient view */
.pt-header { background: var(--brand); color: var(--brand-ink); padding: 1.25rem 1rem 1.5rem; }
.pt-header .inner, .pt-main { max-width: 720px; margin: 0 auto; }
.pt-main { padding: 1rem; }
.pt-ex { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 1rem; overflow: hidden; box-shadow: var(--shadow); }
.pt-ex .media { background: #000; }
.pt-ex .media img, .pt-ex .media video { width: 100%; max-height: 420px; object-fit: contain; display: block; background: #000; }
.pt-ex .media iframe { width: 100%; aspect-ratio: 16/9; border: 0; display: block; }
.pt-ex .body { padding: 1rem; }
.dose { display: flex; flex-wrap: wrap; gap: .4rem; margin: .5rem 0; }
.dose span { background: var(--brand-soft); color: var(--brand); border-radius: 8px; padding: .25rem .6rem; font-weight: 600; font-size: .9rem; }
.cues { margin: .5rem 0 0; padding-left: 1.1rem; }
.check { display: flex; align-items: center; gap: .5rem; margin-top: .75rem; font-weight: 600; cursor: pointer; }
.check input { width: 1.3rem; height: 1.3rem; accent-color: var(--brand); }
.pt-ex.done { opacity: .6; }
.scale { display: grid; grid-template-columns: repeat(11, 1fr); gap: .25rem; }
.scale button { padding: .45rem 0; justify-content: center; font-size: .9rem; }
.scale button.sel { background: var(--brand); color: #fff; border-color: var(--brand); }
.yt-consent { aspect-ratio: 16/9; display: grid; place-items: center; text-align: center; color: #fff; padding: 1rem; background: #1b2326; }

@media print {
  .no-print, .topbar, .modal-backdrop, .toast { display: none !important; }
  body, :root { background: #fff; }
  main, .pt-main { padding: 0; max-width: none; }
  .card, .pt-ex, .item { box-shadow: none; break-inside: avoid; }
  .pt-header { background: #fff !important; color: #000 !important; border-bottom: 2px solid var(--brand); padding: 0 0 .5rem; }
  .pt-ex .media iframe, .yt-consent { display: none; }
  .pt-ex .media img { max-height: 200px; }
  .pt-ex .media video { display: none; }
}
