:root {
  --bg: #000000;
  --surface: #121212;
  --surface-2: #1F1F1F;
  --surface-3: #2A2A2A;
  --text: #FFFFFF;
  --muted: #8A8A8E;
  --line: #222222;
  --primary: #FFFFFF;
  --on-primary: #000000;
  --warn: #FF9F0A;
  --warn-soft: rgba(255, 159, 10, .14);
  --danger: #FF453A;
  --radius: 14px;
  --tabbar-h: 60px;
  --content-w: 640px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body {
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Header ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  background: rgba(0, 0, 0, .82);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
}
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; max-width: var(--content-w); margin: 0 auto; }
#subbar { max-width: var(--content-w); margin: 0 auto; }

.status { width: 28px; height: 28px; display: grid; place-items: center; flex: none; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.status[data-state="live"]::before { background: #30D158; }
.status[data-state="offline"]::before, .status[data-state="error"]::before { background: var(--warn); }
.status[data-state="connecting"]::before { background: #FFD60A; }

/* ---------- Dropdown ---------- */
.dd { position: relative; }
.dd-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 12px 0 14px; border-radius: 10px;
  background: var(--surface-2); font-size: 15px; font-weight: 600;
}
.dd-btn svg { width: 16px; height: 16px; stroke-width: 2.5; color: var(--muted); transition: transform .15s; }
.dd-btn[aria-expanded="true"] svg { transform: rotate(180deg); }
.dd-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 15;
  min-width: 220px; padding: 6px;
  background: rgba(30, 30, 30, .96);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  border: 1px solid var(--surface-3); border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .6);
  animation: pop .14s ease-out; transform-origin: top left;
}
.dd-opt {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 11px 10px 11px 12px; border-radius: 9px; text-align: left; font-size: 16px;
}
.dd-opt:active, .dd-opt:hover { background: var(--surface-3); }
.dd-opt span { flex: 1; }
.dd-opt small { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.dd-opt svg { width: 18px; height: 18px; stroke-width: 2.5; visibility: hidden; }
.dd-opt[aria-selected="true"] svg { visibility: visible; }

/* ---------- Chips (Schnellauswahl) ---------- */
.chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 10px 16px 0; margin: 0 -16px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 7px 13px; border-radius: 999px; background: var(--surface-2); font-size: 15px; white-space: nowrap; }
.chip small { color: var(--muted); margin-left: 5px; font-size: 12px; }
.chip.add::before { content: "+ "; font-weight: 600; }

/* ---------- Listen ---------- */
main { padding: 0 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 96px); max-width: var(--content-w); margin: 0 auto; }
.group-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 4px 8px; }
.spacer { height: 8px; }
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.list > li + li { border-top: 1px solid var(--line); }

.item, .entry { display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 16px; min-height: 62px; }
.item-main, .entry-main { flex: 1; min-width: 0; text-align: left; display: flex; flex-direction: column; gap: 2px; padding: 4px 0; }
.item-name, .entry-name { font-size: 17px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.entry-meta { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { font-size: 12px; font-weight: 600; padding: 1px 7px; border-radius: 6px; background: var(--surface-3); color: #C7C7CC; }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.item.low .qty b { color: var(--warn); }

/* ---------- Stepper ---------- */
.stepper { display: flex; align-items: center; gap: 2px; flex: none; }
.stepper > button {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-2); font-size: 21px; font-weight: 400; line-height: 1;
}
.stepper > button:active { background: var(--surface-3); transform: scale(.92); }
.stepper > button svg { width: 18px; height: 18px; }
.qty { width: 56px; min-width: 56px; text-align: center; display: flex; flex-direction: column; line-height: 1.1; }
.qty b { font-size: 19px; font-weight: 600; font-variant-numeric: tabular-nums; }
.qty small { font-size: 11px; color: var(--muted); }
.stepper.small > button { width: 34px; height: 34px; font-size: 18px; }
.stepper.small .qty { min-width: 46px; }
.stepper.small .qty b { font-size: 16px; }

/* ---------- Einkaufsliste ---------- */
.quick { display: flex; gap: 8px; }
.quick input {
  flex: 1; min-width: 0; height: 44px; padding: 0 14px;
  border-radius: 12px; border: 0; background: var(--surface-2);
  font-size: 17px; outline: none;
}
.quick input::placeholder { color: var(--muted); }
.quick input:focus { box-shadow: 0 0 0 1.5px #555 inset; }
.quick button { width: 44px; height: 44px; border-radius: 12px; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; }
.quick button svg { width: 20px; height: 20px; stroke-width: 2.5; }

.check {
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  border: 1.5px solid #48484A; display: grid; place-items: center; margin-right: 4px;
}
.check svg { width: 15px; height: 15px; stroke-width: 3; opacity: 0; color: var(--on-primary); }
.entry.done .check { background: var(--primary); border-color: var(--primary); }
.entry.done .check svg { opacity: 1; }
.entry.done .entry-name { text-decoration: line-through; color: var(--muted); }
.entry.done { opacity: .6; }

/* ---------- Leerzustand ---------- */
.empty { text-align: center; color: var(--muted); padding: 64px 24px; }
.empty b { display: block; color: var(--text); font-size: 17px; font-weight: 600; margin-bottom: 4px; }

/* ---------- FAB & Tabbar ---------- */
.fab {
  position: fixed; right: 20px; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px); z-index: 6;
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--primary); color: var(--on-primary);
  display: grid; place-items: center; box-shadow: 0 8px 24px rgba(0, 0, 0, .6);
}
.fab svg { width: 24px; height: 24px; stroke-width: 2.5; }
.fab:active { transform: scale(.94); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(10, 10, 10, .86);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
}
.tabbar button {
  position: relative; flex: 1; max-width: 220px; height: var(--tabbar-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 11px; font-weight: 500; color: #636366;
}
.tabbar button svg { width: 23px; height: 23px; stroke-width: 1.8; }
.tabbar button[aria-current="page"] { color: var(--text); }
.badge {
  position: absolute; top: 7px; left: calc(50% + 6px);
  min-width: 17px; height: 17px; padding: 0 5px; border-radius: 9px;
  background: var(--text); color: var(--on-primary); font-size: 11px; font-weight: 700; line-height: 17px; text-align: center;
}

/* ---------- Sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .6); animation: fade .2s ease; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-width: 560px; margin: 0 auto; max-height: 92vh; overflow-y: auto;
  background: #161616; border-radius: 20px 20px 0 0;
  padding: 8px 20px calc(env(safe-area-inset-bottom) + 20px);
  animation: up .25s cubic-bezier(.2, .8, .2, 1);
}
.grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--surface-3); margin: 4px auto 14px; }
.sheet h2 { margin: 0 0 18px; font-size: 20px; font-weight: 600; }
.field { display: block; margin-bottom: 18px; }
.field > span { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin: 0 0 7px 2px; }
.field input[type="text"] {
  width: 100%; height: 48px; padding: 0 14px; font-size: 17px;
  border-radius: 12px; border: 0; background: var(--surface-2); outline: none;
}
.field input[type="text"]:focus { box-shadow: 0 0 0 1.5px #555 inset; }
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg button { padding: 9px 14px; border-radius: 10px; background: var(--surface-2); font-size: 15px; }
.seg button[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); font-weight: 600; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.num { display: flex; align-items: center; justify-content: space-between; background: var(--surface-2); border-radius: 12px; padding: 4px; }
.num button { width: 40px; height: 40px; border-radius: 9px; background: var(--surface-3); font-size: 21px; }
.num input { width: 48px; border: 0; background: none; text-align: center; font-size: 19px; font-weight: 600; outline: none; -moz-appearance: textfield; }
.num input::-webkit-inner-spin-button, .num input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.hint { font-size: 13px; color: var(--muted); margin: -4px 2px 22px; }
.actions { display: flex; gap: 10px; }
.primary { flex: 1; height: 50px; border-radius: 12px; background: var(--primary); color: var(--on-primary); font-weight: 600; font-size: 17px; }
.danger { height: 50px; padding: 0 18px; border-radius: 12px; background: var(--surface-2); color: var(--danger); font-weight: 600; }
.link { color: var(--muted); font-size: 15px; padding: 10px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 16px; right: 16px; z-index: 30;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
  max-width: 480px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 10px 12px 16px; border-radius: 14px;
  background: #262626; color: #fff; font-size: 15px; box-shadow: 0 8px 30px rgba(0, 0, 0, .6);
  animation: up .2s ease;
}
.toast button { font-weight: 600; padding: 6px 8px; white-space: nowrap; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-logo { width: 80px; height: 80px; border-radius: 18px; }
.login-card h1 { margin: 14px 0 6px; font-size: 26px; }
.login-card p { color: var(--muted); }
.login-card form { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.login-card input {
  height: 50px; padding: 0 16px; font-size: 17px; text-align: center;
  border-radius: 12px; border: 0; background: var(--surface-2); outline: none;
}
.login-msg { min-height: 1.4em; font-size: 14px; }

/* ---------- Vorrat: Warenkorb & Da/Leer ---------- */
.cart {
  flex: none; width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; color: var(--muted);
}
.cart svg { width: 20px; height: 20px; stroke-width: 1.8; }
.cart:active { background: var(--surface-2); }
.cart.on { background: var(--primary); color: var(--on-primary); }
.cart.on svg { stroke-width: 2.2; }
.have {
  flex: none; width: 132px; height: 40px; border-radius: 20px;
  background: var(--surface-2); font-size: 15px; font-weight: 600;
}
.have.out { background: var(--warn-soft); color: var(--warn); }
.have:active { transform: scale(.96); }

/* ---------- Rezepte ---------- */
.quick input[type="search"] { -webkit-appearance: none; appearance: none; }
.recipe { display: flex; align-items: center; gap: 10px; padding: 8px 12px 8px 16px; min-height: 66px; }
.recipe-main { flex: 1; min-width: 0; text-align: left; display: flex; flex-direction: column; gap: 3px; padding: 6px 0; }
.recipe .item-meta { flex-wrap: wrap; }
.pill.ok-pill { background: rgba(48, 209, 88, .14); color: #30D158; }
.plan {
  flex: none; height: 34px; padding: 0 14px; border-radius: 17px;
  background: var(--surface-2); font-size: 14px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 5px;
}
.plan svg { width: 15px; height: 15px; stroke-width: 3; }
.plan.on { background: var(--primary); color: var(--on-primary); }

.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.sheet-head h2 { margin-bottom: 14px; }
.ghost { color: var(--muted); font-size: 15px; padding: 4px 0; flex: none; }
.link-btn {
  display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text);
  background: var(--surface-2); border-radius: 12px; padding: 13px 14px; margin-bottom: 18px; font-weight: 500;
}
.link-btn svg { width: 18px; height: 18px; color: var(--muted); }
.sub { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 2px 8px; }
.ing-list { list-style: none; margin: 0 0 20px; padding: 0; background: var(--surface); border-radius: 12px; overflow: hidden; }
.ing { display: flex; align-items: center; gap: 10px; padding: 12px 14px; }
.ing + .ing { border-top: 1px solid var(--line); }
.ing-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ing-amt { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.notes { white-space: pre-wrap; color: #D1D1D6; margin: 0 2px 22px; }
.actions.stack { flex-direction: column; }
.actions.stack > * { flex: none; }
.secondary { height: 50px; border-radius: 12px; background: var(--surface-2); font-weight: 600; font-size: 17px; }
.hint.center { text-align: center; margin: 12px 0 0; }

.ing-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.ing-row .ing-input {
  flex: 1; min-width: 0; height: 44px; padding: 0 12px; font-size: 16px;
  border-radius: 10px; border: 0; background: var(--surface-2); outline: none;
}
.ing-row .ing-input:focus { box-shadow: 0 0 0 1.5px #555 inset; }
.ing-row .ing-input::-webkit-calendar-picker-indicator { display: none !important; opacity: 0; }
.num.mini { padding: 2px; border-radius: 10px; }
.num.mini button { width: 32px; height: 36px; font-size: 18px; border-radius: 8px; }
.num.mini input { width: 30px; font-size: 16px; }
.x { width: 32px; height: 32px; display: grid; place-items: center; color: var(--muted); flex: none; }
.x svg { width: 16px; height: 16px; }
.add-row { display: inline-flex; align-items: center; gap: 6px; color: var(--text); font-size: 15px; font-weight: 500; padding: 8px 2px; }
.add-row svg { width: 16px; height: 16px; stroke-width: 2.5; }
.field textarea {
  width: 100%; padding: 12px 14px; font: inherit; font-size: 16px; color: inherit; resize: vertical;
  border-radius: 12px; border: 0; background: var(--surface-2); outline: none;
}
.field textarea:focus { box-shadow: 0 0 0 1.5px #555 inset; }
.field input[type="url"] {
  width: 100%; height: 48px; padding: 0 14px; font-size: 17px;
  border-radius: 12px; border: 0; background: var(--surface-2); outline: none;
}
.sheet[data-tracked="true"] .untracked-only, .sheet[data-tracked="false"] .tracked-only { display: none; }

/* ---------- iPad ---------- */
@media (min-width: 760px) {
  :root { --content-w: 980px; }
  .top { padding-left: 24px; padding-right: 24px; }
  main { padding-left: 24px; padding-right: 24px; }
  .groups { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; align-items: start; }
  .narrow { max-width: 680px; margin: 0 auto; }
  #subbar .quick, #subbar .chips { max-width: 680px; margin-left: auto; margin-right: auto; }
  #subbar .chips { padding-left: 0; padding-right: 0; }
  .fab { right: max(24px, calc((100vw - var(--content-w)) / 2)); }
}

@keyframes up { from { transform: translateY(24px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.96); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }

/* ---------- Rückfrage ---------- */
.dialog-root { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; }
.dialog-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .6); animation: fade .15s ease; }
.dialog {
  position: relative; width: min(100%, 340px); padding: 20px 16px 16px;
  background: var(--surface-2); border-radius: 18px; text-align: center;
}
.dialog h3 { margin: 0 0 6px; font-size: 17px; font-weight: 600; }
.dialog p { margin: 0 0 4px; color: var(--muted); font-size: 15px; line-height: 1.4; }
.dialog .actions { margin-top: 16px; }
.dialog .actions > * { flex: 1; }
.dialog .secondary { background: var(--surface-3); }
.danger.solid { background: var(--danger); color: #fff; }

/* ---------- Suche im Vorrat ---------- */
.head-row .dd { flex: none; }
.search {
  flex: 1; min-width: 0; height: 36px; display: flex; align-items: center; gap: 6px;
  padding: 0 4px 0 10px; border-radius: 10px; background: var(--surface-2);
}
.search > svg { width: 16px; height: 16px; flex: none; color: var(--muted); stroke-width: 2.2; }
.search input {
  flex: 1; min-width: 0; height: 100%; border: 0; background: none; outline: none;
  font-size: 16px; /* ab 16px zoomt iOS beim Antippen nicht */
  -webkit-appearance: none; appearance: none;
}
.search input::placeholder { color: var(--muted); }
.search input::-webkit-search-cancel-button { display: none; }
.search:focus-within { box-shadow: 0 0 0 1.5px #555 inset; }
.search-clear { width: 28px; height: 28px; flex: none; display: grid; place-items: center; color: var(--muted); }
.search-clear svg { width: 14px; height: 14px; stroke-width: 2.5; }
.empty-actions { display: flex; flex-direction: column; gap: 8px; max-width: 280px; margin: 20px auto 0; }
.empty-actions .secondary { height: 44px; padding: 0 16px; font-size: 15px; color: var(--text); }
