:root {
  --bg: #0e1116;
  --panel: #151a21;
  --card: #1b2129;
  --line: #2a323d;
  --text: #e9edf2;
  --muted: #8c97a6;
  --accent: #4ea1ff;
  --danger: #ff5d5d;
  --ok: #3ecf8e;
  --warn: #f5b642;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { display: flex; flex-direction: column; overflow: hidden; }
button, input { font: inherit; color: inherit; }
button {
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 12px; cursor: pointer; white-space: nowrap;
}
button:hover { border-color: #3b4552; background: #222934; }
select {
  font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 8px; cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: #06121f; font-weight: 600; }
button.primary:hover { filter: brightness(1.1); }
button.danger { color: var(--danger); }
button.on { border-color: var(--accent); color: var(--accent); }
a { color: var(--accent); }

#topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); z-index: 10;
}
.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.logo { color: var(--accent); }
.conn { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); display: inline-block; }
.conn.ok { background: var(--ok); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

main { flex: 1; display: flex; min-height: 0; position: relative; }
#map { flex: 1; background: #1a1f26; }
#panel {
  width: 390px; overflow-y: auto; background: var(--panel); border-left: 1px solid var(--line);
  padding: 12px; display: flex; flex-direction: column; gap: 12px;
}
#clock { display: none; }
#cards { display: flex; flex-direction: column; gap: 10px; }
.empty { color: var(--muted); text-align: center; padding: 24px 8px; line-height: 1.5; }

.card {
  background: var(--card); border: 1px solid var(--line); border-left: 5px solid var(--c);
  border-radius: 12px; padding: 12px 14px;
}
.card header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.card h3 { margin: 0; font-size: 16px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .ago { font-size: 12px; color: var(--muted); }
.card .ago.stale { color: var(--warn); }
.card .tools { display: flex; gap: 4px; }
.card .tools button { padding: 2px 8px; }
.k { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.v { font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; }
.big .v { font-size: 30px; line-height: 1.1; color: var(--c); }
.big .s { font-size: 12px; color: var(--muted); }
.big .vt { font-size: .7em; font-weight: 650; color: var(--text); white-space: nowrap; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; margin-top: 10px; }
.progress { position: relative; height: 8px; border-radius: 4px; background: #2a313b; margin-top: 12px; overflow: hidden; }
.progress .done { position: absolute; inset: 0 auto 0 0; background: color-mix(in srgb, var(--c) 35%, transparent); }
.progress .group { position: absolute; top: 0; bottom: 0; background: var(--c); border-radius: 4px; min-width: 4px; }
/* Stationen */
.stations { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 8px; font-size: 13px; }
.st-status { color: var(--warn); font-weight: 650; margin-bottom: 6px; }
.st-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.st-list li { display: flex; align-items: baseline; gap: 6px; }
.st-list li .km { color: var(--muted); font-size: 12px; flex: 1; }
.st-list li b { font-variant-numeric: tabular-nums; }
.st-list li.done { color: var(--muted); }
.st-list li.next {
  display: block; background: color-mix(in srgb, var(--c) 14%, transparent); border-radius: 8px; padding: 6px 8px; margin: 2px 0;
}
.st-list li.next .st-name { font-weight: 650; font-size: 15px; }
.st-list li.next .km { flex: none; margin-left: 4px; }
.st-list li.next .st-eta { font-weight: 650; color: var(--c); font-variant-numeric: tabular-nums; }
.st-list b.here, .paused { color: var(--warn); }
.st-foot { color: var(--muted); font-size: 12px; margin-top: 4px; }
.stmk {
  width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center;
  font: 700 11px/1 system-ui, sans-serif; background: #fff; color: #111; border: 2px solid var(--c);
  box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
.stmk.fin { font-size: 12px; }
.leaflet-tooltip.sttip { font-size: 12px; padding: 2px 7px; font-weight: 600; }
.leaflet-tooltip.sttip::before { border-right-color: rgba(14,17,22,.9); border-top-color: transparent; }

.backupline { margin-top: 8px; font-size: 12px; color: var(--accent); }
.warnline { margin-top: 8px; font-size: 12px; color: var(--warn); }

#devices h4 { margin: 4px 0 6px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.dev { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.dev .id { font-family: ui-monospace, Consolas, monospace; flex: 1; overflow: hidden; text-overflow: ellipsis; }
.dev .meta { color: var(--muted); font-size: 12px; }
.dev button { padding: 1px 7px; font-size: 12px; }
.hint { color: var(--muted); font-size: 12px; line-height: 1.45; }

.tiles-dark { filter: invert(1) hue-rotate(180deg) brightness(.95) contrast(.9) saturate(.6); }

/* Marker */
.mk {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  font: 800 13px/1 system-ui, sans-serif; color: #fff; background: var(--c);
  border: 3px solid #fff; box-shadow: 0 1px 6px rgba(0,0,0,.55);
}
.mk.tail { background: #fff; color: var(--c); border-color: var(--c); }
.mk.stale { filter: grayscale(1); opacity: .55; }
.leaflet-tooltip.gtip {
  background: rgba(14,17,22,.9); color: #fff; border: 0; border-radius: 8px; padding: 4px 9px;
  font-weight: 650; font-size: 13px; box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
.leaflet-tooltip.gtip::before { border-top-color: rgba(14,17,22,.9); }
.gtip .sw { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }

/* Dialog */
dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px;
  width: min(560px, calc(100vw - 32px)); padding: 18px 20px;
}
dialog::backdrop { background: rgba(0,0,0,.55); }
dialog h2 { margin: 0 0 12px; font-size: 18px; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
dialog input:not([type=color]):not([type=file]) {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; color: var(--text);
}
dialog input[type=color] { width: 54px; height: 36px; padding: 2px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 6px 0 12px; padding: 8px 12px 12px; }
legend { color: var(--muted); font-size: 13px; padding: 0 4px; }
.row { display: flex; gap: 10px; align-items: flex-end; }
.row.wrap { flex-wrap: wrap; }
.row.end { align-items: center; margin-top: 6px; }
.row label { margin-bottom: 10px; }
.grow { flex: 1; min-width: 0; }
.filebtn {
  display: inline-block !important; margin: 0 !important; background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 12px; cursor: pointer; color: var(--text) !important; font-size: inherit !important;
}
.filebtn input { display: none; }
.error { color: var(--danger); font-size: 13px; }
.st-edit { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.st-head { align-items: center; margin-bottom: 6px; }
.st-head b { color: var(--text); font-size: 14px; }
.st-row { display: grid; grid-template-columns: 1fr 86px 76px 32px; gap: 6px; align-items: center; margin-bottom: 6px; }
.st-row input { min-width: 0; width: 100%; }
.st-row .unit { font-size: 11px; color: var(--muted); }
.st-cols { display: grid; grid-template-columns: 1fr 86px 76px 32px; gap: 6px; font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.st-row button { padding: 4px 0; }

#drawbar {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 1000;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
  display: flex; gap: 8px; align-items: center; box-shadow: 0 6px 24px rgba(0,0,0,.5); flex-wrap: wrap; justify-content: center;
}
#drawbar[hidden] { display: none; }

#btnExitStream { display: none; }

/* ---------- ohne Login nur ansehen ---------- */
body:not(.admin) #btnNew,
body:not(.admin) #devices,
body:not(.admin) #history,
body:not(.admin) .card [data-act="edit"],
body:not(.admin) .card [data-act="history"] { display: none; }

/* ---------- Verlauf (Admin) ---------- */
body.history #cards, body.history #devices, body.history #clock { display: none; }
#history[hidden] { display: none; }
#history h4 { margin: 14px 0 6px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.hist-head { display: flex; align-items: center; gap: 8px; }
.hist-head h3 { margin: 0; font-size: 16px; }
.hist-actions { margin: 8px 0; align-items: center; }
.ok-msg { color: var(--ok); font-size: 13px; }
.hist-sum { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-top: 8px; }
.hist-sum .grid { grid-template-columns: repeat(3, 1fr); }
.hist-sum .v { font-size: 15px; }
.hist-tab { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.hist-tab th { text-align: left; color: var(--muted); font-weight: 600; font-size: 11px; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.hist-tab td { padding: 5px 6px; border-bottom: 1px solid var(--line); }
.hist-tab tbody tr { cursor: pointer; }
.hist-tab tbody tr:hover { background: #222934; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 12px; color: var(--muted); margin-top: 12px; }
.legend i { display: inline-block; width: 14px; height: 5px; border-radius: 3px; margin-right: 5px; vertical-align: middle; }
.run { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.run .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.run button { padding: 3px 9px; font-size: 12px; }
.muted { color: var(--muted); font-size: 12px; }
#btnRuns { margin-top: 8px; width: 100%; }
.kmmk {
  width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; background: #111; color: #fff;
  font: 700 10px/1 system-ui, sans-serif; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.5);
}
dialog.small { width: min(380px, calc(100vw - 32px)); }
#settingsDlg { width: min(440px, calc(100vw - 32px)); }
#settingsDlg fieldset { margin: 8px 0 10px; }
dialog label.chk { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; margin: 6px 0; cursor: pointer; }
label.chk input { width: 18px; height: 18px; accent-color: var(--accent); }
body.stream #btnLogin { display: none; }

/* ---------- Stream-Modus ---------- */
body.stream #topbar { display: none; }
body.stream #panel {
  position: absolute; top: 16px; right: 16px; width: 400px; max-height: calc(100% - 32px);
  background: transparent; border: 0; padding: 0; z-index: 500; pointer-events: none; overflow: hidden;
}
body.stream #devices, body.stream .card .tools { display: none; }
body.stream .card {
  background: rgba(14,17,22,.84); backdrop-filter: blur(6px); pointer-events: auto;
  border-color: rgba(255,255,255,.08); border-left-color: var(--c);
}
body.stream .big .v { font-size: 36px; }
body.stream .v { font-size: 20px; }
body.stream #clock {
  display: block; align-self: flex-end; pointer-events: auto;
  background: rgba(14,17,22,.84); border-radius: 10px; padding: 6px 12px;
  font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums;
}
body.stream #btnExitStream {
  display: block; position: absolute; left: 12px; top: 12px; z-index: 600; opacity: 0; transition: opacity .2s;
}
body.stream #btnExitStream:hover { opacity: 1; }
body.stream .leaflet-control-zoom { display: none; }

.card { cursor: pointer; }

@media (max-width: 760px) {
  html, body { height: 100dvh; }
  #topbar { flex-wrap: nowrap; padding: 6px 10px; padding-top: max(6px, env(safe-area-inset-top)); }
  .brand .name, .actions .lbl { display: none; }
  .actions { flex-wrap: nowrap; gap: 4px; min-width: 0; }
  .actions button { padding: 6px 8px; font-size: 16px; }
  #mapStyle { max-width: 100px; font-size: 14px; padding: 6px 4px; }
  main { flex-direction: column; }
  #map { flex: none; height: 56dvh; }
  #panel {
    width: auto; flex: 1; height: auto; border-left: 0; border-top: 1px solid var(--line);
    padding: 8px 8px max(8px, env(safe-area-inset-bottom)); gap: 8px;
  }
  #cards { gap: 8px; }
  .card { padding: 9px 11px; border-radius: 10px; }
  .card header { margin-bottom: 4px; }
  .card h3 { font-size: 15px; }
  .big { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
  .big .k { display: none; }
  .big .v { font-size: 26px; }
  .grid { grid-template-columns: repeat(3, 1fr); gap: 6px 8px; margin-top: 6px; }
  .k { font-size: 10px; }
  .v { font-size: 15px; }
  .progress { margin-top: 8px; }
  dialog { padding: 14px; max-height: calc(100dvh - 24px); }
  dialog .row { flex-wrap: wrap; }
  body.stream #panel { left: 8px; right: 8px; top: auto; bottom: 8px; width: auto; max-height: 45%; overflow-y: auto; }
  body.stream #map { height: 100dvh; }
  body.stream .big .v { font-size: 26px; }
  body.stream .v { font-size: 15px; }
  body.stream #clock { display: none; }
}
