:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f232c;
  --line: #2a2f3a;
  --text: #e5e7eb;
  --muted: #9aa3b2;
  --accent: #3b82f6;
  --accent-2: #2563eb;
  --ok: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --radius: 10px;
  --tabbar-h: 0px;
  --line-strong: #3a4150;
  --bar: rgba(15, 17, 21, .92);
  --bar-solid: rgba(15, 17, 21, .96);
  --chip-on: rgba(59, 130, 246, .12);
  --shadow: rgba(0, 0, 0, .4);
  color-scheme: dark;
}
/* Helles Farbschema: fest gewählt oder "auto", wenn das Gerät hell eingestellt ist (Grundeinstellung: dunkel) */
:root[data-theme="light"] {
  --bg: #eef1f5;
  --panel: #ffffff;
  --panel-2: #f2f4f7;
  --line: #d3d9e2;
  --line-strong: #aab3c0;
  --text: #121826;
  --muted: #586273;
  --accent: #2563eb;
  --accent-2: #1d4ed8;
  --ok: #15803d;
  --warn: #b45309;
  --bad: #dc2626;
  --bar: rgba(255, 255, 255, .92);
  --bar-solid: rgba(255, 255, 255, .97);
  --chip-on: rgba(37, 99, 235, .12);
  --shadow: rgba(15, 23, 42, .18);
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root[data-theme="auto"] {
    --bg: #eef1f5;
    --panel: #ffffff;
    --panel-2: #f2f4f7;
    --line: #d3d9e2;
    --line-strong: #aab3c0;
    --text: #121826;
    --muted: #586273;
    --accent: #2563eb;
    --accent-2: #1d4ed8;
    --ok: #15803d;
    --warn: #b45309;
    --bad: #dc2626;
    --bar: rgba(255, 255, 255, .92);
    --bar-solid: rgba(255, 255, 255, .97);
    --chip-on: rgba(37, 99, 235, .12);
    --shadow: rgba(15, 23, 42, .18);
    color-scheme: light;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 20px; margin: 0 0 14px; }
h2 { font-size: 16px; margin: 22px 0 10px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
small, .muted { color: var(--muted); }

/* ---------- Kopfzeile ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 24px;
  padding: 10px 18px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--bar); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 16px; white-space: nowrap; }
.brand b { color: var(--accent); }
.nav { display: flex; gap: 4px; }
.nav a { color: var(--muted); padding: 7px 12px; border-radius: 8px; }
.nav a.active, .nav a:hover { color: var(--text); background: var(--panel-2); }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: none;
  background: var(--bar-solid); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 7px 0 6px; font-size: 11px; color: var(--muted); }
.tabbar a span { font-size: 19px; line-height: 1.1; }
.tabbar a.active { color: var(--accent); }

main { padding: 16px 18px 40px; max-width: 1800px; margin: 0 auto; }

@media (max-width: 760px) {
  :root { --tabbar-h: 56px; }
  .nav { display: none; }
  .tabbar:not([hidden]) { display: flex; }
  .topbar { padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); }
  main { padding: 10px 10px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom)); }
  /* Bedienleisten über den Bildern: eine Zeile, seitlich wischen statt drei Zeilen Knöpfe */
  .toolbar.tb-scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
    margin-left: -10px; margin-right: -10px; padding: 0 10px 2px; gap: 6px; }
  .toolbar.tb-scroll::-webkit-scrollbar { display: none; }
  .toolbar.tb-scroll > * { flex: 0 0 auto; }
  .toolbar.tb-scroll .spacer { display: none; }
  .toolbar.tb-scroll select { max-width: 46vw; }
  .tile .label { font-size: 12px; }
}
/* Handy quer: oben/unten Leisten schmaler, damit mehr Bild bleibt */
@media (max-width: 1000px) and (max-height: 500px) and (orientation: landscape) {
  .topbar { padding-top: 4px; padding-bottom: 4px; }
  .toolbar.tb-scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .toolbar.tb-scroll::-webkit-scrollbar { display: none; }
  .toolbar.tb-scroll > * { flex: 0 0 auto; }
  .toolbar.tb-scroll .spacer { display: none; }
  .single { max-height: calc(100vh - 120px); }
}

/* ---------- Bedienelemente ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar .spacer { flex: 1; }
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  padding: 8px 14px; border-radius: 8px; font: inherit; cursor: pointer; min-height: 38px;
}
button:hover, .btn:hover { border-color: var(--line-strong); }
.btn { text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-2); }
button.danger { color: var(--bad); }
button:disabled { opacity: .5; cursor: default; }
button.small, .btn.small { padding: 4px 10px; min-height: 30px; font-size: 13px; }
input, select, textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; font: inherit; min-height: 38px; width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=checkbox] { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); }
.toolbar select { width: auto; }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.form-grid .wide { grid-column: 1 / -1; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 12px; }
.hint { font-size: 13px; color: var(--muted); margin: 4px 0 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--panel-2); color: var(--muted); }
.badge.ok { color: var(--ok); } .badge.bad { color: var(--bad); } .badge.warn { color: var(--warn); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }

table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list th { color: var(--muted); font-weight: 500; font-size: 13px; }
table.list input, table.list select { min-height: 34px; padding: 5px 8px; }
.table-wrap { overflow-x: auto; }
#encBox select { min-width: 135px; }

/* ---------- Live-Raster ---------- */
.grid { display: grid; gap: 6px; margin: 0 auto; }   /* Breite wird per JS an die Bildschirmhöhe angepasst */
.tile {
  position: relative; background: #000; border-radius: 8px; overflow: hidden; aspect-ratio: 16 / 9;
  cursor: pointer; border: 1px solid #000;
}
.tile:hover { border-color: var(--line); }
.tile .label {
  position: absolute; left: 0; right: 0; top: 0; z-index: 2; display: flex; align-items: center; gap: 6px;
  padding: 6px 9px; font-size: 13px; background: linear-gradient(rgba(0,0,0,.65), transparent);
  pointer-events: none; text-shadow: 0 1px 2px #000;
}
.tile .label .rec { color: var(--bad); font-size: 11px; font-weight: 700; }
.player { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.player video-stream, .player video, .player img { width: 100%; height: 100%; display: block; }
.player video, .player img { object-fit: contain; background: #000; }
.player .msg { color: var(--muted); font-size: 13px; padding: 10px; text-align: center; }
.tile.empty { display: flex; align-items: center; justify-content: center; color: var(--muted); cursor: default; }

.single { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 16/9; max-height: calc(100vh - 170px); margin: 0 auto; }
.single:fullscreen { max-height: none; border-radius: 0; }

/* Vollbild-Ersatz (iPhone) + Knöpfe */
.pseudo-fs { position: fixed !important; inset: 0 !important; z-index: 1000 !important; width: 100vw !important; height: 100vh !important;
  height: 100dvh !important; max-width: none !important; max-height: none !important; margin: 0 !important; border-radius: 0 !important;
  aspect-ratio: auto !important; background: #000 !important; border: 0 !important;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left) !important; }
body.has-pseudo-fs { overflow: hidden; }
body.has-pseudo-fs .topbar, body.has-pseudo-fs .tabbar, body.has-pseudo-fs .alert-bar { display: none !important; }
.fs-close { position: absolute; top: calc(10px + env(safe-area-inset-top)); right: calc(10px + env(safe-area-inset-right)); z-index: 30;
  width: 44px; height: 44px; min-height: 0; padding: 0; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff; border: 1px solid rgba(255,255,255,.35); font-size: 20px; }
.fs-btn { position: absolute; right: 8px; bottom: 8px; z-index: 8; width: 40px; height: 40px; min-height: 0; padding: 0; border-radius: 50%;
  background: rgba(0,0,0,.5); color: #fff; border: 1px solid rgba(255,255,255,.3); font-size: 18px; opacity: .8; }
.pseudo-fs .fs-btn { display: none; }
:fullscreen .fs-btn { bottom: 14px; right: 14px; }
/* Live-Raster im Vollbild: Bilder füllen den Bildschirm */
.grid:fullscreen, .grid.pseudo-fs { background: #000; padding: 4px; overflow: auto; align-content: center; max-width: none !important; }
.grid.pseudo-fs { padding-top: calc(4px + env(safe-area-inset-top)) !important; }

/* ---------- Aufnahmen ---------- */
.timeline { position: relative; height: 54px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; cursor: pointer; user-select: none; touch-action: pan-y; margin: 10px 0 4px; }
.timeline .seg { position: absolute; top: 8px; bottom: 18px; background: var(--accent); opacity: .75; border-radius: 2px; min-width: 2px; }
.timeline .seg.open { background: var(--ok); }
.timeline .hour { position: absolute; bottom: 1px; font-size: 10px; color: var(--muted); transform: translateX(-50%); }
.timeline .tick { position: absolute; top: 0; bottom: 14px; width: 1px; background: var(--line); }
.timeline .head { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--warn); pointer-events: none; }
.timeline.scrub { cursor: grabbing; }
.timeline.scrub .head { width: 3px; box-shadow: 0 0 6px var(--warn); }
.tl-box { position: relative; }
.tl-tip { position: absolute; top: -26px; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 6px; padding: 2px 7px; font-size: 12px; font-variant-numeric: tabular-nums; pointer-events: none; white-space: nowrap; z-index: 5; }
.day-pick { display: inline-flex; gap: 4px; align-items: center; }
.day-pick button { min-height: 36px; }
.day-pick #dayBtn { min-width: 170px; }
.cal-pop { position: absolute; z-index: 60; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, .35); width: 268px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-head button { min-height: 30px; padding: 2px 10px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; text-align: center; }
.cal-grid i { font-style: normal; font-size: 11px; color: var(--muted); padding: 2px 0; }
.cal-grid button { min-height: 32px; padding: 0; border-radius: 6px; font-variant-numeric: tabular-nums; }
.cal-grid button:disabled { opacity: .3; cursor: default; background: transparent; border-color: transparent; }
.cal-grid button.has { border-color: var(--accent); font-weight: 600; }
.cal-grid button.today { box-shadow: inset 0 -2px 0 var(--ok); }
.cal-grid button.sel { background: var(--accent); color: #fff; }
.cal-foot { font-size: 12px; margin-top: 8px; text-align: center; }
/* ---------- Wiedergabe (mehrere Kameras) ---------- */
.cam-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border: 1px solid var(--line); border-radius: 99px; cursor: pointer; font-size: 13px; color: var(--muted); }
.chip input { width: 15px; height: 15px; }
.chip.on { color: var(--text); border-color: var(--accent); background: var(--chip-on); }
.pb-clock { font-variant-numeric: tabular-nums; font-size: 16px; }
.pb-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; }
.pb-wrap:fullscreen, .pb-wrap.pseudo-fs { display: flex; flex-direction: column; background: #000; padding: 6px; }
.pb-wrap:fullscreen .pb-grid, .pb-wrap.pseudo-fs .pb-grid { flex: 1; min-height: 0; }
.pb-wrap.pseudo-fs .pb-tile { aspect-ratio: auto; }
.pb-wrap.pseudo-fs .pb-grid { max-width: none !important; width: 100%; }
.pb-wrap.pseudo-fs .pb-bar { padding-right: 52px; }
.pb-grid { display: grid; gap: 4px; margin: 0 auto; }   /* Breite wird per JS an die Bildschirmhöhe angepasst */
.pb-tile { position: relative; background: #000; border-radius: 6px; overflow: hidden; aspect-ratio: 16/9; }
.pb-wrap:fullscreen .pb-tile { aspect-ratio: auto; }
.pb-wrap:fullscreen .pb-grid { max-width: none !important; width: 100%; }
/* Schieberegler: am PC aus (dort das Rad), am Handy groß statt Rad */
.shuttle-slider { display: none; }
.shuttle-slider input { width: 100%; height: 44px; accent-color: var(--accent); }
.sh-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: -4px; }
.pb-tile video { width: 100%; height: 100%; object-fit: contain; display: block; }
.pb-tile .label { position: absolute; left: 0; right: 0; top: 0; padding: 5px 8px; font-size: 13px; background: linear-gradient(rgba(0,0,0,.6), transparent); pointer-events: none; }
.pb-gap { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 14px; background: rgba(0,0,0,.75); }
.pb-grid.has-big .pb-tile:not(.big) { display: none; }
.pb-grid.has-big { grid-template-columns: 1fr !important; }
.pb-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px 4px 2px; }
.pb-bar button { min-width: 44px; font-size: 17px; padding: 6px 10px; }
.pb-bar .pb-main { min-width: 56px; }
.pb-bar .spacer { flex: 1; }
.pb-speed { min-width: 58px; text-align: center; font-variant-numeric: tabular-nums; color: var(--muted); }
.shuttle { width: 78px; height: 78px; cursor: grab; touch-action: none; user-select: none; }
.shuttle:active { cursor: grabbing; }
.shuttle svg { width: 100%; height: 100%; display: block; }
.sh-ring { fill: var(--panel-2); stroke: var(--line); stroke-width: 2; }
.sh-tick { stroke: var(--muted); stroke-width: 2; }
.sh-tick.zero { stroke: var(--text); stroke-width: 3; }
.sh-knob { fill: var(--bg); stroke: var(--line); stroke-width: 1.5; }
.sh-dot { fill: var(--accent); transition: cx .12s, cy .12s; }
.shuttle.rev .sh-dot { fill: var(--warn); }
.sh-txt { fill: var(--text); font-size: 15px; font-weight: 600; font-family: inherit; }
@media (max-width: 760px) {
  .pb-bar { gap: 4px; }
  .pb-bar button { min-width: 42px; min-height: 44px; padding: 6px 8px; font-size: 18px; }
  .shuttle { display: none; }
  .shuttle-slider { display: block; flex: 1 1 100%; padding: 4px 6px 0; }
}
.seglist { max-height: 320px; overflow: auto; }

/* ---------- Kamera-Karten ---------- */
.cams { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.cam-card { display: flex; flex-direction: column; gap: 8px; }
.cam-card .thumb { aspect-ratio: 16/9; background: #000 center/cover no-repeat; border-radius: 6px; }
.cam-card .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.probe { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin-top: 12px; }
.probe img { width: 100%; border-radius: 6px; display: block; }
.profiles-pick td { font-size: 13px; }

.tap-hint { display: block; width: 100%; margin: 0 0 8px; min-height: 48px; font-size: 16px; }

/* ---------- Live: Anordnen ---------- */
.grid { grid-auto-flow: dense; }
.grid.arranging .tile { cursor: grab; touch-action: none; outline: 2px dashed var(--accent); outline-offset: -2px; }
.grid.arranging .tile.dragging { opacity: .55; cursor: grabbing; }
.arr-size { position: absolute; right: 6px; top: 6px; z-index: 6; display: flex; gap: 4px; }
.arr-size button { min-height: 30px; min-width: 34px; padding: 2px 6px; font-size: 15px; background: rgba(0,0,0,.65); }
.arr-grip { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 5; font-size: 34px;
  color: #fff; text-shadow: 0 1px 4px #000; pointer-events: none; opacity: .8; }

/* ---------- Live-Statistik ---------- */
.stats { position: absolute; left: 6px; bottom: 6px; z-index: 4; max-width: calc(100% - 12px); pointer-events: none;
  background: rgba(0,0,0,.72); color: #e5e7eb; border-radius: 6px; padding: 5px 8px;
  font: 11.5px/1.45 ui-monospace, Consolas, monospace; }
.stats div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.single .stats { font-size: 13px; }

/* ---------- Bewegung ---------- */
.tile.motion { border-color: var(--warn); box-shadow: inset 0 0 0 2px var(--warn); }
.tile .label .mot { color: var(--warn); font-size: 11px; font-weight: 700; }
/* Bild auf die volle Fläche ziehen (nicht beschneiden): Felder = Anteile des ganzen Kamerabildes, auch bei 4:3 */
.zone-editor { position: relative; aspect-ratio: 16/9; background: #000 center/100% 100% no-repeat; border-radius: 6px; overflow: hidden; touch-action: none; user-select: none; max-width: 720px; }
.zone-editor .zgrid { position: absolute; inset: 0; display: grid; }
.zone-editor .zc { border: 1px solid rgba(255,255,255,.12); }
.zone-editor .zgrid.fine .zc { border-width: 0 1px 1px 0; border-color: rgba(255,255,255,.08); }
.zone-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.zone-tools select { width: auto; }
.zone-editor .zc.on { background: rgba(59,130,246,.28); }
.zone-editor.privacy .zc.on { background: rgba(0,0,0,.88); box-shadow: inset 0 0 0 1px rgba(239,68,68,.55); }
.zone-editor .zc.hit { background: rgba(245,158,11,.6); }
.zone-editor .zc.on.hit { background: rgba(245,158,11,.75); }
.meter { height: 8px; background: var(--panel-2); border-radius: 4px; overflow: hidden; max-width: 720px; }
.meter > div { height: 100%; background: var(--warn); width: 0; transition: width .2s; }
.meter .mark { position: relative; }
input[type=range] { padding: 0; min-height: 30px; }
.timeline .ev { position: absolute; top: 2px; height: 5px; background: var(--warn); border-radius: 2px; min-width: 3px; }
.timeline .ev.obj { background: #e879f9; top: 40px; height: 6px; }
/* Farben je Ereignisart (Zeitleiste + Liste) */
.k-motion { background: var(--warn) !important; }
.k-person { background: #38bdf8 !important; }
.k-car { background: #e879f9 !important; }
.k-truck { background: #f87171 !important; }
.k-motorcycle { background: #fb923c !important; }
.k-bicycle { background: #a3e635 !important; }
.k-animal { background: #4ade80 !important; }
.k-ring { background: #facc15 !important; }
.k-external { background: #94a3b8 !important; }
.k-line { background: #22d3ee !important; }
/* virtuelle Linien + Zählung */
.line-editor svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.line-editor .ln-h { cursor: grab; }
.line-editor.drawing { cursor: crosshair; outline: 2px dashed var(--accent); }
.ln-row { margin-top: 10px; padding-left: 10px; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; }
.cnt-head { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: baseline; margin-bottom: 6px; }
.cnt-num { color: var(--muted); }
.cnt-num b { color: var(--text); font-size: 1.35em; margin-left: 4px; }
.cnt-num i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; }
.cnt-chart { width: 100%; height: 170px; display: block; }
.cnt-chart text { fill: var(--muted); font-size: 18px; }
.cnt-chart .c-axis { stroke: var(--line); stroke-width: 2; }
.c-in { fill: #22d3ee; background: #22d3ee; }
.c-out { fill: #f59e0b; background: #f59e0b; }
.tl-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--muted); margin: 6px 2px 0; }
.tl-legend span { display: inline-flex; align-items: center; }
.tl-legend .kdot { margin-right: 5px; }
.lg-bar { display: inline-block; width: 16px; height: 9px; border-radius: 2px; margin-right: 5px; opacity: .85; }
.lg-head { display: inline-block; width: 3px; height: 13px; background: var(--warn); margin-right: 5px; }
.kdot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.ai-overlay { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.ai-box { position: absolute; border: 2px solid #38bdf8; border-radius: 3px; }
.ai-box.still { border-style: dashed; opacity: .55; }
.ai-box span { position: absolute; left: -2px; top: -20px; background: #38bdf8; color: #000; font-size: 12px; padding: 1px 5px; border-radius: 3px; white-space: nowrap; }

.events { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.ev-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; }
.ev-card:hover { border-color: var(--line-strong); }
.ev-card .img { aspect-ratio: 16/9; background: #000 center/cover no-repeat; }
.ev-card .meta { padding: 8px 10px; font-size: 13px; display: flex; justify-content: space-between; gap: 6px; }
.plate-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px 0; flex-wrap: wrap; }
.plate-row img { height: 30px; border-radius: 3px; }
.face-row img { height: 44px; width: 44px; object-fit: cover; border-radius: 50%; }
/* Gesichter-Verwaltung */
.face-person { border-top: 1px solid var(--line); padding: 10px 0; }
.face-person .row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.face-samples { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.face-sample { position: relative; }
.face-sample img { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; display: block; }
.face-sample button { position: absolute; top: -6px; right: -6px; min-width: 0; padding: 0 6px; line-height: 20px; border-radius: 50%; }
.face-add { width: 72px; height: 72px; border: 2px dashed var(--line); border-radius: 8px; display: flex; align-items: center;
  justify-content: center; cursor: pointer; color: var(--muted); font-size: 13px; }
.face-add:hover { border-color: var(--accent); color: var(--accent); }
.plate { font: 700 14px/1 ui-monospace, Consolas, monospace; background: #f5f5f5; color: #111; padding: 5px 8px; border-radius: 4px; border-left: 8px solid #1d4ed8; letter-spacing: .05em; }
.plate.alarm { outline: 2px solid var(--bad); }
@media (max-width: 760px) { .events { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ---------- Login ---------- */
.login { max-width: 360px; margin: 12vh auto 0; }
.login .brand { justify-content: center; font-size: 20px; margin-bottom: 20px; }
.login form { display: flex; flex-direction: column; gap: 12px; }
.error { color: var(--bad); font-size: 14px; }

.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 20px); transform: translateX(-50%); z-index: 50; background: var(--panel-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 8px; box-shadow: 0 6px 24px var(--shadow); }
.toast.bad { border-color: var(--bad); }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; width: min(520px, 94vw); }
dialog::backdrop { background: rgba(0,0,0,.6); }
.checklist { display: flex; flex-direction: column; gap: 6px; max-height: 300px; overflow: auto; margin: 10px 0; }
pre.log { background: var(--bg); border: 1px solid var(--line); padding: 8px; border-radius: 6px; font-size: 12px; white-space: pre-wrap; max-height: 200px; overflow: auto; }

/* ---- Ein-/Ausgänge */
.io-list { display: flex; flex-direction: column; gap: 6px; }
.io-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.io-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.io-name input { width: 100%; max-width: 260px; margin-bottom: 2px; }
.io-btns { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.io-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--line); flex: none; }
.io-dot.on { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.io-dot.off { background: #4b5563; }
.io-dot.err { background: var(--bad); }
.io-log { max-height: 320px; overflow: auto; font-size: 13px; display: flex; flex-direction: column; gap: 3px; }
.io-log .io-door { color: var(--warn); }
.io-hook { overflow-wrap: anywhere; font-size: 12px; }
.io-item { border-top: 1px dashed var(--line); padding-top: 6px; margin-top: 6px; }
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 50; display: flex; align-items: flex-start;
  justify-content: center; overflow: auto; padding: 4vh 8px; }
.modal { width: min(760px, 100%); margin: 0; }
.modal h3 { font-size: 14px; margin: 16px 0 6px; color: var(--muted); }
.door-btn { position: absolute; right: 8px; bottom: 8px; z-index: 6; }
@media (max-width: 600px) { .io-row { flex-wrap: wrap; } .io-btns { width: 100%; justify-content: flex-start; } }
.io-days { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 4px; }
.io-days .check { margin: 0; }
.cam-io { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 13px; min-height: 0; }
.io-chip { display: inline-flex; align-items: center; gap: 5px; }
.io-chip .io-dot { width: 9px; height: 9px; }
.ai-box.still { border-style: dashed; opacity: .85; }
/* ---- Geführtes Gesichts-Einlernen */
dialog.enroll-dlg { width: min(720px, 96vw); }
.qr { margin: 8px 0; }
.qr svg, .qr img { width: 180px; height: 180px; background: #fff; padding: 6px; border-radius: 8px; display: block; }
ol.steps { padding-left: 20px; margin: 6px 0; }
ol.steps li { margin: 6px 0; }
dialog.ring-dlg { width: min(900px, 98vw); padding: 12px; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,.35); }
.ring-view { max-height: 62vh; }
.ring-actions { flex-wrap: wrap; gap: 8px; }
.ring-actions button { min-height: 48px; font-size: 16px; }
.door-big { background: var(--ok, #16a34a); border-color: var(--ok, #16a34a); color: #fff; font-weight: 600; min-height: 48px; padding: 8px 18px; margin-right: 8px; }
.os-pick { position: relative; touch-action: none; user-select: none; cursor: crosshair; line-height: 0; background: #000; border-radius: 6px; overflow: hidden; }
.os-pick img { width: 100%; display: block; pointer-events: none; min-height: 120px; }
.os-box { position: absolute; border: 2px solid #f59e0b; box-shadow: 0 0 0 9999px rgba(0,0,0,.35); pointer-events: none; }
.os-res { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; }
.os-res figure { margin: 0; }
.os-res img { width: 100%; border-radius: 6px; display: block; }
.os-res figcaption { font-size: 13px; color: var(--muted); margin-top: 4px; }
.enroll-view { position: relative; width: fit-content; max-width: 100%; margin: 8px auto; background: #000; border-radius: 8px; overflow: hidden; }
.enroll-view img { display: block; width: auto; height: auto; max-width: 100%; max-height: 48vh; }
.enroll-box { position: absolute; border: 3px solid var(--warn); border-radius: 8px; transition: all .3s; }
.enroll-box.ok { border-color: var(--ok); box-shadow: 0 0 12px var(--ok); }
.enroll-steps { display: flex; gap: 8px; justify-content: center; margin: 6px 0; }
.enroll-steps span { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-size: 20px;
  background: var(--panel-2); border: 2px solid var(--line); }
.enroll-steps span.now { border-color: var(--accent); }
.enroll-steps span.done { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 25%, transparent); }
.enroll-say { font-size: 20px; font-weight: 600; text-align: center; min-height: 2.6em; margin: 6px 0; }
.enroll-say.ok { color: var(--ok); } .enroll-say.bad { color: var(--bad); }
/* ---- Digitaler Zoom */
.zoom-badge { position: absolute; right: 8px; top: 8px; z-index: 7; background: rgba(0,0,0,.65); border-color: transparent; }
.zoomed { cursor: grab; }
.zoomed:active { cursor: grabbing; }
.single, .pb-tile { touch-action: pan-y; }
/* ---- PTZ-Joystick */
.ptz { position: absolute; left: 10px; bottom: 10px; z-index: 8; display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.ptz-pad { width: 110px; height: 110px; border-radius: 50%; background: rgba(0,0,0,.45); border: 2px solid rgba(255,255,255,.35);
  position: relative; touch-action: none; cursor: grab; }
.ptz-knob { position: absolute; left: 50%; top: 50%; width: 42px; height: 42px; margin: -21px 0 0 -21px; border-radius: 50%;
  background: rgba(255,255,255,.85); box-shadow: 0 2px 8px rgba(0,0,0,.5); pointer-events: none; }
.ptz-side { display: flex; flex-direction: column; gap: 6px; }
.ptz-side button, .ptz-presets button, .ptz-hide { background: rgba(0,0,0,.55); touch-action: none; }
.ptz-presets select { background: rgba(0,0,0,.55); max-width: 150px; }
.ptz-presets { display: flex; gap: 6px; }
.ptz.off > :not(.ptz-hide) { display: none; }
/* ---- Drehen / Einblendung */
.pb-media { position: absolute; inset: 0; }
.osd { position: absolute; left: 8px; bottom: 8px; z-index: 5; padding: 2px 7px; border-radius: 4px; font-size: 13px;
  font-variant-numeric: tabular-nums; color: #fff; background: rgba(0,0,0,.55); pointer-events: none; white-space: nowrap; }
.single .osd { font-size: 15px; }
.guide-list { padding-left: 18px; display: flex; flex-direction: column; gap: 6px; }
/* ---- Hell/Dunkel: Beschriftungen auf Kamerabildern bleiben immer hell (Bild ist dunkel hinterlegt) */
.tile .label, .pb-tile .label, .pb-gap, .arr-size button, .zoom-badge, .ptz button, .ptz select, .door-btn:not(.primary) { color: #f3f4f6; }
.alert-bar { background: var(--bad, #dc2626); color: #fff; padding: 8px 18px; font-size: 14px; line-height: 1.4; }
.alert-bar div + div { margin-top: 4px; }
.theme-btn { margin-left: auto; min-height: 34px; padding: 4px 10px; font-size: 16px; }
.logout-btn { min-height: 34px; padding: 4px 10px; font-size: 16px; margin-left: -16px; }  /* dicht neben ◐ */
@media (max-width: 1050px) and (min-width: 761px) {
  .topbar { gap: 12px; }
  .nav { gap: 0; }
  .nav a { padding: 7px 8px; }
  .logout-btn { margin-left: -6px; }
}
p.ok { color: var(--ok); }
.ex-modes { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; }
