/* ==========================================================================
   Einkaufsliste — Stylesheet
   Mobile first. Hell/Dunkel folgt automatisch dem System.
   ========================================================================== */

:root {
  --bg:        #f4f6f4;
  --surface:   #ffffff;
  --surface-2: #ecefec;
  --text:      #131815;
  --muted:     #6c7a72;
  --line:      #dfe4e0;
  --accent:    #16a34a;
  --accent-ink:#ffffff;
  --danger:    #dc2626;
  --shadow:    0 1px 2px rgba(0,0,0,.05), 0 8px 24px rgba(0,0,0,.06);

  --m0:#e11d48; --m1:#2563eb; --m2:#d97706; --m3:#7c3aed;
  --m4:#0891b2; --m5:#65a30d; --m6:#db2777; --m7:#0f766e;

  --radius: 16px;
  --tap: 48px;
  --kb: 0px;   /* Hoehe der eingeblendeten Tastatur, siehe app.js */
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0f1511;
    --surface:   #18211c;
    --surface-2: #212c25;
    --text:      #e7ece9;
    --muted:     #8d9d95;
    --line:      #2a352e;
    --accent:    #2fbd63;
    --accent-ink:#04170c;
    --danger:    #f05252;
    --shadow:    0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);

    --m0:#fb7185; --m1:#60a5fa; --m2:#fbbf24; --m3:#a78bfa;
    --m4:#22d3ee; --m5:#a3e635; --m6:#f472b6; --m7:#2dd4bf;
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor;
      stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

[hidden] { display: none !important; }

/* ============================== Anmeldung ============================== */

.setup {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  padding: 24px calc(24px + env(safe-area-inset-left)) calc(24px + env(safe-area-inset-bottom));
  background: var(--bg);
  overflow-y: auto;
}
.setup-inner { width: 100%; max-width: 380px; text-align: center; }
.setup-logo { border-radius: 20px; box-shadow: var(--shadow); }
.setup h1 { margin: 18px 0 4px; font-size: 26px; letter-spacing: -.02em; }
.setup-sub { margin: 0 0 28px; color: var(--muted); font-size: 15px; }
.setup-form { text-align: left; display: grid; gap: 16px; }

.field { display: grid; gap: 7px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }

.field input, .code-box {
  width: 100%;
  min-height: var(--tap);
  padding: 0 14px;
  font-size: 16px;            /* < 16px lässt iOS beim Fokus hineinzoomen */
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  outline: none;
}
.field input:focus { border-color: var(--accent); }
#join-code { text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }

.form-error {
  margin: 0; padding: 10px 12px;
  font-size: 14px; color: var(--danger);
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  border-radius: 10px;
}

.btn-primary {
  min-height: var(--tap);
  padding: 0 22px;
  font-weight: 650;
  color: var(--accent-ink);
  background: var(--accent);
  border-radius: 12px;
}
.btn-primary:disabled { opacity: .55; }
.btn-primary:active { transform: scale(.985); }

.btn-ghost-danger {
  min-height: var(--tap);
  padding: 0 18px;
  font-weight: 600;
  color: var(--danger);
  border-radius: 12px;
}
.btn-ghost-danger:active { background: color-mix(in srgb, var(--danger) 12%, transparent); }

/* ================================= App ================================= */

/* iOS verkleinert das Layout-Viewport nicht, wenn die Tastatur aufgeht. --kb wird
   in app.js aus visualViewport berechnet, damit das Eingabefeld sichtbar bleibt. */
.app {
  display: flex; flex-direction: column;
  height: calc(100dvh - var(--kb));
  transition: height .18s ease;
}

.topbar {
  flex: none;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 6px 10px 18px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar-title { flex: 1; display: flex; align-items: center; gap: 9px; min-width: 0; }
.topbar h1 {
  margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.sync-dot {
  flex: none; width: 9px; height: 9px; border-radius: 50%;
  background: var(--muted); transition: background .3s;
}
.sync-dot[data-state="live"]    { background: var(--accent); }
.sync-dot[data-state="pending"] { background: #f59e0b; animation: pulse 1.2s ease-in-out infinite; }
.sync-dot[data-state="offline"] { background: var(--muted); opacity: .5; }
@keyframes pulse { 50% { opacity: .35; } }

.icon-btn {
  flex: none;
  width: var(--tap); height: var(--tap);
  display: grid; place-items: center;
  border-radius: 50%; color: var(--muted);
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { fill: currentColor; stroke: none; }

.scroll {
  flex: 1; min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 10px 12px 0;
}
.scroll-pad { height: 12px; }

/* ------------------------------ Listenzeile ---------------------------- */

.list { list-style: none; margin: 0 0 4px; padding: 0; display: grid; gap: 8px; }

.row {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  user-select: none; -webkit-user-select: none;
}
.row.leaving {
  transition: height .22s ease, opacity .18s ease, margin .22s ease;
  height: 0 !important; opacity: 0; margin-top: -8px; pointer-events: none;
}
.row.flash .row-fg { animation: flash .55s ease; }
@keyframes flash {
  0%, 100% { background: var(--surface); }
  35%      { background: color-mix(in srgb, var(--accent) 26%, var(--surface)); }
}

/* roter Grund, der beim Wischen sichtbar wird */
.row-bg {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: flex-end;
  padding-right: 22px;
  background: var(--danger); color: #fff;
}

.row-fg {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  min-height: 62px;
  padding: 9px 10px 9px 12px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  touch-action: pan-y;
  will-change: transform;
}
.row.swiping .row-fg { transition: none; }
.row-fg.snap { transition: transform .2s cubic-bezier(.2,.8,.3,1); }

.check {
  flex: none;
  width: 27px; height: 27px;
  border: 2.5px solid var(--line);
  border-radius: 50%;
  display: grid; place-items: center;
  transition: background .15s, border-color .15s;
}
.check svg { width: 16px; height: 16px; stroke-width: 3.2; color: var(--accent-ink);
             opacity: 0; transform: scale(.5); transition: opacity .15s, transform .15s; }
.row.done .check { background: var(--accent); border-color: var(--accent); }
.row.done .check svg { opacity: 1; transform: scale(1); }

.row-main { flex: 1; min-width: 0; display: grid; gap: 1px; }
.name {
  font-size: 16.5px; font-weight: 550; letter-spacing: -.005em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row.done .name { text-decoration: line-through; opacity: .45; }
.meta { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.who {
  width: 15px; height: 15px; flex: none;
  border-radius: 50%; color: #fff;
  font-size: 9px; font-weight: 700; line-height: 15px; text-align: center;
}

.pill {
  flex: none;
  min-width: 46px; height: 34px;
  padding: 0 11px;
  font-size: 14.5px; font-weight: 650;
  color: var(--text);
  background: var(--surface-2);
  border-radius: 10px;
}
.pill.pill-add { color: var(--muted); font-weight: 400; }
.pill:active { background: var(--line); }
.row.done .pill { opacity: .45; }

/* --------------------------- Leer / Erledigt --------------------------- */

.empty { padding: 54px 20px; text-align: center; }
.empty-mark { font-size: 42px; opacity: .55; }
.empty-title { margin: 10px 0 2px; font-weight: 650; }
.empty-sub { margin: 0; color: var(--muted); font-size: 14px; }

.done-section { margin-top: 14px; }
.done-head {
  display: flex; align-items: center; gap: 6px;
  min-height: 42px; padding: 0 6px;
  font-size: 14px; font-weight: 600; color: var(--muted);
}
.done-head .chev { width: 18px; height: 18px; transition: transform .2s; }
.done-head[aria-expanded="true"] .chev { transform: rotate(90deg); }
.done-body { padding-top: 4px; }
.list-done .row-fg { min-height: 54px; box-shadow: none; background: var(--surface-2); }
#btn-clear-done { width: 100%; margin-top: 10px; }

/* ------------------------------ Composer ------------------------------- */

.composer {
  flex: none;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
}

.suggestions {
  list-style: none; margin: 0 0 8px; padding: 6px;
  max-height: 216px; overflow-y: auto;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.suggestions li { display: block; }
.suggestions button {
  display: flex; align-items: center; gap: 10px;
  width: 100%; min-height: 44px; padding: 0 10px;
  text-align: left; border-radius: 10px;
}
.suggestions button:active { background: var(--surface-2); }
.suggestions .s-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggestions .s-count { font-size: 12px; color: var(--muted); }

.favorites {
  display: flex; gap: 7px;
  margin-bottom: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.favorites::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  height: 36px; padding: 0 14px;
  font-size: 14.5px; white-space: nowrap;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
}
.chip:active { background: var(--surface-2); transform: scale(.96); }

.add-row { display: flex; gap: 8px; align-items: center; }
#add-input {
  flex: 1; min-width: 0;
  height: 50px; padding: 0 16px;
  font-size: 16px;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 25px;
  outline: none;
}
#add-input:focus { border-color: var(--accent); }
.add-btn {
  flex: none;
  width: 50px; height: 50px;
  display: grid; place-items: center;
  color: var(--accent-ink); background: var(--accent);
  border-radius: 50%;
}
.add-btn:active { transform: scale(.93); }

/* =============================== Sheets ================================ */

.backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,.45);
  animation: fade .2s ease;
}
@keyframes fade { from { opacity: 0; } }

.sheet {
  position: fixed; z-index: 50;
  left: 0; right: 0; bottom: 0;
  display: grid; gap: 16px;
  padding: 8px 18px calc(20px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -8px 40px rgba(0,0,0,.22);
  animation: rise .24s cubic-bezier(.2,.8,.3,1);
  max-height: 88dvh; overflow-y: auto;
}
@keyframes rise { from { transform: translateY(100%); } }
@media (min-width: 620px) {
  .sheet { left: 50%; right: auto; transform: translateX(-50%); width: 460px;
           border-radius: 22px; bottom: 24px; }
  @keyframes rise { from { transform: translate(-50%, 110%); } }
}

.sheet-grip {
  width: 38px; height: 4px; margin: 4px auto 0;
  background: var(--line); border-radius: 2px;
}
.sheet-title { margin: 0; font-size: 18px; }
.sheet-name {
  width: 100%; min-height: var(--tap);
  padding: 0 14px;
  font-size: 17px; font-weight: 600;
  background: var(--surface-2);
  border: 1.5px solid transparent; border-radius: 12px;
  outline: none;
}
.sheet-name:focus { border-color: var(--accent); }

.stepper { display: flex; align-items: center; gap: 10px; }
.step {
  width: 56px; height: 56px; flex: none;
  font-size: 26px; font-weight: 500;
  background: var(--surface-2); border-radius: 16px;
}
.step:active { background: var(--line); }
.qty-input {
  flex: 1; min-width: 0; height: 56px;
  text-align: center; font-size: 21px; font-weight: 650;
  background: none; border: 0; outline: none;
}

.unit-row { display: flex; flex-wrap: wrap; gap: 7px; }
.unit {
  height: 38px; padding: 0 15px;
  font-size: 14.5px;
  background: var(--surface-2); border-radius: 19px;
}
.unit[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 650; }

.sheet-actions { display: flex; gap: 10px; }
.sheet-actions .btn-primary { flex: 1; }

.code-box {
  text-align: left; font-weight: 700; letter-spacing: .08em;
  display: flex; align-items: center;
}
.member-row { display: flex; flex-wrap: wrap; gap: 8px; }
.member {
  display: flex; align-items: center; gap: 7px;
  height: 34px; padding: 0 12px 0 6px;
  font-size: 14px;
  background: var(--surface-2); border-radius: 17px;
}
.member .who { width: 22px; height: 22px; line-height: 22px; font-size: 11px; }

/* ================================ Toast ================================ */

.toast {
  position: fixed; z-index: 70;
  left: 50%; transform: translateX(-50%);
  bottom: calc(96px + env(safe-area-inset-bottom));
  max-width: calc(100vw - 32px);
  padding: 11px 18px;
  font-size: 14.5px;
  color: var(--bg); background: var(--text);
  border-radius: 22px;
  box-shadow: var(--shadow);
  animation: toast-in .22s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
