:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #1b1d21;
  --muted: #6b7280;
  --line: #e6e8ec;
  --spoe: #e2001a;
  --spoe-dark: #b80016;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 6px 18px rgba(0,0,0,.06);
  /* Potenzial-Verlauf: hellrosa (1 = niedrig) -> dunkelrot (5 = hoch) */
  --a1: #fee5d9;
  --a2: #fcae91;
  --a3: #fb6a4a;
  --a4: #de2d26;
  --a5: #a50f15;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 17px;
  line-height: 1.35;
}
.hidden { display: none !important; }
.screen { min-height: 100%; }

/* ---------- Buttons / Inputs ---------- */
button { font: inherit; cursor: pointer; border: none; border-radius: 12px; }
.primary { background: var(--spoe); color: #fff; padding: 15px 18px; font-weight: 600; }
.primary:active { background: var(--spoe-dark); }
.secondary { background: #fff; color: var(--ink); border: 1.5px solid var(--line); padding: 14px 18px; font-weight: 600; }
.wide { width: 100%; }
input, textarea {
  width: 100%; font: inherit; padding: 14px; margin: 6px 0;
  border: 1.5px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink);
}
input:focus, textarea:focus { outline: none; border-color: var(--spoe); }

/* ---------- Login ---------- */
#login { display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { background: var(--card); border-radius: 20px; box-shadow: var(--shadow); padding: 28px 22px; width: 100%; max-width: 380px; }
.brand { font-size: 26px; font-weight: 800; color: var(--spoe); letter-spacing: -.5px; }
.sub { color: var(--muted); margin: 4px 0 18px; }
.error { color: var(--spoe); min-height: 20px; margin: 8px 0 0; font-size: 15px; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  background: #fff; border-bottom: 1px solid var(--line);
  padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top));
}
.gemeinde { flex: 1; min-width: 0; }
.gemeinde-name { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gemeinde-user { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seg { display: inline-flex; background: var(--bg); border-radius: 10px; padding: 3px; flex: none; }
.seg-btn { background: transparent; color: var(--muted); padding: 7px 11px; border-radius: 8px; font-weight: 600; font-size: 14px; }
.seg-btn.active { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.1); }
.icon-btn { background: transparent; color: var(--muted); font-size: 20px; padding: 8px 10px; }

.offline-bar { background: #fff7e6; color: #92600a; border-bottom: 1px solid #f3e2bd; padding: 8px 14px; font-size: 14px; text-align: center; }

/* ---------- Liste ---------- */
.list-toolbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; padding: 10px 12px 8px; background: var(--bg); }
.sort-label { flex: none; color: var(--muted); font-size: 14px; font-weight: 600; }
.sort-select { flex: 1; margin: 0; padding: 9px 10px; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; font-weight: 600; font-size: 14px; }
.list { list-style: none; margin: 0; padding: 2px 12px 28px; }
.row {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border-radius: 14px; box-shadow: var(--shadow);
  padding: 14px 16px; margin-bottom: 10px; min-height: 60px; cursor: pointer;
}
.row:active { transform: scale(.995); }
.dot { width: 26px; height: 26px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 2px rgba(255,255,255,.7); }
.row-main { flex: 1; min-width: 0; }
/* Hausnummer muss immer sichtbar bleiben: lange Adressen umbrechen statt abschneiden */
.row-addr { font-weight: 600; overflow-wrap: anywhere; hyphens: auto; }
.row-sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.row-dist { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; flex: none; }
.row-done { flex: none; background: #eef1f4; color: var(--muted); border-radius: 999px; padding: 2px 9px; font-size: 13px; font-weight: 800; font-variant-numeric: tabular-nums; }
.row-done.full { background: #e7f5e8; color: #2e7d32; }
.row-caret { flex: none; width: 1em; text-align: center; color: var(--muted); font-size: 13px; }
.visited { color: var(--a5); font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 40px; }

/* Ampel-Farben */
.a1 { background: var(--a1); } .a2 { background: var(--a2); } .a3 { background: var(--a3); }
.a4 { background: var(--a4); } .a5 { background: var(--a5); }

/* ---------- Karte ---------- */
#main { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
#listView { flex: 1; min-height: 0; overflow-y: auto; }
#mapView { flex: 1; min-height: 0; position: relative; }
#map { width: 100%; height: 100%; }
.tueren-toggle { display: block; width: 100%; text-align: left; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-weight: 600; font-size: 14px; color: var(--ink); cursor: pointer; }
.tueren-list { margin-top: 8px; max-height: 220px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; }
.tuer-row { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
.tuer-row:last-child { border-bottom: none; }
.tuer-nr { font-weight: 600; flex: none; min-width: 3.4em; }
.tuer-meta { flex: 1; color: var(--muted); }
.tuer-done { flex: none; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; }
.tuer-anliegen { flex: none; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; font-size: 14px; line-height: 1; color: var(--muted); cursor: pointer; }
.tuer-anliegen:active { background: #eceef1; }
.tuer-row.done { opacity: .55; }
.tuer-row.done .tuer-done { background: var(--spoe); color: #fff; border-color: var(--spoe); }
.tueren { width: 100%; }
.tueren-all { display: block; width: 100%; margin-top: 8px; background: #e7f5e8; color: #2e7d32; border: 1px solid #bfe3c4; border-radius: 10px; padding: 11px 12px; font-weight: 700; font-size: 14px; }
.tueren-all:active { background: #d7eeda; }
.row.expanded { margin-bottom: 0; border-radius: 14px 14px 0 0; border-left: 3px solid var(--spoe); }
.tueren-wrap { list-style: none; margin: 0 0 16px; padding: 12px 16px 16px; background: var(--card); border-top: 1px dashed var(--line); border-left: 3px solid var(--spoe); border-radius: 0 0 14px 14px; box-shadow: var(--shadow); }
.tueren-wrap.hidden { display: none; }
.locate-toggle { font-size: 16px; line-height: 30px; text-align: center; text-decoration: none; background: #fff; }
.locate-toggle.off { opacity: .45; }
.abstecken-toggle { font-size: 16px; line-height: 30px; text-align: center; text-decoration: none; background: #fff; }
.abstecken-toggle.active { background: var(--spoe); }

/* ---------- HausbesucherInnen zuteilen ---------- */
.assign-toggle { flex: none; padding: 9px 11px; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; font-weight: 600; font-size: 14px; }
.assign-toggle.active { background: var(--spoe); color: #fff; border-color: var(--spoe); }
.row-check { display: none; flex: none; width: 24px; height: 24px; border-radius: 6px; border: 2px solid var(--line); color: transparent; text-align: center; line-height: 21px; font-weight: 800; font-size: 15px; }
#list.assign .row-check { display: inline-block; }
#list.assign .row { cursor: pointer; }
.row.sel { outline: 2px solid var(--spoe); outline-offset: -1px; }
.row.sel .row-check { background: var(--spoe); border-color: var(--spoe); color: #fff; }
.row-who { flex: 0 1 auto; max-width: 48%; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
@media (max-width: 480px) {
  .row:has(.row-who) { gap: 8px; }
  .row-who { max-width: 24%; }
  .who-chip { line-height: 1.2; text-align: center; }
}
.who-chip { font-size: 12px; font-weight: 700; color: var(--wc, var(--muted)); border: 1px solid var(--wc, var(--line)); border-radius: 999px; padding: 1px 8px; }
.assign-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1100; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: #fff; border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(0,0,0,.1); padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
#assignCount { font-weight: 700; font-size: 14px; flex: none; }
.assign-who { flex: 1 1 140px; min-width: 120px; margin: 0; padding: 9px 10px; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; font-weight: 600; font-size: 14px; }
.assign-who.wide-select { width: 100%; flex: none; margin: 4px 0 10px; }
.assign-bar #assignDo { background: var(--spoe); color: #fff; border-color: var(--spoe); }
.map-hint { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 30px; color: var(--muted); background: var(--bg); }

/* ---------- Sheet (Detail + Anliegen) ---------- */
.sheet { position: fixed; inset: 0; z-index: 1200; background: rgba(0,0,0,.35); display: flex; align-items: flex-end; justify-content: center; }
.sheet-card {
  background: #fff; width: 100%; max-width: 560px;
  border-radius: 20px 20px 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(0,0,0,.18); animation: slideup .18s ease-out;
  max-height: 88vh; overflow-y: auto; position: relative;
}
@keyframes slideup { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-close { position: absolute; right: 12px; top: 10px; background: transparent; font-size: 28px; color: var(--muted); line-height: 1; padding: 4px 8px; }
.sheet-head { display: flex; align-items: center; gap: 16px; margin: 6px 0 14px; }
.ampel-big { width: 52px; height: 52px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 3px rgba(255,255,255,.7); display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; font-size: 19px; font-variant-numeric: tabular-nums; text-shadow: 0 1px 2px rgba(0,0,0,.3); }
.sheet-head > div { flex: 1; min-width: 0; }
.d-done { flex: none; background: #eef1f4; color: var(--muted); border-radius: 999px; padding: 5px 11px; font-size: 14px; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.d-done.full { background: #e7f5e8; color: #2e7d32; }
.d-address { font-size: 20px; font-weight: 700; }
.d-label { color: var(--muted); }
.factors { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip { background: var(--bg); border-radius: 999px; padding: 6px 12px; font-size: 14px; color: #34373d; }
.last-visit { background: #eef7ef; color: #2e7d32; border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }
.d-section-title { font-weight: 700; margin: 6px 0 10px; }
.outcomes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.outcome { padding: 16px 12px; border-radius: 14px; border: 1.5px solid var(--line); background: #fff; font-weight: 600; text-align: center; display: flex; align-items: center; justify-content: center; min-height: 64px; }
.outcome .oc-dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; margin-right: 8px; }
.outcome:active { background: var(--bg); }
.an-for { color: var(--muted); font-size: 14px; margin-bottom: 8px; }
.hint-small { color: var(--muted); font-size: 13px; margin: 10px 0 0; }

/* ---------- Toast ---------- */
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: #1b1d21; color: #fff; padding: 12px 18px; border-radius: 999px; z-index: 1300; box-shadow: var(--shadow); font-size: 15px; }

@media (min-width: 620px) {
  .sheet { align-items: center; }
  .sheet-card { border-radius: 20px; }
}

/* ---------- Registrierung ---------- */
select { width: 100%; font: inherit; padding: 14px; margin: 6px 0; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink); }
.switch { text-align: center; color: var(--muted); font-size: 15px; margin-top: 16px; }
.link { color: var(--spoe); font-weight: 600; cursor: pointer; }

/* ---------- Admin-Verwaltung ---------- */
.badge { background: var(--spoe); color: #fff; border-radius: 999px; padding: 1px 9px; font-size: 13px; margin-left: 6px; vertical-align: middle; }
.admin-body { padding: 14px 12px 30px; max-width: 680px; margin: 0 auto; }
.admin-section { margin-bottom: 22px; }
.admin-section h3 { font-size: 16px; margin: 6px 4px 10px; }
.list-plain { list-style: none; margin: 0; padding: 0; }
.arow { display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 12px 14px; margin-bottom: 8px; }
.arow.col { display: block; }
.arow-main { flex: 1; min-width: 0; }
.arow-actions { display: flex; gap: 8px; flex: none; }
.mini { padding: 10px 13px; border-radius: 10px; font-weight: 600; font-size: 14px; border: 1.5px solid var(--line); background: #fff; }
.mini.approve { background: var(--a5); color: #fff; border-color: var(--a5); }
.mini.reject { color: var(--a1); border-color: #f0c9c4; }
.an-text { margin: 6px 0; }
.super-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.super-row select { flex: 1 1 140px; margin: 0; }
.newuser input { margin: 5px 0; }
.newuser .secondary { margin-top: 6px; }
.data-stats { color: var(--muted); font-size: 15px; margin-bottom: 10px; }
.muster-link { display: inline-block; margin-top: 8px; color: var(--spoe); font-weight: 600; font-size: 14px; text-decoration: none; }
.muster-link:active { opacity: .7; }
.role-select { flex: none; padding: 8px 10px; border-radius: 10px; border: 1.5px solid var(--line); background: #fff; font-weight: 600; font-size: 14px; }
.wrow { margin-bottom: 12px; }
.wrow label { font-size: 14px; display: block; margin-bottom: 4px; }
.wrow .wline { display: flex; align-items: center; gap: 12px; }
.wrow .wslider { flex: 1; accent-color: var(--spoe); }
.wrow .wval { width: 34px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
