/* Mobile-first. Getestet gegen iOS-Safari im Standalone-Modus und Chrome
   auf Android; die safe-area-Angaben sind für das iPhone-Notch nötig. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eceff3;
  --text: #14181d;
  --muted: #667085;
  --border: #dfe3e9;
  --accent: #0b6bcb;
  --accent-text: #ffffff;
  --danger: #c0392b;
  --ok: #1e8449;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1a1f26;
    --surface-2: #232a33;
    --text: #e8ecf1;
    --muted: #98a2b3;
    --border: #2c333d;
    --accent: #4c9aff;
    --accent-text: #0b1220;
    --danger: #ff6b5e;
    --ok: #4ade80;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  /* Verhindert das Gummiband-Scrollen hinter der fixierten Tableiste. */
  overscroll-behavior-y: none;
}

h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }
a { color: var(--accent); }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.strong { font-weight: 600; }
.pad { padding: 12px 16px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Formulare & Knöpfe ---------- */

label { display: block; font-weight: 600; font-size: .9rem; margin: 14px 0 6px; }

input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  /* Unter 16px zoomt iOS beim Fokussieren ins Feld hinein. */
  font-size: 16px;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
button:active { transform: scale(.985); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; width: 100%; margin-top: 18px; }
button.danger { background: transparent; color: var(--danger); border-color: var(--danger); width: 100%; }

.error, .msg { margin: 10px 0 0; font-size: .9rem; }
.error { color: var(--danger); }
.msg.ok { color: var(--ok); }
.msg.bad { color: var(--danger); }

/* ---------- Anmeldung ---------- */

.auth { display: flex; align-items: center; justify-content: center; min-height: 100dvh; padding: 24px; }
.auth-box { width: 100%; max-width: 380px; }
.brand { font-size: 1.4rem; letter-spacing: -.02em; }
.center { text-align: center; }

/* Das Logo bringt weißen Grund und farbige Kontur mit und trägt sich damit
   auf hellem wie dunklem Hintergrund -- keine zweite Variante nötig. */
.logo {
  display: block;
  width: 100%;
  max-width: 275px;
  height: auto;
  margin: 0 auto 16px;
}

/* ---------- Suchleiste ---------- */

.searchbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  padding: max(10px, env(safe-area-inset-top)) 12px 8px;
  border-bottom: 1px solid var(--border);
}
/* Schmales Logo über der Suchzeile. Bewusst klein: die Suchleiste klebt oben
   fest, jeder Pixel geht sonst der Trefferliste verloren. */
.logo-bar {
  display: block;
  height: 28px;
  width: auto;
  margin: 0 auto 8px;
}

.search-row { display: flex; gap: 8px; align-items: center; }
.search-row input { flex: 1; }

.icon-btn {
  flex: 0 0 auto;
  width: 46px; height: 46px;
  padding: 0;
  font-size: 1.25rem;
  display: grid; place-items: center;
}
.icon-btn.on { color: #f5b301; border-color: #f5b301; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips:empty { display: none; }

.chip {
  flex: 0 0 auto;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: .85rem;
  font-weight: 500;
  white-space: nowrap;
}
.chip.active { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.chip .n { opacity: .65; margin-left: 4px; font-variant-numeric: tabular-nums; }

/* ---------- Ergebnisse ---------- */

.status { padding: 10px 16px; font-size: .9rem; }
.status.warn { color: var(--danger); }

.group-head {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  padding: 14px 16px 6px;
  background: var(--bg);
  font-weight: 700;
}
.group-head .n { font-weight: 500; color: var(--muted); font-size: .85rem; }

.offer {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.offer img {
  width: 62px; height: 62px;
  flex: 0 0 auto;
  object-fit: contain;
  border-radius: 8px;
  background: var(--surface-2);
}
.offer .body { flex: 1; min-width: 0; }
.offer .title { font-weight: 600; }
.offer .sub { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.offer .meta { display: flex; gap: 10px; align-items: baseline; margin-top: 6px; flex-wrap: wrap; }

.price { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.price-old { color: var(--muted); text-decoration: line-through; font-size: .85rem; }
.unit { color: var(--muted); font-size: .8rem; }
/* Fußzeile der Angebotskarte: Gültigkeit links, Geltungsbereich rechts. */
.offer .foot {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
}
.until { color: var(--muted); font-size: .78rem; }
.until.soon { color: var(--danger); font-weight: 600; }
.until.upcoming { color: var(--accent); font-weight: 600; }

/* Bewusst zurückhaltend: eine Einordnung, keine Warnung. */
.scope {
  flex: 0 0 auto;
  font-size: .72rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 7px;
  white-space: nowrap;
}

.empty { padding: 48px 24px; text-align: center; color: var(--muted); }

/* ---------- Listen & Karten ---------- */

.list > .item {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.list > .item button { padding: 6px 10px; font-size: .85rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin: 12px 16px; box-shadow: var(--shadow); }
.card.pad { padding: 16px; }

/* ---------- Bevorzugte Märkte ---------- */

/* Umbrechende Chipreihe statt seitlich scrollender -- hier soll man alles
   auf einen Blick sehen, nicht wischen. */
.chips.wrap { flex-wrap: wrap; overflow: visible; }

.pref-list { margin-top: 10px; }
.pref-list:empty::after {
  content: "Noch keine Auswahl — es werden alle Märkte angezeigt.";
  display: block;
  color: var(--muted);
  font-size: .85rem;
  padding: 6px 0;
}

.pref-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  margin-bottom: 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}
.pref-item .pos {
  flex: 0 0 auto;
  width: 22px;
  color: var(--muted);
  font-size: .8rem;
  font-variant-numeric: tabular-nums;
}
.pref-item .name { flex: 1; font-weight: 600; font-size: .92rem; min-width: 0; }
.pref-item button {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  padding: 0;
  display: grid; place-items: center;
  font-size: 1rem;
}
.pref-item button:disabled { opacity: .3; }
.pref-item button.remove { color: var(--danger); border-color: transparent; background: transparent; }

.addhead { margin: 16px 0 6px; }

/* ---------- Einkaufsliste ---------- */

.item.shop { gap: 10px; }
.item.shop .body { flex: 1; min-width: 0; }
.item.shop .name { font-weight: 600; }
.item.shop.done .name { text-decoration: line-through; color: var(--muted); }

/* Der Treffer ist die eigentliche Belohnung -- deshalb farbig und fett. */
.item.shop .hit {
  font-size: .82rem;
  color: var(--ok);
  font-weight: 600;
  margin-top: 2px;
}
.item.shop .hit.none { color: var(--muted); font-weight: 400; }

.item.shop .check {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  padding: 0;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 1.05rem;
}
.item.shop .check.on { background: var(--ok); border-color: transparent; color: #fff; }
.item.shop .kill { border: 0; background: transparent; color: var(--muted); padding: 6px 4px; }

/* Zähler auf dem Tab -- zeigt, wie viele Listeneinträge gerade im Angebot sind. */
#tabbar button { position: relative; }
.badge {
  position: absolute;
  top: 2px;
  left: 50%;
  margin-left: 4px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: .65rem;
  font-style: normal;
  font-weight: 700;
  line-height: 17px;
  text-align: center;
}

.run { border-left: 3px solid var(--ok); }
.run.bad { border-left-color: var(--danger); }
.run .detail { font-size: .8rem; color: var(--muted); word-break: break-word; }

.page-head { padding: max(16px, env(safe-area-inset-top)) 16px 4px; }

/* ---------- Tableiste ---------- */

.tab { padding-bottom: 92px; }

#tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabbar button {
  flex: 1;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: .7rem;
  font-weight: 500;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 6px;
}
#tabbar button span { font-size: 1.25rem; }
#tabbar button.active { color: var(--accent); }

[hidden] { display: none !important; }
