:root {
  --bg: #eef2ee;
  --surface: #ffffff;
  --surface-2: #f5f8f4;
  --ink: #1c2a28;
  --ink-2: #566663;
  --line: #d8e0db;
  --olive: #557427;
  --olive-ink: #ffffff;
  --protein: #c9433a;
  --carbs: #c9931a;
  --fat: #2c7c88;
  --satfat: #8a5a3c;
  --water: #3a86d4;
  --danger: #b4362c;
  --plate-empty: #e3e9e4;
  --radius-lg: 22px;
  --radius: 14px;
  --radius-sm: 9px;
  color-scheme: light;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121918;
    --surface: #1b2423;
    --surface-2: #222d2c;
    --ink: #e4ebe7;
    --ink-2: #98a8a4;
    --line: #2e3b39;
    --olive: #8db352;
    --olive-ink: #142008;
    --protein: #ef6b60;
    --carbs: #e6b440;
    --fat: #4fb2bf;
    --satfat: #d39a72;
    --water: #63a6ec;
    --danger: #ef6b60;
    --plate-empty: #2a3634;
    color-scheme: dark;
  }
}
*, *::before, *::after { box-sizing: inherit; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Commissioner", "Noto Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2.5px solid var(--olive); outline-offset: 2px; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
#app { max-width: 560px; margin: 0 auto; padding: 0 16px calc(96px + env(safe-area-inset-bottom, 0px)); }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 14px 0 6px; gap: 8px; }
.topbar h1 { font-size: 1.5rem; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.datenav { display: flex; align-items: center; gap: 4px; }
.datenav button { background: none; border: 0; width: 40px; height: 40px; border-radius: 50%; font-size: 1.3rem; color: var(--ink-2); }
.datenav button:hover { background: var(--surface); }
.datenav .label { font-weight: 600; min-width: 110px; text-align: center; background: none; border: 0; padding: 6px 4px; border-radius: 10px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--surface); border-top: 1px solid var(--line);
  display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabs .inner { display: grid; grid-template-columns: repeat(5, 1fr); width: 100%; max-width: 560px; }
.tabs button {
  background: none; border: 0; padding: 9px 2px 10px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 0.72rem; color: var(--ink-2); font-weight: 500;
}
.tabs button svg { width: 24px; height: 24px; }
.tabs button[aria-current="page"] { color: var(--olive); font-weight: 700; }

.card { background: var(--surface); border-radius: var(--radius-lg); padding: 18px; margin: 12px 0; }
.card h2 { font-size: 1.05rem; margin: 0 0 10px; font-weight: 700; }
.muted { color: var(--ink-2); }
.small { font-size: 0.85rem; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

/* ---------- plate ---------- */
.plate-wrap { display: grid; grid-template-columns: 1fr; justify-items: center; padding-top: 4px; }
.plate { width: min(280px, 78vw); aspect-ratio: 1; position: relative; }
.plate svg { width: 100%; height: 100%; display: block; overflow: visible; }
.plate .center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; }
.plate .big { font-size: 2.6rem; font-weight: 750; line-height: 1; letter-spacing: -0.02em; }
.plate .over { color: var(--danger); }
.plate-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px; margin-top: 12px; font-size: 0.85rem; color: var(--ink-2); }
.plate-legend span b { color: var(--ink); font-weight: 600; }

.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 18px; }
.macro .name { font-size: 0.82rem; color: var(--ink-2); }
.macro .val { font-weight: 650; }
.bar { height: 8px; border-radius: 99px; background: var(--plate-empty); overflow: hidden; margin: 5px 0 3px; }
.bar > i { display: block; height: 100%; border-radius: 99px; transition: width .35s ease; }
.bar.over > i { background-image: repeating-linear-gradient(45deg, transparent 0 4px, rgba(255,255,255,.35) 4px 8px); }

/* ---------- water ---------- */
.water-top { display: flex; align-items: baseline; justify-content: space-between; }
.water-amount { font-size: 1.6rem; font-weight: 700; color: var(--water); }
.drops { display: flex; flex-wrap: wrap; gap: 5px; margin: 10px 0 12px; }
.drops i { width: 18px; height: 26px; border-radius: 5px 5px 7px 7px; border: 2px solid var(--water); opacity: .35; }
.drops i.on { background: var(--water); opacity: 1; }
.drops i.half { background: linear-gradient(to top, var(--water) 50%, transparent 50%); opacity: 1; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- buttons & inputs ---------- */
.btn {
  border: 0; border-radius: 99px; padding: 10px 16px; font-weight: 600; background: var(--surface-2); color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px;
}
.btn:hover { filter: brightness(0.97); }
.btn.primary { background: var(--olive); color: var(--olive-ink); }
.btn.water { background: color-mix(in srgb, var(--water) 16%, transparent); color: var(--water); }
.btn.ghost { background: none; color: var(--ink-2); padding: 8px 10px; }
.btn.danger { background: none; color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.iconbtn { background: none; border: 0; width: 38px; height: 38px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: var(--ink-2); }
.iconbtn:hover { background: var(--surface-2); }

label.field { display: block; margin: 10px 0; }
label.field > span { display: block; font-size: 0.84rem; color: var(--ink-2); margin-bottom: 4px; }
input[type=text], input[type=number], input[type=search], input[type=password], input[type=date], select, textarea {
  width: 100%; padding: 11px 13px; border-radius: var(--radius-sm); border: 1.5px solid var(--line); background: var(--surface-2);
  min-height: 44px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--olive); }
textarea { resize: vertical; min-height: 80px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 10px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 8px; }
.suffix { position: relative; }
.suffix input { padding-right: 44px; }
.suffix em { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-style: normal; color: var(--ink-2); font-size: 0.85rem; pointer-events: none; }

/* ---------- meals ---------- */
.meal { background: var(--surface); border-radius: var(--radius-lg); margin: 12px 0; overflow: hidden; }
.meal-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px 10px; }
.meal-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.meal-title { font-weight: 700; }
.meal-kcal { font-weight: 650; }
.meal-progress { height: 4px; background: var(--plate-empty); margin: 0 16px; border-radius: 99px; overflow: hidden; }
.meal-progress i { display: block; height: 100%; }
.items { list-style: none; margin: 6px 0 0; padding: 0; }
.items li { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-top: 1px solid var(--line); cursor: pointer; }
.items li:hover { background: var(--surface-2); }
.items .nm { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.items .sub { font-size: 0.8rem; color: var(--ink-2); }
.items .kc { font-weight: 600; white-space: nowrap; }
.meal-actions { display: flex; gap: 4px; padding: 8px 10px 10px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.meal-actions .btn { min-height: 36px; padding: 6px 12px; font-size: 0.88rem; background: none; color: var(--olive); }
.meal-actions .btn:hover { background: var(--surface-2); }

.mini-macros { display: flex; gap: 10px; font-size: 0.8rem; color: var(--ink-2); }
.mini-macros b { font-weight: 600; }
.p { color: var(--protein); } .c { color: var(--carbs); } .f { color: var(--fat); } .s { color: var(--satfat); }

/* ---------- lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.list li:last-child { border-bottom: 0; }
.list .nm { font-weight: 600; }
.badge { font-size: 0.72rem; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.empty { text-align: center; padding: 26px 10px; color: var(--ink-2); }

/* ---------- sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(10, 20, 18, .45); z-index: 40; animation: fade .18s ease; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 92vh; display: flex; flex-direction: column;
  background: var(--surface); border-radius: 24px 24px 0 0; max-width: 560px; margin: 0 auto;
  animation: up .22s cubic-bezier(.2,.8,.3,1); padding-bottom: env(safe-area-inset-bottom, 0px);
}
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 14px 14px 8px 20px; }
.sheet-head h3 { margin: 0; font-size: 1.15rem; flex: 1; }
.sheet-body { overflow-y: auto; padding: 4px 20px 20px; }
.seg { display: flex; background: var(--surface-2); border-radius: 99px; padding: 4px; gap: 2px; margin: 4px 0 12px; overflow-x: auto; }
.seg button { flex: 1; border: 0; background: none; padding: 8px 10px; border-radius: 99px; font-weight: 600; font-size: 0.88rem; color: var(--ink-2); white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet, .sheet-backdrop { animation: none; } .bar > i { transition: none; } }

#reader { width: 100%; border-radius: var(--radius); overflow: hidden; background: #000; min-height: 220px; }
#reader video { border-radius: var(--radius); }

.food-hero { display: flex; gap: 14px; align-items: center; margin-bottom: 8px; }
.food-hero img { width: 64px; height: 64px; object-fit: contain; border-radius: 10px; background: #fff; }
.notice { padding: 10px 14px; border-radius: var(--radius-sm); background: var(--surface-2); font-size: 0.9rem; margin: 8px 0; }
.notice.ok { background: color-mix(in srgb, var(--olive) 14%, transparent); }
.notice.warn { background: color-mix(in srgb, var(--carbs) 18%, transparent); }
.preview-totals { display: grid; grid-template-columns: repeat(5, 1fr); text-align: center; background: var(--surface-2); border-radius: var(--radius); padding: 10px 4px; margin: 10px 0; }
.preview-totals b { display: block; font-size: 1.15rem; }
.preview-totals span { font-size: 0.75rem; color: var(--ink-2); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.chip { border: 1.5px solid var(--line); background: none; border-radius: 99px; padding: 6px 12px; font-size: 0.86rem; }
.chip:hover { border-color: var(--olive); }

/* ---------- planner ---------- */
.plan-item { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.plan-item .g { font-size: 1.25rem; font-weight: 700; min-width: 64px; text-align: right; }
.plan-item .lock { font-size: 0.78rem; }
.plan-item input[type=number] { width: 84px; min-height: 36px; padding: 6px 30px 6px 8px; }
.plan-item .lock { display: inline-flex; align-items: center; gap: 6px; margin-top: 4px; color: var(--ink-2); }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; gap: 10px; padding: 8px 0 140px; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 18px; white-space: normal; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--olive); color: var(--olive-ink); border-bottom-right-radius: 6px; }
.msg.assistant { align-self: flex-start; background: var(--surface); border-bottom-left-radius: 6px; }
.msg p { margin: 0 0 6px; } .msg p:last-child { margin: 0; }
.msg ul { margin: 4px 0; padding-left: 20px; }
.composer { position: fixed; left: 0; right: 0; bottom: calc(62px + env(safe-area-inset-bottom, 0px)); z-index: 15; padding: 10px 16px; background: linear-gradient(to top, var(--bg) 70%, transparent); }
.composer .inner { max-width: 528px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 46px; max-height: 140px; border-radius: 22px; padding: 12px 16px; background: var(--surface); }
.typing::after { content: "…"; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .3; } }

/* ---------- stats ---------- */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.kpi { background: var(--surface-2); border-radius: var(--radius); padding: 12px; }
.kpi b { display: block; font-size: 1.3rem; }
.kpi span { font-size: 0.8rem; color: var(--ink-2); }
.chart-box { position: relative; height: 220px; }

/* ---------- toast & login ---------- */
.toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 16px; z-index: 60; font-weight: 600; font-size: 0.9rem; animation: fade .2s; width: max-content; max-width: min(90vw, 420px); text-align: center; }
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login .card { width: 100%; max-width: 360px; }
.sum-line { display: flex; justify-content: space-between; padding: 8px 0; font-size: 0.9rem; }
.meal-edit { display: grid; grid-template-columns: 1fr 110px auto; gap: 8px; align-items: center; margin-bottom: 8px; }
a.btn { text-decoration: none; }

input[type=checkbox] { width: 18px; height: 18px; min-height: 0; accent-color: var(--olive); margin: 0; flex: none; }
label.small.row { gap: 8px; }
input[type=number] { -moz-appearance: textfield; appearance: textfield; }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.grid3 .suffix input { padding-left: 10px; padding-right: 30px; }
.grid3 .suffix em { right: 9px; }

.satfat-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.satfat-row .name { font-size: 0.82rem; color: var(--ink-2); }
.satfat-row .bar { margin: 0; }
.satfat-row .val { font-weight: 650; white-space: nowrap; }
.preview-totals b { font-size: 1.05rem; }

.badge.recipe { background: color-mix(in srgb, var(--olive) 16%, transparent); color: var(--olive); }
.btn-row.three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.btn-row.three .btn { padding: 8px 6px; font-size: 0.9rem; white-space: nowrap; }
.btn-row.three .btn svg { width: 18px; height: 18px; }
