/* ===== Farben & Grundwerte ============================================== */
:root {
  --bg: #f2f5f1;
  --card: #ffffff;
  --field: #f5f7f4;
  --text: #16201a;
  --muted: #69746d;
  --line: #e5e9e3;
  --accent: #168a55;
  --accent-strong: #0f6d42;
  --accent-soft: #e7f5ed;
  --accent-text: #ffffff;
  --chip: #eef2ec;
  --danger: #c0352b;
  --hero-1: #1fa565;
  --hero-2: #0d6a3f;
  --shadow: 0 1px 2px rgba(16, 32, 22, .05), 0 8px 24px rgba(16, 32, 22, .07);
  --shadow-lift: 0 10px 30px rgba(16, 32, 22, .18);
  --radius: 18px;
  --radius-sm: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1311;
    --card: #181d1a;
    --field: #202723;
    --text: #e8eee9;
    --muted: #97a39b;
    --line: #29312c;
    --accent: #3cc483;
    --accent-strong: #2fa86d;
    --accent-soft: #173326;
    --accent-text: #07120c;
    --chip: #222924;
    --hero-1: #17663f;
    --hero-2: #0b3a24;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lift: 0 10px 30px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
h1, h2, h3 { letter-spacing: -.01em; }
h1 { font-size: 24px; margin: 0; font-weight: 750; }
h2 { font-size: 18px; margin: 0; }
h3 { margin: 4px 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ===== Kopfbereich ====================================================== */
.hero {
  background: linear-gradient(140deg, var(--hero-1) 0%, var(--hero-2) 100%);
  color: #fff;
  padding: calc(18px + env(safe-area-inset-top)) 16px 34px;
  border-radius: 0 0 28px 28px;
  box-shadow: 0 6px 24px rgba(13, 106, 63, .25);
}
.hero-inner {
  max-width: 720px; margin: 0 auto;
  display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { width: 34px; height: 34px; border-radius: 10px; box-shadow: 0 2px 8px rgba(0, 0, 0, .2); }
.hero h1 { color: #fff; }
#status { font-size: 14px; min-height: 1.3em; color: rgba(255, 255, 255, .92); }
#status:empty { display: none; }

.tabs {
  display: flex; gap: 4px; padding: 4px; width: 100%; max-width: 460px;
  background: rgba(255, 255, 255, .16); border-radius: 14px;
  backdrop-filter: blur(6px);
}
.tab {
  flex: 1; padding: 8px 4px; border-radius: 10px; background: none;
  color: rgba(255, 255, 255, .88); font-size: 15px; font-weight: 600;
  transition: background .15s, color .15s;
}
.tab:hover { background: rgba(255, 255, 255, .1); }
.tab.active { background: #fff; color: var(--hero-2); box-shadow: 0 2px 8px rgba(0, 0, 0, .15); }
.tab .lock { font-size: 11px; margin-left: 3px; opacity: .85; }

/* ===== Inhalt & Karten =================================================== */
main { max-width: 720px; margin: -20px auto 0; padding: 0 14px; position: relative; }
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin: 0 0 14px;
}
.card-title { font-size: 17px; font-weight: 700; margin: 0 0 10px; }
.row { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; flex-wrap: wrap; }
.or { color: var(--muted); font-size: 14px; }
label[for] { min-width: 92px; color: var(--muted); font-size: 15px; }

/* ===== Eingaben ========================================================== */
input:not([type]), input[inputmode], input[type=password], input[type=number], input[type=date], select, #new-item {
  font: inherit; color: var(--text);
  background: var(--field); border: 1.5px solid transparent; border-radius: var(--radius-sm);
  min-height: 44px; padding: 9px 12px; outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
input:not([type]), input[inputmode], input[type=password], #new-item { flex: 1; min-width: 0; }
input:focus, select:focus {
  border-color: var(--accent); background: var(--card);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}
::placeholder { color: color-mix(in srgb, var(--muted) 80%, transparent); }
#plz { max-width: 120px; flex: none; text-align: center; letter-spacing: .08em; font-weight: 600; }
#new-qty { width: 60px; flex: none; text-align: center; padding: 9px 4px; }
#day { flex: 1; }
input[type=range] { flex: 1; accent-color: var(--accent); height: 28px; }
output { min-width: 52px; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent-strong); }

/* ===== Knöpfe ============================================================ */
button, .button {
  font: inherit; font-weight: 600; border: 0; border-radius: var(--radius-sm);
  min-height: 44px; padding: 10px 16px; cursor: pointer;
  background: var(--chip); color: var(--text); text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-align: center;
  transition: transform .08s, background .15s, filter .15s;
}
button:active, .button:active { transform: scale(.97); }
button.primary, .button.primary {
  background: linear-gradient(140deg, var(--hero-1), var(--accent-strong));
  color: #fff; box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 35%, transparent);
}
button.primary:hover, .button.primary:hover { filter: brightness(1.05); }
button.secondary { background: var(--accent-soft); color: var(--accent-strong); }
button.link, a.link {
  background: none; color: var(--accent-strong); min-height: 36px; padding: 6px 8px; font-weight: 600; box-shadow: none;
}
button:disabled { opacity: .45; cursor: default; transform: none; box-shadow: none; }
#add-form button {
  font-size: 22px; width: 48px; padding: 0; flex: none;
  background: linear-gradient(140deg, var(--hero-1), var(--accent-strong)); color: #fff;
}
.small-btn { min-height: 36px; padding: 6px 12px; font-size: 14px; }
button.full { display: flex; width: 100%; margin-top: 8px; }

/* ===== Liste ============================================================= */
#list { list-style: none; margin: 10px 0 0; padding: 0; }
#list li { border-top: 1px solid var(--line); padding: 12px 0; }
#list li:first-child { border-top: 0; }
#list li.muted { text-align: center; padding: 22px 0; }
.item-head { display: flex; align-items: center; gap: 10px; }
.item-head input[type=checkbox] {
  appearance: none; -webkit-appearance: none; flex: none;
  width: 26px; height: 26px; margin: 0; border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--muted) 55%, transparent); background: var(--card);
  display: grid; place-items: center; cursor: pointer; transition: all .15s;
}
.item-head input[type=checkbox]:checked { background: var(--accent); border-color: var(--accent); }
.item-head input[type=checkbox]:checked::after {
  content: ""; width: 7px; height: 12px; margin-top: -3px;
  border: solid #fff; border-width: 0 2.5px 2.5px 0; transform: rotate(45deg);
}
.item-name { flex: 1; font-weight: 600; font-size: 16.5px; overflow-wrap: anywhere; }
.done .item-name { text-decoration: line-through; color: var(--muted); font-weight: 500; }
.item-del {
  background: none; color: var(--muted); min-height: 32px; width: 32px; padding: 0;
  font-size: 16px; border-radius: 50%; opacity: .7;
}
.item-del:hover { background: var(--chip); opacity: 1; }

.qty {
  display: inline-flex; align-items: center; flex: none;
  background: var(--chip); border-radius: 999px; padding: 2px;
}
.qty button {
  min-height: 28px; width: 28px; padding: 0; border-radius: 50%;
  background: var(--card); color: var(--accent-strong); font-size: 17px; line-height: 1;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
}
.qty span { min-width: 32px; text-align: center; font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; }

/* ===== Angebots-Chips ===================================================== */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 0 36px; }
.chip {
  --c: var(--accent);
  display: inline-flex; align-items: baseline; justify-content: flex-start; flex-wrap: wrap; gap: 2px 7px; max-width: 100%;
  min-height: 0; padding: 6px 10px 6px 9px; border-radius: 10px; cursor: pointer;
  background: var(--card); color: var(--text); font-size: 13px; font-weight: 400; text-align: left;
  border: 1px solid var(--line); border-left: 4px solid var(--c);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
}
.chip:hover { border-color: color-mix(in srgb, var(--c) 45%, var(--line)); border-left-color: var(--c); }
.chip .dot { display: none; }
.chip .c { color: var(--c); font-weight: 750; font-size: 12px; text-transform: uppercase; letter-spacing: .02em; }
@media (prefers-color-scheme: dark) {
  .chip .c { color: color-mix(in srgb, var(--c) 62%, #fff); }
}
.chip .p { font-weight: 800; font-size: 14px; font-variant-numeric: tabular-nums; }
.chip .s { font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.chip .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 190px; color: var(--muted); }
.chip .d { font-size: 11px; color: var(--muted); font-style: italic; }
.chip.off { opacity: .4; text-decoration: line-through; }
.chip.later { opacity: .6; border-style: dashed; border-left-style: solid; }
.chip.more {
  border: 1px dashed color-mix(in srgb, var(--accent) 50%, transparent); border-left-width: 1px;
  color: var(--accent-strong); font-weight: 600; background: var(--accent-soft);
}
.no-hit { margin: 6px 0 0 36px; font-size: 13px; color: var(--muted); }
.no-hit.searching { color: var(--accent-strong); font-weight: 600; }

/* ===== Summe, Sortierung ================================================== */
.list-total {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--accent-soft); border-radius: 14px; padding: 12px 14px; margin-top: 10px;
}
.list-total strong { font-size: 24px; font-weight: 800; color: var(--accent-strong); font-variant-numeric: tabular-nums; }
.sort { font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 8px; }
.sort select { min-height: 36px; padding: 4px 8px; font-size: 14px; max-width: 200px; }

/* ===== Standort ========================================================== */
#loc-info { margin-top: 6px; }
#loc-card.need { box-shadow: 0 0 0 2px var(--danger), var(--shadow); }
#loc-card.need #loc-info { color: var(--danger); font-weight: 600; }

/* ===== Anmeldung ========================================================= */
#login-card { text-align: center; padding: 26px 18px; }
#login-card .row { max-width: 420px; margin: 14px auto 0; }
#login-title { font-size: 20px; }
.error { color: var(--danger); min-height: 1.2em; margin-top: 6px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; }
body.locked #loc-card, body.locked #list-card, body.locked #route-card, body.locked #sources, body.locked .bar { display: none !important; }

/* ===== Route ============================================================= */
.route-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 6px; }
.route-head .card-title { margin: 0; }
#route-summary {
  margin: 8px 0 0; font-weight: 600; color: var(--accent-strong);
  background: var(--accent-soft); border-radius: 10px; padding: 8px 12px; display: inline-block;
}
#map { height: 300px; border-radius: 14px; margin: 12px 0; z-index: 0; overflow: hidden; }
#stops { padding-left: 0; list-style: none; counter-reset: s; margin: 0; }
#stops > li { border-top: 1px solid var(--line); padding: 12px 0 12px 44px; position: relative; }
#stops > li::before {
  counter-increment: s; content: counter(s);
  position: absolute; left: 0; top: 12px; width: 30px; height: 30px; border-radius: 50%;
  color: #fff; font-weight: 800; display: grid; place-items: center; background: var(--c, var(--accent));
  box-shadow: 0 2px 6px rgba(0, 0, 0, .18);
}
.stop-title { font-weight: 700; }
.stop-items { margin: 6px 0 0; padding: 0; list-style: none; font-size: 14px; }
.stop-items li { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; }
.stop-items .p { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
#maps-link { display: flex; margin-top: 14px; }
#sources { margin: 4px 6px 24px; text-align: center; }

/* ===== Untere Leiste ===================================================== */
.bar {
  position: fixed; z-index: 10;
  left: 50%; transform: translateX(-50%);
  bottom: calc(12px + env(safe-area-inset-bottom));
  width: calc(100% - 24px); max-width: 696px;
  display: flex; gap: 8px; align-items: center;
  padding: 8px; border-radius: 20px;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(14px) saturate(1.4); -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  box-shadow: var(--shadow-lift);
}
/* min-width: 0 → Knöpfe dürfen schmaler als ihr Text werden, statt aus dem Bild zu laufen */
.bar button {
  flex: 1 1 0; min-width: 0; min-height: 48px; border-radius: 14px; padding: 10px 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; }
.toggle input { accent-color: var(--accent); width: 18px; height: 18px; }
.bar .toggle { flex: none; padding: 0 2px 0 6px; font-weight: 600; line-height: 1.15; font-size: 12.5px; }

/* ===== Angebots-Dialog ==================================================== */
dialog {
  border: 0; border-radius: 22px; padding: 18px; width: min(420px, calc(100vw - 28px));
  background: var(--card); color: var(--text); box-shadow: var(--shadow-lift);
}
dialog::backdrop { background: rgba(10, 20, 14, .45); backdrop-filter: blur(3px); }
#od-img { width: 100%; max-height: 210px; object-fit: contain; background: #fff; border-radius: 14px; padding: 6px; }
.od-chain { font-size: 13px; font-weight: 800; margin-top: 10px; text-transform: uppercase; letter-spacing: .03em; }
#od-price { font-size: 22px; color: var(--accent-strong); }

/* ===== Karte & Animationen ================================================ */
.marker-num {
  width: 28px; height: 28px; border-radius: 50%; color: #fff; font-weight: 800; font-size: 13px;
  display: grid; place-items: center; border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .4);
}
.spin { display: inline-block; animation: spin 1s linear infinite; }

/* Laufbalken oben, solange gesucht wird */
body::before {
  content: ""; position: fixed; top: 0; left: 0; right: 0; height: 4px; z-index: 50;
  background: linear-gradient(90deg, transparent 0%, var(--hero-1) 35%, #8ff0bf 50%, var(--hero-1) 65%, transparent 100%);
  background-size: 50% 100%; background-repeat: no-repeat;
  opacity: 0; transition: opacity .2s;
}
body.busy::before { opacity: 1; animation: busybar 1.1s linear infinite; }
@keyframes busybar { from { background-position: -50% 0; } to { background-position: 150% 0; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* Schmale Handys */
@media (max-width: 380px) {
  .chip .t { max-width: 140px; }
  label[for] { min-width: 80px; }
  .bar { gap: 6px; padding: 6px; }
  .bar .toggle { font-size: 12px; padding-left: 4px; }
  .bar button { font-size: 15px; padding: 10px 6px; }
}
