:root {
  --bg: #f4f5f2;
  --card: #ffffff;
  --text: #1c211e;
  --muted: #6b736e;
  --line: #e4e7e2;
  --accent: #1f7a4d;
  --accent-soft: #e3f1e9;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .05);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121513;
    --card: #1c201d;
    --text: #e9ece9;
    --muted: #97a09a;
    --line: #2b302c;
    --accent: #4cc38a;
    --accent-soft: #1f3a2b;
    --danger: #f2948d;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.app { display: flex; flex-direction: column; min-height: 100dvh; max-width: 640px; margin: 0 auto; }

/* Kopfzeile */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.top h1 { font-size: 28px; margin: 0; letter-spacing: -.02em; flex: 1; }
.status { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status.on::before { background: #2fb36d; }
.status.wait::before { background: #e0a526; }
.status.off::before { background: #9aa19c; }
.who { border: 0; background: none; padding: 0; width: 36px; height: 36px; border-radius: 50%; }

/* Liste */
.list { flex: 1; padding: 4px 12px 220px; }
.group { margin: 10px 0 14px; }
.groupTitle {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); margin: 0 6px 6px;
}
.groupTitle .count { margin-left: auto; font-weight: 500; }
.gicon { font-size: 16px; }
.items { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.item {
  display: flex; align-items: center; gap: 12px;
  min-height: 54px; padding: 6px 6px 6px 14px;
  border-top: 1px solid var(--line);
  user-select: none; -webkit-user-select: none;
  cursor: pointer;
}
.item:first-child { border-top: 0; }
.item:active { background: var(--accent-soft); }
.check {
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--muted) 60%, transparent);
  background: none; padding: 0; display: grid; place-items: center; color: transparent;
}
.item.done .check { background: var(--accent); border-color: var(--accent); color: #fff; }
.body { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 8px; }
.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qty { flex: none; font-size: 14px; color: var(--accent); font-weight: 600; }
.item.done .name { text-decoration: line-through; color: var(--muted); }
.item.done .qty { color: var(--muted); }
.badge {
  flex: none; display: inline-grid; place-items: center;
  width: 22px; height: 22px; border-radius: 50%;
  color: #fff; font-size: 11px; font-weight: 700;
}
.badge.big { width: 36px; height: 36px; font-size: 16px; }
.item.done .badge { opacity: .45; }
.more { flex: none; width: 40px; height: 40px; border: 0; background: none; color: var(--muted); border-radius: 10px; display: grid; place-items: center; }

.doneHead { display: flex; align-items: center; justify-content: space-between; margin: 18px 4px 8px; gap: 8px; }
.doneToggle { border: 0; background: none; color: var(--muted); font-size: 14px; font-weight: 600; padding: 8px 4px; }
.finish {
  border: 0; border-radius: 999px; padding: 9px 16px;
  background: var(--accent); color: #fff; font-size: 14px; font-weight: 600;
}
.finish.armed { background: var(--danger); }
.doneGroup .items { opacity: .9; }

.empty { text-align: center; padding: 70px 24px; color: var(--muted); }
.emptyIcon { font-size: 52px; }
.emptyTitle { font-size: 20px; font-weight: 600; color: var(--text); margin: 10px 0 4px; }
.emptyText { margin: 0; }

/* Eingabe unten (Daumenbereich) */
.composer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  max-width: 640px; margin: 0 auto;
  padding: 8px 12px calc(env(safe-area-inset-bottom) + 10px);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.favs { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 10px; scrollbar-width: none; }
.favs::-webkit-scrollbar { display: none; }
.fav {
  flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 7px 13px; font-size: 15px; white-space: nowrap;
}
.fav:active { background: var(--accent-soft); border-color: var(--accent); }
.add { display: flex; gap: 8px; align-items: center; }
.add input {
  flex: 1; min-width: 0; height: 48px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--card);
  font-size: 17px; outline: none;
}
.add input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.iconbtn { flex: none; width: 48px; height: 48px; border-radius: 14px; border: 0; display: grid; place-items: center; }
.addbtn { background: var(--accent); color: #fff; }
.mic { background: var(--card); border: 1px solid var(--line); color: var(--accent); }
.mic.listening { background: var(--danger); color: #fff; border-color: var(--danger); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }

/* Vollbild-Screens */
.screen {
  position: fixed; inset: 0; z-index: 20; background: var(--bg);
  display: grid; place-items: center; padding: 24px;
}
#loginScreen { z-index: 30; }
.screen[hidden] { display: none; }
.card { width: 100%; max-width: 360px; text-align: center; }
.card .logo { font-size: 48px; }
.card h2 { margin: 8px 0 6px; font-size: 24px; }
.card p { color: var(--muted); margin: 0 0 18px; }
.card input {
  width: 100%; height: 50px; padding: 0 16px; margin-bottom: 12px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--card); font-size: 17px;
}
.primary { border: 0; border-radius: 14px; background: var(--accent); color: #fff; font-weight: 600; padding: 13px 20px; }
.card .primary { width: 100%; height: 50px; }
.error { color: var(--danger) !important; }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-bottom: 14px; }
.chip { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 14px 6px 6px; }

/* Bearbeiten */
.sheet {
  border: 0; border-radius: 20px; padding: 20px; width: min(92vw, 420px);
  background: var(--card); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.sheet::backdrop { background: rgba(0, 0, 0, .35); }
.sheet h2 { margin: 0 0 14px; font-size: 20px; }
.sheet label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 12px; }
.sheet input, .sheet select {
  display: block; width: 100%; height: 46px; margin-top: 5px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg); font-size: 17px; font-weight: 400; color: var(--text);
}
.hint { font-weight: 400; }
.meta { font-size: 13px; color: var(--muted); margin: 4px 0 16px; min-height: 1em; }
.row { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }
.ghost { border: 0; background: none; padding: 12px 10px; color: var(--muted); }
.danger { border: 0; background: none; color: var(--danger); padding: 12px 4px; font-weight: 600; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 150px); z-index: 40;
  display: flex; align-items: center; gap: 14px;
  background: #222; color: #fff; padding: 11px 16px; border-radius: 12px; font-size: 15px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25); max-width: 90vw;
}
.toast[hidden] { display: none; }
.toast button { border: 0; background: none; color: #7ee2ae; font-weight: 700; padding: 0; }

/* Feinschliff */
.sheet .row { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.sheet .row .spacer { display: none; }
.sheet .row .primary { grid-column: 1 / -1; order: -1; height: 50px; }
.sheet .row .danger { justify-self: start; }
.sheet .row .ghost { justify-self: end; }
.add input::-webkit-calendar-picker-indicator { display: none !important; }

/* Vorschläge nach Rhythmus */
.due {
  margin: 8px 0 14px; padding: 12px 12px 6px; border-radius: 14px;
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}
.dueTitle { margin: 0 4px 6px; font-size: 15px; font-weight: 700; }
.dueRow { display: flex; align-items: center; gap: 8px; padding: 8px 4px; border-top: 1px solid color-mix(in srgb, var(--accent) 18%, transparent); }
.dueRow:first-of-type { border-top: 0; }
.dueText { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.dueName { font-weight: 600; }
.dueMeta { font-size: 13px; color: var(--muted); }
.dueAdd { flex: none; border: 0; border-radius: 999px; background: var(--accent); color: #fff; font-size: 14px; font-weight: 600; padding: 8px 12px; }
.dueNo { flex: none; width: 36px; height: 36px; border: 0; border-radius: 50%; background: none; color: var(--muted); font-size: 22px; line-height: 1; }

/* Strichcode */
.scanbtn { background: var(--card); border: 1px solid var(--line); color: var(--text); }
.scan { position: fixed; inset: 0; z-index: 25; background: #000; color: #fff; }
.scan[hidden] { display: none; }
.scan video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scanFrame {
  position: absolute; left: 7.5%; right: 7.5%; top: 50%; height: 26vh; transform: translateY(-60%);
  border: 3px solid rgba(255, 255, 255, .9); border-radius: 18px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45);
}
.scanLine { position: absolute; left: 6%; right: 6%; top: 50%; height: 2px; background: #ff5a4f; box-shadow: 0 0 10px #ff5a4f; }
.scanTop {
  position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 14px) 16px 14px; font-size: 16px;
}
.scanTop span { flex: 1; }
.scanTop button { border: 0; border-radius: 999px; background: #fff; color: #111; font-weight: 700; padding: 9px 18px; }
.scanList {
  position: absolute; left: 12px; right: 12px; bottom: calc(env(safe-area-inset-bottom) + 16px);
  list-style: none; margin: 0; padding: 0; max-height: 30vh; overflow: auto;
  display: flex; flex-direction: column; gap: 6px;
}
.scanList li { background: rgba(20, 20, 20, .8); border-radius: 12px; padding: 10px 14px; font-size: 15px; }
.scanList li.ok { border-left: 4px solid #4cc38a; }
.scanList li.skip { color: #bbb; }

/* Aktions-Links */
.deals { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 0 0 16px; }
.dealsLabel { font-size: 13px; font-weight: 600; color: var(--muted); margin-right: 2px; }
.deal {
  text-decoration: none; color: var(--text); font-size: 14px; font-weight: 600;
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; background: var(--bg);
}
#dealMigros { border-color: #ff6600; }
#dealCoop { border-color: #e2001a; }
#dealDenner { border-color: #c8102e; }
#unknownDlg .row { grid-template-columns: 1fr 1fr; }

/* Tabs */
.top { flex-wrap: wrap; }
.tabs {
  flex-basis: 100%; display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px;
  background: color-mix(in srgb, var(--muted) 14%, transparent); padding: 3px; border-radius: 12px; margin-top: 6px;
}
.tab { border: 0; background: none; border-radius: 9px; padding: 7px 4px; font-size: 14px; font-weight: 600; color: var(--muted); }
.tab.active { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.view[hidden], .composer[hidden] { display: none; }
.pane { flex: 1; padding: 8px 12px calc(env(safe-area-inset-bottom) + 40px); }

/* Panels */
.panel { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 14px 14px 12px; margin: 8px 0 14px; }
.panelTitle { margin: 0 0 10px; font-size: 16px; font-weight: 700; }
.panelSub { margin: -6px 0 10px; font-size: 13px; color: var(--muted); }
.panel .panelSub:last-child { margin: 8px 0 0; }
.wide { width: 100%; height: 48px; margin-top: 4px; }

/* Betrag & Laden */
.amountRow { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg); padding: 0 14px; margin-bottom: 12px; }
.amountRow .cur { font-weight: 700; color: var(--muted); }
.amountRow input { flex: 1; min-width: 0; height: 54px; border: 0; background: none; font-size: 26px; font-weight: 700; outline: none; color: var(--text); }
.storeChips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.storeChip { border: 1.5px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 13px; font-size: 14px; font-weight: 600; }
.storeChip[aria-checked="true"] { color: #fff; border-color: transparent; background: var(--store, var(--accent)); }
.store-migros { --store: #ff6600; }
.store-coop { --store: #e2001a; }
.store-denner { --store: #b3002d; }
.store-aldi { --store: #00549f; }
.store-lidl { --store: #0050aa; }
.store-andere { --store: #6b736e; }
.twoCols { display: grid; grid-template-columns: 1fr 1.4fr; gap: 8px; margin-bottom: 8px; }
.twoCols input { height: 44px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); padding: 0 10px; font-size: 16px; min-width: 0; color: var(--text); }
#costDlg .amountRow { margin-top: 4px; }

/* Ausgaben-Liste */
.expense { display: flex; align-items: center; gap: 10px; padding: 8px 6px 8px 14px; border-top: 1px solid var(--line); min-height: 58px; }
.expense:first-child { border-top: 0; }
.storeDot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--store, var(--muted)); }
.body.col { flex-direction: column; align-items: flex-start; gap: 1px; }
.sub { font-size: 13px; color: var(--muted); }
.amount { flex: none; font-weight: 700; font-variant-numeric: tabular-nums; }
.expense .more { font-size: 22px; }

/* Kennzahlen */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kpi { display: flex; flex-direction: column; gap: 2px; background: var(--bg); border-radius: 12px; padding: 10px; min-width: 0; }
.kpiLabel { font-size: 12px; color: var(--muted); }
.kpiValue { font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpiNote { font-size: 11px; color: var(--muted); }
.kpiNote.up { color: var(--danger); }
.kpiNote.down { color: var(--accent); }

/* Balken */
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar { display: grid; grid-template-columns: minmax(70px, 34%) 1fr auto; align-items: center; gap: 8px; font-size: 14px; }
.barLabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barTrack { height: 10px; border-radius: 999px; background: color-mix(in srgb, var(--muted) 15%, transparent); overflow: hidden; }
.barFill { display: block; height: 100%; border-radius: 999px; background: var(--store, var(--accent)); }
.barValue { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bars.vertical { flex-direction: row; align-items: stretch; gap: 6px; height: 150px; }
.bars.vertical .bar { flex: 1; display: flex; flex-direction: column-reverse; align-items: center; gap: 4px; font-size: 12px; }
.bars.vertical .barTrack { flex: 1; width: 100%; max-width: 34px; display: flex; align-items: flex-end; border-radius: 8px; }
.bars.vertical .barFill { width: 100%; border-radius: 8px; opacity: .55; }
.bars.vertical .bar.current .barFill { opacity: 1; }
.bars.vertical .barValue { font-size: 10.5px; min-height: 1.2em; }
.bars.vertical .barLabel { color: var(--muted); }

/* Wer macht was */
.whoTable { display: flex; flex-direction: column; }
.whoRow { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr; align-items: center; gap: 6px; padding: 8px 0; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; text-align: right; }
.whoRow.head { border-top: 0; font-size: 12px; color: var(--muted); padding-top: 0; }
.whoName { display: flex; align-items: center; gap: 8px; text-align: left; font-weight: 600; }
.facts { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; }
