:root {
  --bg: #f4f5f7; --card: #fff; --text: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --accent: #0ea5e9; --go: #16a34a; --go-d: #15803d; --stop: #dc2626; --stop-d: #b91c1c;
  --warn: #f59e0b; --chip: #eef2f7; --input: #fff;
  --r: 16px; --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 16px rgba(15,23,42,.06);
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1120; --card: #131c2e; --text: #e5e7eb; --muted: #94a3b8; --line: #23304a; --chip: #1c2740; --input: #0f172a;
    --shadow: 0 1px 2px rgba(0,0,0,.3); }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { min-height: 100dvh; }
#view { padding: calc(12px + var(--safe-t)) 14px calc(90px + var(--safe-b)); max-width: 680px; margin: 0 auto; }
h1 { font-size: 1.5rem; margin: 6px 0 14px; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 18px 0 8px; }
h3 { font-size: 1rem; margin: 0 0 6px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; gap: 10px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.hidden { display: none !important; }
.center { text-align: center; }
.mt { margin-top: 12px; } .mb { margin-bottom: 12px; }

/* Karten */
.card { background: var(--card); border-radius: var(--r); padding: 14px; box-shadow: var(--shadow); margin-bottom: 12px; }
.card.tap { cursor: pointer; }
.card.tap:active { transform: scale(.99); }
.list-item { display: flex; gap: 12px; align-items: flex-start; }

/* Buttons */
button, .btn { font: inherit; border: 0; border-radius: 12px; padding: 12px 16px; background: var(--chip); color: var(--text);
  cursor: pointer; min-height: 46px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; }
button:disabled { opacity: .5; }
button.primary { background: var(--accent); color: #fff; font-weight: 600; }
button.go { background: var(--go); color: #fff; font-weight: 700; }
button.stop { background: var(--stop); color: #fff; font-weight: 700; }
button.danger { background: transparent; color: var(--stop); border: 1px solid currentColor; }
button.ghost { background: transparent; color: var(--accent); padding: 8px 10px; min-height: 36px; }
button.block { width: 100%; }
button.lg { font-size: 1.15rem; min-height: 58px; border-radius: 16px; }
button.icon { padding: 8px; min-width: 42px; min-height: 42px; }

.bigbtn { width: min(64vw, 240px); aspect-ratio: 1; border-radius: 50%; font-size: 1.35rem; font-weight: 800; margin: 18px auto 10px;
  display: flex; flex-direction: column; box-shadow: 0 10px 30px rgba(22,163,74,.35); letter-spacing: .01em; }
.bigbtn small { font-weight: 500; font-size: .85rem; opacity: .9; }
.bigbtn.stop { box-shadow: 0 10px 30px rgba(220,38,38,.35); }
.bigbtn:active { transform: scale(.97); }

/* Formulare */
label { display: block; font-size: .85rem; color: var(--muted); margin: 12px 0 5px; font-weight: 500; }
input, textarea, select { font: inherit; width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--input); color: var(--text); min-height: 46px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { min-height: 80px; resize: vertical; }
input[type=checkbox] { width: auto; min-height: 0; }
.input-wrap { position: relative; }
.suggest { position: absolute; z-index: 30; left: 0; right: 0; top: 100%; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); max-height: 240px; overflow: auto; margin-top: 4px; }
.suggest div { padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: .92rem; }
.suggest div:last-child { border-bottom: 0; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.chip { background: var(--chip); border-radius: 999px; padding: 7px 12px; font-size: .9rem; min-height: 0; }
.chip.near { background: color-mix(in srgb, var(--accent) 18%, var(--chip)); }
.chip.on { background: var(--accent); color: #fff; }

.switch { display: flex; align-items: center; gap: 12px; padding: 4px 0; }
.switch input { appearance: none; width: 50px; height: 30px; border-radius: 99px; background: var(--line); position: relative; cursor: pointer; flex: none; border: 0; padding: 0; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked { background: var(--go); }
.switch input:checked::after { left: 23px; }

/* Status */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; background: var(--chip); font-size: .8rem; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.on { background: var(--go); animation: pulse 1.6s infinite; }
.dot.warn { background: var(--warn); }
@keyframes pulse { 50% { opacity: .35; } }
.timer { font-size: 2.6rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat { font-variant-numeric: tabular-nums; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.stats > div { background: var(--chip); border-radius: 12px; padding: 10px; }
.stats b { display: block; font-size: 1.2rem; }

.route { display: grid; grid-template-columns: 14px 1fr; gap: 2px 10px; font-size: .95rem; }
.route .a, .route .b { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; }
.route .a { background: var(--go); } .route .b { background: var(--stop); }
.trip-meta { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: .85rem; margin-bottom: 6px; }
.purpose { font-weight: 600; margin-top: 6px; }
.chain { border-left: 4px solid var(--accent); }
.chain-head { background: color-mix(in srgb, var(--accent) 12%, var(--card)); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; font-size: .92rem; }
.chain-head b { font-variant-numeric: tabular-nums; }
.badge { font-size: .72rem; padding: 2px 8px; border-radius: 99px; background: var(--chip); color: var(--muted); }
.badge.live { background: var(--stop); color: #fff; }

.connect-box { border: 2px solid var(--accent); border-radius: 14px; padding: 12px; margin: 12px 0; background: color-mix(in srgb, var(--accent) 8%, var(--card)); }
.seg { display: grid; grid-template-columns: 36px 1fr; gap: 10px; align-items: start; }
.seg-ico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; font-size: 1.1rem; background: var(--chip); }
.seg.stay .seg-ico { background: color-mix(in srgb, var(--warn) 25%, var(--chip)); }
.seg.move .seg-ico { background: color-mix(in srgb, var(--accent) 25%, var(--chip)); }

.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; margin-top: 8px; }
.photos .ph { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--chip); }
.photos img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photos .ph span { position: absolute; left: 4px; bottom: 4px; font-size: .7rem; background: rgba(0,0,0,.6); color: #fff; padding: 1px 6px; border-radius: 6px; }

.map { height: 240px; border-radius: 14px; overflow: hidden; background: var(--chip); z-index: 0; }
.map.tall { height: 340px; }
.leaflet-container { font: inherit; }

/* Tabbar */
#tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
#tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 9px; color: var(--muted);
  text-decoration: none; font-size: .72rem; font-weight: 500; }
#tabs svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#tabs svg .fill { fill: currentColor; stroke: none; }
#tabs a.on { color: var(--accent); }

/* Bottom-Sheet */
.backdrop { position: fixed; inset: 0; background: rgba(2,6,23,.5); z-index: 100; display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s; }
.sheet { background: var(--bg); width: 100%; max-width: 680px; max-height: 94dvh; overflow: auto; border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(18px + var(--safe-b)); animation: up .2s ease-out; overscroll-behavior: contain; }
.sheet.full { height: 100dvh; max-height: 100dvh; border-radius: 0; display: flex; flex-direction: column; padding-top: calc(8px + var(--safe-t)); }
.sheet .grab { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 4px auto 10px; }
.sheet-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.sheet-head h2 { margin: 0; flex: 1; }
.sheet-foot { position: sticky; bottom: calc(-18px - var(--safe-b)); background: var(--bg); padding: 12px 0 calc(6px); margin-top: 14px; display: flex; gap: 10px; }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
@keyframes fade { from { opacity: 0; } }
.picker-map { flex: 1; border-radius: 14px; position: relative; min-height: 200px; }
.crosshair { position: absolute; left: 50%; top: 50%; z-index: 500; pointer-events: none; transform: translate(-50%, -100%); font-size: 36px; line-height: 1; filter: drop-shadow(0 2px 2px rgba(0,0,0,.4)); }

#toast { position: fixed; left: 50%; bottom: calc(86px + var(--safe-b)); transform: translateX(-50%) translateY(20px); background: #0f172a; color: #fff;
  padding: 11px 16px; border-radius: 12px; opacity: 0; transition: .2s; z-index: 200; max-width: 90vw; pointer-events: none; font-size: .95rem; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--stop); }

/* Login */
.login { max-width: 380px; margin: 8vh auto 0; }
.logo { display: flex; align-items: center; gap: 10px; font-size: 1.6rem; font-weight: 800; margin-bottom: 18px; }
.logo svg { width: 42px; height: 42px; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
td, th { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.codes { font-family: ui-monospace, monospace; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--chip); padding: 12px; border-radius: 12px; }
.qr { background: #fff; padding: 8px; border-radius: 12px; display: inline-block; }
.qr img { display: block; width: 200px; height: 200px; }
.notice { background: color-mix(in srgb, var(--warn) 18%, var(--card)); border-radius: 12px; padding: 10px 12px; font-size: .9rem; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.spinner { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.leaflet-marker-start, .leaflet-marker-end { border-radius: 50%; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.5); }
.leaflet-marker-start { background: var(--go); } .leaflet-marker-end { background: var(--stop); }
.leaflet-marker-stay { background: var(--warn); border-radius: 50%; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.5); color: #000; font-size: 11px; font-weight: 700; display: grid !important; place-items: center; }
