/* PrimeCam – gemeinsames Stylesheet für Betrachter und Admin */
/* Hell ist Standard. Dunkel per data-theme="dark", oder "system" = wie das Betriebssystem. */
:root {
  --bg: #f4f6f8;
  --bg-2: #ffffff;
  --bg-3: #eceff3;
  --line: #d5dbe1;
  --text: #1c2128;
  --muted: #5b6672;
  --accent: #0b6bcb;
  --accent-2: #2a86e0;
  --ok: #1a7f37;
  --warn: #9a6700;
  --err: #cf222e;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(31, 35, 40, .10);
  --topbar: rgba(255, 255, 255, .85);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0d1117; --bg-2: #161b22; --bg-3: #21262d; --line: #30363d;
  --text: #e6edf3; --muted: #8b949e; --accent: #4fa3ff; --accent-2: #7cc4ff;
  --ok: #3fb950; --warn: #d29922; --err: #f85149;
  --shadow: 0 8px 30px rgba(0, 0, 0, .35); --topbar: rgba(22, 27, 34, .85);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --bg: #0d1117; --bg-2: #161b22; --bg-3: #21262d; --line: #30363d;
    --text: #e6edf3; --muted: #8b949e; --accent: #4fa3ff; --accent-2: #7cc4ff;
    --ok: #3fb950; --warn: #d29922; --err: #f85149;
    --shadow: 0 8px 30px rgba(0, 0, 0, .35); --topbar: rgba(22, 27, 34, .85);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-2); }
img { max-width: 100%; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
code, pre { font-family: var(--mono); font-size: .88em; }
pre { background: var(--bg-3); padding: 12px; border-radius: 8px; overflow-x: auto; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.hidden { display: none !important; }

/* Kopfzeile */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px; background: var(--topbar);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 10px; color: var(--text); font-weight: 700; font-size: 1.1rem; }
.brand small { color: var(--muted); font-weight: 400; font-size: .85rem; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); align-self: center; }
.topbar nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.topbar nav a { color: var(--muted); padding: 6px 12px; border-radius: 8px; }
.topbar nav a:hover, .topbar nav a.active { color: var(--text); background: var(--bg-3); }
.theme-toggle { margin-left: 4px; background: none; border: 1px solid var(--line); color: var(--text); border-radius: 8px; width: 34px; height: 34px; cursor: pointer; font-size: 1rem; line-height: 1; }
.theme-toggle:hover { border-color: var(--accent); }

.wrap { max-width: 1400px; margin: 0 auto; padding: 24px 20px 60px; }
.wrap.narrow { max-width: 900px; }
footer.foot { color: var(--muted); text-align: center; font-size: .85rem; padding: 30px 20px; }

/* Buttons & Formulare */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg-3); color: var(--text); font: inherit; cursor: pointer;
  transition: background .15s, border-color .15s; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--text); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--err); }
.btn.danger:hover { border-color: var(--err); }
.btn.sm { padding: 4px 10px; font-size: .85rem; }
.btn.icon { padding: 7px 9px; }
.btn[disabled] { opacity: .45; cursor: default; }
.btn.on { background: color-mix(in srgb, var(--accent) 25%, var(--bg-3)); border-color: var(--accent); }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); border-color: var(--accent); }
input[type=checkbox] { width: auto; accent-color: var(--accent); transform: scale(1.15); }
textarea { min-height: 120px; font-family: var(--mono); font-size: .9em; }
label { display: block; font-weight: 500; margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.field .help { color: var(--muted); font-size: .82rem; margin-top: 3px; }
.field.check { display: flex; gap: 10px; align-items: flex-start; }
.field.check label { margin: 0; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0 20px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }

/* Karten */
.card { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 20px; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 20px; }

.flash { padding: 10px 16px; border-radius: 10px; margin-bottom: 18px; border: 1px solid; }
.flash.ok { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.flash.warn { border-color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent); }
.flash.error { border-color: var(--err); background: color-mix(in srgb, var(--err) 12%, transparent); }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: .78rem; background: var(--bg-3); border: 1px solid var(--line); white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.badge.ok::before { background: var(--ok); } .badge.warn::before { background: var(--warn); } .badge.err::before { background: var(--err); }
.badge.plain::before { display: none; }

table.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { color: var(--muted); font-weight: 500; font-size: .85rem; }
.tbl tr:hover td { background: color-mix(in srgb, var(--bg-3) 50%, transparent); }
.tbl-wrap { overflow-x: auto; }

.meter { height: 8px; background: var(--bg-3); border-radius: 99px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.meter.warn > i { background: var(--warn); } .meter.err > i { background: var(--err); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; }
.tabs a { padding: 10px 16px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--text); border-color: var(--accent); }

.log { font-family: var(--mono); font-size: .8rem; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px; height: 420px; overflow-y: auto; }
.log div { white-space: pre-wrap; word-break: break-all; padding: 1px 0; }
.log .f-error { color: var(--err); } .log .f-command, .log .f-command-exec { color: var(--accent); }
.log .f-response { color: var(--ok); } .log .f-storage, .log .f-timelapse { color: var(--warn); }
.log time { color: var(--muted); margin-right: 8px; }

/* ---------------- Übersicht ---------------- */
.hero { padding: 10px 0 20px; }
.cam-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 22px; }
.cam-card { position: relative; display: block; border-radius: var(--radius); overflow: hidden; background: var(--bg-2); border: 1px solid var(--line); color: var(--text); transition: transform .2s, box-shadow .2s; }
.cam-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); color: var(--text); }
.cam-card .img { aspect-ratio: 16/9; background: var(--bg-3) center/cover no-repeat; }
.cam-card .img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-card .meta { padding: 12px 14px; display: flex; gap: 10px; align-items: center; }
.cam-card .meta b { font-weight: 600; }
.cam-card .meta .muted { font-size: .85rem; }
.cam-card .temp { position: absolute; top: 10px; right: 10px; background: rgba(0,0,0,.55); color: #fff; padding: 3px 10px; border-radius: 99px; font-size: .85rem; backdrop-filter: blur(4px); }
.cam-card.stale .img { filter: grayscale(.8) brightness(.7); }

/* ---------------- Betrachter ---------------- */
.viewer { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; }
@media (max-width: 1100px) { .viewer { grid-template-columns: 1fr; } }
.stage { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 16/9; user-select: none; }
.stage img.layer { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; opacity: 0; transition: opacity var(--fade, .5s) ease; }
.stage img.layer.show { opacity: 1; }
.stage .spinner { position: absolute; top: 14px; right: 14px; width: 22px; height: 22px; border: 3px solid rgba(255,255,255,.25); border-top-color: #fff; border-radius: 50%; animation: spin 1s linear infinite; z-index: 5; display: none; }
.stage.loading .spinner { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }
.stage .nav-zone { position: absolute; top: 0; bottom: 0; width: 18%; z-index: 4; cursor: pointer; display: flex; align-items: center; opacity: 0; transition: opacity .2s; }
.stage:hover .nav-zone { opacity: 1; }
.stage .nav-zone.l { left: 0; justify-content: flex-start; background: linear-gradient(90deg, rgba(0,0,0,.35), transparent); }
.stage .nav-zone.r { right: 0; justify-content: flex-end; background: linear-gradient(-90deg, rgba(0,0,0,.35), transparent); }
.stage .nav-zone span { color: #fff; font-size: 2.4rem; padding: 0 14px; text-shadow: 0 2px 8px #000; }
.stage .badge-ts { position: absolute; left: 12px; bottom: 12px; z-index: 6; background: rgba(0,0,0,.6); color: #fff; padding: 4px 12px; border-radius: 99px; font-size: .9rem; backdrop-filter: blur(4px); }
.stage .errmsg { position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); z-index: 7; background: rgba(0,0,0,.75); color: #fff; padding: 14px 20px; border-radius: 10px; text-align: center; max-width: 80%; }
.stage .progress { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--accent); z-index: 6; transition: width .1s linear; }
.stage .labels { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.stage .labels a, .stage .labels span { position: absolute; transform: translate(-50%, -100%); pointer-events: auto; color: #fff; font-size: .78rem; background: rgba(0,0,0,.55); padding: 2px 8px; border-radius: 6px; white-space: nowrap; }
.stage .labels a::after, .stage .labels span::after { content: ""; position: absolute; left: 50%; top: 100%; width: 1px; height: 14px; background: rgba(255,255,255,.7); }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 12px 0; }
.toolbar .group { display: flex; gap: 4px; }
.toolbar .sep { width: 1px; height: 26px; background: var(--line); margin: 0 4px; }

.cal { display: grid; gap: 8px; margin: 10px 0; }
.cal .line { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.cal .line > span.lbl { width: 54px; color: var(--muted); font-size: .8rem; }
.chip { padding: 3px 9px; border-radius: 7px; background: var(--bg-3); border: 1px solid transparent; color: var(--text); font-size: .82rem; cursor: pointer; font-variant-numeric: tabular-nums; }
.chip:hover { border-color: var(--accent); }
.chip.act { background: var(--accent); color: #fff; }

.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.thumbs a { position: relative; display: block; border-radius: 8px; overflow: hidden; aspect-ratio: 16/9; background: var(--bg-3); }
.thumbs img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .2s; }
.thumbs a:hover img { transform: scale(1.05); }
.thumbs a span { position: absolute; left: 6px; bottom: 5px; color: #fff; font-size: .75rem; text-shadow: 0 1px 3px #000; }

.side .card { padding: 14px 16px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: .9rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.panel-tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.panel { display: none; } .panel.active { display: block; }

.mini-cams { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.mini-cams a { position: relative; display: block; border-radius: 8px; overflow: hidden; aspect-ratio: 16/9; }
.mini-cams img { width: 100%; height: 100%; object-fit: cover; }
.mini-cams span { position: absolute; left: 6px; bottom: 4px; color: #fff; font-size: .75rem; text-shadow: 0 1px 3px #000; }

.videos { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.video-item { cursor: pointer; border-radius: 10px; overflow: hidden; background: var(--bg-3); border: 1px solid var(--line); }
.video-item .poster { aspect-ratio: 16/9; background: #000 center/cover; position: relative; }
.video-item .poster::after { content: "▶"; position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 2rem; text-shadow: 0 2px 10px #000; opacity: .85; }
.video-item .t { padding: 8px 10px; font-size: .88rem; }
video.player { width: 100%; border-radius: var(--radius); background: #000; }

/* Vollbild-Zoom */
.zoom { position: fixed; inset: 0; z-index: 100; background: #000; display: none; cursor: grab; overflow: hidden; touch-action: none; }
.zoom.open { display: block; }
.zoom img { position: absolute; left: 0; top: 0; transform-origin: 0 0; max-width: none; user-select: none; -webkit-user-drag: none; }
.zoom .zbar { position: absolute; top: 12px; right: 12px; display: flex; gap: 6px; z-index: 2; }
.zoom .zhint { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); color: rgba(255,255,255,.7); font-size: .85rem; background: rgba(0,0,0,.5); padding: 4px 12px; border-radius: 99px; }

/* Admin: Bereichs-Editor */
.region-editor { position: relative; display: inline-block; max-width: 100%; user-select: none; }
.region-editor img { display: block; max-width: 100%; border-radius: 8px; }
.region-editor .rg { position: absolute; border: 2px solid var(--warn); background: color-mix(in srgb, var(--warn) 25%, transparent); cursor: move; }
.region-editor .rg.sel { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 25%, transparent); }
.region-editor .rg .h { position: absolute; right: -6px; bottom: -6px; width: 12px; height: 12px; background: #fff; border-radius: 3px; cursor: nwse-resize; }
.region-editor .rg b { position: absolute; left: 4px; top: 2px; font-size: .75rem; color: #fff; text-shadow: 0 1px 2px #000; }
.region-editor .lb { position: absolute; transform: translate(-50%, -100%); background: rgba(0,0,0,.65); color: #fff; font-size: .78rem; padding: 2px 8px; border-radius: 6px; cursor: move; white-space: nowrap; }
.region-editor .lb.sel { outline: 2px solid var(--accent); }

.stat { display: flex; flex-direction: column; }
.stat b { font-size: 1.5rem; font-weight: 600; }
.stat span { color: var(--muted); font-size: .82rem; }
.stats { display: flex; gap: 28px; flex-wrap: wrap; }

.login-box { max-width: 380px; margin: 10vh auto; }
kbd { font-family: var(--mono); font-size: .8em; background: var(--bg-3); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; }

@media (max-width: 640px) {
  .topbar { padding: 8px 12px; flex-wrap: wrap; }
  .wrap { padding: 16px 12px 40px; }
  .cam-grid { grid-template-columns: 1fr; }
  .stage .nav-zone { opacity: .6; }
}
details.sec > summary { cursor: pointer; list-style: none; }
details.sec > summary::-webkit-details-marker { display: none; }
details.sec > summary::before { content: "▸ "; color: var(--muted); }
details.sec[open] > summary::before { content: "▾ "; }
.region-editor .rg.ign { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 20%, transparent); border-style: dashed; }
/* Panorama-Modus (z.B. 220°-Kameras): volle Höhe, seitlich schwenken */
.stage { transition: aspect-ratio .3s; }
.stage.pano { cursor: grab; touch-action: pan-y; }
.stage.pano:active { cursor: grabbing; }
.stage.pano img.layer { object-fit: cover; object-position: var(--panx, 50%) 50%; }
.stage.pano .nav-zone { width: 8%; }
.stage .pano-hint { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 6; background: rgba(0,0,0,.65); color: #fff; padding: 8px 16px; border-radius: 99px; font-size: .95rem; pointer-events: none; }
/* Betrachter ohne Seitenleiste (Besucher) */
.viewer.wide { grid-template-columns: minmax(0, 1fr); max-width: 1400px; }
.settings-wrap { position: relative; }
.popover { position: absolute; bottom: calc(100% + 8px); left: 0; z-index: 40; width: 280px; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px 12px; box-shadow: var(--shadow); }
@media (max-width: 640px) { .popover { position: fixed; left: 12px; right: 12px; top: auto; bottom: 12px; width: auto; } }
/* Fenster „Zeitraffer & Videos“ */
.modal { position: fixed; inset: 0; z-index: 90; background: rgba(0,0,0,.55); display: grid; place-items: center; padding: 20px; }
.modal-box { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); width: min(1100px, 100%); max-height: 90vh; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.modal-head { padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 16px 18px; overflow-y: auto; }
@media (max-width: 640px) { .modal { padding: 0; } .modal-box { max-height: 100vh; height: 100%; border-radius: 0; } }
.acc { display: inline-flex; align-items: center; gap: 2px; font-size: .85rem; font-weight: 500; padding: 1px 7px; border-radius: 99px; background: var(--bg-3); border: 1px solid var(--line); cursor: help; vertical-align: middle; white-space: nowrap; }
.acc-users { color: var(--accent); }

/* Livestream & Kamerasteuerung */
.live-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); gap: 18px; margin-top: 12px; }
@media (max-width: 900px) { .live-grid { grid-template-columns: 1fr; } }
.live-grid video, .live-video { width: 100%; background: #000; border-radius: 8px; aspect-ratio: 16 / 9; }
.ptz-pad { display: grid; grid-template-columns: repeat(3, 52px); grid-template-rows: repeat(3, 44px); gap: 6px; }
.ptz-pad .btn { width: 100%; height: 100%; justify-content: center; padding: 0; font-size: 18px; }
.preset-list { display: flex; flex-direction: column; gap: 6px; }
.preset-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.preset-row form { margin: 0; }

/* Video an der Stelle des Kamerabilds */
.stage-video { position: absolute; inset: 0; z-index: 8; background: #000; display: flex; flex-direction: column; }
.stage-video video { flex: 1; min-height: 0; width: 100%; object-fit: contain; background: #000; }
.stage-video-bar { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  color: #fff; font-size: .9rem; background: linear-gradient(180deg, rgba(0,0,0,.6), transparent); text-shadow: 0 1px 4px #000; }
.video-item.act { outline: 2px solid var(--accent, #1a73e8); }

/* Wartungshinweis auf der Übersicht */
.notice-maint { display: flex; gap: 12px; align-items: flex-start; margin: 18px 0; padding: 14px 18px; border-radius: var(--radius);
  background: #fff4d6; border: 1px solid #f0b429; border-left: 6px solid #e8890c; color: #5c3b00; font-weight: 500; line-height: 1.5; }
.notice-maint .ico { font-size: 1.3rem; line-height: 1.2; }
@media (prefers-color-scheme: dark) { :root[data-theme="system"] .notice-maint { background: #3a2a0a; border-color: #8a6116; border-left-color: #e8890c; color: #ffdf9e; } }
:root[data-theme="dark"] .notice-maint { background: #3a2a0a; border-color: #8a6116; border-left-color: #e8890c; color: #ffdf9e; }

/* deaktivierte (archivierte) Kameras im Admin */
.cam-off { opacity: .5; }
.cam-off img { filter: grayscale(1); }
.cam-off:hover { opacity: .8; }

/* Admin-Übersicht: kompakte Kamerakacheln */
.dash-cams { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.dash-cam { display: flex; flex-direction: column; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px;
  overflow: hidden; color: inherit; text-decoration: none; transition: border-color .15s; }
.dash-cam:hover { border-color: var(--accent); }
.dash-cam .img { aspect-ratio: 16/9; background: var(--bg-3); overflow: hidden; min-height: 0; }
.dash-cam .img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.dash-cam .t { padding: 7px 10px 2px; font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dash-cam .m { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 2px 10px 7px; font-size: .75rem; min-height: 30px; }
.dash-cam .img { margin-top: auto; }
.dash-cam .m .badge { font-size: .72rem; padding: 1px 7px; }
.cards.dash-top { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.cards.dash-top { align-items: start; }
.dash-alerts { max-height: 340px; overflow-y: auto; }
.dash-cam .n { padding: 0 10px 6px; font-size: .74rem; margin-top: -3px; }
