:root {
  --bg: #f6f5f2; --surface: #ffffff; --surface-2: #efede8; --text: #1b1c1f; --muted: #6b6d73;
  --line: #e3e0d9; --accent: #2f6f5e; --accent-ink: #ffffff; --warn: #b4532a; --danger: #b3261e;
  --p1: #b3261e; --p2: #c77a12; --p3: #4a6fa5; --p4: #8a8d93;
  --work: #3d5a99; --personal: #8a4f9e; --growth: #2f6f5e; --health: #b4532a;
  --radius: 14px; --good: #2e7d4f;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --surface: #171a20; --surface-2: #1f232b; --text: #ecebe7; --muted: #9a9ca3;
    --line: #2a2e37; --accent: #5fb39a; --accent-ink: #0f1115; --warn: #e08a5f; --danger: #ef6b62;
    --p1: #ef6b62; --p2: #e3a443; --p3: #7f9fd4; --p4: #8a8d93;
    --work: #7f9fd4; --personal: #c08ad2; --growth: #5fb39a; --health: #e08a5f; --good: #3f9e67;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 16px/1.45 var(--font); }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.btn, .hero a { color: inherit; text-decoration: none; }
.btn.primary { color: var(--accent-ink); }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.hidden { display: none !important; }

/* login */
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login-card h1 { margin: 0 0 8px; font-size: 22px; }
.logo { font-size: 34px; color: var(--accent); }
.err { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 14px; }

/* shell */
.app { height: 100dvh; display: flex; flex-direction: column; max-width: 760px; margin: 0 auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: calc(env(safe-area-inset-top) + 10px) 18px 8px; }
.topbar h2 { margin: 0; font-size: 26px; letter-spacing: -0.02em; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.view.scroll { overflow-y: auto; padding: 4px 16px 24px; display: block; -webkit-overflow-scrolling: touch; }
.tabbar { display: flex; justify-content: space-around; border-top: 1px solid var(--line); background: var(--surface);
  padding: 6px 4px calc(env(safe-area-inset-bottom) + 6px); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); text-decoration: none; padding: 4px 0; }
.tabbar a.active { color: var(--accent); }

/* buttons & inputs */
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 11px 16px; cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 6px 12px; font-size: 14px; }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent; color: var(--muted); cursor: pointer; flex-shrink: 0; }
.icon-btn.recording { color: var(--danger); background: var(--surface-2); }
input[type=text], input[type=password], input[type=number], input[type=search], input[type=date], input[type=time], input[type=datetime-local], textarea, select {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 11px 13px; font-size: 16px; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 12px; font-size: 14px; cursor: pointer; white-space: nowrap; }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip.ghost { color: var(--muted); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0; scrollbar-width: none; }
.seg { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 7px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.seg button.active { background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,.12); font-weight: 600; }
.search { margin: 4px 0 12px; }

/* chat */
.messages { flex: 1; overflow-y: auto; padding: 8px 14px 12px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 86%; padding: 9px 13px; border-radius: 18px; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-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 6px; } .msg.assistant p:last-child { margin: 0; }
.msg.assistant ul, .msg.assistant ol { margin: 4px 0 6px; padding-left: 20px; }
.msg .time { display: block; font-size: 11px; opacity: .6; margin-top: 4px; }
.msg.typing { color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.action { font-size: 12.5px; background: var(--surface-2); border-radius: 8px; padding: 3px 8px; color: var(--text); }
.msg-media { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.msg-media img { width: 84px; height: 84px; object-fit: cover; border-radius: 10px; }
.empty-chat { margin: auto; text-align: center; color: var(--muted); padding: 24px; max-width: 360px; }
.empty-chat h3 { color: var(--text); margin: 0 0 6px; }
.composer { border-top: 1px solid var(--line); background: var(--bg); padding: 6px 10px 8px; }
.mode-row { display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 6px; scrollbar-width: none; }
.mode-row .quick { display: contents; }
.composer-row { display: flex; align-items: flex-end; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 3px; }
.composer-row textarea { border: 0; background: transparent; resize: none; max-height: 160px; padding: 9px 4px; }
.composer.note-mode .composer-row { border-color: var(--warn); }
.send-btn { width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; flex-shrink: 0; cursor: pointer; }
.send-btn:disabled { opacity: .4; }
.attach-preview { display: flex; gap: 8px; overflow-x: auto; }
.attach-preview:not(:empty) { padding: 4px 2px 8px; }
.att { position: relative; flex-shrink: 0; width: 64px; height: 64px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; font-size: 11px; text-align: center; overflow: hidden; padding: 4px; }
.att img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.att button { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border-radius: 50%; border: 0; background: rgba(0,0,0,.65); color: #fff; font-size: 12px; line-height: 1; cursor: pointer; }

/* cards & lists */
.section-h { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 2px 8px; display: flex; justify-content: space-between; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; }
.hero { background: var(--accent); color: var(--accent-ink); border: 0; }
.hero .label { font-size: 12px; opacity: .8; text-transform: uppercase; letter-spacing: .06em; }
.hero .big { font-size: 19px; font-weight: 600; margin-top: 2px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.event { display: flex; gap: 12px; align-items: baseline; }
.event .t { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; min-width: 54px; }
.event.past { opacity: .5; }
.task { display: flex; gap: 12px; align-items: flex-start; }
.check { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); background: transparent; flex-shrink: 0; margin-top: 1px; cursor: pointer; display: grid; place-items: center; }
.check.p1 { border-color: var(--p1); } .check.p2 { border-color: var(--p2); }
.check.done { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.check svg { width: 14px; height: 14px; stroke-width: 3; }
.task .body { flex: 1; min-width: 0; cursor: pointer; }
.task .title { font-weight: 500; }
.task.is-done .title { text-decoration: line-through; color: var(--muted); }
.meta { display: flex; flex-wrap: wrap; gap: 6px 10px; font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.cat { font-weight: 600; text-transform: capitalize; }
.cat.work { color: var(--work); } .cat.personal { color: var(--personal); } .cat.growth { color: var(--growth); } .cat.health { color: var(--health); }
.overdue { color: var(--danger); font-weight: 600; }
.next { font-size: 13.5px; margin-top: 4px; }
.next::before { content: "→ "; color: var(--accent); }
.note-card .note-title { font-weight: 600; }
.note-card .note-body { white-space: pre-wrap; max-height: 4.4em; overflow: hidden; color: var(--text); font-size: 14.5px; margin-top: 2px; }
.note-card .thumbs { display: flex; gap: 6px; margin-top: 8px; }
.note-card .thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; }
.tag { font-size: 12px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 32px 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 4px 2px; }
.fact { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14.5px; }
.fact:last-child { border: 0; }
.fact button { border: 0; background: none; color: var(--muted); cursor: pointer; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--p4); margin-right: 6px; }
.status-dot.on { background: var(--accent); }

/* sheet */
.sheet { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.4); }
.sheet-body { position: relative; width: 100%; max-width: 640px; max-height: 88dvh; overflow-y: auto; background: var(--bg);
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(env(safe-area-inset-bottom) + 18px); animation: up .18s ease-out; }
.sheet-body h3 { margin: 0 0 14px; }
.sheet-body img.full, .sheet-body video { width: 100%; border-radius: 12px; margin: 8px 0; }
@keyframes up { from { transform: translateY(30px); opacity: .5; } to { transform: none; opacity: 1; } }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 80px); background: var(--text); color: var(--bg);
  padding: 9px 16px; border-radius: 999px; font-size: 14px; z-index: 30; max-width: 90%; }
@media (min-width: 761px) { .app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); } }

/* v2: top actions, health, bills, security */
.top-actions { display: flex; gap: 2px; align-items: center; }
.tabbar a span { font-size: 10.5px; }
.snap-row { display: flex; gap: 8px; margin: 4px 0 10px; }
.snap-btn { flex: 2; text-align: center; cursor: pointer; }
.snap-row .btn:not(.snap-btn) { flex: 1; }
.verdict { display: inline-block; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 2px 8px; border-radius: 6px; color: #fff; }
.v-great, .v-good { background: var(--good); } .v-okay { background: var(--p3); } .v-limit { background: var(--p2); } .v-avoid { background: var(--danger); }
.meal-card .headline { font-weight: 600; font-size: 16.5px; margin: 6px 0 4px; }
.meal-card img.photo { width: 100%; max-height: 220px; object-fit: cover; border-radius: 10px; margin-bottom: 8px; }
.macros { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 8px 0; text-align: center; }
.macros div { background: var(--surface-2); border-radius: 8px; padding: 6px 2px; }
.macros b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; }
.macros span { font-size: 11px; color: var(--muted); }
.flag { display: inline-block; font-size: 12px; border: 1px solid var(--p2); color: var(--p2); border-radius: 6px; padding: 1px 6px; margin: 2px 4px 2px 0; }
.meter { margin: 8px 0; }
.meter .lbl { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 3px; }
.meter .lbl b { font-variant-numeric: tabular-nums; font-weight: 600; }
.meter .track { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.meter .fill { height: 100%; border-radius: 4px; background: var(--accent); }
.meter .fill.over { background: var(--p2); }
.meal-row { display: flex; gap: 10px; align-items: center; cursor: pointer; }
.meal-row img, .meal-row .ph { width: 48px; height: 48px; border-radius: 8px; object-fit: cover; background: var(--surface-2); flex-shrink: 0; display: grid; place-items: center; }
.meal-row .grow { flex: 1; min-width: 0; }
.meal-row .kcal { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 21px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.stat .s { font-size: 12px; color: var(--muted); }
.stat.alert .v { color: var(--danger); }
.quick-metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.quick-metrics button { padding: 9px 4px; font-size: 13px; }
.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; stroke: none; stroke-width: 0; }
.qr svg { stroke: none; }
.qr svg path { fill: #000; }
.chart .bar { fill: var(--accent); }
.chart .bar.over { fill: var(--p2); }
.chart .bar.empty { fill: var(--surface-2); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .target { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 3; }
.chart .axis { fill: var(--muted); font-size: 10px; font-family: var(--font); }
.chart .base { stroke: var(--line); stroke-width: 1; }
.tip { position: absolute; pointer-events: none; background: var(--text); color: var(--bg); font-size: 12px; padding: 5px 8px; border-radius: 6px; white-space: nowrap; transform: translate(-50%, 0); top: 0; z-index: 2; box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.bill-row { display: flex; gap: 10px; align-items: center; }
.bill-row .grow { flex: 1; min-width: 0; cursor: pointer; }
.bill-row .amt { font-weight: 650; font-variant-numeric: tabular-nums; text-align: right; }
.badge { font-size: 11px; border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; color: var(--muted); }
.badge.warn { border-color: var(--p2); color: var(--p2); }
.badge.bad { border-color: var(--danger); color: var(--danger); }
.qr { background: #fff; padding: 10px; border-radius: 12px; width: 220px; margin: 10px auto; }
.qr svg { width: 100%; height: auto; display: block; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; word-break: break-all; }
.session { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.session:last-child { border: 0; }
.disclaimer { font-size: 11.5px; color: var(--muted); text-align: center; margin: 14px 0 4px; }
.msg-md p { margin: 0 0 6px; } .msg-md ul, .msg-md ol { margin: 4px 0 6px; padding-left: 20px; }
