:root {
  --bg: #f3f5f2;
  --card: #ffffff;
  --text: #1c2420;
  --muted: #637068;
  --line: #dfe5e0;
  --accent: #1f7a4d;
  --accent-soft: #e2f2e9;
  --warn: #b5472a;
  --deal: #d1392b;
  --c-supermarket: #2b6cb0;
  --c-discount: #d69e2e;
  --c-beverages: #6b46c1;
  --c-bakery: #b7791f;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111613;
    --card: #1b221e;
    --text: #e7ece9;
    --muted: #93a098;
    --line: #2c3530;
    --accent: #3fb07a;
    --accent-soft: #1f3a2c;
    --warn: #e0785c;
    --deal: #ff6b5b;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
}
a { color: var(--accent); }
h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
h3 { font-size: 1rem; margin: 0 0 .4rem; }

.topbar {
  position: sticky; top: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--accent); color: #fff;
}
.brand { font-weight: 700; font-size: 1.1rem; }
.loc-badge {
  background: rgba(255,255,255,.18); color: #fff; border: 0; border-radius: 999px;
  padding: 5px 12px; font-size: .85rem; max-width: 60vw;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

main { max-width: 720px; margin: 0 auto; padding: 12px 16px; }
.tab { display: none; }
.tab.active { display: block; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.muted { color: var(--muted); font-size: .88rem; margin: .4rem 0; }
.hidden { display: none !important; }

.row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row > input[type=text], .row > input[type=search] { flex: 1; min-width: 0; }

input[type=text], input[type=search], input[type=number], select {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px;
}
input.small, select.small { width: 9rem; padding: 6px 9px; }

.btn {
  font: inherit; cursor: pointer; border-radius: 10px; padding: 9px 14px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.wide { width: 100%; margin-top: 4px; }
.btn.tiny { padding: 4px 9px; font-size: .85rem; }
.btn.danger { color: var(--warn); }
.btn:disabled { opacity: .5; }

.slider { display: block; margin: 8px 0; }
.slider input { width: 100%; accent-color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip {
  border: 1px solid var(--line); border-radius: 999px; padding: 5px 11px;
  background: var(--card); color: var(--text); font: inherit; font-size: .88rem; cursor: pointer;
}
.chip.on { background: var(--accent-soft); border-color: var(--accent); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }

.map { height: 320px; border-radius: var(--radius); border: 1px solid var(--line); margin-bottom: 12px; z-index: 0; }

/* Marktliste */
.chain { border-top: 1px solid var(--line); }
.chain:first-child { border-top: 0; }
.chain-head { display: flex; align-items: center; gap: 8px; padding: 10px 0; cursor: pointer; }
.chain-head .name { flex: 1; font-weight: 600; }
.chain-head .count { color: var(--muted); font-size: .85rem; }
.chain-stores { padding: 0 0 8px 18px; }
.store { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: .92rem; }
.store .info { flex: 1; min-width: 0; }
.store .addr { color: var(--muted); font-size: .8rem; }
.off { opacity: .45; }

.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: .15s;
}
.switch span::before {
  content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px;
  border-radius: 50%; background: #fff; transition: .15s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(18px); }

/* Scanner */
.scanbox { position: relative; margin-top: 10px; border-radius: var(--radius); overflow: hidden; background: #000; }
.scanbox video { width: 100%; display: block; max-height: 55vh; object-fit: cover; }
.scanline { position: absolute; left: 10%; right: 10%; top: 50%; height: 2px; background: #f33; box-shadow: 0 0 8px #f33; }
.scanbox .btn { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); }

/* Ergebnisse */
.product-head { display: flex; gap: 12px; align-items: center; }
.product-head img { width: 64px; height: 64px; object-fit: contain; background: #fff; border-radius: 8px; }
.price-row {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 0;
  border-top: 1px solid var(--line);
}
.price-row:first-of-type { border-top: 0; }
.price-row.has-img { grid-template-columns: 56px 1fr auto; }
.price-row.has-img .thumb { grid-row: span 2; }
.price-row.has-img .sub { grid-column: 2 / -1; }
.thumb {
  width: 56px; height: 56px; object-fit: contain; background: #fff;
  border-radius: 8px; border: 1px solid var(--line); cursor: zoom-in; flex: none;
}
.thumb.sm { width: 36px; height: 36px; border-radius: 6px; }
.thumb.xs { width: 28px; height: 28px; border-radius: 5px; vertical-align: middle; margin-right: 6px; }
.lightbox {
  position: fixed; inset: 0; z-index: 3000; background: rgba(0,0,0,.8);
  display: grid; place-items: center; padding: 24px; cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 80vh; background: #fff; border-radius: 12px; padding: 8px; }
.lightbox p { color: #fff; text-align: center; margin: 10px 0 0; }
.price-row .p { font-weight: 700; font-size: 1.1rem; text-align: right; }
.price-row .p.best { color: var(--accent); }
.price-row .p .add { display: block; margin: 4px 0 0 auto; font-size: .78rem; font-weight: 600; color: var(--accent); border-color: var(--accent); }
.price-row .p .add.done { background: var(--accent); color: #fff; }
.price-row .meta { color: var(--muted); font-size: .8rem; }
.price-row .sub { grid-column: 1 / -1; }
.badge {
  display: inline-block; font-size: .72rem; padding: 1px 7px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); margin-right: 4px; font-weight: 600;
}
.badge.deal { background: rgba(209,57,43,.12); color: var(--deal); }
.badge.gray { background: var(--line); color: var(--muted); }
.old { text-decoration: line-through; color: var(--muted); font-weight: 400; font-size: .85rem; margin-right: 4px; }

/* Liste */
.item { display: flex; align-items: center; gap: 8px; }
.item .name { flex: 1; min-width: 0; cursor: pointer; }
.item .best { font-size: .82rem; color: var(--muted); }
.qty { display: flex; align-items: center; gap: 4px; }
.qty b { min-width: 1.4em; text-align: center; }
.item .del { padding: 4px 8px; margin-left: 2px; }
.totalbar {
  position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 900;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--card); border: 2px solid var(--accent); border-radius: var(--radius);
  padding: 10px 14px; margin-top: 12px; box-shadow: 0 -4px 16px rgba(0,0,0,.12);
}
.totalbar .sum { font-size: 1.25rem; }
.totalbar .sum b { color: var(--accent); }
.totalbar .muted { margin: 0; font-size: .8rem; }
.toast.tappable { cursor: pointer; text-decoration: underline; }
.cands { margin-top: 8px; border-top: 1px dashed var(--line); padding-top: 6px; }
.cand { display: flex; gap: 8px; align-items: center; font-size: .88rem; padding: 3px 0; }
.cand .l { flex: 1; min-width: 0; }

/* Plan */
.hero { background: var(--accent); color: #fff; border: 0; }
.hero .big { font-size: 1.6rem; font-weight: 800; margin: 4px 0; }
.hero .muted { color: rgba(255,255,255,.85); }
.stop { border-left: 3px solid var(--accent); padding: 4px 0 4px 12px; margin: 10px 0; }
.stop .t { font-weight: 700; }
.stop ul { margin: 4px 0 0; padding-left: 0; list-style: none; font-size: .92rem; }
.stop li { display: flex; align-items: center; padding: 2px 0; }
.days { width: 100%; border-collapse: collapse; font-size: .9rem; }
.days td, .days th { padding: 6px 4px; border-top: 1px solid var(--line); text-align: left; }
.days tr.bestday td { font-weight: 700; color: var(--accent); }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 1000;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; border: 0; background: none; color: var(--muted); font-size: 1.25rem;
  padding: 8px 0 6px; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer;
}
.tabbar button span { font-size: .72rem; }
.tabbar button.active { color: var(--accent); font-weight: 700; }

.toast {
  position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 2000;
  max-width: 90vw; font-size: .92rem; box-shadow: 0 4px 16px rgba(0,0,0,.3);
}
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid input, .form-grid select { width: 100%; }
