:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #eef2ef;
  --ink: #15201f;
  --ink-2: #4b5a58;
  --ink-3: #7d8a88;
  --line: #e2e4de;
  --brand: #0f3d3e;
  --brand-2: #1c5b5c;
  --mint: #2fbf8f;
  --mint-soft: #dff5ec;
  --amber: #c98a1b;
  --amber-soft: #fbf0d9;
  --rose: #c2453d;
  --rose-soft: #fbe6e3;
  --user-bubble: #0f3d3e;
  --user-ink: #ffffff;
  --shadow: 0 1px 2px rgba(15, 61, 62, .06), 0 6px 20px rgba(15, 61, 62, .06);
  --radius: 16px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --serif: "Fraunces", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1716;
    --surface: #142220;
    --surface-2: #1a2b29;
    --ink: #e8efed;
    --ink-2: #b2c0bd;
    --ink-3: #82918e;
    --line: #243634;
    --brand: #7fd6b8;
    --brand-2: #a6e6cf;
    --mint: #3fd3a1;
    --mint-soft: #173a30;
    --amber: #e3ad4a;
    --amber-soft: #3a2f17;
    --rose: #ef7c72;
    --rose-soft: #3d1f1c;
    --user-bubble: #245e57;
    --user-ink: #f2fbf8;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--brand); }
[hidden] { display: none !important; }

#app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(var(--safe-t) + 16px) 16px calc(var(--nav-h) + var(--safe-b) + 24px);
}
#app.no-nav { padding-bottom: calc(var(--safe-b) + 24px); }

.boot { display: grid; place-items: center; min-height: 70dvh; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--mint);
  animation: spin .8s linear infinite;
}
.spinner.sm { width: 18px; height: 18px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Type */
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font: 600 28px/1.15 var(--serif); letter-spacing: -.01em; }
h2 { font: 600 20px/1.25 var(--serif); }
h3 { font-size: 15px; font-weight: 600; }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.tiny { font-size: 12px; color: var(--ink-3); }
.center { text-align: center; }
.stack > * + * { margin-top: 12px; }
.stack-lg > * + * { margin-top: 20px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

/* Page header */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.page-head p { margin: 6px 0 0; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card.tint { background: var(--mint-soft); border-color: transparent; box-shadow: none; }
.card.brand { background: var(--brand); color: #fff; border-color: transparent; }
@media (prefers-color-scheme: dark) { .card.brand { background: #1c4a46; } }
.card.brand .muted, .card.brand .tiny { color: rgba(255,255,255,.75); }
.card h3 + p { margin: 4px 0 0; }
.card p { margin: 0; }
.card-link { display: block; text-decoration: none; color: inherit; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  font-weight: 600; text-decoration: none; color: var(--ink);
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { background: var(--mint); border-color: var(--mint); color: #08201a; } }
.btn.ghost { background: transparent; border-color: transparent; color: var(--brand); padding: 0 8px; }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.on-brand { background: #fff; color: var(--brand); border-color: #fff; }
@media (prefers-color-scheme: dark) { .btn.on-brand { color: #0f3d3e; } }

/* Forms */
label.field { display: block; }
label.field > span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
label.field > small { display: block; color: var(--ink-3); font-size: 13px; margin: -2px 0 8px; }
input[type=text], input[type=email], input[type=number], textarea, select {
  width: 100%; min-height: 46px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  outline: none;
}
textarea { resize: vertical; min-height: 84px; line-height: 1.45; }
input:focus, textarea:focus, select:focus { border-color: var(--mint); box-shadow: 0 0 0 3px var(--mint-soft); }
.otp { letter-spacing: .4em; font-size: 22px; text-align: center; font-weight: 600; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.seg button {
  min-height: 42px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-weight: 500; font-size: 14px;
}
.seg button.on { background: var(--brand); border-color: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .seg button.on { background: var(--mint); border-color: var(--mint); color: #08201a; } }

input[type=range] { width: 100%; accent-color: var(--mint); height: 28px; }
.slider-head { display: flex; justify-content: space-between; align-items: baseline; }
.slider-val { font: 600 18px var(--serif); color: var(--brand); min-width: 2ch; text-align: right; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { width: 40px; height: 24px; border-radius: 12px; background: var(--line); position: relative; transition: background .15s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + .track { background: var(--mint); }
.switch input:checked + .track::after { transform: translateX(16px); }

/* Pills */
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.pill.mint { background: var(--mint-soft); color: var(--brand); }
@media (prefers-color-scheme: dark) { .pill.mint { color: var(--mint); } }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.rose { background: var(--rose-soft); color: var(--rose); }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 14px; font-size: 14px; cursor: pointer; text-align: left; }
.chip:hover { border-color: var(--mint); }

/* Stats */
.stat-num { font: 600 44px/1 var(--serif); letter-spacing: -.02em; }
.stat-num small { font: 500 16px var(--sans); color: var(--ink-3); margin-left: 2px; }
.card.brand .stat-num small { color: rgba(255,255,255,.7); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.kpi b { display: block; font: 600 24px var(--serif); }
.kpi span { font-size: 12px; color: var(--ink-3); }

.bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--mint); border-radius: 4px; }
.bars .row { gap: 12px; }
.bars .lbl { width: 72px; font-size: 13px; color: var(--ink-2); flex: none; }
.bars .val { width: 28px; font-size: 13px; text-align: right; font-weight: 600; flex: none; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 14px 0; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.list-item-link { display: block; text-decoration: none; color: inherit; }

/* Chat */
.chat-wrap { display: flex; flex-direction: column; min-height: calc(100dvh - var(--safe-t) - 40px); }
.chat-head {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  margin: calc(-1 * var(--safe-t) - 16px) -16px 0; padding: calc(var(--safe-t) + 10px) 12px 10px;
  border-bottom: 1px solid var(--line);
}
.chat-title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msgs { flex: 1; padding: 16px 0 8px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 18px; line-height: 1.5; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--user-bubble); color: var(--user-ink); border-bottom-right-radius: 6px; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg.assistant p { margin: 0 0 8px; }
.msg.assistant p:last-child, .msg.assistant ul:last-child, .msg.assistant ol:last-child { margin-bottom: 0; }
.msg.assistant ul, .msg.assistant ol { margin: 0 0 8px; padding-left: 20px; }
.msg.assistant li { margin: 2px 0; }
.typing { display: inline-flex; gap: 4px; padding: 14px 16px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.composer {
  position: sticky; bottom: 0; background: var(--bg);
  margin: 0 -16px; padding: 10px 12px calc(var(--safe-b) + 10px);
  border-top: 1px solid var(--line);
  display: flex; gap: 8px; align-items: flex-end;
}
.composer textarea { min-height: 46px; max-height: 160px; resize: none; border-radius: 22px; padding: 11px 16px; }
.send { width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--brand); color: #fff; display: grid; place-items: center; cursor: pointer; flex: none; }
@media (prefers-color-scheme: dark) { .send { background: var(--mint); color: #08201a; } }
.send:disabled { opacity: .45; }
.notice { font-size: 13px; color: var(--ink-2); background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.notice.warn { background: var(--amber-soft); color: var(--ink); }
.notice.err { background: var(--rose-soft); color: var(--ink); }

/* Chart */
.chart svg { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--line); }
.chart .line { stroke: var(--mint); fill: none; stroke-width: 2.5; }
.chart .area { fill: var(--mint-soft); }
.chart .dot { fill: var(--surface); stroke: var(--mint); stroke-width: 2.5; }
.chart text { fill: var(--ink-3); font-size: 11px; font-family: var(--sans); }

/* Tabs */
.tabs { display: flex; gap: 6px; overflow-x: auto; margin: 0 -16px 16px; padding: 0 16px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { text-decoration: none; color: var(--ink); border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 14px; font-size: 14px; font-weight: 500; cursor: pointer; white-space: nowrap; }
.tab.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* Report */
.pain { border-left: 3px solid var(--mint); padding-left: 12px; }
.pain .rank { font: 600 13px var(--sans); color: var(--mint); }
blockquote { margin: 8px 0 0; padding: 8px 12px; background: var(--surface-2); border-radius: 10px; font-size: 14px; color: var(--ink-2); font-style: italic; }

/* Avatar */
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--mint-soft); color: var(--brand); display: grid; place-items: center; font-weight: 600; font-size: 14px; flex: none; }
@media (prefers-color-scheme: dark) { .avatar { color: var(--mint); } }

/* Bottom nav */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
  display: flex; justify-content: center;
}
.nav-inner { display: flex; width: 100%; max-width: 640px; }
.nav a {
  flex: 1; height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; color: var(--ink-3); font-size: 11px; font-weight: 500;
}
.nav a svg { width: 22px; height: 22px; }
.nav a.on { color: var(--brand); }
@media (prefers-color-scheme: dark) { .nav a.on { color: var(--mint); } }

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + var(--safe-b) + 14px); z-index: 20;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-size: 14px; max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgba(0,0,0,.2);
}

/* Login */
.login { min-height: 90dvh; display: flex; flex-direction: column; justify-content: center; }
.brandmark { width: 64px; height: 64px; border-radius: 18px; background: var(--brand); color: #fff; display: grid; place-items: center; font: 600 30px var(--serif); margin-bottom: 20px; }
@media (prefers-color-scheme: dark) { .brandmark { background: #1c4a46; } }

table.simple { width: 100%; border-collapse: collapse; font-size: 14px; }
table.simple td, table.simple th { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.simple th { font-size: 12px; color: var(--ink-3); font-weight: 600; }

details summary { cursor: pointer; font-weight: 600; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
