/* Webcam-Verwaltung – keine externen Ressourcen (keine Web-Fonts, keine CDNs). */
:root {
  --paper: #edf1f3;
  --panel: #ffffff;
  --ink: #16212b;
  --muted: #586977;
  --line: #d2dbe2;
  --accent: #0e6a7d;
  --accent-ink: #ffffff;
  --live: #d0233a;
  --ok: #1f7a4f;
  --warn: #a35f00;
  --error: #b42318;
  --field: #f7f9fa;
  --screen: #0b1217;
  --radius-s: 6px;
  --radius-l: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0d151b;
    --panel: #152029;
    --ink: #e2e9ee;
    --muted: #8fa1ae;
    --line: #26343f;
    --accent: #5cb8cf;
    --accent-ink: #062027;
    --ok: #4cc38a;
    --warn: #e0a243;
    --error: #f0776b;
    --field: #0f1a21;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 15px/1.5 var(--font); font-variant-numeric: tabular-nums;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.125rem; }
h3 { font-size: 1rem; margin-top: 1rem; }
p { margin: 0 0 .75rem; }
code { font-size: .9em; background: var(--field); border: 1px solid var(--line);
       border-radius: 4px; padding: .05em .35em; word-break: break-all; }
code.big { font-size: 1.25rem; padding: .2em .5em; letter-spacing: .04em; }
.muted { color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Kopfzeile */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: .75rem clamp(1rem, 3vw, 2rem); background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: .6rem; font-weight: 700; color: var(--ink); text-decoration: none; }
.brand-lens {
  width: 1.1rem; height: 1.1rem; border-radius: 50%; display: inline-block;
  background: radial-gradient(circle at 35% 35%, #9ed6e4 0 18%, var(--accent) 19% 55%, var(--screen) 56%);
  box-shadow: 0 0 0 2px var(--line);
}
.nav { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.nav a { color: var(--ink); text-decoration: none; }
.nav a:hover { color: var(--accent); }
.inline { display: inline; margin: 0; }

.page { max-width: 1280px; margin: 0 auto; padding: 1.5rem clamp(1rem, 3vw, 2rem) 4rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.back { display: inline-block; margin-bottom: .25rem; font-size: .9rem; text-decoration: none; }
.back::before { content: "‹ "; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.stack > * { margin-top: 0; margin-bottom: 0; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.narrow { max-width: 640px; }

/* Buttons */
.button {
  appearance: none; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  font: inherit; font-weight: 600; padding: .55rem 1rem; border-radius: var(--radius-s);
  cursor: pointer; text-decoration: none; display: inline-block; text-align: center;
}
.button:hover { border-color: var(--accent); }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.button.primary:hover { filter: brightness(1.08); }
.button.danger { background: var(--error); border-color: var(--error); color: #fff; }
.button.danger-quiet { color: var(--error); }
.button.wide { width: 100%; }
.link-button { appearance: none; border: 0; background: none; color: var(--accent); font: inherit; padding: 0; cursor: pointer; }
.nav .link-button { color: var(--muted); }
.danger-text { color: var(--error); }

/* Meldungen */
.notice { border-radius: var(--radius-s); padding: .75rem 1rem; margin-bottom: 1rem; border: 1px solid; }
.notice.success { border-color: color-mix(in srgb, var(--ok) 45%, transparent); background: color-mix(in srgb, var(--ok) 10%, var(--panel)); }
.notice.error { border-color: color-mix(in srgb, var(--error) 45%, transparent); background: color-mix(in srgb, var(--error) 10%, var(--panel)); }
.notice ul { margin: .25rem 0 0; padding-left: 1.2rem; }

/* Formulare */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-l); padding: 1.25rem; margin: 0; min-width: 0; }
fieldset.panel { padding-top: .5rem; }
legend { font-weight: 650; font-size: 1.125rem; padding: 0 .4rem; margin-left: -.4rem; }
.grid-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem 1.25rem; margin-top: .75rem; }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field-label { font-weight: 600; font-size: .9rem; }
.field small, .check small { color: var(--muted); font-size: .82rem; display: block; }
input[type=text], input[type=number], input[type=password], input:not([type]), select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--field);
  border: 1px solid var(--line); border-radius: var(--radius-s); padding: .5rem .65rem;
}
textarea { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.with-unit { display: flex; align-items: center; gap: .5rem; }
.with-unit input { max-width: 9rem; }
.unit { color: var(--muted); font-size: .9rem; }
.check { display: flex; gap: .6rem; align-items: flex-start; cursor: pointer; }
.check input { margin-top: .25rem; width: 1.05rem; height: 1.05rem; accent-color: var(--accent); }
.grid-fields .check { grid-column: 1 / -1; }
input[type=file] { font: inherit; max-width: 100%; }
.savebar {
  position: sticky; bottom: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-l); padding: .75rem 1rem;
  box-shadow: 0 -6px 18px color-mix(in srgb, var(--paper) 80%, transparent);
}

/* Das Kamerabild mit OSD-Leiste – das prägende Element der Oberfläche */
.screen { position: relative; background: var(--screen); border-radius: var(--radius-s); overflow: hidden; aspect-ratio: 16 / 9; }
.screen img { width: 100%; height: 100%; object-fit: cover; display: block; }
.osd {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: .5rem;
  padding: .45rem .7rem; color: #fff; font-size: .82rem; font-weight: 600;
  background: linear-gradient(to top, rgba(0,0,0,.72), rgba(0,0,0,0));
}
.osd-time { margin-left: auto; opacity: .9; }
.lamp { width: .6rem; height: .6rem; border-radius: 50%; display: inline-block; background: #8a98a3; flex: none; }
.lamp.ok { background: var(--live); box-shadow: 0 0 0 0 rgba(208,35,58,.6); animation: rec 2s infinite; }
.lamp.stale { background: var(--warn); }
.lamp.error { background: var(--error); }
.lamp.waiting { background: #8a98a3; }
@keyframes rec { 0% { box-shadow: 0 0 0 0 rgba(208,35,58,.55); } 70% { box-shadow: 0 0 0 .45rem rgba(208,35,58,0); } 100% { box-shadow: 0 0 0 0 rgba(208,35,58,0); } }
@media (prefers-reduced-motion: reduce) { .lamp.ok { animation: none; } }

.badge { display: inline-flex; align-items: center; gap: .45rem; font-weight: 600; font-size: .9rem; padding: .3rem .7rem; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); }

/* Übersicht */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1.25rem; }
.tile { display: block; color: inherit; text-decoration: none; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-l); padding: .5rem; }
.tile:hover { border-color: var(--accent); }
.tile-body { padding: .75rem .5rem .25rem; }
.tile-body h2 { margin-bottom: .2rem; }
.tile-body p { margin-bottom: .4rem; font-size: .9rem; }
.tile-meta { display: flex; flex-wrap: wrap; gap: .35rem 1rem; color: var(--muted); font-size: .82rem; }
.empty { background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius-l); padding: 2.5rem; max-width: 640px; }

/* Bearbeiten */
.edit-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 1.5rem; align-items: start; }
.edit-aside { position: sticky; top: 1rem; }
.preview .screen { aspect-ratio: auto; min-height: 180px; }
.preview .screen img { height: auto; object-fit: contain; }
.preview { display: flex; flex-direction: column; gap: .75rem; }
.preview > * { margin: 0; }
.overlay-file { display: flex; gap: 1rem; align-items: flex-start; margin-top: .5rem; padding-bottom: .5rem; border-bottom: 1px solid var(--line); }
.overlay-thumb {
  width: 140px; flex: none; border-radius: var(--radius-s); border: 1px solid var(--line);
  background: repeating-conic-gradient(#c8d0d6 0 25%, #eef1f3 0 50%) 0 0 / 14px 14px;
}
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; margin: .75rem 0 1rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; min-width: 0; }
.facts.compact { font-size: .88rem; margin: 0; }
.copy-row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.secret { border: 2px solid var(--accent); border-radius: var(--radius-s); padding: 1rem; margin-bottom: 1rem; background: color-mix(in srgb, var(--accent) 8%, var(--panel)); }
.danger-zone { border-color: color-mix(in srgb, var(--error) 40%, var(--line)); }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1.5rem; align-items: start; }
.table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; }
.table th, .table td { text-align: left; padding: .55rem .4rem; border-bottom: 1px solid var(--line); }
.table th { font-size: .85rem; color: var(--muted); font-weight: 600; }
.right { text-align: right !important; }

@media (max-width: 960px) {
  .edit-layout { grid-template-columns: 1fr; }
  .edit-aside { position: static; order: -1; }
}

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-l); padding: 2rem; }
.login-card h1 { display: flex; align-items: center; gap: .6rem; font-size: 1.4rem; }
.login-card .field { margin-bottom: 1rem; }
.login .notice { width: min(380px, 100%); }

/* Öffentliche Seiten */
body.public { background: var(--screen); color: #e6edf1; }
.public-bar { background: transparent; border-bottom-color: #1e2b34; }
.public-bar .brand { color: #e6edf1; }
.public-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 1rem; }
.public-cam { position: relative; display: block; border-radius: var(--radius-s); overflow: hidden; color: #fff; text-decoration: none; background: #000; }
.public-cam img { width: 100%; display: block; }
.public-name { position: absolute; left: 0; right: 0; bottom: 0; padding: .6rem .8rem; font-weight: 600; background: linear-gradient(to top, rgba(0,0,0,.75), rgba(0,0,0,0)); }
.public-foot { margin-top: 2rem; font-size: .85rem; }
.public-foot a { color: #7f909c; }
.empty-public { color: #9fb0bc; }
.single-cam { margin: 0; min-height: 100vh; display: grid; place-items: center; }
.single-cam img { max-width: 100%; max-height: 100vh; display: block; }

/* Livestream */
.screen video { width: 100%; height: 100%; display: block; background: var(--screen); }
.preview .screen.video { aspect-ratio: 16 / 9; }
.preview .screen.video .osd { top: 0; bottom: auto; background: linear-gradient(to bottom, rgba(0,0,0,.65), rgba(0,0,0,0)); pointer-events: none; }
.screen.noimg img { visibility: hidden; }
.screen.noimg::after { content: "Kein Standbild"; position: absolute; inset: 0; display: grid; place-items: center; color: #9fb0bc; font-size: .9rem; }
.notice.small { font-size: .85rem; padding: .5rem .75rem; margin: 0; word-break: break-word; }
.wide-field { grid-column: 1 / -1; }
[hidden] { display: none !important; }
.public-cam video { width: 100%; display: block; aspect-ratio: 16 / 9; background: #000; }
.public-missing { display: grid; place-items: center; aspect-ratio: 16 / 9; color: #7f909c; }
.live-tag { display: inline-block; margin-left: .4rem; padding: 0 .4rem; border-radius: 3px; background: var(--live); font-size: .75rem; vertical-align: middle; }
.single-cam video { width: 100%; max-height: 100vh; display: block; background: #000; }
.grid-fields .field:has(> #f-source_type),
.grid-fields .field:has(> #f-rtsp_url),
.grid-fields .field:has(> #f-stream_mode),
.grid-fields .field:has(> #f-text_template) { grid-column: 1 / -1; }
