:root {
  --bg: #0b1220;
  --panel: #111a2e;
  --panel-2: #172238;
  --line: #243149;
  --text: #e5ecf7;
  --muted: #8b9bb8;
  --accent: #38bdf8;
  --accent-ink: #06253a;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --blink: #60a5fa;
  --ring: #fb923c;
  --radius: 14px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
body { min-height: 100dvh; }
button, input, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--bad); margin: 8px 0 0; font-size: 14px; }

/* Kopfzeile */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + var(--sat)) 12px 8px;
  background: rgba(11, 18, 32, .92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 18px; margin: 0; flex: 1; font-weight: 700; letter-spacing: .2px; }
.top .count { color: var(--muted); font-weight: 500; font-size: 14px; margin-left: 6px; }

.btn {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  border-radius: 10px; padding: 8px 12px; min-height: 38px; font-weight: 600; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { background: #3b1a1f; border-color: #6b2630; color: #fecaca; }
.btn.icon { width: 38px; padding: 0; font-size: 17px; }
.btn.wide { width: 100%; }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn.active { background: #1d3a4d; border-color: var(--accent); color: var(--accent); }

/* Statuszeile */
.statusbar { display: flex; flex-direction: column; gap: 6px; padding: 8px 12px 0; }
.notice { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); font-size: 14px; }
.notice.warn { border-color: #5a4411; background: #2a2210; color: #fde68a; }
.notice.bad { border-color: #6b2630; background: #2a1215; color: #fecaca; }
.notice .spacer { flex: 1; }

/* Modus-Chips (Ring-Standort) */
.chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip { border: 1px solid var(--line); background: var(--panel-2); color: var(--text); border-radius: 999px; padding: 4px 10px; font-size: 13px; min-height: 30px; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }

/* Kachelraster */
.grid { display: grid; grid-template-columns: 1fr; gap: 12px; padding: 12px 12px calc(24px + var(--sab)); }
@media (min-width: 700px) { .grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1100px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1500px) { .grid { grid-template-columns: repeat(4, 1fr); } }

.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.tile.offline { opacity: .7; }
.media { position: relative; aspect-ratio: 16 / 9; background: #05080f; overflow: hidden; }
.media img, .media video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.media img.empty { object-fit: none; }
.media .tag { position: absolute; top: 8px; left: 8px; padding: 2px 8px; border-radius: 6px; font-size: 11px; font-weight: 800; letter-spacing: .5px; text-transform: uppercase; color: #fff; }
.tag.blink { background: var(--blink); }
.tag.ring { background: var(--ring); }
.media .liveind { position: absolute; top: 8px; right: 8px; padding: 2px 8px; border-radius: 6px; font-size: 11px; font-weight: 800; background: #dc2626; color: #fff; letter-spacing: .5px; }
.media .liveind::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #fff; margin-right: 5px; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.media .msg { position: absolute; left: 0; right: 0; bottom: 0; padding: 6px 10px; background: rgba(0,0,0,.55); color: #fff; font-size: 13px; }
.media .msg.err { background: rgba(127, 29, 29, .85); }
.media .motion { position: absolute; bottom: 8px; right: 8px; background: var(--warn); color: #1f1300; font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 6px; }
.media .tap { position: absolute; inset: 0; border: 0; background: transparent; padding: 0; }

.meta { padding: 10px 12px 0; }
.meta .name { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.meta .sub { color: var(--muted); font-size: 13px; margin-top: 2px; display: flex; gap: 10px; flex-wrap: wrap; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); } .dot.warn { background: var(--warn); }

.btns { display: flex; gap: 6px; padding: 10px 12px 12px; }
.btns .btn { flex: 1; min-width: 0; }
.btns .btn.icon { flex: 0 0 38px; }

/* Vollbild-Ansicht einer Kamera */
.tile.focus { position: fixed; inset: 0; z-index: 40; border-radius: 0; border: 0; background: #000; }
.tile.focus .media { aspect-ratio: auto; flex: 1; }
.tile.focus .media img, .tile.focus .media video { object-fit: contain; }
.tile.focus .meta { padding-top: 8px; }
.tile.focus .btns { padding-bottom: calc(12px + var(--sab)); }

/* Bottom-Sheet */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 50; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  max-height: 88dvh; overflow: auto; background: var(--panel); border-top-left-radius: 18px; border-top-right-radius: 18px;
  border-top: 1px solid var(--line); padding: 8px 16px calc(20px + var(--sab));
}
@media (min-width: 700px) { .sheet { left: 50%; right: auto; width: 560px; transform: translateX(-50%); } }
.sheet .grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 12px; }
.sheet h2 { font-size: 17px; margin: 0 0 4px; display: flex; align-items: center; gap: 8px; }
.sheet h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 18px 0 6px; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .lbl { flex: 1; }
.row .lbl small { display: block; color: var(--muted); font-size: 12px; }
.row select, .row input[type=number], .row input[type=text], .row input[type=password], .row input[type=email] {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 38px; font-size: 16px; min-width: 0;
}
.row input[type=range] { width: 140px; accent-color: var(--accent); }
.row .val { min-width: 28px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.switch { position: relative; width: 48px; height: 28px; flex: 0 0 48px; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: #334155; transition: .15s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: .15s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:disabled + span { opacity: .4; }
.actions-row { display: flex; gap: 8px; margin-top: 14px; }
.actions-row .btn { flex: 1; }

/* Formulare (Konten, Login) */
.field { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; }
.field span { font-size: 13px; color: var(--muted); }
.field input { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 16px; min-height: 42px; }
.acct { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin: 10px 0; background: var(--panel-2); }
.acct h3 { margin: 0 0 6px; font-size: 15px; text-transform: none; letter-spacing: 0; color: var(--text); display: flex; align-items: center; gap: 8px; }
.pill { font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 999px; background: #334155; color: #e2e8f0; text-transform: uppercase; letter-spacing: .4px; }
.pill.ok { background: #064e3b; color: #a7f3d0; } .pill.warn { background: #4a3311; color: #fde68a; } .pill.bad { background: #4c1d24; color: #fecaca; }

/* Login-Seite */
.login-body { display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 28px 22px; text-align: center; }
.login-card h1 { margin: 6px 0 0; font-size: 24px; }
.login-card p { margin: 4px 0 18px; }
.login-card form { text-align: left; }
.login-logo { font-size: 44px; }

/* Toasts */
.toasts { position: fixed; left: 12px; right: 12px; top: calc(60px + var(--sat)); z-index: 60; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { background: #1f2937; color: #fff; border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 10px; padding: 10px 12px; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.4); pointer-events: auto; }
.toast.warn { border-left-color: var(--warn); } .toast.bad { border-left-color: var(--bad); } .toast.ok { border-left-color: var(--ok); }

/* Ereignisliste */
.events { list-style: none; margin: 0; padding: 0; }
.events li { padding: 8px 0; border-bottom: 1px solid var(--line); display: flex; gap: 10px; font-size: 14px; }
.events li time { color: var(--muted); flex: 0 0 52px; font-variant-numeric: tabular-nums; }
.clips { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.clip { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; display: block; color: inherit; text-decoration: none; }
.clip img { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; background: #000; }
.clip div { padding: 6px 8px; font-size: 12px; color: var(--muted); }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }
