:root {
  --bg: #f6f7f6;
  --surface: #ffffff;
  --surface-2: #eef1ef;
  --text: #17201d;
  --muted: #5d6b66;
  --line: #dde3e0;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --ok: #15803d;
  --low: #b45309;
  --high: #b91c1c;
  --unknown: #7c8a85;
  --bar-bg: #e4e9e6;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1412; --surface: #171e1b; --surface-2: #1f2824; --text: #e8eeeb; --muted: #9aa8a2;
    --line: #2b3632; --accent: #2dd4bf; --accent-ink: #062a26; --ok: #4ade80; --low: #fbbf24; --high: #f87171;
    --unknown: #7f8d88; --bar-bg: #26312d; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1412; --surface: #171e1b; --surface-2: #1f2824; --text: #e8eeeb; --muted: #9aa8a2;
  --line: #2b3632; --accent: #2dd4bf; --accent-ink: #062a26; --ok: #4ade80; --low: #fbbf24; --high: #f87171;
  --unknown: #7f8d88; --bar-bg: #26312d; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }

.top { position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: 1px solid var(--line); }
.top-inner { max-width: 720px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 8px; min-height: 52px; }
.top h1 { font-size: 17px; margin: 0; flex: 1; }
main { max-width: 720px; margin: 0 auto; padding: 12px 16px 24px; }

.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; display: flex; background: var(--surface);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs a { flex: 1; text-align: center; padding: 6px 0 8px; font-size: 11px; color: var(--muted); text-decoration: none; }
.tabs a .ti { display: block; font-size: 20px; line-height: 26px; }
.tabs a.active { color: var(--accent); font-weight: 600; }
.tabs .add-tab .ti { background: var(--accent); color: var(--accent-ink); border-radius: 50%; width: 30px; height: 30px; line-height: 30px; margin: -2px auto 0; }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); padding: 12px 14px; margin-bottom: 12px; }
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 8px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.card h2 .sp { flex: 1; }
.row { display: flex; align-items: center; gap: 8px; }
.row.sb { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stack > * + * { margin-top: 8px; }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 9px 14px; cursor: pointer; min-height: 40px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger { color: var(--high); }
.btn.block { width: 100%; }
.btn.sm { padding: 4px 10px; min-height: 32px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }
.iconbtn { border: none; background: transparent; font-size: 22px; padding: 4px 10px; cursor: pointer; min-width: 40px; min-height: 40px; color: var(--text); }

input[type=text], input[type=number], input[type=search], input[type=password], input[type=date], input:not([type]), select {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 9px 12px; min-height: 42px;
}
input:focus, select:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.field { display: block; margin-bottom: 10px; }
label.field > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 3px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 10px; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; font-size: 13.5px; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: none; }
.item { display: flex; align-items: center; gap: 10px; padding: 9px 2px; cursor: pointer; width: 100%; text-align: left; border: none; background: none; }
.item .t { font-weight: 500; }
.item .s { font-size: 12.5px; color: var(--muted); }

.badge { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--surface-2); color: var(--muted); vertical-align: middle; }
.badge.warn { color: var(--low); }
.badge.bad { color: var(--high); }

/* energy + macros */
.energy { display: flex; align-items: baseline; gap: 6px; }
.energy .big { font-size: 30px; font-weight: 700; }
.bar { height: 8px; background: var(--bar-bg); border-radius: 4px; overflow: hidden; position: relative; }
.bar > i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 4px; background: var(--accent); }
.bar.ok > i { background: var(--ok); } .bar.low > i, .bar.low_incomplete > i { background: var(--low); } .bar.high > i { background: var(--high); }
.bar .range { position: absolute; top: 0; bottom: 0; border-left: 2px solid var(--text); border-right: 2px solid var(--text); opacity: .35; }
.macros { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.macro .v { font-weight: 600; font-size: 16px; }
.macro .l { font-size: 12px; color: var(--muted); }

/* nutrient rows */
.nut { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 7px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.nut:last-child { border-bottom: none; }
.nut .bar { grid-column: 1 / -1; height: 6px; }
.nut .val { text-align: right; font-variant-numeric: tabular-nums; }
.nut .st-low, .nut .st-low_incomplete { color: var(--low); } .nut .st-high { color: var(--high); } .nut .st-ok { color: var(--ok); }
.cov { font-size: 11.5px; color: var(--low); }

/* meals */
.meal-h { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.meal-h h3 { margin: 0; font-size: 15px; flex: 1; }
.entry { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); cursor: pointer; }
.entry .g { color: var(--muted); font-variant-numeric: tabular-nums; }
.pending { opacity: .6; }

/* sheet */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; background: var(--surface); border-radius: 16px 16px 0 0;
  max-height: 88vh; overflow-y: auto; padding: 14px 16px calc(16px + env(safe-area-inset-bottom)); max-width: 720px; margin: 0 auto; }
.sheet h3 { margin: 0 0 10px; font-size: 17px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 30;
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 999px; font-size: 14px; max-width: calc(100% - 32px); }

.qty { font-size: 28px; text-align: center; font-weight: 600; }
.preview { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; gap: 6px; margin: 10px 0; }
.preview b { display: block; font-size: 17px; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tbl td, table.tbl th { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.tbl td.r, table.tbl th.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.tbl input { min-height: 34px; padding: 4px 6px; }

.notice { border-left: 3px solid var(--low); background: var(--surface-2); padding: 8px 10px; border-radius: 6px; font-size: 13.5px; margin-bottom: 10px; }
.notice.info { border-left-color: var(--accent); }
.center { text-align: center; }
video.scan { width: 100%; border-radius: 10px; background: #000; max-height: 50vh; object-fit: cover; }
svg.chart { width: 100%; height: auto; display: block; }
svg.chart text { fill: var(--muted); font-size: 10px; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }
@media (max-width: 380px) { .macros { grid-template-columns: repeat(2, 1fr); } .grid3 { grid-template-columns: 1fr 1fr; } }
