:root {
  --bg: #F7F3EC;
  --surface: #FFFFFF;
  --surface-2: #F1EBE0;
  --ink: #1E1C18;
  --muted: #6B665C;
  --line: #E6DFD2;
  --accent: #2D6A4F;
  --accent-ink: #FFFFFF;
  --accent-soft: #E2EEE7;
  --user: #2D6A4F;
  --user-ink: #FFFFFF;
  --protein: #3B6FB6;
  --carbs: #C98E12;
  --fat: #D0603A;
  --fiber: #6E8B3D;
  --danger: #B3261E;
  --warn-bg: #FFF4DB;
  --warn-ink: #7A5200;
  --shadow: 0 1px 2px rgba(30, 28, 24, .06), 0 4px 16px rgba(30, 28, 24, .06);
  --radius: 18px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141310; --surface: #1E1C18; --surface-2: #26231E; --ink: #F1ECE2; --muted: #A39C8E;
    --line: #34302A; --accent: #6FC79A; --accent-ink: #0E1A14; --accent-soft: #1F3329;
    --user: #2F5E47; --user-ink: #F1ECE2;
    --protein: #7EA6E0; --carbs: #E6B44A; --fat: #EE8A66; --fiber: #A7C26E;
    --danger: #F2B8B5; --warn-bg: #3A2F14; --warn-ink: #F3D58A;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141310; --surface: #1E1C18; --surface-2: #26231E; --ink: #F1ECE2; --muted: #A39C8E;
  --line: #34302A; --accent: #6FC79A; --accent-ink: #0E1A14; --accent-soft: #1F3329;
  --user: #2F5E47; --user-ink: #F1ECE2;
  --protein: #7EA6E0; --carbs: #E6B44A; --fat: #EE8A66; --fiber: #A7C26E;
  --danger: #F2B8B5; --warn-bg: #3A2F14; --warn-ink: #F3D58A;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--font);
  font-size: 16px; line-height: 1.45; -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
#app { height: 100dvh; max-width: 680px; margin: 0 auto; position: relative; }
.screen { height: 100%; }
.screen.center { display: grid; place-items: center; padding: 24px 16px; }
.screen.scroll { overflow-y: auto; }

/* ---------- basics ---------- */
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 600; cursor: pointer; text-decoration: none;
  transition: transform .08s ease, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.block { width: 100%; }
.btn.link { background: none; border: none; color: var(--muted); min-height: 40px; font-weight: 500; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.icon-btn {
  width: 40px; height: 40px; display: inline-grid; place-items: center; flex: none;
  border: none; background: none; border-radius: 12px; cursor: pointer; color: var(--ink);
}
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.icon-btn:hover { background: var(--surface-2); }
.chip-btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 2px 10px; font-size: 13px; font-weight: 600; cursor: pointer; margin-left: 8px;
}

.stack { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; border: 0; padding: 0; margin: 0; min-width: 0; }
.field > span, .field > legend { font-size: 14px; font-weight: 600; color: var(--muted); padding: 0; }
.field em { font-style: normal; font-weight: 400; opacity: .8; }
.field input, .field select {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); outline: none;
}
.field input:focus, .field select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.row2 { display: grid; grid-template-columns: 1fr 1.4fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 3px; min-height: 48px; }
.seg label { display: grid; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: grid; place-items: center; border-radius: 9px; font-weight: 600; color: var(--muted); }
.seg input:checked + span { background: var(--accent); color: var(--accent-ink); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.form-error { color: var(--danger); font-size: 14px; margin: 0; min-height: 0; }
.form-error:empty { display: none; }
.hint, .fine { color: var(--muted); font-size: 14px; margin: 0; }
.lede { color: var(--muted); margin: 4px 0 0; }

/* ---------- login ---------- */
.auth-card { width: 100%; max-width: 380px; }
.brand-mark svg { width: 56px; height: 56px; display: block; }
.app-name { font-size: 30px; letter-spacing: -.02em; margin: 14px 0 0; font-weight: 800; }
.app-name.small { font-size: 18px; margin: 0; }
.auth-card .lede { margin-bottom: 24px; }
.auth-tabs { margin-bottom: 18px; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 72px; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: none; color: var(--accent); font-weight: 600; font-size: 14px; padding: 8px 10px; cursor: pointer; border-radius: 8px; }
.form-ok { color: var(--accent); font-size: 14px; margin: 0; }
.form-ok:empty { display: none; }

/* ---------- onboarding ---------- */
.onboard { padding: 20px 16px 40px; }
.onboard-head { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 22px; }
.onboard-head h1 { font-size: 26px; letter-spacing: -.02em; margin: 6px 0 0; line-height: 1.2; }

/* ---------- chat layout ---------- */
.chat { display: flex; flex-direction: column; }
.topbar {
  padding: max(10px, env(safe-area-inset-top)) 16px 12px; background: var(--bg);
  border-bottom: 1px solid var(--line); position: relative; z-index: 2;
}
.topbar-row { display: flex; align-items: center; justify-content: space-between; }
.title-wrap { display: flex; align-items: center; gap: 10px; min-width: 0; }
.access {
  font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); white-space: nowrap; border: none; cursor: pointer;
}
.access.expired { background: var(--warn-bg); color: var(--warn-ink); }
.menu {
  position: absolute; right: 12px; top: calc(100% - 18px); background: var(--surface);
  border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 6px;
  min-width: 210px; z-index: 5;
}
.menu button { display: block; width: 100%; text-align: left; padding: 11px 12px; border: 0; background: none; border-radius: 10px; cursor: pointer; }
.menu button:hover { background: var(--surface-2); }

.today { margin-top: 10px; }
.today-nums { font-size: 15px; color: var(--muted); }
.today-nums b { font-size: 22px; color: var(--ink); font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.meter { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 6px 0 4px; }
.meter i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .6s ease; }
.meter i.over { background: var(--fat); }
.today-left { font-size: 13px; color: var(--muted); }

.banner {
  margin: 10px 16px 0; padding: 10px 14px; border-radius: 12px; font-size: 14px;
  background: var(--warn-bg); color: var(--warn-ink); display: flex; gap: 10px; align-items: center; justify-content: space-between;
}
.banner .chip-btn { flex: none; }

.messages { flex: 1; overflow-y: auto; padding: 16px 16px 8px; display: flex; flex-direction: column; gap: 12px; overscroll-behavior: contain; }

.msg { max-width: 88%; }
.msg.user { align-self: flex-end; }
.msg.bot { align-self: flex-start; width: 100%; max-width: 100%; }
.bubble { padding: 10px 14px; border-radius: var(--radius); }
.msg.user .bubble { background: var(--user); color: var(--user-ink); border-bottom-right-radius: 6px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.bot .bubble { background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg-time { font-size: 11px; color: var(--muted); margin-top: 3px; text-align: right; }
.msg.bot .msg-time { text-align: left; }
.thumbs { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; margin-bottom: 6px; }
.thumbs img { width: 76px; height: 76px; object-fit: cover; border-radius: 12px; display: block; }
.photo-count { font-size: 13px; opacity: .85; display: block; }

.welcome h3 { margin: 0 0 6px; font-size: 17px; }
.welcome p { margin: 0 0 8px; }
.welcome ul { margin: 0; padding-left: 18px; color: var(--muted); }
.welcome li { margin: 3px 0; }

.typing { display: inline-flex; gap: 5px; align-items: center; color: var(--muted); font-size: 14px; }
.dots { display: inline-flex; gap: 4px; margin-right: 6px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: bob 1s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .15s; } .dots i:nth-child(3) { animation-delay: .3s; }
@keyframes bob { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* ---------- report card ---------- */
.report { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); border-bottom-left-radius: 6px; overflow: hidden; box-shadow: var(--shadow); }
.report-head { padding: 14px 16px 10px; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.report-head h3 { margin: 0; font-size: 17px; line-height: 1.25; }
.conf { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kcal-big { text-align: right; flex: none; }
.kcal-big b { font-size: 28px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; display: block; line-height: 1; }
.kcal-big span { font-size: 12px; color: var(--muted); }
.macros { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 0 16px 14px; }
.macro { background: var(--surface-2); border-radius: 12px; padding: 8px 10px; }
.macro b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; }
.macro span { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.macro span::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.macro-bar { display: flex; height: 6px; margin: 0 16px 14px; border-radius: 99px; overflow: hidden; background: var(--surface-2); }
.macro-bar i { display: block; height: 100%; background: var(--c); }
.items { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.items li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.items li:last-child { border-bottom: 0; }
.items .name { font-weight: 600; }
.items .qty { font-size: 13px; color: var(--muted); }
.items .ik { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.items .im { font-size: 12px; color: var(--muted); white-space: nowrap; text-align: right; }
.report-foot { padding: 12px 16px 14px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.report-foot p { margin: 0; }
.micros { display: flex; flex-wrap: wrap; gap: 6px; }
.micros span { font-size: 12px; background: var(--surface-2); padding: 4px 10px; border-radius: 999px; }
.tip { background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; font-size: 14px; }
.tip b { color: var(--accent); }
details.assume summary { cursor: pointer; font-size: 13px; color: var(--muted); font-weight: 600; }
details.assume ul { margin: 6px 0 0; padding-left: 18px; font-size: 13px; color: var(--muted); }
.notfood { color: var(--muted); }
.err-bubble { border-color: var(--danger) !important; }
.err-bubble .retry { margin-top: 8px; }

/* ---------- composer ---------- */
.composer { padding: 8px 12px max(10px, env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); }
.attachments { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 10px; align-items: center; }
.att { position: relative; flex: none; }
.att img { width: 64px; height: 64px; object-fit: cover; border-radius: 12px; display: block; border: 1px solid var(--line); }
.att.loading img { opacity: .45; }
.att button {
  position: absolute; top: -6px; right: -6px; width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--bg); background: var(--ink); color: var(--bg); display: grid; place-items: center; cursor: pointer; padding: 0;
}
.att button svg { width: 12px; height: 12px; }
.att-count { font-size: 12px; color: var(--muted); padding-left: 4px; white-space: nowrap; }
.composer-row { display: flex; align-items: flex-end; gap: 4px; }
.icon-btn.tool { width: 44px; height: 44px; color: var(--muted); }
.icon-btn.tool svg { fill: none; }
textarea#note {
  flex: 1; min-width: 0; resize: none; min-height: 44px; max-height: 140px; padding: 11px 14px;
  border-radius: 22px; border: 1px solid var(--line); background: var(--surface); outline: none; line-height: 1.35;
}
.send {
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; cursor: pointer; flex: none; transition: opacity .15s, transform .08s;
}
.send svg { width: 22px; height: 22px; }
.send:disabled { opacity: .35; cursor: default; }
.send:not(:disabled):active { transform: scale(.94); }

/* ---------- paywall sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(15, 14, 12, .45); display: flex; align-items: flex-end; justify-content: center; z-index: 20; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  background: var(--bg); width: 100%; max-width: 520px; border-radius: 24px 24px 0 0; position: relative;
  padding: 26px 20px max(24px, env(safe-area-inset-bottom)); max-height: 92dvh; overflow-y: auto; animation: rise .25s ease;
}
@keyframes rise { from { transform: translateY(30px); opacity: .6; } }
@media (min-width: 600px) { .sheet-backdrop { align-items: center; } .sheet { border-radius: 24px; } }
.sheet-close { position: absolute; top: 10px; right: 10px; }
.sheet-close svg { fill: none; }
.sheet h2 { margin: 0 0 6px; font-size: 24px; letter-spacing: -.02em; line-height: 1.2; padding-right: 36px; }
.eyebrow { margin: 0 0 4px; font-size: 13px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .06em; }
.price { margin: 0 0 14px; color: var(--muted); }
.price b { font-size: 34px; color: var(--ink); letter-spacing: -.02em; }
.perks { list-style: none; padding: 0; margin: 0 0 20px; display: flex; flex-direction: column; gap: 8px; }
.perks li { padding-left: 28px; position: relative; }
.perks li::before { content: ""; position: absolute; left: 0; top: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--accent-soft); }
.perks li::after { content: ""; position: absolute; left: 6px; top: 6px; width: 5px; height: 8px; border: solid var(--accent); border-width: 0 2px 2px 0; transform: rotate(45deg); }
#pw-offer .fine { margin-top: 10px; text-align: center; }
.qr-wrap { display: flex; flex-direction: column; align-items: center; gap: 12px; margin: 14px 0; }
.qr { background: #fff; padding: 12px; border-radius: 16px; width: 220px; height: 220px; display: grid; place-items: center; border: 1px solid var(--line); }
.qr svg, .qr img { width: 196px; height: 196px; display: block; }
.mobile-only { display: none; }
@media (pointer: coarse) { .mobile-only { display: inline-flex; } }
.pay-details { margin: 0 0 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.pay-details div { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; gap: 10px; }
.pay-details div + div { border-top: 1px solid var(--line); }
.pay-details dt { color: var(--muted); font-size: 14px; }
.pay-details dd { margin: 0; display: flex; align-items: center; min-width: 0; }
.pay-details code { font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
#pw-pay .field { margin: 14px 0 10px; }
#pw-pay .form-error { margin-bottom: 10px; }
.wait-icon { display: grid; place-items: center; height: 56px; }
#pw-wait p, #pw-active p { color: var(--muted); }
#pw-wait .btn, #pw-active .btn { margin-top: 10px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  z-index: 30; max-width: calc(100% - 32px); box-shadow: var(--shadow); animation: fade .2s;
}

@media (max-width: 380px) {
  .row3 { grid-template-columns: 1fr 1fr; }
  .macros { grid-template-columns: repeat(2, 1fr); }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
