:root {
  --bg: #000;
  --text: #f1f3f6;
  --muted: #a8b1c0;
  --surface: rgba(20, 24, 32, 0.78);
  --surface-2: rgba(30, 36, 48, 0.85);
  --surface-3: rgba(46, 54, 70, 0.85);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.20);
  --ctrl: 36px;             /* unified height for all top-bar controls */
  --accent: #4dabf7;
  --accent-soft: rgba(77, 171, 247, 0.22);
  --accent-border: rgba(77, 171, 247, 0.55);
  --danger: #ff6b6b;
  --danger-soft: rgba(255, 107, 107, 0.20);
  --danger-border: rgba(255, 107, 107, 0.55);
  --success: #51cf66;
  --warn: #e67e22;              /* status orange (stall, negative samples, weak metrics) */
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 36px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

body { user-select: none; }
body, input, button, select, textarea { font-family: inherit; }
input { user-select: text; }

/* Keyboard focus: a clear ring for tab-users. Uses box-shadow (not outline) so
   the many `outline:none` rules don't need per-element :focus-visible overrides.
   :focus-visible → only on keyboard nav, never on mouse/touch. */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
}

/* ---------- Background video --------------------------------------------- */

.bg-video {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  z-index: 0;
  display: block;
}
body.unlocked .bg-video { cursor: crosshair; }

/* Subtle gradient masks at top/bottom for overlay legibility */
body::before, body::after {
  content: "";
  position: fixed;
  left: 0;
  right: 0;
  height: 130px;
  z-index: 5;
  pointer-events: none;
  transition: opacity .35s ease;
}
body::before {
  top: 0;
  background: linear-gradient(180deg, rgba(0,0,0,0.65), rgba(0,0,0,0));
}
body::after {
  bottom: 0;
  background: linear-gradient(0deg,   rgba(0,0,0,0.78), rgba(0,0,0,0));
}
body.locked::after { opacity: 0; }                /* nothing below the bottom bar when locked */
body.ui-hidden::before, body.ui-hidden::after { opacity: 0; }

/* ---------- Loader ------------------------------------------------------- */

.loader {
  position: fixed;
  inset: 0;
  z-index: 4;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--muted);
  transition: opacity 0.4s ease;
}
.loader.hidden { opacity: 0; pointer-events: none; }
.loader-text { font-size: 0.95rem; }
.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid rgba(255,255,255,0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Guest maintenance overlay (stream also hard-blocked server-side) */
.guest-block {
  position: fixed;
  inset: 0;
  z-index: 20;                 /* over video/loader/info-bar (≤12), under topbar (40) so the lock stays usable */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 38%, #1a2230, #0b0e14 80%);
  text-align: center;
}
/* `.guest-block { display:flex }` would otherwise override the [hidden] attribute
   (author CSS beats the UA [hidden]{display:none}); make hidden actually hide. */
.guest-block[hidden] { display: none !important; }
.guest-block-card { max-width: 420px; color: var(--text); }
.guest-block .gb-emoji { font-size: 3.4rem; line-height: 1; margin-bottom: 12px; }
.guest-block h2 { margin: 0 0 8px; font-size: 1.4rem; }
.guest-block p  { margin: 0; opacity: 0.82; line-height: 1.5; }
.guest-block .gb-unlock { margin-top: 20px; }
/* admin toggle in the ⋯ menu: lit red while guests are currently blocked */
#guest-toggle.active { background: var(--danger); border-color: var(--danger); }
/* In maintenance, a guest can ONLY log in — hide every other top-bar action
   (viewer count, ❄️ Abkühlen, 🔔 Push, quality switch, ⋯). */
body.guests-blocked .topbar-right > *:not(.lock-btn) { display: none !important; }

/* ---------- Overlay shell & auto-hide ----------------------------------- */

.overlay {
  position: fixed;
  z-index: 10;
  transition: opacity .3s ease, transform .3s ease;
}
.overlay-top {
  top: 0; left: 0; right: 0;
  padding: 14px clamp(12px, 2.4vw, 24px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.overlay-bottom {
  bottom: 0; left: 0; right: 0;
  padding: 12px clamp(12px, 2.4vw, 24px) calc(env(safe-area-inset-bottom, 0px) + 14px);
}

/* Auto-hide fades the title + buttons, but the viewer count pill stays pinned
   (always visible — guests too). Container keeps pointer-events:none so the top
   strip stays click-through; only the pill re-enables clicks (admin → list). */
body.ui-hidden .overlay-top { pointer-events: none; }
body.ui-hidden .overlay-top .title              { opacity: 0; transform: translateY(-6px); }
body.ui-hidden .topbar-right > :not(.viewers)   { opacity: 0; }
body.ui-hidden .overlay-top .viewers            { opacity: 1; pointer-events: auto; }
body.ui-hidden .overlay-bottom { opacity: 0; transform: translateY(6px);  pointer-events: none; }
body.ui-hidden .controls-panel { opacity: 0; transform: translate(-8px, -50%); pointer-events: none; }
body.ui-hidden .steering       { opacity: 0; transform: translateY(8px);       pointer-events: none; }

/* Controls are hidden entirely while locked */
body.locked   #controls,
body.locked   #steering { display: none; }
/* Guests (locked) see only the viewer count + live glows — hide every button. */
body.locked .topbar-right .icon-btn { display: none; }
/* …except the ❄️ Abkühlen button, which everyone may use (1×/Tag). */
body.locked .topbar-right .cooldown-btn { display: inline-flex; }
.cooldown-btn.used { opacity: 0.4; }
.cooldown-btn:not(.used):not(:disabled):hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Topbar ------------------------------------------------------- */

.title {
  margin: 0;
  font-size: clamp(1rem, 2.2vw, 1.35rem);
  font-weight: 600;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 10px;
  text-shadow: 0 2px 6px rgba(0,0,0,0.5);
  transition: opacity .3s ease, transform .3s ease;
}
.title-emoji { font-size: 1.2em; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.viewers {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: var(--ctrl);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 13px;
  font-size: 0.82rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.viewers-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 8px rgba(81,207,102,0.6);
  animation: pulse 2.4s ease-in-out infinite;
}
/* Doubles as the stream-liveness light (JS toggles .stalled): green pulse = live,
   orange static = stream hängt, rot static = Wartungsmodus. */
.viewers-dot.stalled {
  background: var(--warn);
  box-shadow: 0 0 8px rgba(230,126,34,0.6);
  animation: none;
}
body.maintenance-on .viewers-dot {
  background: var(--danger) !important;
  box-shadow: 0 0 8px rgba(231,76,60,0.6) !important;
  animation: none !important;
}
.viewers #viewer-count { color: var(--text); font-weight: 600; }
body.unlocked .viewers { cursor: pointer; }
body.unlocked .viewers:hover #viewer-count { text-decoration: underline; }
.viewers-summary { color: var(--muted); font-size: 0.85rem; margin-bottom: 10px; }
.viewer-row {
  display: grid;
  grid-template-columns: 1fr 1.4fr auto;
  gap: 10px;
  align-items: baseline;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  background: var(--surface-2);
  font-size: 0.9rem;
}
.viewer-ip { font-weight: 600; color: var(--text); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.viewer-rdns { color: var(--muted); overflow-wrap: anywhere; }
.viewer-meta { color: var(--muted); font-size: 0.8rem; white-space: nowrap; }
/* Quality (HD/4K) toggle — stays visible for guests (not an .icon-btn). */
.quality-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  height: var(--ctrl);
  padding: 0 14px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  transition: border-color .15s, background .15s, opacity .3s ease;
}
.quality-btn:hover { border-color: var(--border-strong); background: var(--surface-3); }
.quality-btn.on { background: var(--success); color: #000; border-color: var(--success); }
.stream-overlay {
  position: fixed;
  top: 64px;
  left: 12px;
  z-index: 40;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 0.72rem;
  line-height: 1.5;
  padding: 6px 10px;
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  pointer-events: none;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.stream-overlay b { color: var(--success); }
.yt-body { display: flex; flex-direction: column; gap: 14px; }
.yt-toggle { display: flex; align-items: center; gap: 10px; font-size: 0.95rem; cursor: pointer; }
.yt-toggle input { width: 18px; height: 18px; }
.yt-row { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--muted); }
.yt-key-input {
  width: 100%; box-sizing: border-box; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface-2); color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem;
}
.yt-status { font-size: 0.85rem; color: var(--muted); min-height: 1.2em; }
.yt-hint { color: var(--muted); font-weight: 400; font-size: 0.8em; }
.yt-embed { position: fixed; inset: 0; width: 100%; height: 100%; border: 0; z-index: 6; background: #000; }
@keyframes live-pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.55); opacity: 0.4; } }
#youtube-btn { position: relative; }
#youtube-btn.yt-live::after {
  content: ''; position: absolute; top: 2px; right: 2px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger); box-shadow: 0 0 6px var(--danger);
  animation: live-pulse 1.4s ease-in-out infinite;
}
body.youtube-mode .detect-overlay,
body.youtube-mode #stream-overlay,
body.foto-mode .detect-overlay,
body.foto-mode #stream-overlay { display: none; }
/* The "Foto" <img> shares .bg-video styling; keep the hidden attribute working
   (author display:block would otherwise override the UA [hidden] rule). */
.bg-video[hidden] { display: none; }
.yt-exit {
  display: none; position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
  z-index: 50; padding: 8px 16px; border-radius: 999px; cursor: pointer;
  background: rgba(0, 0, 0, 0.72); color: #fff; border: 1px solid rgba(255, 255, 255, 0.35);
  font-size: 0.85rem; font-weight: 600; backdrop-filter: blur(4px);
}
.yt-exit:hover { background: rgba(0, 0, 0, 0.9); }
body.youtube-mode .yt-exit { display: block; }
.train-badge {
  position: fixed; top: 56px; left: 50%; transform: translateX(-50%);
  z-index: 46; padding: 5px 12px; border-radius: 999px;
  background: rgba(20, 20, 30, 0.82); color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.18);
  font-size: 0.75rem; font-weight: 600; white-space: nowrap;
  backdrop-filter: blur(4px); pointer-events: none;
}
.train-badge.done {
  background: rgba(34, 90, 50, 0.88);
  border-color: var(--success);
  color: #d7ffd7;
}
/* System-stats overlay (admin only): CPU / GPU / Traffic, top-left under topbar */
.sys-stats {
  position: fixed; top: 70px; left: clamp(12px, 2.4vw, 24px);
  z-index: 12; display: flex; flex-direction: column; gap: 2px;
  padding: 7px 11px; border-radius: 10px;
  background: rgba(20, 20, 30, 0.72); backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  font-size: 0.72rem; line-height: 1.35; color: #e8e8ef;
  font-variant-numeric: tabular-nums; pointer-events: none;
  transition: opacity .3s ease;
}
.sys-stats b { font-weight: 700; }
.sys-stats .ss-dim { opacity: 0.62; font-weight: 400; }
body.locked .sys-stats { display: none !important; }
body.ui-hidden .sys-stats { opacity: 0; }

/* Environment telemetry bar — always visible (guests too), bottom-centre.
   Click-through so it never blocks the video or controls. */
/* Full-width single-line telemetry strip pinned to the very bottom — ALWAYS
   visible (never fades with the auto-hide UI). */
.info-bar {
  position: fixed; z-index: 11;
  left: 0; right: 0; bottom: 0;
  display: flex; flex-wrap: nowrap; gap: 0; justify-content: center; align-items: center;
  padding: 6px 12px calc(6px + env(safe-area-inset-bottom, 0px));
  background: rgba(12, 14, 20, 0.80); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  color: #eef0f6; font-size: 0.78rem; line-height: 1.2;
  font-variant-numeric: tabular-nums; pointer-events: none;
  white-space: nowrap; overflow: hidden;
}
/* `display:flex` would override the [hidden] attribute, so make hidden work
   (bar appears once loadInfo() has data, then stays — it never fades out). */
.info-bar[hidden] { display: none !important; }
.info-bar .ib-item { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.info-bar .ib-item + .ib-item { margin-left: 14px; padding-left: 14px; border-left: 1px solid rgba(255, 255, 255, 0.14); }
.info-bar .ib-em { font-size: 0.9em; }
.info-bar .ib-val { font-weight: 700; }
.info-bar .ib-lbl { opacity: 0.75; font-weight: 400; }
.info-bar.stale .ib-val { opacity: 0.7; }   /* dim values when data is old — bar stays visible */
.info-bar .ib-eta .ib-val { color: #ffd166; }   /* hatch-ETA chip: stand out from telemetry */

/* Mini weekly sparkline inside an icon. */
.info-bar .ib-spark { margin-left: 5px; opacity: 0.85; vertical-align: middle; overflow: visible; }
/* The bar is pointer-events:none by default; re-enable it once history exists so
   the whole bar becomes a tap target opening the detail charts. */
.info-bar.has-history { pointer-events: auto; cursor: pointer; }
.info-bar.has-history:hover { background: rgba(20, 24, 34, 0.9); }

/* Detail modal: ONE combined weekly chart (2 Y-axes) + legend + crosshair tooltip. */
#info-modal .modal-card { width: min(96vw, 1100px); max-width: none; }
#info-body { display: block; }
.ic-ranges { display: flex; gap: 6px; justify-content: center; margin-bottom: 10px; }
.ic-range {
  background: rgba(255, 255, 255, 0.05); border: 1px solid rgba(255, 255, 255, 0.12);
  color: #cfd3df; border-radius: 8px; padding: 4px 13px; font-size: 0.8rem; cursor: pointer;
}
.ic-range:hover { background: rgba(255, 255, 255, 0.10); }
.ic-range.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.ic-legend { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 10px; }
.ic-leg {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.10);
  color: #eef0f6; border-radius: 999px; padding: 4px 11px; font-size: 0.8rem; cursor: pointer;
}
.ic-leg b { font-variant-numeric: tabular-nums; }
.ic-leg.off { opacity: 0.4; text-decoration: line-through; }
.ic-leg .dot, .ic-tip .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: 0 0 auto; }
.ic-wrap { position: relative; width: 100%; }
.ic-wrap svg { width: 100%; height: auto; display: block; touch-action: none; }
.ic-grid { stroke: rgba(255, 255, 255, 0.10); stroke-width: 1; }
.ic-vgrid { stroke: rgba(255, 255, 255, 0.05); }
.ic-line { fill: none; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.ic-cross { stroke: rgba(255, 255, 255, 0.45); stroke-width: 1; stroke-dasharray: 3 3; }
.ic-ylab { fill: rgba(255, 255, 255, 0.55); font-size: 11px; font-variant-numeric: tabular-nums; }
.ic-xlab { fill: rgba(255, 255, 255, 0.45); font-size: 11px; }
.ic-tip {
  position: absolute; top: 6px; pointer-events: none; white-space: nowrap;
  background: rgba(12, 14, 20, 0.94); border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px; padding: 6px 9px; font-size: 0.76rem; line-height: 1.5;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}
.ic-tip-t { opacity: 0.7; margin-bottom: 2px; font-size: 0.72rem; }
.ic-tip div { display: flex; align-items: center; gap: 6px; }
.ic-tip b { font-variant-numeric: tabular-nums; }
.ic-fc-btn.on { background: #b8860b; border-color: #b8860b; }   /* Prognose aktiv (amber) */

/* Event markers + forecast region on the chart */
.ic-fc { fill: rgba(255, 210, 74, 0.06); }
.ic-now { stroke: rgba(255, 255, 255, 0.55); stroke-width: 1; stroke-dasharray: 2 2; }
.ic-nowlab { fill: rgba(255, 255, 255, 0.6); }
.ic-ev { cursor: help; }
.ic-evline { stroke: #ffd24a; stroke-width: 1; stroke-dasharray: 4 3; opacity: 0.75; }
.ic-evlab { font-size: 13px; }
/* Wärmebasierte Schlupf-Prognose: Unsicherheits-Band + ETA-Marker */
.ic-eta-band { fill: rgba(255, 209, 102, 0.14); }
.ic-eta-line { stroke: #ffd166; stroke-width: 1.5; }
.ic-eta-lab { fill: #ffd166; font-size: 10px; font-weight: 700; }
/* Reife-/Wärmesummen-Kurve (kumulierte Gradtage auf eigener 0–100%-Skala) */
.ic-matline { fill: none; stroke: #ffd166; stroke-width: 1.6; }
.ic-matproj { stroke-dasharray: 5 4; opacity: 0.8; }
.ic-matgrid { stroke: rgba(255, 209, 102, 0.28); stroke-width: 1; stroke-dasharray: 2 4; }
.ic-matlab { fill: rgba(255, 209, 102, 0.85); font-size: 9px; }
.ic-leg-mat b { color: #ffd166; }

/* Logbuch modal */
.log-body { max-height: 52vh; overflow-y: auto; margin-bottom: 10px; }
/* Schlupf-Schnell-Erfassung + Gesamt-Zähler */
.log-hatch-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 10px; margin-bottom: 10px;
  background: rgba(81, 207, 102, 0.08);
  border: 1px solid rgba(81, 207, 102, 0.25); border-radius: var(--radius-sm);
}
.log-hatch-row[hidden] { display: none; }
.log-hatch-lbl { font-weight: 600; }
.log-hatch-row input[type="number"] { width: 64px; }
.log-hatch-sum {
  padding: 6px 4px 10px; font-size: 0.95em; color: var(--success);
  border-bottom: 1px solid rgba(255, 255, 255, 0.07); margin-bottom: 4px;
}
.log-item {
  display: flex; align-items: flex-start; gap: 10px; padding: 9px 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
.log-item.future { background: rgba(255, 210, 74, 0.05); border-radius: 8px; }
.log-ic { font-size: 1.4em; line-height: 1.2; flex: 0 0 auto; }
.log-main { flex: 1 1 auto; min-width: 0; }
.log-h { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; }
.log-date { opacity: 0.6; font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.log-note { opacity: 0.8; font-size: 0.85rem; margin-top: 2px; white-space: pre-wrap; }
.log-act { display: flex; gap: 4px; flex: 0 0 auto; }
.log-act button { background: none; border: none; cursor: pointer; font-size: 1em; padding: 2px 4px; opacity: 0.7; }
.log-act button:hover { opacity: 1; }
.log-form { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; padding: 10px; background: rgba(255, 255, 255, 0.04); border-radius: 10px; }
.log-form[hidden] { display: none; }
.log-form-row { display: flex; gap: 8px; }
.log-form input, .log-form textarea {
  background: rgba(0, 0, 0, 0.3); border: 1px solid rgba(255, 255, 255, 0.15);
  color: #eef0f6; border-radius: 8px; padding: 7px 10px; font: inherit;
}
.log-form .log-icon-in { width: 3.2em; text-align: center; flex: 0 0 auto; }
.log-form #log-title-in { flex: 1 1 auto; min-width: 0; }
.log-form #log-date { flex: 0 0 auto; }
.log-form textarea { resize: vertical; }
.log-eta { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; opacity: 0.9; cursor: pointer; }
.log-eta[hidden] { display: none; }
.log-eta .log-eta-days { width: 3.6em; text-align: center; padding: 3px 4px; }

@media (max-width: 768px) {
  /* Sit directly on top of the bottom tab bar when it's shown (unlocked). */
  body.unlocked .info-bar { bottom: calc(env(safe-area-inset-bottom, 0px) + 56px); padding-bottom: 6px; }
  /* On a narrow phone the strip is wider than the screen. Centering + overflow:hidden
     clips it on BOTH edges; instead pin it left and let it scroll horizontally so
     every sensor stays reachable. */
  .info-bar {
    font-size: 0.7rem;
    justify-content: flex-start;
    overflow-x: auto; overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-left: calc(10px + env(safe-area-inset-left, 0px));
    padding-right: calc(10px + env(safe-area-inset-right, 0px));
  }
  .info-bar::-webkit-scrollbar { display: none; }
  .info-bar .ib-item { flex: 0 0 auto; min-width: 0; }
  .info-bar .ib-item + .ib-item { margin-left: 9px; padding-left: 9px; }
}

.viewers-label { display: none; }
@media (min-width: 640px) { .viewers-label { display: inline; } }

@keyframes pulse {
  0%,100% { opacity: 1; }
  50%     { opacity: 0.35; }
}

.icon-btn {
  appearance: none;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  width: var(--ctrl);
  height: var(--ctrl);
  border-radius: 10px;
  font: inherit;
  font-size: 1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, border-color .15s, transform .06s, opacity .3s ease;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.icon-btn:active { transform: scale(0.94); }

body.unlocked .lock-btn { background: var(--accent-soft); border-color: var(--accent-border); }

/* (Desktop top-bar redesign lives at the very END of this file so it wins
   source-order over the safe-area padding override below.) */

/* ---------- Bottom controls --------------------------------------------- */

/* Combined control panel — pinned to the left edge, laid out top → bottom. */
.controls-panel {
  left: clamp(12px, 2vw, 22px);
  top: 50%;
  transform: translateY(-50%);
  width: clamp(184px, 16vw, 212px);
  max-height: calc(100vh - 116px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 11px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  scrollbar-width: thin;
}
.ctrl-section { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.ctrl-section + .ctrl-section { border-top: 1px solid var(--border); padding-top: 9px; }

/* Patrol Start/Stop split the row evenly. */
.patrol-row .btn { flex: 1 1 0; justify-content: center; }

/* Positions as a vertical list (one full-width row each). */
.preset-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 40vh;
  overflow-y: auto;
  scrollbar-width: thin;
}
.preset-list .btn { width: 100%; }
.preset-list .btn .btn-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px 10px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.card-title {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.card-sub {
  font-size: 0.75rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.btn-row { display: flex; flex-wrap: wrap; gap: 6px; }
/* Content-sized, so Patrol Start/Stop & co. match the other buttons instead of
   stretching to fill the card width. */
.btn-row .btn { flex: 0 1 auto; }

.btn-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(124px, 1fr));
  gap: 6px;
  max-height: 38vh;
  overflow-y: auto;
}
@media (max-width: 720px) {
  .btn-grid { max-height: 28vh; }
}

.btn {
  appearance: none;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 7px 12px;
  border-radius: 10px;
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  text-align: left;
  transition: background .12s ease, border-color .12s ease, transform .06s ease;
  min-height: 34px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: progress; }

.btn-emoji { font-size: 1.05em; line-height: 1; flex-shrink: 0; }

.btn-primary { background: var(--accent-soft); border-color: var(--accent-border); }
.btn-primary:hover { background: rgba(77,171,247,0.32); border-color: rgba(77,171,247,0.75); }

.btn-danger { background: var(--danger-soft); border-color: var(--danger-border); }
.btn-danger:hover { background: rgba(255,107,107,0.32); border-color: rgba(255,107,107,0.75); }

.btn-ghost {
  appearance: none;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 4px 9px;
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  font-size: 0.75rem;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: color .12s, border-color .12s, background .12s;
}
.btn-ghost:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-2); }
.btn-ghost.spinning .btn-emoji { display: inline-block; animation: spin 0.6s linear infinite; }

.placeholder {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 14px 8px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}
.placeholder.error { color: var(--danger); border-color: var(--danger-border); }

/* ---------- D-pad + zoom (right side) ----------------------------------- */

.steering {
  right: clamp(12px, 2vw, 22px);
  /* clear the full-width telemetry strip pinned to the very bottom (~34px) */
  bottom: calc(env(safe-area-inset-bottom, 0px) + 44px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(3, 44px);
  gap: 4px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}
.dpad-btn {
  appearance: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background .1s, border-color .1s, transform .04s;
}
.dpad-btn:hover  { background: var(--surface-3); border-color: var(--border-strong); }
.dpad-btn:active,
.dpad-btn.active { background: var(--accent-soft); border-color: var(--accent-border); transform: scale(0.95); }

.dpad-up    { grid-column: 2; grid-row: 1; }
.dpad-left  { grid-column: 1; grid-row: 2; }
.dpad-stop  { grid-column: 2; grid-row: 2; color: var(--danger); font-size: 0.9rem; }
.dpad-right { grid-column: 3; grid-row: 2; }
.dpad-down  { grid-column: 2; grid-row: 3; }

.zoom-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.zoom-btn {
  justify-content: center;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 6px;
}

.focus-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.focus-btn {
  justify-content: center;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 6px;
}
.focus-btn:active,
.focus-btn.active { background: var(--accent-soft); border-color: var(--accent-border); transform: scale(0.96); }
/* Autofocus toggle reflects the camera's current AF state. */
#autofocus-btn.af-on  { background: var(--accent-soft); border-color: var(--accent-border); }
#autofocus-btn.af-off { opacity: 0.6; }

.speed-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
}
.speed-row label   { flex: 0 0 auto; opacity: 0.85; }
.speed-row input[type="range"] { flex: 1 1 auto; min-width: 0; accent-color: var(--accent-border); }
.speed-row #move-speed-val { flex: 0 0 auto; min-width: 1.9em; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

@media (max-width: 720px) {
  .controls-panel {
    width: clamp(150px, 46vw, 196px);
    max-height: calc(100vh - 180px);
    gap: 8px;
    padding: 10px;
  }
  .preset-list { max-height: 32vh; }
  .dpad { grid-template-columns: repeat(3, 42px); grid-template-rows: repeat(3, 42px); }
}

/* ---------- Modals ------------------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fade .2s ease;
}
.modal[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  background: #14181f;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 22px 22px 18px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow);
  animation: pop .22s cubic-bezier(.2,.7,.3,1.2);
}
@keyframes pop { from { transform: scale(0.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.modal-title { margin: 0 0 4px; font-size: 1.1rem; font-weight: 600; }
.modal-sub   { margin: 0 0 14px; color: var(--muted); font-size: 0.88rem; }

.modal-form { display: flex; flex-direction: column; gap: 10px; }
.modal-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.modal-label input {
  background: #0c0f14;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  letter-spacing: normal;
  text-transform: none;
}
.modal-label input:focus {
  outline: none;
  border-color: var(--accent-border);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.modal-error {
  background: var(--danger-soft);
  border: 1px solid var(--danger-border);
  color: var(--danger);
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.shortcuts {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 12px;
}
.shortcuts th, .shortcuts td {
  text-align: left;
  padding: 6px 8px;
  font-size: 0.9rem;
}
.shortcuts th {
  color: var(--muted);
  font-weight: 600;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.83rem;
  white-space: nowrap;
  width: 30%;
}
.shortcuts tr + tr th, .shortcuts tr + tr td { border-top: 1px solid var(--border); }

/* ---------- Toast -------------------------------------------------------- */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translate(-50%, 14px);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  opacity: 0;
  transition: opacity .25s, transform .25s;
  pointer-events: none;
  z-index: 80;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  max-width: calc(100vw - 32px);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.success { border-color: var(--success); }
.toast.error   { border-color: var(--danger); }
.toast.viewer  { border-left: 3px solid var(--accent); text-align: left; line-height: 1.4; }
.toast.viewer .vt-ip   { font-variant-numeric: tabular-nums; font-weight: 600; }
.toast.viewer .vt-meta { opacity: 0.68; font-size: 0.85em; }

/* ---------- Cursor hide while ui-hidden -------------------------------- */
body.ui-hidden { cursor: none; }

/* ---------- Detection overlay ------------------------------------------ */

.detect-overlay {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

/* ---------- Detection button & badge ----------------------------------- */

.detect-btn {
  position: relative;
}
.detect-btn.spinning span:first-child {
  display: inline-block;
  animation: spin 0.6s linear infinite;
}
.detect-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--success);
  color: #000;
  font-size: 0.6rem;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  line-height: 1;
}

/* ---------- Toast with thumbnail --------------------------------------- */

.toast.detection {
  bottom: auto;
  left: auto;
  top: 70px;
  right: 16px;
  transform: translateX(16px);
  pointer-events: auto;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  border-color: var(--success);
  max-width: 340px;
}
.toast.detection:hover { border-color: var(--success); filter: brightness(1.08); }
.toast.show.detection { transform: translateX(0); }
.toast-thumb {
  border-radius: 6px;
  object-fit: cover;
  height: 48px;
  width: 48px;
  flex-shrink: 0;
}

/* ---------- Gallery modal ---------------------------------------------- */

.modal-card-wide {
  max-width: 720px;
}
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  max-height: 60vh;
  overflow-y: auto;
  padding: 4px;
  margin-bottom: 12px;
}
/* Big detection-gallery modal — wide, with a normal scrollable grid + pager */
.gallery-card { max-width: none; width: 92vw; }
.gallery-card .gallery-grid {
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  max-height: 72vh;
  overflow-y: auto;
}
/* Day switcher = a top bar: [◀]  day label (fills center)  [▶], pinned while scrolling. */
.gallery-pager {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 12px;
  position: sticky; top: 0; z-index: 2;
  background: #14181f; padding: 4px 0 8px;
}
.gallery-day-nav { flex: none; padding: 8px 14px; font-size: 1rem; }
.gallery-day-nav:disabled { opacity: 0.3; }
.gallery-dayhead {
  flex: 1; min-width: 0; margin: 0; padding: 8px 10px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border); text-align: center;
  font-size: 0.9rem; font-weight: 600; color: var(--text); text-transform: capitalize;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.gallery-item {
  position: relative;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  transition: border-color .15s;
}
/* ▶ overlay for detections that have a 30s clip */
.gallery-play {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%);
  width: 46px; height: 46px; border-radius: 50%; padding-left: 3px;
  background: rgba(0, 0, 0, 0.55); border: 2px solid rgba(255, 255, 255, 0.85);
  color: #fff; font-size: 1.15rem; line-height: 1; cursor: pointer; z-index: 2;
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent; transition: background .15s, transform .1s;
}
.gallery-play:hover { background: rgba(0, 0, 0, 0.78); transform: translate(-50%, -50%) scale(1.08); }
/* Clip player fills the whole window (#clip-modal prefix beats the mobile
   .modal-card{width:96vw!important} rule via higher specificity). */
/* z-index above the lightbox (50) so the player opens IN FRONT when launched from
   a detail image (▶ Video) — both are .modal (z-index 50) and the lightbox comes
   later in the DOM, so without this the video would render behind it. */
#clip-modal { z-index: 90; padding: 0 !important; align-items: center; justify-content: center; overflow: hidden; }
#clip-modal .clip-card {
  width: 100vw !important; max-width: 100vw !important;
  height: 100dvh !important; max-height: 100dvh !important;
  margin: 0; padding: 0 !important; background: #000;
  border: 0; border-radius: 0; position: relative;
  display: flex; align-items: center; justify-content: center;
}
#clip-modal .clip-video {
  width: 100%; height: 100%; max-height: none;
  object-fit: contain; background: #000; border-radius: 0; display: block;
}
#clip-modal .modal-actions {
  position: absolute; top: max(10px, env(safe-area-inset-top)); right: 12px;
  margin: 0; z-index: 3; gap: 8px;
}
#clip-modal .modal-actions .btn {
  background: rgba(0, 0, 0, 0.55); border: 1px solid rgba(255, 255, 255, 0.35); color: #fff;
  backdrop-filter: blur(4px);
}

.gallery-actions {
  position: absolute; top: 6px; right: 6px;
  display: flex; gap: 6px; opacity: 0;
  transition: opacity .15s;
}
.gallery-item:hover .gallery-actions,
.gallery-item:focus-within .gallery-actions { opacity: 1; }
.gallery-act {
  width: 32px; height: 32px; border-radius: 8px; border: none; cursor: pointer;
  background: rgba(0, 0, 0, 0.62); color: #fff; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; font-size: 0.95rem;
}
.gallery-act:hover { background: rgba(0, 0, 0, 0.85); }
.gallery-act.del:hover { background: rgba(255, 107, 107, 0.9); }
.gallery-act.learn:hover { background: rgba(81, 207, 102, 0.9); }
.gallery-item:hover {
  border-color: var(--border-strong);
}
.gallery-item img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
}
.gallery-info {
  padding: 8px;
  font-size: 0.8rem;
  color: var(--muted);
}
.gallery-info strong {
  color: var(--text);
  display: block;
  margin-bottom: 2px;
}

/* ---------- Live-Pointer ------------------------------------------------- */

.pointer-glow {
  position: fixed;
  pointer-events: none;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: radial-gradient(circle, hsl(var(--glow-hue, 320) 90% 60% / 0.85) 0%, hsl(var(--glow-hue, 320) 90% 60% / 0.4) 35%, hsl(var(--glow-hue, 320) 90% 60% / 0) 70%);
  box-shadow: 0 0 30px 10px hsl(var(--glow-hue, 320) 90% 60% / 0.6);
  transform: translate(-50%, -50%) scale(0.4);
  opacity: 0;
  animation: pointer-pulse 2200ms ease-out forwards;
  z-index: 9999;
}
@keyframes pointer-pulse {
  0%   { opacity: 0;    transform: translate(-50%, -50%) scale(0.4); }
  15%  { opacity: 1;    transform: translate(-50%, -50%) scale(1.0); }
  50%  { opacity: 0.85; transform: translate(-50%, -50%) scale(1.2); }
  100% { opacity: 0;    transform: translate(-50%, -50%) scale(1.8); }
}
.pointer-glow .pointer-label {
  position: absolute;
  top: -28px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  padding: 2px 8px;
  border-radius: 8px;
  font-size: 0.75rem;
  white-space: nowrap;
}

/* ---------- Modell-Test -------------------------------------------------- */

.test-card { max-width: min(95vw, 1200px); }

.test-dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 32px 16px;
  text-align: center;
  cursor: pointer;
  color: var(--muted);
  transition: border-color .15s, background .15s;
  margin-bottom: 12px;
}
.test-dropzone:hover, .test-dropzone.drag {
  border-color: var(--success);
  background: rgba(107, 207, 107, 0.06);
}
.test-dropzone.busy {
  cursor: wait;
  opacity: 0.6;
}
.test-image-wrap {
  background: #000;
  border-radius: var(--radius-sm);
  max-height: 60vh;
  overflow: hidden;
  margin-bottom: 10px;
  display: flex;
  justify-content: center;
}
.test-image-wrap img {
  max-width: 100%;
  max-height: 60vh;
  object-fit: contain;
}
.test-controls {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

/* ---------- Lernbilder --------------------------------------------------- */

.training-card {
  max-width: min(95vw, 1400px);
}
.training-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
  margin-bottom: 10px;
}
.training-toolbar .modal-label {
  display: flex;
  flex-direction: column;
  font-size: 0.8rem;
  color: var(--muted);
}
.training-pager {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  font-size: 0.85rem;
}
.training-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
  max-height: 65vh;
  overflow-y: auto;
  padding: 4px;
  margin-bottom: 12px;
}
.tile-del {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .15s, background .15s;
  z-index: 3;
}
.train-tile:hover .tile-del,
.tile-del:focus-visible { opacity: 1; }
.tile-del:hover { background: rgba(255, 107, 107, 0.85); }
.train-tile {
  position: relative;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 1 / 1;
}
.train-tile.unannot  { border-color: #b04848; }
.train-tile.annot    { border-color: #4a8a4a; }
.train-tile.negative { border-color: #6a7a8c; }
.train-tile img {
  width: 100%;
  height: 100%;
  object-fit: contain;       /* show the FULL image so boxes can line up */
  display: block;
}
.train-tile .boxes {
  position: absolute;        /* JS sizes this to the contained image rect */
  pointer-events: none;
}
.train-tile .boxes div {
  position: absolute;
  border: 2px solid #65d265;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.4);
  border-radius: 2px;
}
.train-tile .boxes div.cls-0 { border-color: #65d265; }
.train-tile .boxes div.cls-1 { border-color: #65b6d2; }

/* Lightbox annotation overlay (training images) */
.lb-boxes { position: absolute; pointer-events: none; }
.lb-boxes div {
  position: absolute;
  border: 2px solid #65d265;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.5);
  border-radius: 2px;
}
.lb-boxes div.cls-0 { border-color: #65d265; }
.lb-boxes div.cls-1 { border-color: #65b6d2; }
.train-tile .badge {
  position: absolute;
  top: 4px; left: 4px;
  font-size: 0.65rem;
  padding: 1px 5px;
  border-radius: 8px;
  background: rgba(0,0,0,0.7);
  color: #fff;
}
.train-tile .badge.warn { background: rgba(176, 72, 72, 0.85); }
.train-tile .badge.negative { background: rgba(106, 122, 140, 0.85); }

/* ---------- KI-Status / Model -------------------------------------------- */

.model-body {
  max-height: 65vh;
  overflow-y: auto;
  margin-bottom: 12px;
  font-size: 0.9rem;
  line-height: 1.5;
}
.model-section {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 10px;
}
.model-section h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
  color: var(--text);
}
.model-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  column-gap: 12px;
  row-gap: 4px;
}
.model-grid dt {
  color: var(--muted);
  font-weight: normal;
}
.model-grid dd {
  margin: 0;
  color: var(--text);
}
.model-grid dd .pill {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 8px;
  font-size: 0.75rem;
  background: var(--surface-1);
  border: 1px solid var(--border);
  margin-right: 4px;
}
.model-grid dd.good { color: var(--success); }
.model-grid dd.warn { color: var(--warn); }
.model-grid dd.bad  { color: #e26a5b; }
.model-versions {
  font-size: 0.85rem;
}
.model-versions .row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  border-bottom: 1px dashed var(--border);
}
.model-versions .row:last-child { border-bottom: none; }
.model-versions .row.active { color: var(--text); font-weight: 600; }

/* ---------- Lightbox --------------------------------------------------- */

.lightbox-card {
  max-width: none;
  width: 98vw;
  height: 96vh;
  display: flex;
  flex-direction: column;
}
.lightbox-image-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #000;
  border-radius: var(--radius-sm);
  flex: 1;
  min-height: 0;
  overflow: hidden;
  margin-bottom: 8px;
}
.lightbox-image-wrap img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}
a.btn { text-decoration: none; }
.lightbox-info {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 12px;
  line-height: 1.5;
}
.lightbox-info strong {
  color: var(--text);
}
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 64px;
  border: none;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, opacity .15s;
  z-index: 2;
}
.lightbox-nav:hover { background: rgba(0, 0, 0, 0.7); }
.lightbox-nav:disabled { opacity: 0.25; cursor: default; }
.lightbox-prev { left: 8px; }
.lightbox-next { right: 8px; }
.lightbox-counter {
  position: absolute;
  top: 8px;
  right: 10px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  z-index: 2;
}

/* ---------- Annotation modal ------------------------------------------- */

.annotate-card {
  width: 100%;
  max-width: none;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
}
.annotate-container {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-bottom: 12px;
  background: #000;
}
.annotate-canvas {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 72vh;
  display: block;
  cursor: crosshair;
  touch-action: none;
}
.annotate-controls {
  margin-bottom: 12px;
}
.annotate-controls select {
  background: #0c0f14;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  width: 100%;
}

/* ---------- Card-head action group (icon-only ghost buttons) ------------ */
.card-actions { display: flex; gap: 4px; }
.btn-ghost.icon-only { padding: 3px 7px; }

/* ---------- Positions & patrol manager ---------------------------------- */
.ptzmgr-body { display: flex; flex-direction: column; gap: 18px; }
.ptzmgr-sec { display: flex; flex-direction: column; gap: 8px; }
.ptzmgr-h {
  margin: 0; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--muted);
}
.ptzmgr-list {
  display: flex; flex-direction: column; gap: 6px;
  max-height: 34vh; overflow-y: auto; scrollbar-width: thin;
}
.ptz-row {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 5px 8px;
}
.ptz-emoji { font-size: 1.1em; flex-shrink: 0; }
.ptz-num {
  flex-shrink: 0; width: 20px; height: 20px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--text);
  font-size: 0.72rem; font-weight: 700; font-variant-numeric: tabular-nums;
}
.ptz-name {
  flex: 1; min-width: 0; background: #0c0f14; color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 5px 8px; font: inherit; font-size: 0.85rem;
}
.ptz-name:focus { outline: none; border-color: var(--accent-border); }
.ptz-pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.85rem; }
.ptz-mini {
  display: inline-flex; align-items: center; gap: 4px; flex-shrink: 0;
  font-size: 0.72rem; color: var(--muted);
}
.ptz-mini input {
  width: 52px; background: #0c0f14; color: var(--text);
  border: 1px solid var(--border); border-radius: 7px;
  padding: 4px 6px; font: inherit; font-size: 0.8rem;
  font-variant-numeric: tabular-nums; text-align: right;
}
.iconbtn {
  appearance: none; flex-shrink: 0;
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  width: 30px; height: 30px; border-radius: 8px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.9rem; transition: background .12s, border-color .12s, transform .06s;
}
.iconbtn:hover:not(:disabled) { background: var(--surface-3); border-color: var(--border-strong); }
.iconbtn:active:not(:disabled) { transform: scale(0.92); }
.iconbtn:disabled { opacity: 0.35; cursor: default; }
.iconbtn.danger:hover:not(:disabled) { border-color: var(--danger-border); color: var(--danger); }
.ptzmgr-add { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ptzmgr-add input[type="text"] {
  flex: 1; min-width: 140px; background: #0c0f14; color: var(--text);
  border: 1px solid var(--border); border-radius: 9px;
  padding: 8px 11px; font: inherit; font-size: 0.9rem;
}
.ptzmgr-add input[type="text"]:focus { outline: none; border-color: var(--accent-border); }
.ptzmgr-slider { display: flex; align-items: center; gap: 10px; }
.ptzmgr-slider input[type="range"] { flex: 1; }
.ptzmgr-slider span { min-width: 28px; text-align: right; font-variant-numeric: tabular-nums; }

/* ======================================================================
   Mobile / touch / PWA   (iPhone usability + installable PWA + push bell)
   ====================================================================== */

/* Snappier taps: kill the 300ms delay, the grey flash, accidental selection. */
button, .btn, .icon-btn, .quality-btn, .more-btn, a.btn {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
/* Holding a steering button must never scroll/zoom the page. */
.dpad-btn, .zoom-btn, .focus-btn { touch-action: none; }

/* Notch / rounded-corner safe areas (we ship viewport-fit=cover). */
.overlay-top {
  padding-top: max(14px, env(safe-area-inset-top));
  padding-left: max(clamp(12px, 2.4vw, 24px), env(safe-area-inset-left));
  padding-right: max(clamp(12px, 2.4vw, 24px), env(safe-area-inset-right));
}

/* ---- 🔔 Push bell — public like ❄️ (shown for guests once JS un-hides it) ---- */
body.locked .topbar-right .notify-btn:not([hidden]) { display: inline-flex; }
/* The 🔒 must stay tappable while locked — otherwise there is no way to unlock
   on a touch device (no physical "L" key). */
body.locked .topbar-right .lock-btn { display: inline-flex; }
.notify-btn.on { background: var(--accent-soft); border-color: var(--accent-border); color: #cfe9ff; }
.notify-btn.busy { opacity: 0.5; pointer-events: none; }

/* ---- 🔔 Notification settings modal ---- */
.notify-body { display: flex; flex-direction: column; gap: 16px; }
.notify-status {
  display: flex; align-items: center; gap: 10px;
  font-size: 1rem; font-weight: 600;
  padding: 12px 14px; border-radius: 12px;
  background: rgba(255,255,255,0.05); border: 1px solid var(--border);
}
.notify-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--muted); flex: none;
  box-shadow: 0 0 0 4px rgba(255,255,255,0.06);
}
.notify-status.on .notify-dot { background: #51cf66; box-shadow: 0 0 0 4px rgba(81,207,102,0.18); }
.notify-status.off .notify-dot { background: #888; }
.notify-hint { color: var(--muted); font-weight: 400; font-size: 0.82rem; line-height: 1.45; margin: 0; }
.notify-events { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px 14px; margin: 0; }
.notify-events legend { font-size: 0.82rem; color: var(--muted); padding: 0 6px; }
.notify-events[disabled] { opacity: 0.45; pointer-events: none; }
.notify-event { display: flex; align-items: flex-start; gap: 12px; padding: 9px 0; cursor: pointer; }
.notify-event + .notify-event { border-top: 1px solid rgba(255,255,255,0.06); }
.notify-event input { width: 20px; height: 20px; margin-top: 2px; flex: none; accent-color: #4dabf7; }
.notify-event-txt { display: flex; flex-direction: column; gap: 2px; }
.notify-event-txt b { font-size: 0.95rem; font-weight: 600; }
.notify-event-txt small { color: var(--muted); font-size: 0.78rem; }
#notify-toggle.btn-warn { font-weight: 600; }
#notify-toggle.busy { opacity: 0.5; pointer-events: none; }
#notify-toggle:disabled { opacity: 0.4; pointer-events: none; }

/* ---- Overflow group: inline on desktop, ⋯ dropdown on phones ---- */
.more-wrap, .topbar-secondary { display: contents; }   /* desktop: flow inline as before */
.more-btn { display: none; }
/* Auto-hide must still fade the (display:contents) overflow buttons + ⋯ */
body.ui-hidden .topbar-secondary > *,
body.ui-hidden .more-btn { opacity: 0; }

@media (max-width: 768px) {
  :root { --ctrl: 40px; }                       /* touch targets (room for ☰ + ⋯ + lock) */

  .overlay-top { gap: 6px; padding-bottom: 10px; }
  .topbar-right { gap: 6px; }

  /* Title shrinks to just the 🦎 so the action bar fits. */
  .title .title-text { display: none; }       /* keep only 🦎 + ☰ on phones */
  .title { gap: 7px; }

  /* The desktop-only .topbar-left wrapper must NOT exist as a box on phones —
     display:contents hoists the title + (fixed) status badges back to direct
     children of .overlay-top, so the mobile flex layout is exactly as before. */
  .topbar-left { display: contents; }

  /* Compact training badge, centered just below the topbar (never overlapping). */
  .train-badge {
    top: max(64px, calc(env(safe-area-inset-top) + 60px));
    max-width: calc(100vw - 20px);
    font-size: 0.7rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }

  /* Viewer list: stack each row so a long rDNS wraps normally (was breaking
     one character per line in the narrow 3-column grid). */
  .viewer-row { grid-template-columns: 1fr; gap: 2px; }

  /* Collapse the secondary buttons into a dropdown under ⋯ */
  .more-wrap { display: inline-flex; position: relative; }
  .more-btn  { display: inline-flex; }
  body.locked .more-btn { display: none; }      /* a guest's menu would be empty */
  .topbar-secondary { display: none; }
  .more-wrap.open .more-btn { background: var(--surface-3); border-color: var(--border-strong); }
  /* Pinned to the viewport (not the narrow ⋯ button) so it can never be
     clipped: starts just below the topbar, capped to the real screen height
     incl. safe areas, scrolls internally if the list is taller than the phone. */
  .more-wrap.open .topbar-secondary {
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: fixed;
    top: calc(env(safe-area-inset-top) + 58px);
    right: max(8px, env(safe-area-inset-right));
    left: auto;
    width: min(80vw, 252px);
    padding: 8px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 70px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    z-index: 70;
  }
  /* While the ⋯ menu is open it owns the screen: hide the left control panel and
     the steering d-pad so the two can never overlap / fight for the same space. */
  body.menu-open .controls-panel,
  body.menu-open .steering { opacity: 0; pointer-events: none; }
  .more-wrap.open .topbar-secondary .icon-btn {
    width: 100%;
    height: 46px;
    justify-content: flex-start;
    gap: 12px;
    padding: 0 14px;
    border-radius: 10px;
    font-size: 1.05rem;
    backdrop-filter: none;
  }
  /* Spell out the action next to its icon (uses each button's aria-label). */
  .more-wrap.open .topbar-secondary .icon-btn::after {
    content: attr(aria-label);
    font-size: 0.92rem;
    font-weight: 500;
    letter-spacing: 0;
    text-transform: none;
    color: var(--text);
  }

  /* Modals: scrollable, fit the dynamic viewport (iOS browser chrome). */
  .modal { padding: 10px; overflow-y: auto; }

  /* Normal modals are vertically CENTERED and kept clear of the notch/home-
     indicator (safe-area padding) so the title never hides behind the iOS status
     bar (was top-pinned → title behind the clock). The card height is capped to
     the padded area, so centering never clips it. The lightbox / clip / annotate
     modals are full-screen and manage their own safe-area — excluded here. */
  .modal:not(#lightbox):not(#clip-modal):not(#annotate-modal) {
    --modal-pad-top: max(10px, env(safe-area-inset-top, 0px));
    --modal-pad-bottom: max(10px, env(safe-area-inset-bottom, 0px));
    padding: var(--modal-pad-top) 10px var(--modal-pad-bottom);
    align-items: center;
  }
  .modal-card:not(.lightbox-card):not(.clip-card):not(.annotate-card),
  .gallery-card,
  .test-card,
  .training-card {
    width: 96vw !important;
    max-width: 96vw !important;
    max-height: calc(100dvh - var(--modal-pad-top) - var(--modal-pad-bottom));
    margin: auto 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px 14px 14px;
  }
  .gallery-grid,
  .gallery-card .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); max-height: none; }

  /* Lernbilder: stacked toolbar, full-width selects, 2–3 column grid, no nested scroll. */
  .training-toolbar { gap: 8px; }
  .training-toolbar .modal-label { flex: 1 1 42%; }
  .training-toolbar .modal-select { width: 100%; }
  .training-pager { margin-left: 0; width: 100%; justify-content: center; }
  .training-grid { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); max-height: none; }

  /* Lightbox: truly full-screen on a phone. */
  .lightbox-card {
    width: 100vw !important;
    max-width: none !important;
    height: 100dvh !important;
    border-radius: 0;
    padding: 10px;
    padding-top: max(10px, env(safe-area-inset-top));
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }
  .lightbox-nav { width: 40px; height: 72px; font-size: 1.8rem; }

  /* Action rows wrap and grow into thumb-sized buttons. */
  .modal-actions { flex-wrap: wrap; gap: 8px; }
  .modal-actions .btn,
  .modal-actions a.btn { flex: 1 1 auto; justify-content: center; min-height: 44px; }

  /* Left control panel = a slide-in drawer on mobile. Hidden by default so it
     never covers the video while you operate; the ☰ button toggles it, and it
     no longer re-appears on its own when you touch the screen. */
  .controls-panel {
    top: max(104px, calc(env(safe-area-inset-top) + 96px));
    width: clamp(180px, 62vw, 240px);
    max-height: calc(100dvh - 190px);
    transform: translateX(-115%);
    opacity: 0;
    pointer-events: none;
  }
  body.controls-open .controls-panel { transform: translateX(0); opacity: 1; pointer-events: auto; }
  .preset-list { max-height: 38vh; }
  .preset-list .btn { min-height: 40px; }

  /* ☰ drawer toggle — only on mobile, only when unlocked. */
  body.unlocked .controls-toggle { display: inline-flex; }

  /* The CPU/GPU/Traffic stats overlay sits top-left — exactly where the control
     panel lives on a phone. No room side-by-side, so hide it here (kept on
     desktop). Available on the phone via the 🧠 KI-Status modal instead. */
  .sys-stats { display: none !important; }

  /* Let the "65 Pos. · 30 Neg." counter wrap instead of overlapping the title. */
  .controls-panel .card-head { flex-wrap: wrap; gap: 2px 8px; }

  /* Steering: bigger d-pad, lifted above the iOS home indicator. */
  .steering {
    right: max(12px, env(safe-area-inset-right));
    bottom: max(16px, calc(env(safe-area-inset-bottom) + 12px));
  }
  .dpad { grid-template-columns: repeat(3, 50px); grid-template-rows: repeat(3, 50px); }
  .dpad-btn { font-size: 1.05rem; }
  .zoom-btn { min-height: 44px; }
}

/* Very narrow phones: tighten the action bar even more. */
@media (max-width: 380px) {
  :root { --ctrl: 40px; }
  .topbar-right { gap: 4px; }
  .controls-panel { width: clamp(140px, 46vw, 172px); }
}

/* Landscape phones: don't let the panels eat the (short) height. */
@media (max-height: 480px) and (orientation: landscape) {
  .controls-panel { top: 56px; transform: none; max-height: calc(100dvh - 70px); }
  .preset-list { max-height: 26vh; }
}

/* ---------- Model review & release (KI-Status → Versionen) -------------- */
.train-badge.done { pointer-events: auto; cursor: pointer; }
.ver-card {
  padding: 9px 11px; border-radius: 10px; margin-bottom: 7px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.ver-card.active { border-color: var(--success); background: rgba(81, 207, 102, 0.10); }
.ver-head { display: flex; align-items: center; gap: 10px; }
.ver-head strong { font-size: 0.95rem; }
.ver-date { color: var(--muted); font-size: 0.78rem; }
.ver-action { margin-left: auto; }
.ver-action .btn { padding: 4px 12px; font-size: 0.8rem; min-height: 0; }
.ver-metrics { font-size: 0.82rem; margin-top: 4px; font-variant-numeric: tabular-nums; }
.ver-metrics b.good { color: var(--success); }
.ver-metrics b.warn { color: var(--warn); }
.ver-metrics b.bad  { color: #e26a5b; }
.ver-delta { display: inline-block; margin-top: 4px; font-size: 0.78rem; font-weight: 600; }
.ver-delta.good { color: var(--success); }
.ver-delta.bad  { color: #e26a5b; }
.ver-data { margin-top: 3px; font-size: 0.75rem; }
.ver-action .btn + .btn { margin-left: 6px; }

/* ---------- Activity dashboard (📊) ---------- */
.stats-body { display: flex; flex-direction: column; gap: 18px; }
.stat-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat-kpis .kpi { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 6px; text-align: center; }
.stat-kpis .kpi-val { font-size: 1.05rem; font-weight: 700; color: var(--text); }
.stat-kpis .kpi-lbl { font-size: 0.66rem; opacity: 0.6; margin-top: 3px; }
.stat-section h3 { font-size: 0.82rem; margin: 0 0 10px; opacity: 0.85; }
.bar-chart { display: flex; align-items: flex-end; gap: 3px; height: 130px; }
.bar-col { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.bar-col .bar { width: 72%; max-width: 24px; background: var(--accent-border); border-radius: 3px 3px 0 0; transform-origin: bottom; animation: barGrow .45s cubic-bezier(.2,.8,.2,1) both; }
@keyframes barGrow { from { transform: scaleY(0); } to { transform: scaleY(1); } }
.bar-col.peak .bar { background: var(--danger); }
.bar-col .bar-val { font-size: 0.6rem; opacity: 0.7; height: 13px; line-height: 13px; }
.bar-col .bar-lbl { font-size: 0.56rem; opacity: 0.55; margin-top: 4px; white-space: nowrap; }
.stat-foot { font-size: 0.72rem; opacity: 0.7; }
.placeholder.small { font-size: 0.78rem; padding: 12px 4px; opacity: 0.75; }
/* Today timeline: a marker per sighting on a 0–24h axis. */
.timeline { position: relative; height: 26px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.timeline .tl-mark { position: absolute; top: 3px; bottom: 3px; width: 2px; margin-left: -1px; background: var(--accent-border); border-radius: 1px; opacity: 0.8; animation: fade .4s ease both; }
.timeline .tl-empty { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); font-size: 0.72rem; opacity: 0.5; }
.tl-axis { position: relative; height: 14px; margin-top: 3px; }
.tl-axis .tl-tick { position: absolute; transform: translateX(-50%); font-size: 0.6rem; opacity: 0.5; }
.tl-axis .tl-tick::after { content: ' Uhr'; }
@media (max-width: 768px) {
  .stat-kpis { grid-template-columns: repeat(2, 1fr); }
  .bar-chart { height: 104px; }
  .tl-axis .tl-tick::after { content: ''; }
}

/* ---------- Gallery training-status markers + negative learning -------- */
.gallery-mark {
  position: absolute; left: 6px; top: 6px; z-index: 1;
  font-size: 0.66rem; font-weight: 700; padding: 2px 7px; border-radius: 8px;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  pointer-events: none; white-space: nowrap;
}
.gallery-mark.positive { background: rgba(34, 90, 50, 0.85); color: #d7ffd7; border: 1px solid var(--success); }
.gallery-mark.negative { background: rgba(120, 72, 20, 0.85); color: #ffe6c2; border: 1px solid var(--warn); }
.gallery-act.neg:hover { background: rgba(230, 150, 40, 0.9); }
.btn-warn { border-color: rgba(230, 160, 60, 0.5); color: #ffcf99; }
.btn-warn:hover { border-color: var(--warn); background: rgba(230, 160, 60, 0.14); }
.train-tag { font-weight: 600; font-size: 0.82rem; }
.train-tag.pos { color: var(--success); }
.train-tag.neg { color: var(--warn); }

/* ---------- Lightbox zoom/pan (wheel + pinch + drag) ------------------- */
/* We handle the gestures in JS; stop the browser from scrolling/zooming here. */
.lightbox-image-wrap { touch-action: none; }
.lightbox-image-wrap.zoomed { cursor: grab; }
#lightbox-img { transition: none; }

/* Live video: let our pinch/drag-zoom handlers receive the touches. */
#video { touch-action: none; }

/* ☰ drawer toggle — lives in the topbar title (mobile only, when unlocked). */
.controls-toggle {
  display: none;
  width: var(--ctrl); height: var(--ctrl); border-radius: 10px;
  align-items: center; justify-content: center;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); font-size: 1.05rem; cursor: pointer;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  flex: none;
}
body.controls-open .controls-toggle { background: var(--accent-soft); border-color: var(--accent-border); }

/* Touch devices have no hover → reveal the per-tile / per-card action buttons
   permanently (gallery download/learn/neg/delete, Lernbilder delete). */
@media (hover: none) {
  .gallery-actions { opacity: 1; }
  .tile-del { opacity: 0.92; }
  /* Bigger tap targets on touch (where these are always visible). The action
     row wraps to 2×2 so four 40px buttons never overflow a small thumbnail. */
  .gallery-actions { flex-wrap: wrap; justify-content: flex-end; max-width: 92px; gap: 5px; }
  .gallery-act { width: 40px; height: 40px; font-size: 1.05rem; }
  .tile-del { width: 38px; height: 38px; }
}
.yt-link { text-decoration: none; gap: 6px; margin-top: 4px; }

/* ====================================================================
   Mobile bottom navigation — Live · Galerie · KI · Steuern · Mehr.
   Live-first: the video stays clean; PTZ lives under "Steuern".
   ==================================================================== */
.bottomnav { display: none; }

@media (max-width: 768px) {
  /* The bottom nav replaces the topbar ☰/🎮/⋯ buttons. */
  .controls-toggle { display: none !important; }
  .steering-toggle { display: none !important; }
  .more-btn { display: none !important; }

  body.unlocked .bottomnav {
    display: flex;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
    justify-content: space-around; align-items: stretch;
    padding: 5px 4px calc(env(safe-area-inset-bottom) + 5px);
    background: rgba(10, 12, 18, 0.94);
    border-top: 1px solid var(--border);
    backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  }
  /* While a modal/sheet is open, hide the nav (close it to return). */
  body:has(.modal:not([hidden])) .bottomnav { display: none; }

  .bn-btn {
    flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; padding: 4px 2px; min-height: 46px;
    background: none; border: none; color: var(--muted); cursor: pointer; font: inherit;
    -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  }
  .bn-ic { font-size: 1.3rem; line-height: 1; }
  .bn-lb { font-size: 0.62rem; font-weight: 600; }
  .bn-btn.active { color: var(--text); }
  .bn-btn.active .bn-lb { color: var(--accent); }

  /* Independent tabs: "Menü" → controls-open (left panel), "Steuern" →
     steering-open (right d-pad). */
  body.unlocked #steering { display: none; }
  body.unlocked.steering-open #steering { display: block; }
  #steering { bottom: calc(env(safe-area-inset-bottom) + 74px); }   /* clear the nav */

  /* "Mehr" tab → the ⋯ menu, restyled as a bottom sheet above the nav. */
  .more-wrap.open .topbar-secondary {
    top: auto;
    bottom: calc(env(safe-area-inset-bottom) + 58px);
    left: 8px; right: 8px; width: auto;
    max-height: 56dvh;
    border-radius: 16px;
    animation: sheet-up .22s ease;
  }
  @keyframes sheet-up {
    from { transform: translateY(14px); opacity: 0; }
    to   { transform: none; opacity: 1; }
  }
  /* CONTAINING-BLOCK-FALLE: backdrop-filter auf .overlay-top (Docked-Toolbar-
     Look unten) macht die Topbar zum Containing Block für position:fixed-
     Nachfahren — und das ⋯-Sheet liegt im DOM IN der Topbar. Seine bottom:-
     Koordinate wirkte dadurch relativ zur ~56px-Bar statt zum Viewport → das
     Sheet wurde über den oberen Bildschirmrand hinausgeschoben ("klebt oben,
     unsichtbar"). Solange das Sheet offen ist, den Filter abschalten → fixed
     bezieht sich wieder aufs echte Viewport. Der 0.85-Hintergrund bleibt. */
  body.menu-open .overlay-top {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  /* Offenes Sheet ist IMMER voll sichtbar — auch bei auto-versteckter UI
     (ui-hidden setzt die Buttons sonst auf opacity 0 → "leeres" Menü). */
  body.ui-hidden .more-wrap.open .topbar-secondary > * { opacity: 1; }

  /* Pin the action row (Schliessen etc.) to the bottom of scrollable modals so
     it's ALWAYS reachable — a long gallery used to bury it off-screen, and in a
     Safari tab the bottom toolbar hid it. (Lightbox/annotate use a flex layout
     where the footer is already pinned, so they're excluded.) */
  .modal-card:not(.lightbox-card):not(.annotate-card):not(.clip-card) .modal-actions {
    position: sticky;
    bottom: 0;
    margin: 8px -14px -14px;
    padding: 10px 14px calc(env(safe-area-inset-bottom) + 10px);
    background: #14181f;
    border-top: 1px solid var(--border);
    z-index: 2;
  }
}

/* ======================================================================
   Handy-HOCHFORMAT: Kamera-App-Layout (Reolink/UniFi-Muster).
   Im Portrait ist das 16:9-Video nur ein schmaler Streifen in der MITTE —
   die alte schwebende Steuerung lag genau darüber und verdeckte das Bild,
   während oben/unten riesige schwarze Flächen leer blieben. Neu: sobald
   Steuern ODER Menü offen ist, dockt das Video OBEN unter der Topbar an
   (object-position verschiebt den Inhalt im contain-Letterbox), und die
   Bedienung füllt als Deck den freien Bereich darunter. Nichts überlappt
   mehr das Bild. Querformat = Vollbild mit Overlays, wie gehabt.
   ====================================================================== */
@media (max-width: 768px) and (orientation: portrait) {
  :root { --video-dock-top: calc(env(safe-area-inset-top, 0px) + 64px); }

  /* Video oben andocken, solange ein Bedien-Deck offen ist. */
  body.steering-open .bg-video,
  body.controls-open .bg-video {
    object-position: 50% var(--video-dock-top);
  }

  /* --- Steuern: volles Deck unter dem Video ---------------------------- */
  body.unlocked.steering-open #steering { display: grid; }
  body.steering-open #steering {
    left: 10px; right: 10px;
    top: calc(var(--video-dock-top) + 56.25vw + 10px);   /* 16:9-Videohöhe */
    bottom: calc(env(safe-area-inset-bottom, 0px) + 96px); /* über Info-Bar + Nav */
    grid-template-columns: auto 1fr;
    grid-template-areas: "dpad zoom" "dpad focus" "speed speed";
    gap: 8px;
    align-content: start;
    overflow-y: auto;
  }
  body.steering-open .dpad      { grid-area: dpad; align-self: start; }
  body.steering-open .zoom-row  { grid-area: zoom;  display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  body.steering-open .focus-row { grid-area: focus; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  body.steering-open .speed-row { grid-area: speed; }
  body.steering-open .zoom-btn,
  body.steering-open .focus-btn { min-height: 48px; }

  /* Das offene Deck liegt NEBEN dem Video, nicht darauf — Auto-Hide der UI
     darf es deshalb nicht ausblenden. */
  body.ui-hidden.steering-open #steering { opacity: 1; pointer-events: auto; }

  /* --- Menü: Presets & Co. als volle Fläche unter dem Video ------------ */
  body.controls-open .controls-panel {
    left: 10px; right: 10px; width: auto;
    top: calc(var(--video-dock-top) + 56.25vw + 10px);
    transform: none;
    max-height: calc(100dvh - var(--video-dock-top) - 56.25vw - env(safe-area-inset-bottom, 0px) - 110px);
  }
  /* Presets zweispaltig — wie Positions-Kacheln in Kamera-Apps. */
  body.controls-open .preset-list {
    display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
    max-height: none;
  }
  body.controls-open .preset-list .btn { min-height: 46px; }
  body.ui-hidden.controls-open .controls-panel { opacity: 1; pointer-events: auto; }
}

/* Respect users who ask for less motion (iOS: Einstellungen → Bedienungshilfen →
   Bewegung reduzieren). Near-instant animations/transitions instead of pulsing,
   sweeping, popping. Liveness still reads via colour, just without the pulse. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ======================================================================
   Desktop top-bar — full-width docked toolbar  (kept LAST so it wins
   source-order over the safe-area padding override above).
   One bar flush to the very top, spanning the full width (the bottom
   telemetry .info-bar, mirrored up top). It carries everything: title +
   CPU/GPU + training status on the left, and the action icons on the right
   that EXPAND on hover to reveal their name. Always visible (opted out of the
   auto-hide fade) so it reads as a real docked toolbar.
   Mobile (≤768px) is deliberately untouched — there the secondary icons live
   in the ⋯ bottom-sheet + bottom-nav, which is already a modern layout.
   ====================================================================== */
@media (min-width: 769px) {
  .overlay-top {
    top: 0; left: 0; right: 0;
    height: 50px;
    padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
    gap: 16px;
    background: rgba(12, 14, 20, 0.82);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.10);
  }

  /* Left group: title + status info; shrinks/ellipsises first when space is tight. */
  .topbar-left {
    display: flex; align-items: center; gap: 16px;
    min-width: 0; flex: 1 1 auto; overflow: hidden;
  }
  .topbar-left .title { flex: none; }

  /* Pull the CPU/GPU + training status INTO the bar — they are position:fixed
     floating overlays by default; here they flow inline. (Mobile keeps fixed.) */
  .overlay-top .sys-stats,
  .overlay-top .train-badge {
    position: static; transform: none; top: auto; left: auto; right: auto;
    margin: 0; z-index: auto; pointer-events: auto;
  }
  .overlay-top .sys-stats {
    flex-direction: row; align-items: center; gap: 14px;
    padding: 0; background: none; border: none;
    backdrop-filter: none; -webkit-backdrop-filter: none;
    font-size: 0.74rem; color: #d6dae6;
    min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  }
  .overlay-top .sys-stats .ss-row { display: inline-flex; align-items: center; gap: 4px; flex: none; }
  .overlay-top .train-badge {
    flex: none; max-width: 40vw; border-radius: 8px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }

  /* Flatten the remaining pills (viewers + LIVE) so the bar reads as a square
     toolbar, not a row of round lozenges. */
  .topbar-right > .viewers,
  .topbar-right > .quality-btn { border-radius: 8px; }

  /* Right group: the action cluster sits flush in the bar (no separate pill). */
  .topbar-right {
    flex: none; gap: 2px; padding: 0;
    background: none; border: none; border-radius: 0;
    backdrop-filter: none; -webkit-backdrop-filter: none; overflow: visible;
  }

  /* Every action icon: borderless, and it EXPANDS on hover to reveal its name
     (from the button's aria-label). The emoji stays put and the label grows to
     its right, so the cursor never slides off the icon. NO overflow:hidden on
     the button itself — the detect-count badge sits outside it; the label clips
     via its own max-width:0. */
  .topbar-right > .icon-btn,
  .topbar-right .topbar-secondary > .icon-btn {
    width: auto; min-width: var(--ctrl); padding: 0 9px;
    background: transparent; border: none; border-radius: 6px;
    backdrop-filter: none; -webkit-backdrop-filter: none;
  }
  .topbar-right > .icon-btn::after,
  .topbar-right .topbar-secondary > .icon-btn::after {
    content: attr(aria-label);
    max-width: 0; opacity: 0; overflow: hidden; white-space: nowrap;
    font-size: 0.8rem; font-weight: 500; letter-spacing: 0; text-transform: none;
    transition: max-width .25s ease, opacity .2s ease, margin-left .25s ease;
  }
  .topbar-right > .icon-btn:hover,
  .topbar-right .topbar-secondary > .icon-btn:hover {
    background: rgba(255, 255, 255, 0.10);
  }
  .topbar-right > .icon-btn:hover::after,
  .topbar-right .topbar-secondary > .icon-btn:hover::after {
    max-width: 220px; opacity: 1; margin-left: 8px;
  }
  /* Keep the active-state accents (the flatten above would otherwise clobber). */
  .topbar-right > .notify-btn.on           { background: var(--accent-soft); }
  body.unlocked .topbar-right > .lock-btn  { background: var(--accent-soft); }

  /* Docked = always visible: opt the bar out of the auto-hide fade. */
  body.ui-hidden .overlay-top { pointer-events: auto; }
  body.ui-hidden .overlay-top .title { opacity: 1; transform: none; }
  body.ui-hidden .overlay-top .topbar-right > :not(.viewers),
  body.ui-hidden .overlay-top .topbar-secondary > *,
  body.ui-hidden .overlay-top .sys-stats,
  body.ui-hidden .overlay-top .train-badge { opacity: 1; }
}

/* Pull-tab handle: hidden by default (shown on desktop when unlocked). */
.controls-handle { display: none; }

/* ======================================================================
   Desktop: left control panel (Patrouille · Positionen · Trainingsdaten)
   as a FULL-HEIGHT slide-in drawer — toggled by the ☰ button in the title,
   slides in from the left, default hidden so the video stays clean. Mirrors
   the mobile drawer behaviour. (Kept last so it wins over the base
   .controls-panel + .overlay rules.)
   ====================================================================== */
@media (min-width: 769px) {
  /* ☰ in der Titelzeile entfällt als Drawer-Trigger — der Pfeil-Tab links ersetzt ihn. */
  body.unlocked .controls-toggle { display: none; }

  /* 🎮 hides/shows the right d-pad. Default visible; .steering-off hides it. */
  body.steering-off #steering { display: none; }
  body.steering-off .steering-toggle { opacity: 0.55; }

  body { --drawer-w: clamp(208px, 18vw, 248px); }   /* drawer width = handle's open offset */

  .controls-panel {
    top: 0; left: 0;
    width: var(--drawer-w);
    height: 100dvh; max-height: none;
    margin: 0; border-radius: 0;
    border: none; border-right: 1px solid var(--border);
    padding: 60px 13px calc(env(safe-area-inset-bottom, 0px) + 18px) 34px;  /* left pad clears the edge tab */
    transform: translateX(-100%);   /* parked off the left edge by default */
    opacity: 1; pointer-events: none;
    overflow: hidden;               /* no whole-panel scrollbar — only the list scrolls */
    transition: transform .28s ease;
    z-index: 9;                      /* below the docked top bar (overlay z:10) */
  }
  /* Open when pinned (click) OR while hovering the handle / the panel itself —
     hover-to-open in addition to click. The handle stays put during hover so the
     cursor never loses it (no flicker); once the cursor moves onto the panel it
     sustains the open state. Leaving both closes it (unless pinned via click). */
  body.controls-open .controls-panel,
  body.unlocked.controls-hover .controls-panel {
    transform: translateX(0);
    pointer-events: auto;
  }

  /* Use the full height: the Positionen list flexes to fill the panel and
     scrolls internally only if there are more presets than fit — instead of the
     whole panel getting a scrollbar. Patrouille/Trainingsdaten keep their size. */
  .controls-panel .ctrl-section:has(.preset-list) { flex: 1 1 auto; min-height: 0; }
  .controls-panel .ctrl-section:has(.preset-list) .preset-list { flex: 1 1 auto; max-height: none; }

  /* Auto-hide must not fight the drawer — keep it parked unless explicitly open. */
  body.ui-hidden .controls-panel            { transform: translateX(-100%); opacity: 1; }
  body.ui-hidden.controls-open .controls-panel { transform: translateX(0); }

  /* Pull-tab on the left edge: half-visible handle, vertically centred. Slides to
     the drawer's right edge when open; the chevron flips. Replaces the ☰. */
  body.unlocked .controls-handle {
    display: flex; align-items: center; justify-content: center;
    position: fixed; top: 50%; left: 0; transform: translateY(-50%);
    width: 26px; height: 60px;
    border: 1px solid var(--border); border-left: none; border-radius: 0 12px 12px 0;
    background: rgba(18, 21, 29, 0.80);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    color: var(--text); cursor: pointer; z-index: 31; opacity: 0.7;
    transition: left .28s ease, opacity .15s ease, background .15s ease;
  }
  body.unlocked .controls-handle:hover { opacity: 1; background: var(--surface-2); }
  /* Tab stays at the left edge in all states (so hover never loses the cursor);
     the chevron flips to signal open — via pin (click) or hover. */
  .controls-handle .chev { font-size: 1.6rem; line-height: 1; transition: transform .28s ease; }
  body.controls-open .controls-handle .chev,
  body.unlocked.controls-hover .controls-handle .chev { transform: rotate(180deg); }
}

/* ======================================================================
   Mobile (≤768px): bring the SAME flat, docked toolbar look to phones.
   The desktop redesign above was min-width:769 only, so phones still showed
   the old round boxes. Touch has no hover, so there's no label-expand here —
   just the flat buttons in a docked, full-width top strip.
   ====================================================================== */
@media (max-width: 768px) {
  /* Docked, full-width top strip (mirrors the bottom info-bar, up top). */
  .overlay-top {
    background: rgba(12, 14, 20, 0.85);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.10);
  }

  /* Flatten the visible top-bar controls: no more separate round boxes — they
     sit flat on the bar (direct children only, so the ⋯ bottom-sheet icons keep
     their own list styling). */
  .topbar-right > .icon-btn,
  .topbar-right > .quality-btn,
  .topbar-right > .viewers {
    background: transparent; border: none; border-radius: 8px;
    backdrop-filter: none; -webkit-backdrop-filter: none;
  }
  .topbar-right > .icon-btn:active { background: rgba(255, 255, 255, 0.16); }

  /* Keep the state accents (the flatten above would otherwise clobber them). */
  .topbar-right > .quality-btn.on          { background: var(--success); color: #000; }
  .topbar-right > .notify-btn.on           { background: var(--accent-soft); }
  body.unlocked .topbar-right > .lock-btn  { background: var(--accent-soft); }

  /* Training status: flat chip instead of a round pill. */
  .train-badge { border-radius: 8px; }
}
