:root {
  --bg: #f4f6f4; --card: #fff; --ink: #18211b; --muted: #6a756d; --line: #e3e8e4; --soft: #eef2ee;
  --accent: #16a34a; --accent-ink: #fff;
  --fridge: #2563eb; --fridge-bg: #e6eefd; --freezer: #0891b2; --freezer-bg: #e0f4f8; --pantry: #b7791f; --pantry-bg: #fbefd5;
  --ok: #0f9d6b; --ok-bg: #e3f6ee; --warn: #b7791f; --warn-bg: #fdf1d9; --bad: #d33b3b; --bad-bg: #fde8e8;
  --shadow: 0 1px 2px rgba(20,30,24,.06), 0 4px 16px rgba(20,30,24,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1310; --card: #171d19; --ink: #e8eee9; --muted: #98a59c; --line: #26302a; --soft: #1e2621;
    --accent: #3ddc84; --accent-ink: #0e1310;
    --fridge: #7aa8ff; --fridge-bg: #17284a; --freezer: #5fd3ea; --freezer-bg: #113640; --pantry: #f5c04a; --pantry-bg: #3a2f12;
    --ok: #3ddc97; --ok-bg: #12312a; --warn: #f5c04a; --warn-bg: #3a2f12; --bad: #ff7b7b; --bad-bg: #3b1a1d;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.25);
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; padding-bottom: 96px; -webkit-text-size-adjust: 100%; }
.wrap { max-width: 720px; margin: 0 auto; padding: 0 16px; }
[hidden] { display: none !important; }

header.top { position: sticky; top: 0; z-index: 5; background: var(--card); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top); }
header.top .wrap:first-child { display: flex; align-items: center; gap: 10px; height: 56px; }
h1 { font-size: 20px; margin: 0; letter-spacing: -.02em; }
#search { flex: 1; min-width: 0; margin-left: auto; max-width: 260px; }
.badge { font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--warn-bg); color: var(--warn); cursor: pointer; border: 0; }
.badge.err { background: var(--bad-bg); color: var(--bad); }

.tabs { display: flex; gap: 6px; padding-bottom: 10px; overflow-x: auto; }
.tab { flex: 1; appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 12px; padding: 9px 10px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.tab small { color: var(--muted); font-weight: 500; margin-left: 4px; }
.tab[aria-selected=true] { border-color: transparent; color: #fff; }
.tab[data-loc=fridge][aria-selected=true] { background: var(--fridge); } .tab[data-loc=freezer][aria-selected=true] { background: var(--freezer); } .tab[data-loc=pantry][aria-selected=true] { background: var(--pantry); }
.tab[aria-selected=true] small { color: rgba(255,255,255,.8); }
.tab.all[aria-selected=true] { background: var(--accent); color: var(--accent-ink); }

input, select { font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; min-width: 0; width: 100%; }
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.list { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 10px; }
.item { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 12px 12px 12px 14px; display: flex; align-items: center; gap: 10px; border-left: 4px solid var(--line); }
.item.fridge { border-left-color: var(--fridge); } .item.freezer { border-left-color: var(--freezer); } .item.pantry { border-left-color: var(--pantry); }
.item .main { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; }
.item .name { font-weight: 600; overflow-wrap: anywhere; }
.item .meta { font-size: 13px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 2px; }
.pill { font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px; }
.pill.ok { background: var(--ok-bg); color: var(--ok); } .pill.soon { background: var(--warn-bg); color: var(--warn); } .pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.fridge { background: var(--fridge-bg); color: var(--fridge); } .pill.freezer { background: var(--freezer-bg); color: var(--freezer); } .pill.pantry { background: var(--pantry-bg); color: var(--pantry); }
.stepper { display: flex; align-items: center; gap: 2px; flex: none; }
.stepper button { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--soft); color: var(--ink); font-size: 20px; line-height: 1; cursor: pointer; }
.stepper output { min-width: 44px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.stepper output small { display: block; font-size: 11px; font-weight: 500; color: var(--muted); margin-top: -3px; }
.empty { text-align: center; color: var(--muted); padding: 48px 12px; }

.fab { position: fixed; right: max(18px, env(safe-area-inset-right)); bottom: max(18px, env(safe-area-inset-bottom)); width: 60px; height: 60px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); font-size: 32px; line-height: 1; box-shadow: 0 6px 20px rgba(0,0,0,.28); cursor: pointer; z-index: 6; }

.btn { appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-weight: 600; padding: 9px 16px; border-radius: 10px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; white-space: nowrap; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; }

dialog { border: 0; border-radius: 18px; padding: 0; background: var(--card); color: var(--ink); width: min(520px, calc(100% - 24px)); max-height: calc(100% - 24px); box-shadow: 0 20px 60px rgba(0,0,0,.4); }
dialog::backdrop { background: rgba(8,12,10,.55); }
dialog form, .pad { padding: 18px; } dialog h2 { margin: 0 0 12px; font-size: 18px; }
.sheet { margin: auto auto 12px; padding: 8px; display: none; }
.sheet[open] { display: grid; gap: 6px; }
.menu-btn { appearance: none; border: 0; background: var(--soft); color: var(--ink); font: inherit; font-weight: 600; padding: 16px; border-radius: 12px; cursor: pointer; display: flex; align-items: center; gap: 14px; text-align: left; font-size: 17px; }
.menu-btn span { width: 28px; text-align: center; font-size: 22px; }
.menu-btn.cancel { background: none; justify-content: center; color: var(--muted); }

.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.fields label, .fields .lbl, .lbl { display: grid; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
.fields .wide { grid-column: 1 / -1; }
.row { display: flex; gap: 8px; align-items: center; } .row.between { justify-content: space-between; } .pad.row { padding-bottom: 0; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.chip { appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-weight: 600; padding: 7px 14px; border-radius: 999px; cursor: pointer; }
.chip[aria-pressed=true] { color: #fff; border-color: transparent; }
.chip[data-loc=fridge][aria-pressed=true] { background: var(--fridge); } .chip[data-loc=freezer][aria-pressed=true] { background: var(--freezer); } .chip[data-loc=pantry][aria-pressed=true] { background: var(--pantry); }
.actions { display: flex; gap: 8px; margin-top: 16px; align-items: center; } .actions.pad { margin-top: 0; justify-content: flex-end; }
.grow { flex: 1; }
.hint { color: var(--muted); font-size: 14px; margin: 0 0 10px; } .scan ~ .hint { padding: 8px 18px 0; margin: 0; }
.error { color: var(--bad); font-weight: 600; margin: 12px 0 0; }

.scan { position: relative; background: #000; aspect-ratio: 4 / 3; border-radius: 18px 18px 0 0; overflow: hidden; }
.scan video { width: 100%; height: 100%; object-fit: cover; }
.aim { position: absolute; inset: 22% 10%; border: 3px solid rgba(255,255,255,.85); border-radius: 14px; box-shadow: 0 0 0 999px rgba(0,0,0,.35); }

.rlist { list-style: none; margin: 12px 0; padding: 0; display: grid; gap: 8px; max-height: 45vh; overflow-y: auto; }
.rlist li { display: grid; grid-template-columns: auto 1fr 64px; gap: 8px; align-items: center; }
.rlist input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); }
.file { cursor: pointer; }

.toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 600; z-index: 20; max-width: calc(100% - 32px); box-shadow: var(--shadow); }
@media (max-width: 420px) { #search { max-width: none; } .fields { grid-template-columns: 1fr; } }
