:root {
  --primary: #7b1fa2;
  --primary-dark: #4a0072;
  --bg: #f4f1f7;
  --card: #ffffff;
  --text: #222;
  --muted: #6b6b75;
  --border: #e2dde8;
  --done: #2e7d32;
  --planned: #f9a825;
  --open: #e53935;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17141b; --card: #221e27; --text: #eee; --muted: #a59fae; --border: #38323f;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
[hidden] { display: none !important; }

/* ---------- Buttons / Inputs ---------- */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--card); color: var(--text);
  border-radius: 10px; padding: .7rem 1rem; font-size: 1rem; cursor: pointer; font-weight: 600;
}
.btn:disabled { opacity: .5; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.done { background: var(--done); border-color: var(--done); color: #fff; }
.btn.planned { background: var(--planned); border-color: var(--planned); color: #222; }
.btn.danger { background: var(--open); border-color: var(--open); color: #fff; }
.btn.link { background: none; border: none; color: var(--primary); padding: .5rem; font-weight: 500; }
.btn.small { padding: .35rem .7rem; font-size: .875rem; }
.btn.current { outline: 3px solid var(--text); outline-offset: 2px; }
input, select, textarea {
  font: inherit; width: 100%; padding: .65rem .75rem; border-radius: 10px;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
}
label { display: block; font-weight: 600; font-size: .9rem; margin: .75rem 0; }
label > input, label > select { margin-top: .3rem; font-weight: 400; }

/* ---------- Login ---------- */
.center-page { display: flex; align-items: center; justify-content: center; min-height: 100%; padding: 16px; }
.card { background: var(--card); border-radius: var(--radius); padding: 1.5rem; box-shadow: 0 4px 24px rgba(0,0,0,.08); }
.login-card { width: 100%; max-width: 380px; }
.login-card h1 { margin: .25rem 0 1rem; font-size: 1.4rem; text-align: center; }
.login-card .btn { width: 100%; margin-top: .5rem; }
.logo { font-size: 2.5rem; text-align: center; color: #f9a825; }
.alert { background: #fdecea; color: #b71c1c; padding: .6rem .8rem; border-radius: 8px; margin-bottom: .5rem; }
.alert.ok { background: #e8f5e9; color: #1b5e20; }

/* ---------- App-Layout ---------- */
body.app { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
.topbar { background: var(--primary); color: #fff; padding: .5rem 16px .6rem; padding-top: max(.5rem, env(safe-area-inset-top)); flex: none; }
.topbar-row { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.brand { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who { display: flex; gap: .75rem; align-items: center; font-size: .85rem; flex: none; }
.who .link { color: #fff; opacity: .85; }
.team-chip { background: rgba(255,255,255,.2); padding: .15rem .55rem; border-radius: 99px; font-weight: 600; }
.progress { all: unset; display: block; width: 100%; margin-top: .45rem; cursor: pointer; }
.bar { display: flex; height: 12px; background: rgba(255,255,255,.3); border-radius: 99px; overflow: hidden; }
.bar .done { background: #66bb6a; transition: width .4s; }
.bar .planned { background: #ffca28; transition: width .4s; }
.bar.sm { height: 8px; background: var(--border); min-width: 60px; }
.progress-text { font-size: .85rem; margin-top: .25rem; }
.progress-text strong { font-size: 1.05rem; }
.stats-panel { background: var(--card); color: var(--text); border-radius: 10px; padding: .75rem; margin-top: .5rem; max-height: 45vh; overflow: auto; }
.stats-panel h3 { margin: 0 0 .4rem; font-size: .95rem; }
.stats-panel table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.stats-panel td { padding: .2rem .25rem; }
.stats-panel td.num { text-align: right; white-space: nowrap; }
.stats-panel td.mini { width: 35%; }
.stats-grid { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 700px) { .stats-grid { grid-template-columns: 1fr 1fr; } }

.tabs { display: flex; background: var(--card); border-bottom: 1px solid var(--border); flex: none; }
.tab { flex: 1; border: none; background: none; padding: .75rem; font-size: 1rem; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; cursor: pointer; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.views { flex: 1; position: relative; min-height: 0; }
.view { position: absolute; inset: 0; display: none; }
.view.active { display: block; }
#map { position: absolute; inset: 0; }
.view-list { overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: env(safe-area-inset-bottom); }

/* Desktop: Karte und Liste nebeneinander */
@media (min-width: 900px) {
  .tabs { display: none; }
  .views { display: grid; grid-template-columns: 1fr 400px; }
  .view { position: relative; display: block; }
  .view-list { border-left: 1px solid var(--border); }
}

.map-tools { position: absolute; right: 12px; bottom: 44px; z-index: 500; display: flex; flex-direction: column; gap: 8px; }
.fab { width: 46px; height: 46px; border-radius: 50%; border: none; background: var(--card); box-shadow: 0 2px 8px rgba(0,0,0,.25); font-size: 1.3rem; cursor: pointer; }
.fab.active { background: #bbdefb; }
.legend { position: absolute; left: 8px; bottom: 22px; z-index: 500; background: var(--card); border-radius: 8px; padding: .3rem .5rem; font-size: .78rem; box-shadow: 0 1px 6px rgba(0,0,0,.2); display: flex; flex-wrap: wrap; gap: .2rem .6rem; max-width: calc(100% - 80px); }
.lg { display: inline-flex; align-items: center; gap: .3rem; }
.sw { display: inline-block; width: 18px; height: 5px; border-radius: 3px; background: var(--c); }
.sw.dash { background: repeating-linear-gradient(90deg, var(--c) 0 5px, transparent 5px 8px); }

.leaflet-interactive:focus { outline: none; }

/* ---------- Liste ---------- */
.list-tools { position: sticky; top: 0; background: var(--bg); padding: 10px 16px; z-index: 2; border-bottom: 1px solid var(--border); }
.filters { display: flex; gap: .4rem; margin-top: .5rem; overflow-x: auto; }
.chip { border: 1px solid var(--border); background: var(--card); color: var(--text); border-radius: 99px; padding: .35rem .8rem; font-size: .875rem; cursor: pointer; white-space: nowrap; }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.street-list { padding: 0 16px 24px; }
.group-head { display: flex; justify-content: space-between; font-weight: 700; padding: 1rem 0 .4rem; font-size: .95rem; }
.row { display: flex; align-items: center; gap: .7rem; width: 100%; text-align: left; background: var(--card); color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: .7rem .8rem; margin-bottom: 6px; cursor: pointer; font: inherit; }
.row.mine { border-left: 4px solid var(--primary); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-name { font-weight: 600; }
.row-sub { font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { display: inline-block; width: 14px; height: 14px; border-radius: 50%; flex: none; margin-right: .3rem; vertical-align: middle; }
.row .dot { margin-right: 0; }
.team-dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.nogeo { color: var(--muted); font-size: .8rem; }
.empty { text-align: center; padding: 2rem; }

/* ---------- Bottom-Sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 1000; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1001; background: var(--card); color: var(--text); border-radius: 18px 18px 0 0; padding: .5rem 16px calc(16px + env(safe-area-inset-bottom)); box-shadow: 0 -4px 24px rgba(0,0,0,.2); max-width: 560px; margin: 0 auto; max-height: 90dvh; overflow: auto; }
.sheet-handle { width: 40px; height: 5px; background: var(--border); border-radius: 3px; margin: .25rem auto .75rem; }
.sheet h2 { margin: 0; font-size: 1.3rem; }
.sheet-status { margin: .75rem 0; }
.sheet-status .note { margin-top: .4rem; font-style: italic; }
.badge { color: #fff; padding: .15rem .55rem; border-radius: 99px; font-size: .85rem; font-weight: 700; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-top: .75rem; }
.sheet-actions .btn[data-set="offen"] { grid-column: 1 / -1; }
.sheet-footer { display: flex; justify-content: space-between; margin-top: .5rem; }
.note-label { margin: .5rem 0; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(24px + env(safe-area-inset-bottom)); background: #323232; color: #fff; padding: .7rem 1.1rem; border-radius: 10px; z-index: 2000; max-width: calc(100% - 32px); box-shadow: 0 4px 14px rgba(0,0,0,.3); }
.toast.error { background: #c62828; }
body.offline .topbar { background: #616161; }
body.offline .brand::after { content: " · offline"; font-weight: 400; }

/* ---------- Admin ---------- */
.admin main { max-width: 1100px; margin: 0 auto; padding: 16px; }
.admin .topbar { position: sticky; top: 0; z-index: 1100; }
.admin section.card { margin-bottom: 1rem; }
.admin h2 { margin-top: 0; font-size: 1.15rem; }
.admin table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.admin th, .admin td { text-align: left; padding: .4rem .4rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.admin td input, .admin td select { padding: .35rem .5rem; }
.admin td input[type=color] { width: 44px; padding: 0; height: 34px; }
.form-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: end; }
.form-row > * { flex: 1 1 160px; }
.form-row > .btn { flex: 0 0 auto; }
#import-map { height: 420px; border-radius: 10px; margin: .75rem 0; }
.import-list { max-height: 320px; overflow: auto; border: 1px solid var(--border); border-radius: 10px; padding: .5rem; columns: 2 220px; }
.import-list label { margin: .15rem 0; font-weight: 400; display: flex; gap: .4rem; align-items: center; break-inside: avoid; }
.import-list input { width: auto; }
.steps { padding-left: 1.2rem; }
.steps li { margin-bottom: .3rem; }
.table-wrap { overflow-x: auto; }
.table-wrap.scroll { max-height: 500px; overflow-y: auto; }
.list-count { margin: .5rem 0 0; }
.status-pill { font-size: .78rem; padding: .1rem .45rem; border-radius: 99px; color: #fff; }

/* ---------- Admin: Reiter ---------- */
.admin-tabs { position: sticky; top: 0; z-index: 1050; display: flex; gap: .25rem; overflow-x: auto; background: var(--card); border-bottom: 1px solid var(--border); padding: 0 16px; }
.admin .topbar { position: static; }
.admin-tabs a { padding: .8rem .9rem; text-decoration: none; color: var(--muted); font-weight: 600; white-space: nowrap; border-bottom: 3px solid transparent; }
.admin-tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- Admin: Übersicht ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.kpi { background: var(--card); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: 0 4px 24px rgba(0,0,0,.06); }
.kpi-label { font-size: .85rem; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 2rem; font-weight: 800; line-height: 1.2; margin-top: .2rem; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: .85rem; color: var(--muted); }
.kpi.hero { background: var(--primary); color: #fff; }
.kpi.hero .kpi-label, .kpi.hero .kpi-sub { color: rgba(255,255,255,.85); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.dash-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; margin-bottom: 1rem; }
.dash-grid > .card { margin-bottom: 0 !important; }
@media (min-width: 1000px) { .dash-grid { grid-template-columns: 1.3fr 1fr; } }

/* gestapelter Balken: erledigt | geplant (schraffiert) | offen, 2px Abstand */
.stack { display: flex; gap: 2px; height: 12px; min-width: 120px; }
.stack.big { height: 22px; margin: .5rem 0; }
.stack .seg { min-width: 4px; }
.stack .seg:first-child { border-radius: 4px 0 0 4px; }
.stack .seg:last-child { border-radius: 0 4px 4px 0; }
.stack .seg:only-child { border-radius: 4px; }
.seg.done, .sw-box.done { background: #2e7d32; }
.seg.planned, .sw-box.planned { background: repeating-linear-gradient(135deg, #eda100 0 5px, #f6cd70 5px 8px); }
.seg.open, .sw-box.open { background: var(--border); }
.stack-legend { display: flex; gap: 1.2rem; font-size: .85rem; color: var(--muted); }
.stack-legend span { display: inline-flex; align-items: center; gap: .4rem; }
.sw-box { display: inline-block; width: 14px; height: 14px; border-radius: 3px; }

.dash-table th { font-size: .8rem; color: var(--muted); font-weight: 600; }
.dash-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dash-table .barcell { min-width: 130px; }
.team-row { cursor: pointer; }
.team-row:hover { background: var(--bg); }
.caret { display: inline-block; width: 1rem; color: var(--muted); }
.hbar { display: inline-block; width: calc(100% - 3rem); height: 10px; background: var(--border); border-radius: 4px; overflow: hidden; vertical-align: middle; margin-right: .4rem; }
.hbar > div { height: 100%; border-radius: 0 4px 4px 0; }
tr.detail td { background: var(--bg); }
.detail-block { margin: .4rem 0 .6rem; }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .35rem; }
.chip-s { font-size: .8rem; padding: .15rem .55rem; border-radius: 99px; border: 1px solid var(--border); background: var(--card); }
.chip-s.erledigt { border-color: #2e7d32; }
.chip-s.geplant { border-color: #eda100; border-style: dashed; }
details { margin-bottom: .6rem; }
summary { cursor: pointer; padding: .25rem 0; }
ul.plain { list-style: none; padding: 0; margin: .25rem 0; }
ul.plain li { padding: .35rem 0; border-bottom: 1px solid var(--border); font-size: .9rem; }
.dash-table td:first-child { white-space: nowrap; }
.dash-table .barcell { white-space: nowrap; }
.hbar { width: calc(100% - 3.2rem); min-width: 60px; }
.form-row > .btn { max-width: 100%; white-space: normal; }
@media (max-width: 600px) { .kpis { grid-template-columns: 1fr 1fr; gap: .6rem; } .kpi-value { font-size: 1.6rem; } }
.dash-grid > *, .admin main > * { min-width: 0; }
.admin main { overflow-x: hidden; }
.device-code { font-size: 2.2rem; font-weight: 800; letter-spacing: .15em; font-family: ui-monospace, Menlo, monospace; background: var(--bg); border-radius: 10px; padding: .6rem; margin: .5rem 0; }
.tab-badge { background: #c62828; color: #fff; border-radius: 99px; font-size: .72rem; padding: .05rem .45rem; margin-left: .2rem; }
.alert-bar { display: block; background: #fff3cd; color: #5d4300; border-radius: var(--radius); padding: .8rem 1rem; margin-bottom: 1rem; font-weight: 600; text-decoration: none; }
.switch { display: inline-flex; align-items: center; gap: .4rem; font-weight: 600; margin: 0; cursor: pointer; }
.switch input { width: 20px; height: 20px; }
.dev-card { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; border: 2px solid #eda100; border-radius: 10px; padding: .75rem; margin-bottom: .5rem; }
.dev-code { font-family: ui-monospace, Menlo, monospace; font-size: 1.4rem; font-weight: 800; letter-spacing: .1em; }
.dev-info { flex: 1; min-width: 160px; }
.dev-actions { display: flex; gap: .4rem; }
.dev-pill { font-size: .78rem; padding: .1rem .5rem; border-radius: 99px; font-weight: 600; border: 1px solid var(--border); }
.dev-pill.pending { border-color: #eda100; border-style: dashed; }
.dev-pill.approved { border-color: #2e7d32; }
.dev-pill.blocked { border-color: #c62828; }
.dev-label { min-width: 140px; }
.geo-status { background: var(--bg); border-radius: 10px; padding: .75rem; margin: .5rem 0; font-size: .9rem; line-height: 1.7; }
.card h3 { font-size: 1rem; margin: 1.25rem 0 .4rem; }
.logo img { display: block; margin: 0 auto; border-radius: 20px; box-shadow: 0 6px 20px rgba(27,20,82,.35); }
.brand { display: flex; align-items: center; gap: .45rem; }
.brand-icon { border-radius: 6px; flex: none; }
