:root {
  --bg: #f4f5f2;
  --card: #ffffff;
  --text: #1c1f1a;
  --muted: #6b7065;
  --line: #e3e5df;
  --accent: #15803d;
  --accent-soft: #dcfce7;
  --accent-text: #ffffff;
  --danger: #c2410c;
  --chip: #eef0eb;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121411;
    --card: #1c1f1b;
    --text: #eceee9;
    --muted: #9aa094;
    --line: #2b2f2a;
    --accent: #22c55e;
    --accent-soft: #163a22;
    --accent-text: #06210f;
    --danger: #fb923c;
    --chip: #262a25;
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overscroll-behavior-y: contain;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.error { color: var(--danger); min-height: 1.2em; margin: 8px 0 0; }

/* ---------- Kopfzeile ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: var(--bg);
}
.top h1 { font-size: 24px; margin: 0; flex: 1; letter-spacing: -.01em; }
.count { color: var(--muted); font-size: 15px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  font-size: 20px; display: grid; place-items: center;
}
.icon-btn:active { background: var(--chip); }

main { max-width: 640px; margin: 0 auto; padding: 0 12px calc(96px + var(--safe-b)); }

/* ---------- Eingabe ---------- */
.addbar-wrap { position: sticky; top: calc(64px + var(--safe-t)); z-index: 15; padding-bottom: 8px; background: var(--bg); }
.addbar {
  display: flex; gap: 8px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 6px; border: 1px solid var(--line);
}
.addbar input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent;
  padding: 10px 10px; font-size: 17px;
}
.add-btn {
  width: 46px; height: 46px; border-radius: 11px;
  background: var(--accent); color: var(--accent-text);
  font-size: 28px; line-height: 1; font-weight: 500;
}
.add-btn:active { transform: scale(.95); }

.suggest { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 2px 2px; }
.suggest-label { width: 100%; font-size: 13px; color: var(--muted); padding-left: 4px; }
.chip {
  padding: 8px 12px; border-radius: 999px; background: var(--card);
  border: 1px solid var(--line); font-size: 15px;
}
.chip:active { background: var(--accent-soft); }
.chip.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.quick-row { display: flex; gap: 8px; margin: 4px 2px 12px; }
.quick-row .btn { flex: 1; }

/* ---------- Liste ---------- */
.group { margin: 0 0 14px; }
.group-h {
  font-size: 14px; font-weight: 600; color: var(--muted);
  padding: 4px 6px 6px; text-transform: uppercase; letter-spacing: .03em;
}
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; border: 1px solid var(--line); }
.item {
  display: flex; align-items: center; gap: 12px;
  min-height: 56px; padding: 6px 4px 6px 14px;
  border-top: 1px solid var(--line);
  user-select: none;
}
.item:first-child { border-top: 0; }
.item:active { background: var(--chip); }
.check {
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--muted); display: grid; place-items: center;
  font-size: 15px; color: transparent;
}
.item.done .check { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.item-main { flex: 1; min-width: 0; padding: 6px 0; }
.item-name { overflow-wrap: anywhere; }
.item-meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.item.done .item-name { text-decoration: line-through; color: var(--muted); }
.qty {
  flex: none; font-size: 15px; font-weight: 600;
  background: var(--accent-soft); color: var(--text);
  padding: 4px 10px; border-radius: 999px; max-width: 40%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.item.done .qty { background: var(--chip); color: var(--muted); }
.edit-btn { flex: none; width: 44px; height: 44px; border-radius: 50%; color: var(--muted); font-size: 18px; }
.edit-btn:active { background: var(--line); }

.done-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin: 22px 2px 8px;
}
.done-toggle { font-weight: 600; color: var(--muted); padding: 10px 4px; }

.empty { text-align: center; padding: 48px 20px 24px; color: var(--muted); }
.empty .big { font-size: 48px; margin-bottom: 8px; }
.empty p { margin: 6px 0; }

/* ---------- Knöpfe ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 16px; border-radius: 12px;
  background: var(--chip); font-weight: 600; font-size: 16px;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); background: transparent; }
.btn.small { min-height: 38px; padding: 0 12px; font-size: 15px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }

/* ---------- Rezepte ---------- */
.recipe-card { display: flex; align-items: center; gap: 10px; padding: 12px 12px 12px 16px; margin-bottom: 10px; }
.recipe-main { flex: 1; min-width: 0; padding: 4px 0; }
.recipe-name { font-weight: 600; font-size: 18px; overflow-wrap: anywhere; }
.recipe-sub { font-size: 14px; color: var(--muted); margin-top: 2px; }
.fab {
  position: fixed; right: 18px; bottom: calc(84px + var(--safe-b)); z-index: 25;
  width: 58px; height: 58px; border-radius: 18px;
  background: var(--accent); color: var(--accent-text);
  font-size: 32px; box-shadow: 0 4px 14px rgba(0,0,0,.2);
}
.fab:active { transform: scale(.95); }

/* ---------- Tabs unten ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabs button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 10px; font-size: 13px; color: var(--muted); font-weight: 600;
}
.tabs .tab-ico { font-size: 22px; filter: grayscale(1); opacity: .7; }
.tabs button.active { color: var(--accent); }
.tabs button.active .tab-ico { filter: none; opacity: 1; }

/* ---------- Sheet (Fenster von unten) ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; justify-content: flex-end; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.4); animation: fade .15s ease-out; }
.sheet {
  position: relative; background: var(--card); color: var(--text);
  border-radius: 20px 20px 0 0; max-height: 92vh; overflow-y: auto;
  padding: 8px 18px calc(18px + var(--safe-b));
  width: 100%; max-width: 640px; margin: 0 auto;
  animation: up .2s ease-out;
}
.sheet::before { content: ""; display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 12px; }
.sheet h2 { margin: 0 0 14px; font-size: 21px; overflow-wrap: anywhere; }
.sheet label.lbl { display: block; font-size: 14px; color: var(--muted); font-weight: 600; margin: 14px 0 6px; }
.field {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); outline: 0; font-size: 17px;
}
.field:focus { border-color: var(--accent); }
textarea.field { min-height: 110px; resize: vertical; }
.row { display: flex; gap: 8px; align-items: center; }
.sheet-actions { display: flex; gap: 10px; margin-top: 20px; }
.sheet-actions .btn { flex: 1; }
.cat-grid { display: flex; flex-wrap: wrap; gap: 8px; }

.ing-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.ing-row .qty-in { width: 32%; flex: none; }
.ing-row .name-in { flex: 1; min-width: 0; }
.ing-row .del { width: 40px; height: 40px; flex: none; color: var(--muted); font-size: 20px; border-radius: 50%; }

.stepper { display: inline-flex; align-items: center; gap: 4px; background: var(--chip); border-radius: 12px; padding: 3px; }
.stepper button { width: 40px; height: 40px; border-radius: 10px; font-size: 22px; font-weight: 600; }
.stepper button:active { background: var(--line); }
.stepper span { min-width: 92px; text-align: center; font-weight: 600; }

.pick { display: flex; align-items: center; gap: 12px; padding: 12px 2px; border-top: 1px solid var(--line); }
.pick:first-child { border-top: 0; }
.pick input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.pick .pick-name { flex: 1; overflow-wrap: anywhere; }
.pick .hint { display: block; font-size: 13px; color: var(--muted); }
.pick .q { color: var(--muted); font-weight: 600; white-space: nowrap; }

.list-btn { display: flex; width: 100%; text-align: left; align-items: center; gap: 12px; padding: 14px 4px; border-top: 1px solid var(--line); }
.list-btn:first-child { border-top: 0; }
.list-btn .grow { flex: 1; }

.notes-view { white-space: pre-wrap; background: var(--bg); border-radius: 12px; padding: 12px 14px; }

/* ---------- Anmeldung ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-box { width: 100%; max-width: 360px; text-align: center; }
.login-logo { width: 84px; height: 84px; border-radius: 20px; }
.login h1 { margin: 12px 0 4px; }
.user-pick { display: flex; gap: 10px; margin: 12px 0 16px; }
.user-pick button {
  flex: 1; min-height: 56px; border-radius: 14px; background: var(--card);
  border: 2px solid var(--line); font-weight: 600; font-size: 18px;
}
.user-pick button.on { border-color: var(--accent); background: var(--accent-soft); }
#pinInput {
  width: 100%; text-align: center; font-size: 26px; letter-spacing: .3em;
  padding: 12px; border-radius: 14px; border: 1px solid var(--line); background: var(--card);
  margin-bottom: 12px; outline: 0;
}
#pinInput:focus { border-color: var(--accent); }

/* ---------- Hinweise ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(84px + var(--safe-b)); z-index: 60;
  display: flex; align-items: center; gap: 14px;
  background: #222; color: #fff; border-radius: 12px; padding: 12px 16px;
  box-shadow: 0 4px 16px rgba(0,0,0,.25); max-width: calc(100% - 32px); font-size: 15px;
}
.toast button { color: #86efac; font-weight: 700; padding: 4px 2px; }
.offline {
  position: fixed; top: calc(8px + var(--safe-t)); left: 50%; transform: translateX(-50%); z-index: 70;
  background: var(--danger); color: #fff; padding: 6px 14px; border-radius: 999px; font-size: 14px;
}

@keyframes up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
