:root {
  --bg: #f6f5f1; --card: #ffffff; --ink: #1c1b18; --muted: #6b675e; --line: #e6e3da;
  --accent: #0f766e; --accent-soft: #d8efec; --warn: #b45309; --warn-soft: #fbecd6;
  --bad: #b91c1c; --bad-soft: #fbe1e1; --good: #15803d;
  --p: #2563eb; --c: #d97706; --f: #9333ea; --z: #e23744;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12130f; --card: #1c1d18; --ink: #ecebe6; --muted: #a29e93; --line: #2d2e28;
    --accent: #2dd4bf; --accent-soft: #123a36; --warn: #f59e0b; --warn-soft: #3a2a10;
    --bad: #f87171; --bad-soft: #3b1515; --good: #4ade80;
    --p: #60a5fa; --c: #fbbf24; --f: #c084fc; --z: #fb7185; --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #12130f; --card: #1c1d18; --ink: #ecebe6; --muted: #a29e93; --line: #2d2e28;
  --accent: #2dd4bf; --accent-soft: #123a36; --warn: #f59e0b; --warn-soft: #3a2a10;
  --bad: #f87171; --bad-soft: #3b1515; --good: #4ade80;
  --p: #60a5fa; --c: #fbbf24; --f: #c084fc; --z: #fb7185; --shadow: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); font-size: 13px; }
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--bg); border-bottom: 1px solid var(--line); }
.top > div { text-align: center; }
#dateLabel { font-weight: 650; font-size: 17px; }
.navbtn { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); font-size: 20px; }
main { max-width: 640px; margin: 0 auto; padding: 12px 16px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
main > *, .summary > * { min-width: 0; }
html, body { overflow-x: hidden; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 8px; font-size: 14px; letter-spacing: .02em; text-transform: uppercase; color: var(--muted); font-weight: 650; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.summary { display: grid; grid-template-columns: 132px 1fr; gap: 14px; align-items: center; }
.ring text { fill: var(--ink); }
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; }
.macro { display: grid; gap: 3px; margin-bottom: 8px; font-size: 13px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 6px 12px; font-size: 13px; white-space: nowrap; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.tip { border-left: 4px solid var(--accent); }
.tip.warn { border-left-color: var(--warn); }
.tip.bad { border-left-color: var(--bad); }
.slot { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px; }
.slot:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }
.slot-h { display: flex; justify-content: space-between; align-items: center; font-weight: 650; margin-bottom: 4px; }
.item { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.item .name { flex: 1; min-width: 0; }
.item .name small { display: block; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kc { font-variant-numeric: tabular-nums; text-align: right; min-width: 64px; font-size: 13px; }
.qty { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 99px; }
.qty button { border: 0; background: none; width: 28px; height: 28px; }
.qty span { min-width: 26px; text-align: center; font-size: 13px; }
.x { border: 0; background: none; color: var(--muted); width: 28px; height: 28px; }
.add { border: 1px dashed var(--accent); color: var(--accent); background: none; border-radius: 99px; padding: 3px 10px; font-size: 13px; }
.ztag { color: var(--z); font-weight: 650; font-size: 11px; letter-spacing: .03em; }
.btn { border: 0; background: var(--accent); color: #fff; border-radius: 10px; padding: 10px 14px; font-weight: 600; }
.btn.ghost { background: none; color: var(--accent); border: 1px solid var(--accent); }
input[type=number], input[type=text], input[type=search], select, textarea {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; width: 100%; }
label.f { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.supp { display: flex; gap: 10px; align-items: flex-start; padding: 7px 0; }
.supp input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--accent); flex: none; }
.supp.done .sname { text-decoration: line-through; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 10px; }
.list li { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; font-size: 14px; }
.list { margin: 0; padding: 0; list-style: none; }
.tabs { position: fixed; bottom: 0; left: 0; right: 0; display: grid; grid-template-columns: repeat(4, 1fr); background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
.tabs button { border: 0; background: none; padding: 12px 4px; font-weight: 600; color: var(--muted); }
.tabs button.on { color: var(--accent); }
#toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 8px 14px; border-radius: 99px; font-size: 13px; opacity: 0; transition: opacity .2s; pointer-events: none; }
#toast.show { opacity: .92; }
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.login { max-width: 360px; margin: 18vh auto 0; }
@media (max-width: 380px) { .summary { grid-template-columns: 112px 1fr; } .grid4 { grid-template-columns: 1fr 1fr; } }
