/* Einkaufszettel – Mobile-First-Styles */

:root {
  --bg: #f4f6f4;
  --surface: #ffffff;
  --surface-2: #eef2ee;
  --text: #17201b;
  --muted: #66736b;
  --line: #dde4de;
  --accent: #15803d;
  --accent-strong: #116632;
  --accent-soft: #dcf3e3;
  --on-accent: #ffffff;
  --danger: #c2261d;
  --danger-soft: #fde7e5;
  --checked: #9aa59e;
  --shadow: 0 6px 24px rgba(16, 40, 24, .12);
  --radius: 16px;
  --row-h: 60px;
  --kb: 0px;                       /* Höhe der iOS-Tastatur (per JS gesetzt) */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1210;
    --surface: #161d19;
    --surface-2: #1e2722;
    --text: #e8eee9;
    --muted: #8d9a92;
    --line: #26312b;
    --accent: #22a355;
    --accent-strong: #2fbd66;
    --accent-soft: #173523;
    --on-accent: #ffffff;
    --danger: #ff6b5f;
    --danger-soft: #3a1a17;
    --checked: #5b6760;
    --shadow: 0 6px 24px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.35;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
  min-height: 100dvh;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }

/* ---------- Kopfzeile ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 1px 0 rgba(0,0,0,.08);
}
@media (prefers-color-scheme: dark) { .topbar { background: var(--surface); } }
.topbar__title { display: flex; align-items: baseline; gap: 10px; flex: 1; min-width: 0; }
.topbar h1 { margin: 0; font-size: 24px; font-weight: 750; letter-spacing: -.01em; }
.counter { font-size: 14px; opacity: .85; white-space: nowrap; }
.sync {
  width: 10px; height: 10px; border-radius: 50%;
  background: #86efac; flex: none;
  transition: background .2s;
}
.sync.is-offline { background: #fbbf24; }
.sync.is-pending { background: #93c5fd; animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .35; } }

.topbar .btn--ghost {
  color: var(--on-accent);
  border-color: rgba(255,255,255,.45);
  min-height: 40px; padding: 0 14px; font-size: 15px;
}
@media (prefers-color-scheme: dark) { .topbar .btn--ghost { color: var(--text); border-color: var(--line); } }

/* ---------- Liste ---------- */
main {
  padding: 8px 12px calc(150px + var(--safe-bottom));
  max-width: 640px; margin: 0 auto;
}

.group { margin: 8px 0 4px; }
.group__head {
  position: sticky; top: var(--topbar-h, calc(60px + var(--safe-top))); z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: 6px 6px;
  font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted);
  background: var(--bg);
}
.group__head .n { margin-left: auto; font-weight: 600; }
.group__items {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 0 var(--line);
}

.item {
  display: flex; align-items: center;
  min-height: var(--row-h);
  border-top: 1px solid var(--line);
  user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: background .15s, opacity .2s;
}
.item:first-child { border-top: 0; }
.item:active { background: var(--surface-2); }
.item.is-highlight { animation: flash 1s ease; }
@keyframes flash { 0%, 40% { background: var(--accent-soft); } 100% { background: transparent; } }

.item__toggle {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 14px;
  min-height: var(--row-h);
  padding: 8px 4px 8px 14px;
  background: none; border: 0; text-align: left;
}
.check {
  flex: none;
  width: 32px; height: 32px; border-radius: 50%;
  border: 2.5px solid var(--line);
  display: grid; place-items: center;
  transition: background .15s, border-color .15s, transform .15s;
}
.check svg { width: 18px; height: 18px; stroke: var(--on-accent); stroke-width: 3.2; fill: none; opacity: 0; stroke-linecap: round; stroke-linejoin: round; }
.item.is-checked .check,
.item.is-checking .check { background: var(--accent); border-color: var(--accent); }
.item.is-checked .check svg,
.item.is-checking .check svg { opacity: 1; }
.item.is-checking .check { transform: scale(1.12); }

.item__text { min-width: 0; display: flex; flex-direction: column; }
.item__name { font-size: 18px; font-weight: 520; overflow-wrap: anywhere; }
.item__cat { display: inline-block; margin-left: 6px; }  /* inline-block: nicht mit durchgestrichen */
.item__qty { font-size: 14px; color: var(--muted); }
.item.is-checked .item__name,
.item.is-checking .item__name { text-decoration: line-through; text-decoration-thickness: 2px; color: var(--checked); }
.item.is-checked .item__qty { color: var(--checked); }

.item__del {
  flex: none;
  width: 52px; height: var(--row-h);
  display: grid; place-items: center;
  background: none; border: 0; color: var(--muted);
}
.item__del svg { width: 22px; height: 22px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.item__del:active { color: var(--danger); }

.group--done .group__head { color: var(--checked); }
.group--done .item__cat { font-size: 15px; opacity: .7; margin-left: 4px; }

.empty { text-align: center; padding: 18vh 24px 0; }
.empty__icon { font-size: 56px; }
.empty p { margin: 6px 0; font-size: 18px; }
.muted { color: var(--muted); font-size: 15px; }

.footer-links { text-align: center; margin-top: 28px; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; padding: 12px; font-size: 15px; }

/* ---------- Eingabeleiste ---------- */
.composer {
  position: fixed; left: 0; right: 0; bottom: var(--kb); z-index: 20;
  padding: 8px 12px calc(10px + var(--safe-bottom));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.composer__row {
  display: flex; gap: 8px; align-items: center;
  max-width: 640px; margin: 0 auto;
}
.composer__input {
  flex: 1; min-width: 0;
  height: 54px; padding: 0 16px;
  border-radius: 27px; border: 1.5px solid var(--line);
  background: var(--surface);
  font-size: 18px;               /* >= 16px verhindert Auto-Zoom auf iOS */
  outline: none;
}
.composer__input:focus { border-color: var(--accent); }
.cat-btn, .add-btn {
  flex: none; width: 54px; height: 54px; border-radius: 50%;
  display: grid; place-items: center; border: 0;
}
.cat-btn { background: var(--surface); border: 1.5px solid var(--line); font-size: 26px; }
.cat-btn.is-manual { border-color: var(--accent); }
.add-btn { background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow); }
.add-btn:active { background: var(--accent-strong); transform: scale(.96); }
.add-btn svg { width: 28px; height: 28px; stroke: currentColor; stroke-width: 2.6; fill: none; stroke-linecap: round; }

.suggestions {
  display: flex; gap: 8px; overflow-x: auto;
  max-width: 640px; margin: 0 auto;
  scrollbar-width: none;
}
.suggestions::-webkit-scrollbar { display: none; }
.suggestions:not(:empty) { padding-bottom: 8px; }
.chip {
  flex: none;
  display: inline-flex; align-items: center; gap: 6px;
  height: 40px; padding: 0 14px;
  border-radius: 20px; border: 1px solid var(--line);
  background: var(--surface); font-size: 16px; white-space: nowrap;
}
.chip:active { background: var(--accent-soft); }

/* ---------- Buttons ---------- */
.btn {
  min-height: 48px; padding: 0 18px;
  border-radius: 12px; border: 1.5px solid transparent;
  font-weight: 600; font-size: 16px;
  background: var(--surface-2);
}
.btn--primary { background: var(--accent); color: var(--on-accent); }
.btn--primary:active { background: var(--accent-strong); }
.btn--ghost { background: transparent; border-color: var(--line); }
.btn--danger { background: var(--danger-soft); color: var(--danger); }
.btn--block { width: 100%; }
.btn--lg { min-height: 56px; font-size: 18px; }

/* ---------- Bottom Sheets ---------- */
.sheet {
  border: 0; padding: 0; margin: auto 0 0 0;
  width: 100%; max-width: 100%;
  max-height: 88dvh;
  background: var(--surface); color: var(--text);
  border-radius: 22px 22px 0 0;
  box-shadow: var(--shadow);
}
@media (min-width: 700px) {
  .sheet { max-width: 560px; margin: auto; border-radius: 22px; }
}
.sheet[open] { animation: sheet-in .22s ease-out; }
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } }
.sheet::backdrop { background: rgba(0,0,0,.4); }
.sheet__inner { padding: 8px 16px calc(16px + var(--safe-bottom)); display: grid; gap: 14px; }
.sheet__handle { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 0; }
.sheet__title { margin: 0; font-size: 19px; text-align: center; }
.sheet__actions { display: grid; grid-template-columns: auto 1fr 1fr; gap: 8px; }

.cat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cat-opt {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 78px; padding: 6px;
  border-radius: 14px; border: 2px solid transparent;
  background: var(--surface-2); font-size: 13px; line-height: 1.15; text-align: center;
}
.cat-opt .e { font-size: 28px; }
.cat-opt.is-active { border-color: var(--accent); background: var(--accent-soft); }
.cat-grid--compact .cat-opt { min-height: 62px; }
.cat-grid--compact .cat-opt .e { font-size: 22px; }

.field { display: grid; gap: 6px; }
.field > span { font-size: 14px; color: var(--muted); font-weight: 600; }
.field input {
  height: 50px; padding: 0 14px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--bg); font-size: 18px; outline: none;
}
.field input:focus { border-color: var(--accent); }

/* ---------- Login ---------- */
.login {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  padding: 24px; padding-top: calc(24px + var(--safe-top));
  background: var(--bg);
}
.login__card { width: 100%; max-width: 360px; text-align: center; display: grid; gap: 12px; }
.login__card h2 { margin: 0; font-size: 26px; }
.login__card p { margin: 0; }
.login__icon { font-size: 48px; }
.login__input {
  height: 64px; text-align: center; font-size: 30px; letter-spacing: .3em;
  border-radius: 16px; border: 2px solid var(--line); background: var(--surface); outline: none;
}
.login__input:focus { border-color: var(--accent); }
.login__error { color: var(--danger); min-height: 1.4em; font-size: 15px; }
.login.is-shake .login__input { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 50% { transform: translateX(8px); } 75% { transform: translateX(-4px); } }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 12px; right: 12px; z-index: 40;
  bottom: calc(96px + var(--safe-bottom) + var(--kb));
  max-width: 520px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px;
  min-height: 52px; padding: 6px 8px 6px 18px;
  border-radius: 14px;
  background: #1f2a24; color: #fff;
  box-shadow: var(--shadow);
  animation: toast-in .2s ease-out;
}
@media (prefers-color-scheme: dark) { .toast { background: #e8eee9; color: #111; } }
@keyframes toast-in { from { transform: translateY(12px); opacity: 0; } }
#toastText { flex: 1; }
.toast__action {
  min-height: 42px; padding: 0 14px; border-radius: 10px; border: 0;
  background: transparent; color: #86efac; font-weight: 700; font-size: 16px;
}
@media (prefers-color-scheme: dark) { .toast__action { color: var(--accent); } }

.noscript { padding: 24px; text-align: center; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
.sheet__title:focus { outline: none; }

/* ---------- Accounts, Einstellungen (v2) ---------- */
.small { font-size: 13px; }
.center { text-align: center; margin: -6px 0 0; }
.hint { text-align: center; color: var(--muted); font-size: 13px; margin: 18px 0 0; }

.icon-btn {
  flex: none; width: 44px; height: 44px; margin-right: -6px;
  display: grid; place-items: center;
  background: none; border: 0; border-radius: 50%;
}
.avatar {
  display: inline-grid; place-items: center; flex: none;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--av, #64748b); color: #fff;
  font-weight: 700; font-size: 15px; line-height: 1;
  box-shadow: 0 0 0 2px rgba(255,255,255,.55);
}
.avatar--lg { width: 48px; height: 48px; font-size: 20px; box-shadow: none; }
.avatar--sm { width: 28px; height: 28px; font-size: 13px; box-shadow: none; }

.item__by { color: var(--muted); }

.me-card { display: flex; align-items: center; gap: 14px; padding: 12px 14px; border-radius: 14px; background: var(--surface-2); }
.me-card__name { font-size: 19px; font-weight: 700; }

.settings-sec h3 { margin: 4px 2px 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.settings-sec > p { margin: 6px 2px 0; }

.rows { list-style: none; margin: 0; padding: 0; border-radius: 14px; overflow: hidden; background: var(--surface-2); }
.rows li { display: flex; align-items: center; gap: 12px; min-height: 54px; padding: 6px 8px 6px 14px; border-top: 1px solid var(--line); }
.rows li:first-child { border-top: 0; }
.rows .grow { flex: 1; min-width: 0; }
.rows .sub { display: block; font-size: 13px; color: var(--muted); }
.badge { display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 8px; font-size: 11px; font-weight: 700; background: var(--accent-soft); color: var(--accent-strong); vertical-align: 2px; }
.row-btn {
  flex: none; min-width: 44px; height: 44px; padding: 0 10px;
  border-radius: 10px; border: 0; background: transparent; color: var(--muted); font-size: 14px; font-weight: 600;
}
.row-btn:active { background: var(--line); }
.row-btn:disabled { opacity: .25; }
.row-btn--danger { color: var(--danger); }
.row-btn svg { width: 22px; height: 22px; stroke: currentColor; stroke-width: 2.4; fill: none; stroke-linecap: round; stroke-linejoin: round; }
#catOrder .e { font-size: 22px; width: 28px; text-align: center; }

.switch-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px; background: var(--surface-2); }
.switch-row > span { flex: 1; }
.switch-row small { display: block; font-size: 13px; }
.switch {
  appearance: none; -webkit-appearance: none; flex: none;
  width: 52px; height: 32px; border-radius: 16px; margin: 0;
  background: var(--line); position: relative; cursor: pointer; transition: background .2s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 26px; height: 26px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .2s;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }

.pw-details { border-radius: 14px; background: var(--surface-2); }
.pw-details summary { padding: 15px 14px; font-weight: 600; cursor: pointer; list-style-position: inside; }
.pw-form { display: grid; gap: 12px; padding: 0 14px 14px; }

.sheet__actions--two { grid-template-columns: 1fr 1fr; }
.sheet { overscroll-behavior: contain; }

/* Login / Registrierung */
.login { overflow-y: auto; align-items: start; }
.login__card { margin: max(4vh, 12px) auto 24px; }
.login__logo { margin: 0 auto; border-radius: 18px; }
.login .field { text-align: left; }
.login .field input { background: var(--surface); }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 14px; background: var(--surface-2); }
.seg button { min-height: 44px; border: 0; border-radius: 10px; background: transparent; font-weight: 600; color: var(--muted); }
.seg button.is-active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* v2.1: Leeren-Knopf im Abschnitt "Im Wagen", Feinschliff */
.group__head .n + .group__clear { margin-left: 12px; }
.group__clear {
  min-height: 36px; padding: 0 12px; border: 0; border-radius: 10px;
  background: var(--danger-soft); color: var(--danger);
  font-size: 14px; font-weight: 700; text-transform: none; letter-spacing: 0;
}
.rows--plain { background: var(--surface); }
.rows .row-btn:not(:has(svg)) { font-size: 13px; padding: 0 8px; }
.sync.is-offline {
  width: auto; height: auto; padding: 3px 9px; border-radius: 10px;
  background: #fbbf24; color: #3b2a00; font-size: 12px; font-weight: 700; line-height: 1.2;
}

/* ---------- v3: Verschieben, Menge, Wer hat's gemacht ---------- */
.composer__qty {
  flex: none; width: 82px; height: 54px; padding: 0 10px;
  border-radius: 27px; border: 1.5px solid var(--line);
  background: var(--surface); font-size: 17px; text-align: center; outline: none;
}
.composer__qty:focus { border-color: var(--accent); }
.composer__qty:not(:placeholder-shown) { border-color: var(--accent); font-weight: 700; color: var(--accent-strong); }
.composer__row { gap: 6px; }
.cat-btn, .add-btn { width: 50px; height: 50px; }
.composer__input { height: 54px; padding: 0 14px; }
.chip--qty { min-width: 48px; justify-content: center; font-weight: 600; }
.chip.is-active { border-color: var(--accent); background: var(--accent-soft); }

.item__qty { display: flex; flex-wrap: wrap; column-gap: 0; }
.item__amount { font-weight: 700; color: var(--accent-strong); }
.item.is-checked .item__amount { color: var(--checked); }
.item__checked-by { color: var(--accent); }
.item.is-checked .item__checked-by { color: var(--accent); }
.item__qty .dot { white-space: pre; }

.item__grip {
  flex: none; width: 40px; height: var(--row-h);
  display: grid; place-items: center;
  background: none; border: 0; color: var(--muted); opacity: .7;
  touch-action: none; cursor: grab;
}
.item__grip svg { width: 20px; height: 20px; fill: currentColor; }
.item__del { width: 46px; }
.item__toggle { padding-right: 0; }

.list.is-dragging, .list.is-dragging * { user-select: none; -webkit-user-select: none; cursor: grabbing; }
.group--empty { display: none; }
.list.is-dragging .group--empty { display: block; }
.group--empty .group__items {
  min-height: 52px; background: transparent; box-shadow: none;
  border: 2px dashed var(--line); border-radius: var(--radius);
}
.list.is-dragging .group--empty .group__items:empty::before {
  content: "hierher ziehen"; display: block; padding: 14px; text-align: center; color: var(--muted); font-size: 14px;
}
.item.is-drag-source { opacity: .3; }
.item--ghost {
  position: fixed; z-index: 60; margin: 0; pointer-events: none;
  background: var(--surface); border-radius: 14px; border-top: 0;
  box-shadow: 0 14px 34px rgba(0,0,0,.28); transform: scale(1.03);
}

.btn--sm { min-height: 40px; padding: 0 12px; font-size: 14px; margin-left: auto; }
#editMeta { white-space: pre-line; line-height: 1.5; }

/* Eigenes Ausgleichs-Scrollen beim Ziehen; Browser-Scroll-Anchoring würde sich sonst addieren */
html { overflow-anchor: none; }

/* ---------- v4: Ein Einkaufswagen pro Person ---------- */
.group--cart .group__head { gap: 6px; }
.group__toggle {
  flex: 1; min-width: 0; min-height: 40px;
  display: flex; align-items: center; gap: 8px; padding: 0;
  background: none; border: 0; color: inherit; text-align: left;
  font: inherit; text-transform: inherit; letter-spacing: inherit;
}
.group__toggle .n { margin-left: 6px; }
.group__toggle .chev { margin-left: auto; margin-right: 6px; font-size: 14px; transition: transform .15s; }
.group--cart.is-collapsed .group__items { display: none; }
.group--cart.is-collapsed .chev { transform: rotate(-90deg); }
.group--cart:not(.is-collapsed) .chev { transform: none; }
.group--mine .group__head { color: var(--accent-strong); }
.group--cart + .group--cart { margin-top: 2px; }
.avatar--xs { width: 22px; height: 22px; font-size: 11px; box-shadow: none; }

/* ---------- v4.1: Löschen erst nach zweitem Tipp ---------- */
.item__del .del-label { display: none; }
.item__del.is-armed {
  width: auto; height: 44px; margin-right: 8px; padding: 0 14px;
  display: flex; align-items: center; gap: 6px;
  border-radius: 12px; background: var(--danger); color: #fff;
  font-weight: 700; font-size: 15px; animation: armed-in .15s ease-out;
}
.item__del.is-armed .del-label { display: inline; }
.item:has(.item__del.is-armed) .item__grip { display: none; }
.group__clear .lbl-armed { display: none; }
.group__clear.is-armed { background: var(--danger); color: #fff; animation: armed-in .15s ease-out; }
.group__clear.is-armed .lbl { display: none; }
.group__clear.is-armed .lbl-armed { display: inline; }
@keyframes armed-in { from { transform: scale(.92); opacity: .6; } }
