:root {
  --bg: #f6f7f5; --card: #ffffff; --text: #1b1f1c; --muted: #6b726d; --line: #e3e6e3;
  --accent: #1f6f43; --kroger: #1b5fb4; --costco: #c8202f; --danger: #b3261e;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #121513; --card: #1c201d; --text: #e8ebe8; --muted: #98a09a; --line: #2b302c;
    --accent: #4fb07a; --kroger: #6aa3ef; --costco: #ef6a75; --danger: #ef6a63; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; border-radius: 10px; padding: 10px 14px; background: var(--accent); color: #fff; }
input { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.muted { color: var(--muted); }
.err { color: var(--danger); min-height: 1.2em; }
[hidden] { display: none !important; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: 100%; max-width: 360px; display: grid; gap: 10px; }
.login h1 { margin: 0; }

header { position: sticky; top: 0; z-index: 2; background: var(--bg); padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  border-bottom: 1px solid var(--line); }
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: var(--line); padding: 3px; border-radius: 12px; }
.tabs button { background: transparent; color: var(--text); padding: 8px 4px; border-radius: 9px; font-size: 15px; }
.tabs button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,.15); font-weight: 600; }
.tabs .n { color: var(--muted); font-weight: 400; }
.add { display: flex; gap: 6px; margin-top: 8px; }
.add input { flex: 1; min-width: 0; }
.plus { font-size: 22px; padding: 6px 16px; }
.offline { margin-top: 6px; font-size: 13px; color: var(--muted); text-align: center; }

.chip { background: transparent; border: 2px solid var(--line); color: var(--muted); padding: 6px 10px; font-weight: 700; min-width: 42px; }
.chip.k[aria-pressed="true"] { background: var(--kroger); border-color: var(--kroger); color: #fff; }
.chip.c[aria-pressed="true"] { background: var(--costco); border-color: var(--costco); color: #fff; }
.chip.big { flex: 1; padding: 10px; }

main { padding: 8px 12px calc(env(safe-area-inset-bottom) + 80px); max-width: 640px; margin: 0 auto; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 6px 8px 6px 4px; margin: 6px 0; }
.check { width: 48px; height: 48px; flex: none; background: transparent; padding: 0; display: grid; place-items: center; }
.check::before { content: ""; width: 24px; height: 24px; border: 2px solid var(--muted); border-radius: 50%; }
.check.done::before { background: var(--accent); border-color: var(--accent); }
.body { flex: 1; min-width: 0; padding: 6px 0; }
.name { font-weight: 500; overflow-wrap: anywhere; }
.meta { font-size: 13px; color: var(--muted); }
.tags { display: flex; gap: 4px; }
.tag { font-size: 12px; font-weight: 700; padding: 2px 7px; border-radius: 6px; color: #fff; }
.tag.k { background: var(--kroger); } .tag.c { background: var(--costco); }
.list.small li { padding: 2px 8px 2px 4px; }
.list.small .name { font-weight: 400; color: var(--muted); }
.readd { background: transparent; color: var(--accent); padding: 8px; }
.empty { text-align: center; color: var(--muted); padding: 24px 0; }
.bought { margin-top: 18px; }
.bought summary { color: var(--muted); padding: 8px 4px; cursor: pointer; }
.foot { text-align: center; font-size: 13px; margin-top: 24px; }
.foot a { color: var(--muted); }

.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; z-index: 5; }
.panel { width: 100%; max-width: 640px; margin: 0 auto; background: var(--bg); border-radius: 16px 16px 0 0;
  padding: 16px 12px calc(env(safe-area-inset-bottom) + 16px); display: grid; gap: 10px; }
.row { display: flex; gap: 8px; align-items: center; }
.qty { width: 80px; flex: none; }
.grow { flex: 1; }
.ghost { background: transparent; color: var(--text); }
.danger { background: transparent; color: var(--danger); }

.toast { position: fixed; left: 12px; right: 12px; bottom: calc(env(safe-area-inset-bottom) + 14px); z-index: 4;
  max-width: 616px; margin: 0 auto; background: #222; color: #fff; border-radius: 12px; padding: 6px 6px 6px 14px;
  display: flex; align-items: center; gap: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.3); }
.toast span { flex: 1; }
.toast button { background: transparent; color: #8fd8ac; font-weight: 700; }
