:root {
  --green: #16a34a;
  --green-dark: #15803d;
  --bg: #f6f7f8;
  --card: #ffffff;
  --text: #1a1a1a;
  --muted: #6b7280;
  --border: #e5e7eb;
  --danger: #dc2626;
  --nav-h: 64px;
  --header-h: 52px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  overscroll-behavior-y: contain;
}

.hidden { display: none !important; }

/* Header */
.app-header {
  position: sticky;
  top: 0;
  height: calc(var(--header-h) + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--green);
  color: #fff;
  font-weight: 600;
  z-index: 10;
}
.app-header h1 { font-size: 1.15rem; margin: 0; }
.conn-dot {
  position: absolute;
  right: 16px;
  bottom: 12px;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: #fbbf24;
  transition: background .3s;
}
.conn-dot.online { background: #4ade80; }
.conn-dot.offline { background: #ef4444; }

/* Main */
#app {
  padding: 12px 12px calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px);
  min-height: calc(100vh - var(--header-h));
}
.screen { max-width: 640px; margin: 0 auto; }

/* Add form */
.add-form {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.add-form input {
  flex: 1;
  font-size: 17px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card);
}
.add-form input:focus { outline: 2px solid var(--green); border-color: var(--green); }
.add-btn {
  width: 52px;
  border: none;
  border-radius: 14px;
  background: var(--green);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  font-weight: 300;
}
.add-btn:active { background: var(--green-dark); }

/* List */
.list { list-style: none; margin: 0; padding: 0; }
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 14px;
  margin-bottom: 8px;
  transition: opacity .2s;
}
.list-item.checked { opacity: 0.5; }
.list-item.checked .item-name { text-decoration: line-through; }
.check {
  width: 26px; height: 26px;
  flex: 0 0 26px;
  border-radius: 50%;
  border: 2px solid var(--green);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 16px;
  background: transparent;
}
.list-item.checked .check { background: var(--green); }
.item-body { flex: 1; min-width: 0; }
.item-name { font-weight: 500; }
.item-meta { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
.src-badge {
  display: inline-block;
  font-size: 0.68rem;
  padding: 1px 7px;
  border-radius: 999px;
  background: #eef2ff;
  color: #4338ca;
  margin-right: 6px;
}
.src-badge.auto_minstock { background: #fef3c7; color: #92400e; }
.src-badge.auto_weekplan { background: #dcfce7; color: #166534; }
.src-badge.siri { background: #e0f2fe; color: #075985; }
.src-badge.photo_diff { background: #fae8ff; color: #86198f; }
.del-btn {
  background: none; border: none; color: var(--muted);
  font-size: 20px; padding: 6px;
}

/* Done section */
.done-wrap { margin-top: 18px; }
.done-head {
  display: flex; justify-content: space-between; align-items: center;
  color: var(--muted); font-size: 0.85rem; margin-bottom: 6px;
}
.link-btn { background: none; border: none; color: var(--green); font-size: 0.85rem; }

.empty { text-align: center; color: var(--muted); margin-top: 40px; }
.error { color: var(--danger); }

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  z-index: 10;
}
.nav-btn {
  flex: 1;
  border: none; background: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  font-size: 0.7rem;
  color: var(--muted);
}
.nav-btn span { font-size: 1.3rem; }
.nav-btn.active { color: var(--green); }

/* FAB */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px);
  width: 60px; height: 60px;
  border-radius: 50%;
  border: none;
  background: var(--green);
  color: #fff;
  font-size: 34px;
  box-shadow: 0 6px 16px rgba(22,163,74,.4);
  z-index: 11;
}
.fab:active { background: var(--green-dark); }
.fab-menu {
  position: fixed;
  right: 18px;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 84px);
  display: flex; flex-direction: column; gap: 8px;
  z-index: 11;
}
.fab-menu button {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 0.95rem;
  box-shadow: 0 4px 12px rgba(0,0,0,.1);
  text-align: left;
}
.fab-menu button[disabled] { opacity: 0.55; }
.fab-menu small { color: var(--muted); }

/* Token gate */
.gate {
  position: fixed; inset: 0;
  background: var(--green);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  z-index: 100;
}
.gate-card {
  background: var(--card);
  border-radius: 18px;
  padding: 28px 22px;
  max-width: 360px; width: 100%;
  text-align: center;
}
.gate-card h1 { margin: 0 0 8px; }
.gate-card input {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  margin: 14px 0;
}
.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
  left: 50%; transform: translateX(-50%);
  background: #1f2937; color: #fff;
  padding: 10px 18px; border-radius: 999px;
  font-size: 0.9rem; z-index: 50;
  opacity: 0; transition: opacity .25s;
  pointer-events: none;
  max-width: 90vw;
}
.toast.show { opacity: 1; }

/* ── Phase 2: Vorrat, Sheets, Scanner ─────────────────────────────── */

.cat-head {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  margin: 18px 4px 8px;
}

.pantry-item { gap: 8px; }
.pantry-item.below-min { border-color: #f59e0b; background: #fffbeb; }
.fresh-dot {
  width: 11px; height: 11px; flex: 0 0 11px; border-radius: 50%;
  background: #9ca3af;
}
.fresh-dot.high { background: #22c55e; }
.fresh-dot.medium { background: #f59e0b; }
.fresh-dot.low { background: #ef4444; }

.qty-btn {
  width: 38px; height: 38px; flex: 0 0 38px;
  border: 1px solid var(--border); border-radius: 10px;
  background: #fff; font-size: 22px; line-height: 1; color: var(--text);
}
.qty-btn:active { background: #f3f4f6; }
.qty-count { min-width: 22px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }

/* Bottom-Sheet */
.sheet-overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0,0,0,.35);
  display: flex; align-items: flex-end;
  opacity: 0; transition: opacity .2s;
}
.sheet-overlay.open { opacity: 1; }
.sheet {
  background: var(--card);
  width: 100%;
  max-height: 88vh; overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 8px 18px calc(env(safe-area-inset-bottom) + 22px);
  transform: translateY(100%);
  transition: transform .25s ease;
}
.sheet-overlay.open .sheet { transform: translateY(0); }
.sheet-handle {
  width: 40px; height: 4px; border-radius: 2px;
  background: #d1d5db; margin: 8px auto 12px;
}
.sheet-title { margin: 0 0 12px; font-size: 1.15rem; }

/* Formulare in Sheets */
.edit-form, .resolve { display: flex; flex-direction: column; }
.edit-form label, .resolve label { font-size: .8rem; color: var(--muted); margin: 10px 0 4px; }
.edit-form input, .resolve input {
  padding: 12px 14px; font-size: 16px;
  border: 1px solid var(--border); border-radius: 12px; background: #fff;
}
.switch-row { flex-direction: row !important; align-items: center; gap: 10px; margin-top: 14px !important; color: var(--text) !important; font-size: 1rem !important; }
.switch-row input { width: 22px; height: 22px; }

.btn-secondary {
  margin-top: 12px; padding: 13px; border-radius: 12px;
  background: #f3f4f6; border: 1px solid var(--border); font-size: 16px; color: var(--text);
}
.btn-danger {
  margin-top: 10px; padding: 13px; border-radius: 12px;
  background: #fff; border: 1px solid var(--danger); color: var(--danger); font-size: 16px;
}
.btn-primary { margin-top: 12px; }
.muted { color: var(--muted); font-size: .9rem; }

.resolve-img { max-width: 120px; align-self: center; border-radius: 12px; margin-bottom: 8px; }
.candidate {
  text-align: left; padding: 12px 14px; margin: 6px 0;
  border: 1px solid var(--border); border-radius: 12px; background: #f9fafb; font-size: .95rem;
}

/* Scanner */
.reader { width: 100%; border-radius: 12px; overflow: hidden; }
.scan-hint { text-align: center; color: var(--muted); margin: 12px 0; }

/* ── Phase 3: Bon-Scan ────────────────────────────────────────────── */
.receipt-list { margin-top: 8px; }
.receipt-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 4px; border-bottom: 1px solid var(--border);
}
.receipt-row.excluded { opacity: .45; }
.receipt-row input[type=checkbox] { width: 22px; height: 22px; flex: 0 0 22px; }
.qty-input {
  width: 52px; flex: 0 0 52px; text-align: center;
  padding: 8px 4px; border: 1px solid var(--border); border-radius: 10px; font-size: 16px;
}
.receipt-label { flex: 1; min-width: 0; }
.assign-btn {
  margin-top: 4px; font-size: .82rem;
  background: #f3f4f6; border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 10px; color: var(--muted); max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.assign-btn.assigned { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.picker-results { display: flex; flex-direction: column; margin-top: 10px; max-height: 50vh; overflow-y: auto; }
.candidate.new { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; font-weight: 600; }

/* ── Phase 4: Wochenplan & Rezepte ────────────────────────────────── */
.day-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; padding: 10px 12px; margin-bottom: 10px;
}
.day-head { display: flex; justify-content: space-between; align-items: center; font-weight: 600; }
.day-add {
  width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border);
  background: #fff; font-size: 18px; color: var(--green);
}
.day-empty { color: var(--muted); margin: 6px 0; }
.plan-entry {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 0; border-top: 1px solid var(--border);
}
.plan-badge { display: inline-block; font-size: .7rem; padding: 1px 8px; border-radius: 999px; margin-top: 3px; }
.badge-plan { background: #eef2ff; color: #4338ca; }
.badge-cooked { background: #dcfce7; color: #166534; }
.badge-skip { background: #f3f4f6; color: #6b7280; }
.plan-actions { display: flex; gap: 4px; flex-shrink: 0; }
.mini-btn {
  font-size: .78rem; padding: 6px 9px; border-radius: 9px;
  border: 1px solid var(--border); background: #fff; color: var(--text);
}
.mini-btn.cook { background: var(--green); color: #fff; border-color: var(--green); }
.mini-btn.del { color: var(--muted); }

/* Zutaten-Editor */
.ing-list { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.ing-row { display: flex; gap: 6px; align-items: center; }
.ing-amount { width: 64px; flex: 0 0 64px; }
.ing-unit { width: 56px; flex: 0 0 56px; }
.ing-name { flex: 1; min-width: 0; }
.ing-row input { padding: 10px; font-size: 15px; border: 1px solid var(--border); border-radius: 10px; }
.ing-link, .ing-del { background: #f3f4f6; border: 1px solid var(--border); border-radius: 9px; width: 38px; flex: 0 0 38px; height: 38px; }
.ing-del { color: var(--muted); }

/* ── Phase 5: Foto-Snapshot, Feasibility ──────────────────────────── */
.recipe-toolbar { display: flex; gap: 8px; margin-bottom: 10px; }
.tool-btn {
  flex: 1; padding: 12px 8px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--card); font-size: .9rem; color: var(--text);
}
.mini-check { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.mini-check input { width: 20px; height: 20px; }
.feasibility-result { margin-top: 14px; }
.feasible-yes { color: var(--green-dark); font-weight: 600; }
.feasible-no { color: #b45309; font-weight: 500; }
