:root {
  --bg: #f6f1e8;
  --surface: #fffdf9;
  --surface-2: #efe8db;
  --line: #e2d8c6;
  --ink: #2f2a22;
  --ink-2: #6b6255;
  --ink-3: #958b7c;
  --sage: #6f8f72;
  --sage-deep: #4d6b51;
  --sage-soft: #e3ebe0;
  --brown: #9a7552;
  --brown-soft: #f1e6d8;
  --on-accent: #ffffff;
  --red: #b3412f; --red-soft: #f8e3de;
  --orange: #b8681c; --orange-soft: #f8ead8;
  --yellow: #8a7414; --yellow-soft: #f5efd2;
  --green: #3f7a4c; --green-soft: #e1eedf;
  --shadow: 0 1px 2px rgba(60, 45, 20, .06), 0 4px 16px rgba(60, 45, 20, .06);
  --radius: 16px;
  --font: 'Heebo', 'Segoe UI', Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1a16; --surface: #262320; --surface-2: #302c27; --line: #3d3832;
    --ink: #f1ebe0; --ink-2: #c3b9a9; --ink-3: #8f8677;
    --sage: #8fb293; --sage-deep: #a9c8ac; --sage-soft: #2c3a2d; --brown: #c9a37d; --brown-soft: #3a3027;
    --on-accent: #16201a;
    --red: #ec8b79; --red-soft: #3d2420; --orange: #e9a35e; --orange-soft: #3b2c1c; --yellow: #d8c46a; --yellow-soft: #36311a; --green: #8cc69a; --green-soft: #22332a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1c1a16; --surface: #262320; --surface-2: #302c27; --line: #3d3832;
  --ink: #f1ebe0; --ink-2: #c3b9a9; --ink-3: #8f8677;
  --sage: #8fb293; --sage-deep: #a9c8ac; --sage-soft: #2c3a2d; --brown: #c9a37d; --brown-soft: #3a3027;
  --on-accent: #16201a;
  --red: #ec8b79; --red-soft: #3d2420; --orange: #e9a35e; --orange-soft: #3b2c1c; --yellow: #d8c46a; --yellow-soft: #36311a; --green: #8cc69a; --green-soft: #22332a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--ink); line-height: 1.55; font-size: 16px; -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; font-weight: 600; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }
a { color: var(--sage-deep); }
.muted { color: var(--ink-2); } .small { font-size: .85rem; } .tiny { font-size: .75rem; color: var(--ink-3); }
.hidden { display: none !important; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: .75rem; }
.grow { flex: 1; min-width: 0; }

/* layout */
.wrap { max-width: 720px; margin: 0 auto; padding: 16px 16px 96px; }
.wrap.wide { max-width: 1280px; }
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar .inner { max-width: 1280px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: .75rem; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 600; color: var(--ink); text-decoration: none; }
.brand .leaf { width: 30px; height: 30px; border-radius: 50%; background: var(--sage-soft); display: grid; place-items: center; color: var(--sage-deep); }
.demo-badge { background: var(--brown-soft); color: var(--brown); border-radius: 999px; padding: 2px 10px; font-size: .75rem; font-weight: 600; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card + .card { margin-top: 14px; }
.card h2 { margin-bottom: .75rem; }
.card.soft { background: var(--sage-soft); border-color: transparent; box-shadow: none; }

/* buttons & inputs */
.btn { appearance: none; border: 1px solid transparent; background: var(--sage-deep); color: var(--on-accent); font: inherit; font-weight: 600; border-radius: 12px; padding: .7rem 1.15rem; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 44px; text-decoration: none; }
.btn:hover { filter: brightness(1.05); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn.ghost { background: transparent; color: var(--sage-deep); border-color: transparent; }
.btn.danger { background: var(--surface); color: var(--red); border-color: var(--line); }
.btn.sm { min-height: 34px; padding: .35rem .75rem; font-size: .85rem; border-radius: 10px; }
.btn.block { width: 100%; }
label.field { display: block; }
label.field > span { display: block; font-weight: 500; margin-bottom: .35rem; }
input[type=text], input[type=number], input[type=tel], input[type=email], input[type=password], input[type=date], input[type=url], select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: .65rem .8rem; min-height: 44px;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .chip:focus-visible { outline: 2px solid var(--sage); outline-offset: 2px; }
.pin-input { letter-spacing: .6em; text-align: center; font-size: 1.4rem; max-width: 220px; }
.check { display: flex; gap: .6rem; align-items: flex-start; cursor: pointer; }
.check input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--sage-deep); flex: none; }

/* chips / options */
.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip { appearance: none; font: inherit; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px; padding: .5rem .95rem; cursor: pointer; min-height: 42px; text-align: start; }
.chip[aria-pressed="true"] { background: var(--sage-deep); border-color: var(--sage-deep); color: var(--on-accent); }
.chips.col { flex-direction: column; } .chips.col .chip { border-radius: 12px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.scale { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; }
.scale .chip { padding: .5rem 0; text-align: center; border-radius: 10px; min-width: 0; }
.scale-labels { display: flex; justify-content: space-between; font-size: .75rem; color: var(--ink-3); margin-top: .25rem; }
.discuss { margin-top: .6rem; font-size: .85rem; }

/* questionnaire */
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--sage); border-radius: 99px; transition: width .3s; }
.q { padding: 16px 0; border-bottom: 1px solid var(--line); }
.q:last-child { border-bottom: 0; }
.q .qt { font-weight: 500; margin-bottom: .6rem; }
.q .qt .req { color: var(--brown); }
.q .help { font-size: .82rem; color: var(--ink-3); margin: -.35rem 0 .5rem; }
.q.invalid .qt { color: var(--red); }
.followups { margin-top: .75rem; padding: 12px; border-radius: 12px; background: var(--surface-2); display: grid; gap: .6rem; }
.followups label > span { font-size: .85rem; font-weight: 500; }
.sec-list { display: grid; gap: .5rem; }
.sec-item { display: flex; align-items: center; gap: .75rem; padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); cursor: pointer; text-align: start; font: inherit; color: inherit; width: 100%; }
.sec-item .num { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--ink-2); font-size: .85rem; flex: none; }
.sec-item.done .num { background: var(--sage-deep); color: var(--on-accent); }
.wizard-nav { position: sticky; bottom: calc(58px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); padding: 18px 0 12px; display: flex; gap: .6rem; }
.wizard-nav .btn { flex: 1; }

/* alerts & flags */
.alert { border-radius: 12px; padding: 12px 14px; margin-top: .6rem; font-size: .92rem; border: 1px solid transparent; }
.alert.emergency { background: var(--red-soft); color: var(--ink); border-color: var(--red); }
.alert.care { background: var(--brown-soft); color: var(--ink); }
.alert.info { background: var(--sage-soft); color: var(--ink); }
.flag { display: grid; grid-template-columns: auto 1fr; gap: .2rem .6rem; padding: 10px 12px; border-radius: 12px; margin-bottom: .5rem; }
.flag .ic { grid-row: span 2; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: .8rem; color: #fff; }
.flag .t { font-weight: 600; }
.flag .a { font-size: .88rem; color: var(--ink-2); }
.flag.emergency, .flag.red { background: var(--red-soft); } .flag.emergency .ic, .flag.red .ic { background: var(--red); }
.flag.orange { background: var(--orange-soft); } .flag.orange .ic { background: var(--orange); }
.flag.yellow { background: var(--yellow-soft); } .flag.yellow .ic { background: var(--yellow); }
.pill { display: inline-flex; align-items: center; gap: .35rem; border-radius: 999px; padding: 2px 10px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.pill::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.emergency, .pill.red { background: var(--red-soft); color: var(--red); }
.pill.orange { background: var(--orange-soft); color: var(--orange); }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.none { background: var(--surface-2); color: var(--ink-3); }

/* tabs & nav */
.tabs { display: flex; gap: .25rem; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 16px; scrollbar-width: none; }
.tabs button { appearance: none; background: none; border: 0; border-bottom: 2px solid transparent; font: inherit; color: var(--ink-2); padding: .6rem .9rem; cursor: pointer; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--sage-deep); border-bottom-color: var(--sage-deep); font-weight: 600; }
.bottom-nav { position: fixed; bottom: 0; inset-inline: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--line); display: flex; justify-content: space-around; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
.bottom-nav button { appearance: none; background: none; border: 0; font: inherit; font-size: .72rem; color: var(--ink-3); display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 6px; cursor: pointer; min-width: 56px; position: relative; }
.bottom-nav button svg { width: 22px; height: 22px; }
.bottom-nav button[aria-current="page"] { color: var(--sage-deep); font-weight: 600; }
.badge { position: absolute; top: 0; inset-inline-end: 8px; background: var(--brown); color: #fff; border-radius: 99px; font-size: .65rem; padding: 0 5px; }

/* kv lists in reports */
.kv { display: grid; grid-template-columns: minmax(110px, 30%) 1fr; gap: .35rem 1rem; margin: 0; }
.kv dt { color: var(--ink-2); font-size: .9rem; }
.kv dd { margin: 0; white-space: pre-wrap; }
ul.clean { margin: 0; padding-inline-start: 1.1rem; } ul.clean li { margin-bottom: .3rem; }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { padding: .5rem .6rem; border-bottom: 1px solid var(--line); text-align: start; vertical-align: top; }
th { background: var(--surface-2); font-weight: 600; color: var(--ink-2); font-size: .8rem; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; } tr.clickable:hover td { background: var(--surface-2); }

/* plan sheet (coach) */
.week-block { margin-bottom: 22px; }
.week-head { display: flex; align-items: center; gap: .5rem; background: var(--surface-2); padding: 8px 12px; border-radius: 12px 12px 0 0; border: 1px solid var(--line); border-bottom: 0; }
.week-head input { max-width: 180px; font-weight: 600; min-height: 36px; padding: .3rem .6rem; }
.days { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 820px), 1fr)); gap: 12px; border: 1px solid var(--line); border-radius: 0 0 12px 12px; padding: 12px; background: var(--surface); }
.day { min-width: 0; }
.day-head { display: flex; gap: .5rem; align-items: center; margin-bottom: .4rem; }
.day-head input { font-weight: 600; min-height: 36px; padding: .3rem .6rem; }
table.sheet { font-size: .82rem; table-layout: fixed; }
table.sheet th { padding: .35rem .4rem; font-size: .72rem; }
table.sheet th.plan { background: var(--sage-soft); color: var(--sage-deep); }
table.sheet th.act { background: var(--brown-soft); color: var(--brown); }
table.sheet td { padding: 2px; }
table.sheet td.ro { padding: .35rem .4rem; background: color-mix(in srgb, var(--brown-soft) 45%, transparent); font-size: .8rem; }
table.sheet input { min-height: 32px; padding: .25rem .4rem; border-radius: 8px; font-size: .82rem; border-color: transparent; background: transparent; }
table.sheet input:hover, table.sheet input:focus { border-color: var(--line); background: var(--surface); }
table.sheet .ex-name input { font-weight: 600; }
.note-flag { color: var(--orange); font-weight: 600; }

/* plan (client) */
.ex-card { border: 1px solid var(--line); border-radius: 14px; padding: 12px; background: var(--surface); }
.ex-card + .ex-card { margin-top: 10px; }
.ex-card.done { border-color: var(--sage); }
.ex-card .target { display: flex; gap: .4rem; flex-wrap: wrap; margin: .35rem 0 .6rem; }
.tag { background: var(--surface-2); border-radius: 8px; padding: 2px 8px; font-size: .82rem; }
.tag.plan { background: var(--sage-soft); color: var(--sage-deep); }
.actual { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.actual label > span { font-size: .78rem; color: var(--ink-2); margin-bottom: .15rem; }

/* body map */
.bodymap { display: grid; grid-template-columns: 160px 1fr; gap: 14px; align-items: start; }
.bodymap svg { width: 100%; height: auto; }
.bodymap .zone { fill: var(--surface-2); stroke: var(--line); cursor: pointer; transition: fill .15s; }
.bodymap .zone:hover { fill: var(--sage-soft); }
.bodymap .zone.on { fill: var(--orange); stroke: var(--orange); }
.bodymap .sil { fill: var(--surface-2); opacity: .55; }
.pain-row { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 8px; }
@media (max-width: 520px) { .bodymap { grid-template-columns: 110px 1fr; } }

/* charts */
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--ink-3); font-size: 10px; font-family: var(--font); }
.chart .line { fill: none; stroke: var(--sage-deep); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--sage-deep); stroke: var(--surface); stroke-width: 2; }
.chart .hit { fill: transparent; }
.chart .pt:hover .dot { r: 6; }
.chart-empty { color: var(--ink-3); font-size: .85rem; padding: 18px 0; text-align: center; }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }

/* misc */
.list-item { display: flex; gap: .75rem; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.file-ic { width: 38px; height: 38px; border-radius: 10px; background: var(--brown-soft); color: var(--brown); display: grid; place-items: center; font-size: .7rem; font-weight: 700; flex: none; }
.msg { max-width: 85%; padding: 10px 12px; border-radius: 14px; margin-bottom: 8px; white-space: pre-wrap; }
.msg.me { background: var(--sage-soft); margin-inline-start: auto; }
.msg.them { background: var(--surface-2); }
.msg.private { background: var(--yellow-soft); border: 1px dashed var(--yellow); }
.msg .meta { font-size: .72rem; color: var(--ink-3); margin-top: 4px; }
.empty { text-align: center; color: var(--ink-3); padding: 24px 8px; }
.hero { text-align: center; padding: 28px 8px 8px; }
.hero .big-leaf { width: 72px; height: 72px; margin: 0 auto 12px; border-radius: 50%; background: var(--sage-soft); color: var(--sage-deep); display: grid; place-items: center; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.stat .v { font-size: 1.5rem; font-weight: 600; }
.stat .l { font-size: .8rem; color: var(--ink-2); }
.legal { max-height: 240px; overflow: auto; background: var(--surface-2); border-radius: 12px; padding: 12px 14px; font-size: .88rem; }
.draft-note { background: var(--yellow-soft); border-radius: 10px; padding: 6px 10px; font-size: .8rem; }
.modal-back { position: fixed; inset: 0; background: rgba(20, 15, 10, .45); z-index: 60; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: var(--radius); padding: 20px; width: 100%; max-width: 480px; max-height: 90vh; overflow: auto; }
#toast { position: fixed; bottom: 84px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: .6rem 1rem; border-radius: 12px; opacity: 0; pointer-events: none; transition: .25s; z-index: 80; font-size: .9rem; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--red); color: #fff; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--sage-deep); border-radius: 50%; animation: spin 1s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 640px) {
  h1 { font-size: 1.35rem; }
  .card { padding: 14px; }
  .kv { grid-template-columns: 1fr; gap: 0; } .kv dd { margin-bottom: .5rem; }
  .days { grid-template-columns: 1fr; padding: 8px; }
}

@media print {
  .topbar, .bottom-nav, .tabs, .no-print, .btn, #toast { display: none !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  .wrap { max-width: none; padding: 0; }
}

/* exercise figure: arrow + cue bubble */
.exfig { display: grid; grid-template-columns: 120px 1fr; gap: 10px; align-items: center; margin: .5rem 0; }
.exfig svg { width: 100%; height: auto; max-height: 190px; }
.exfig .sil { fill: var(--surface-2); }
.exfig .target { fill: var(--red); opacity: .85; animation: pulse 2.2s ease-in-out infinite; }
.exfig .arrow { fill: none; stroke: var(--red); stroke-width: 2.4; stroke-linecap: round; }
.exfig .ah { fill: var(--red); }
@keyframes pulse { 50% { opacity: .45; } }
@media (prefers-reduced-motion: reduce) { .exfig .target { animation: none; } }
.bubble { position: relative; background: var(--red); color: #fff; font-weight: 600; border-radius: 14px; padding: 10px 12px; font-size: .92rem; line-height: 1.35; box-shadow: var(--shadow); }
.exfig:not(.photo) .bubble::after { content: ''; position: absolute; top: 50%; inset-inline-start: -8px; transform: translateY(-50%); border: 8px solid transparent; border-inline-end-color: var(--red); border-inline-start: 0; }
.bubble .tiny-m { display: block; font-weight: 400; font-size: .72rem; opacity: .85; margin-top: 2px; }
.exfig.photo { display: block; position: relative; border-radius: 12px; overflow: hidden; background: var(--surface-2); }
.exfig.photo img { display: block; width: 100%; height: auto; }
.exfig.photo .overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.exfig.photo .overlay line { stroke: var(--red); stroke-width: .8; vector-effect: non-scaling-stroke; stroke-width: 2.5; }
.exfig.photo .spot { position: absolute; width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 50%; border: 3px solid #fff; background: var(--red); box-shadow: 0 0 0 3px rgba(179, 65, 47, .35); }
.bubble.abs { position: absolute; max-width: 55%; }
.exdetails { background: var(--surface-2); border-radius: 12px; padding: 10px 14px; margin-top: .5rem; font-size: .88rem; }
.exdetails h4 { margin: .3rem 0; font-size: .85rem; color: var(--ink-2); }
.exdetails ol, .exdetails ul { margin: 0 0 .4rem; padding-inline-start: 1.2rem; }
.ex-label { display: inline-grid; place-items: center; min-width: 30px; height: 26px; padding: 0 6px; border-radius: 8px; background: var(--brown); color: #fff; font-size: .8rem; font-weight: 700; margin-inline-end: .4rem; }
.ex-head { display: flex; align-items: center; gap: .3rem; }
.cue-toggle { appearance: none; border: 0; background: none; color: var(--red); font: inherit; font-weight: 600; font-size: .85rem; cursor: pointer; padding: .2rem 0; display: inline-flex; gap: .3rem; align-items: center; }
.cue-toggle .chev { transition: transform .2s; display: inline-block; }
.cue-toggle[aria-expanded="true"] .chev { transform: rotate(-90deg); }
.info-dot { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: var(--sage-soft); color: var(--sage-deep); font-size: .7rem; font-weight: 700; cursor: help; flex: none; }
.lib-editor .exfig { max-width: 360px; }
.spot-pick { position: relative; cursor: crosshair; max-width: 360px; }
.spot-pick img { width: 100%; display: block; border-radius: 12px; }
.in-artifact #print { display: none !important; }
.tagline { color: var(--brown); font-weight: 500; letter-spacing: .01em; margin: -.2rem 0 .6rem; }
.brand { white-space: nowrap; }
@media (max-width: 480px) {
  .topbar .inner { gap: .35rem; }
  .topbar .demo-badge { display: none; }
  .topbar .btn.sm { padding: .3rem .5rem; }
}
