:root {
  --bg: #f4f4f2; --surface: #ffffff; --surface2: #ececea; --text: #191919; --text2: #666666;
  --line: #e2e2df; --accent: #257de0; --accent-text: #ffffff; --good: #0aac23; --bubble-me: #257de0;
  --bubble-coach: #ffffff; --safe-top: env(safe-area-inset-top); --safe-bottom: env(safe-area-inset-bottom);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f0f0f; --surface: #1b1b1b; --surface2: #262626; --text: #efefef; --text2: #9c9c9c;
    --line: #2e2e2e; --accent: #338ced; --bubble-me: #2a6fc0; --bubble-coach: #1f1f1f; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { font: 16px/1.45 -apple-system, system-ui, sans-serif; background: var(--bg); color: var(--text);
  overscroll-behavior: none; }
button, input, textarea { font: inherit; color: inherit; }
.app { display: flex; flex-direction: column; height: 100dvh; }
header.top { padding: calc(var(--safe-top) + 10px) 16px 8px; display: flex; justify-content: space-between; align-items: baseline; }
header.top h1 { font-size: 24px; margin: 0; letter-spacing: -0.02em; }
header.top button { background: none; border: 0; color: var(--text2); padding: 4px; }
main { flex: 1; overflow-y: auto; padding: 0 16px 16px; -webkit-overflow-scrolling: touch; }
section[hidden] { display: none !important; }
.card { background: var(--surface); border-radius: 16px; padding: 16px; margin: 12px 0; }
.card h2 { font-size: 13px; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: .04em; margin: 0 0 10px; }
.big { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.muted { color: var(--text2); font-size: 14px; }
.meter { height: 8px; background: var(--surface2); border-radius: 4px; overflow: hidden; margin: 8px 0 4px; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.habits { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; font-variant-numeric: tabular-nums; }
.habits .val { color: var(--text2); text-align: right; }
.morning { white-space: pre-wrap; }
ul.meals { list-style: none; margin: 0; padding: 0; }
ul.meals li { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }
ul.meals li:first-child { border-top: 0; }
nav.tabs { display: flex; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: var(--safe-bottom); }
nav.tabs button { flex: 1; background: none; border: 0; padding: 10px 0 8px; color: var(--text2); font-size: 12px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; }
nav.tabs button svg { width: 24px; height: 24px; }
nav.tabs button[aria-selected="true"] { color: var(--accent); }
/* chat */
#chat { display: flex; flex-direction: column; height: 100%; }
#messages { flex: 1; overflow-y: auto; padding: 8px 0; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 82%; padding: 9px 13px; border-radius: 18px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--bubble-me); color: #fff; border-bottom-right-radius: 6px; }
.msg.assistant { align-self: flex-start; background: var(--bubble-coach); border-bottom-left-radius: 6px; }
.msg.pending { color: var(--text2); font-style: italic; }
.msg.failed { color: #d1364b; border: 1px solid currentColor; background: transparent; }
.msg .photo { font-size: 13px; opacity: .8; display: block; }
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 8px 0 4px; }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); background: var(--surface); border-radius: 20px;
  padding: 9px 14px; max-height: 120px; outline: none; }
.iconbtn { width: 42px; height: 42px; border-radius: 21px; border: 0; background: var(--surface2); display: grid; place-items: center; flex: none; }
.iconbtn.send { background: var(--accent); color: var(--accent-text); }
.iconbtn svg { width: 22px; height: 22px; }
.preview { font-size: 13px; color: var(--text2); padding: 0 4px; }
/* charts */
svg.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); } .chart .axis { fill: var(--text2); font-size: 11px; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.chart .dot { fill: var(--text2); opacity: .45; } .chart .bar { fill: var(--accent); }
/* forms */
label { display: block; margin: 10px 0 4px; font-size: 14px; color: var(--text2); }
input[type=number], input[type=email], input[type=password] { width: 100%; padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); }
.btn { display: block; width: 100%; margin-top: 14px; padding: 12px; border-radius: 12px; border: 0; background: var(--accent);
  color: var(--accent-text); font-weight: 600; }
.btn.secondary { background: var(--surface2); color: var(--text); }
code.token { display: block; word-break: break-all; background: var(--surface2); padding: 8px; border-radius: 8px; font-size: 13px; user-select: all; }
.error { color: #d1364b; font-size: 14px; margin-top: 8px; }
