:root {
  --bg: #faf7f2; --card: #ffffff; --ink: #1f1d1a; --muted: #5f5a53; --line: #e6e0d6;
  --accent: #d9622b; --accent-ink: #ffffff; --accent-soft: #fbe6da;
  --ok: #2f7d4f; --warn: #b4581b; --bad: #b3261e;
  --p: #3d6fb6; --c: #c4912a; --f: #8a5a9e;
  --radius: 14px; --tab-h: 64px;
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", "Leelawadee UI", "Sarabun", sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-padding-bottom: calc(var(--tab-h) + 20px + env(safe-area-inset-bottom)); scroll-padding-top: 12px; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); }
body { line-height: 1.55; font-size: 16px; overflow-x: hidden; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; line-height: 1.5; color: inherit; }
input, select, textarea { font-size: 16px; }
.view { max-width: 560px; margin: 0 auto; padding: 12px 14px calc(var(--tab-h) + 24px + env(safe-area-inset-bottom)); }
.loading { color: var(--muted); text-align: center; padding: 40px 0; }
h1 { font-size: 22px; margin: 6px 0 12px; line-height: 1.5; }
h2 { font-size: 18px; margin: 0 0 8px; line-height: 1.5; }
h3 { font-size: 16px; margin: 0 0 6px; line-height: 1.5; }
p { margin: 6px 0; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: 0 0 12px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; min-width: 44px;
  padding: 8px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); cursor: pointer; text-decoration: none; color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.accent { background: var(--accent-soft); border-color: #f0b896; color: #8f3a12; font-weight: 600; }
.btn.danger { color: var(--bad); border-color: #e7c2bf; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.sel, .chip.sel { background: var(--accent-soft); border-color: var(--accent); color: #7a3210; font-weight: 600; }
.chip { display: inline-flex; align-items: center; min-height: 44px; padding: 6px 12px; border-radius: 22px; border: 1px solid var(--line); background: var(--card); cursor: pointer; }
.field { display: block; margin: 0 0 12px; }
.field > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .input { width: 100%; min-height: 44px; padding: 8px 12px; border: 1px solid #cfc7ba; border-radius: 10px; background: #fff; }
.field input:focus, .field select:focus, .input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.err { color: var(--bad); font-size: 14px; margin-top: 4px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg .btn { flex: 1 1 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; }
.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 10px; background: #fff1d6; color: #7a4a00; border: 1px solid #f0d49a; line-height: 1.6; }
.badge.raw { background: #eef3fb; color: #2b4f86; border-color: #c9d8ef; }
/* tab bar */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); z-index: 20; }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: var(--tab-h);
  color: var(--muted); text-decoration: none; font-size: 13px; line-height: 1.5; }
.tabbar a .ti { font-size: 16px; line-height: 1.3; }
.tabbar a.on { color: var(--accent); font-weight: 600; }
/* today */
.datebar { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.datebar .label { flex: 1; text-align: center; font-weight: 600; font-size: 17px; }
.big { font-size: 34px; font-weight: 700; line-height: 1.3; }
.unit { font-size: 14px; color: var(--muted); margin-left: 3px; }
.bar { height: 10px; border-radius: 6px; background: #efe9df; overflow: hidden; margin: 4px 0 2px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.bar.p > i { background: var(--p); } .bar.c > i { background: var(--c); } .bar.f > i { background: var(--f); }
.bar.over > i { background: var(--bad); }
.macro { min-width: 0; }
.macro .v { font-weight: 600; }
.meal-head { display: flex; align-items: center; gap: 8px; }
.meal-head h2 { margin: 0; flex: 1; }
.entry { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 48px; padding: 6px 0; border: 0; border-top: 1px solid var(--line);
  background: transparent; text-align: left; cursor: pointer; }
.entry .nm { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.entry .kc { white-space: nowrap; font-weight: 600; }
.leu { font-size: 14px; margin: 6px 0 2px; }
.leu.reached { color: var(--ok); } .leu.below { color: var(--warn); } .leu.incomplete { color: var(--muted); }
.meal-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.meal-actions .btn { flex: 1 1 auto; }
/* add */
.tabs { display: flex; gap: 4px; margin: 10px 0; }
.tabs .btn { flex: 1; padding: 6px 4px; font-size: 15px; }
.food { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 52px; padding: 8px 10px; border: 0; border-bottom: 1px solid var(--line);
  background: #fff; text-align: left; cursor: pointer; }
.food .nm { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.food .kc { white-space: nowrap; color: var(--muted); font-size: 14px; }
.list { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: #fff; }
.empty { padding: 18px 14px; text-align: center; color: var(--muted); }
/* sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(20, 16, 10, .38); z-index: 30; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; max-height: 88vh; overflow-y: auto; background: #fff; z-index: 31;
  border-radius: 18px 18px 0 0; padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); max-width: 560px; margin: 0 auto; }
.sheet .sheet-top { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 6px; }
.sheet .sheet-top h2 { flex: 1; margin: 6px 0 0; overflow-wrap: anywhere; }
.facts { font-size: 14px; color: var(--muted); }
.preview { background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; margin: 10px 0; }
.preview .big { font-size: 26px; }
.star { font-size: 22px; color: #b8b0a3; }
.star.on { color: var(--accent); }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + 16px + env(safe-area-inset-bottom)); z-index: 40;
  background: #2a2622; color: #fff; padding: 10px 16px; border-radius: 12px; max-width: 92vw; display: flex; gap: 10px; align-items: center; }
.toast button { background: transparent; color: #ffc9a8; border: 0; min-height: 44px; min-width: 44px; font-weight: 600; cursor: pointer; }
.update-banner { position: sticky; top: 0; z-index: 25; }
.update-banner button { width: 100%; min-height: 48px; border: 0; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; }
/* charts */
.chart svg { display: block; width: 100%; height: auto; }
.chart text { font-size: 11px; fill: var(--muted); font-family: inherit; }
.notready { color: var(--muted); background: #f2eee7; border-radius: 10px; padding: 10px; }
table.simple { width: 100%; border-collapse: collapse; font-size: 14px; }
table.simple td { padding: 6px 4px; border-top: 1px solid var(--line); }
.hide { display: none !important; }
