/*!
 * Webpulse Kamerazentrale – Design-System
 * Aufbau nach bewährten Open-Source-Konzepten:
 *  - Design-Tokens als CSS Custom Properties (vgl. Open Props, Tabler, Radix Colors)
 *  - Modern-Normalize-artiger Reset
 *  - Komponenten mit flacher Spezifität, Zustände über .is-* Klassen
 *  - Hell/Dunkel über prefers-color-scheme + manueller Override [data-theme]
 * Keine externen Abhängigkeiten, keine Webfonts von Drittservern.
 */

/* ------------------------------------------------------------------ Tokens */
:root {
  --font-sans: "Inter", "InterVariable", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;

  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-8: 32px; --space-10: 40px;

  --radius-sm: 8px; --radius: 12px; --radius-lg: 16px; --radius-pill: 999px;

  --text-xs: 0.75rem; --text-sm: 0.8125rem; --text-base: 0.9375rem;
  --text-lg: 1.125rem; --text-xl: 1.375rem; --text-2xl: 1.75rem; --text-3xl: 2.125rem;

  --ease: cubic-bezier(.2, .8, .2, 1);
  --sidebar-w: 248px;

  /* Farben – hell */
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-2: #f7f9fa;
  --surface-3: #eef2f5;
  --border: #e2e7ec;
  --border-strong: #cfd7df;
  --text: #0f1c26;
  --text-2: #3b4b58;
  --muted: #6a7987;
  --primary: #0b7285;
  --primary-hover: #095f6e;
  --primary-soft: #e3f3f5;
  --primary-text: #ffffff;
  --success: #2f9e44; --success-soft: #e6f6ea;
  --warning: #e67700; --warning-soft: #fff3e0;
  --danger: #e03131;  --danger-soft: #fdecec;
  --info: #4263eb;    --info-soft: #ebefff;
  --neutral-soft: #eef1f4;

  --tone-battery: #2f9e44;
  --tone-signal: #4263eb;
  --tone-temp: #e8590c;
  --tone-time: #7048e8;
  --tone-next: #0b7285;

  --shadow-sm: 0 1px 2px rgba(16, 32, 48, .06);
  --shadow: 0 1px 2px rgba(16, 32, 48, .05), 0 4px 16px rgba(16, 32, 48, .06);
  --shadow-lg: 0 12px 40px rgba(16, 32, 48, .18);
  --focus: 0 0 0 3px rgba(11, 114, 133, .35);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1117; --surface: #111a22; --surface-2: #15202a; --surface-3: #1b2833;
    --border: #22313d; --border-strong: #2e404e;
    --text: #e7eef4; --text-2: #c2ced8; --muted: #8796a4;
    --primary: #3bc9db; --primary-hover: #66d9e8; --primary-soft: #0f3038; --primary-text: #062026;
    --success: #51cf66; --success-soft: #11301a;
    --warning: #ffa94d; --warning-soft: #352409;
    --danger: #ff6b6b;  --danger-soft: #3a1416;
    --info: #748ffc;    --info-soft: #18204a;
    --neutral-soft: #1b2631;
    --tone-battery: #51cf66; --tone-signal: #748ffc; --tone-temp: #ff922b; --tone-time: #9775fa; --tone-next: #3bc9db;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, .55);
    --focus: 0 0 0 3px rgba(59, 201, 219, .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1117; --surface: #111a22; --surface-2: #15202a; --surface-3: #1b2833;
  --border: #22313d; --border-strong: #2e404e;
  --text: #e7eef4; --text-2: #c2ced8; --muted: #8796a4;
  --primary: #3bc9db; --primary-hover: #66d9e8; --primary-soft: #0f3038; --primary-text: #062026;
  --success: #51cf66; --success-soft: #11301a;
  --warning: #ffa94d; --warning-soft: #352409;
  --danger: #ff6b6b;  --danger-soft: #3a1416;
  --info: #748ffc;    --info-soft: #18204a;
  --neutral-soft: #1b2631;
  --tone-battery: #51cf66; --tone-signal: #748ffc; --tone-temp: #ff922b; --tone-time: #9775fa; --tone-next: #3bc9db;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, .55);
  --focus: 0 0 0 3px rgba(59, 201, 219, .4);
  color-scheme: dark;
}

/* ------------------------------------------------------------------- Reset */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font-sans); font-size: var(--text-base); line-height: 1.5;
  color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv11", "ss01";
}
img, svg { display: block; max-width: 100%; }
img { height: auto; }
h1, h2, h3, p, dl, dd, pre { margin: 0; }
h1 { font-size: var(--text-2xl); line-height: 1.2; letter-spacing: -0.02em; font-weight: 700; }
h2 { font-size: var(--text-base); font-weight: 650; letter-spacing: -0.005em; }
h3 { font-size: var(--text-lg); font-weight: 650; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
code { font-family: var(--font-mono); font-size: .88em; background: var(--surface-3); padding: .1em .35em; border-radius: 5px; }
:focus-visible { outline: none; box-shadow: var(--focus); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.icon { width: 1.15em; height: 1.15em; flex: none; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------- Utilities */
.muted { color: var(--muted); }
.small { font-size: var(--text-sm); }
.mono { font-family: var(--font-mono); }
.nowrap { white-space: nowrap; }
.text-danger { color: var(--danger); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.sep { display: inline-block; width: 4px; height: 4px; border-radius: 50%; background: var(--border-strong); vertical-align: middle; margin: 0 6px; }
.label-sm { font-size: var(--text-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* ------------------------------------------------------------------ Shell */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.is-staging .shell { min-height: calc(100vh - 36px); }

.env-banner {
  position: sticky; top: 0; z-index: 60; display: flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 var(--space-4); font-size: var(--text-sm);
  color: #3d2600; background: repeating-linear-gradient(135deg, #ffd43b 0 14px, #fcc419 14px 28px);
}
.env-banner .icon { width: 16px; height: 16px; }

.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: var(--space-5);
  padding: var(--space-5) var(--space-4); background: var(--surface); border-right: 1px solid var(--border);
  overflow-y: auto;
}
.is-staging .sidebar { top: 36px; height: calc(100vh - 36px); }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; }
.icon-btn.sidebar-close { display: none; }

.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; color: #fff;
  background: linear-gradient(140deg, #15aabf, #0b7285 60%, #0a4f5c);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 2px 6px rgba(11, 114, 133, .35);
}
.brand-mark .icon { width: 20px; height: 20px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 1.02rem; letter-spacing: -0.01em; }
.brand-text span { font-size: var(--text-xs); color: var(--muted); }

.cam-switch { display: grid; gap: 6px; }
.cam-switch select { width: 100%; }

.nav { display: grid; gap: 2px; }
.nav-link {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 500; background: none; border: 0; text-align: left;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.nav-link .icon { width: 19px; height: 19px; color: var(--muted); transition: color .15s var(--ease); }
.nav-link:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav-link.is-active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-link.is-active .icon { color: var(--primary); }

.sidebar-foot { margin-top: auto; display: grid; gap: var(--space-3); }
.version { font-size: var(--text-xs); color: var(--muted); padding: 0 12px; }

.theme-switch { display: grid; grid-template-columns: repeat(3, 1fr); padding: 3px; background: var(--surface-3); border-radius: 10px; }
.theme-switch button { display: grid; place-items: center; height: 30px; border: 0; background: none; border-radius: 8px; color: var(--muted); }
.theme-switch button .icon { width: 16px; height: 16px; }
.theme-switch button.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar { display: none; }
.content { flex: 1; width: 100%; max-width: 1360px; margin: 0 auto; padding: var(--space-8) var(--space-8) var(--space-10); }
.footer { display: flex; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; max-width: 1360px; width: 100%; margin: 0 auto; padding: var(--space-4) var(--space-8) var(--space-6); font-size: var(--text-xs); color: var(--muted); }
.backdrop { display: none; }

/* ------------------------------------------------------------- Page head */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-6); }
.page-sub { margin-top: 6px; color: var(--muted); display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.page-actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }

/* ---------------------------------------------------------------- Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); padding: var(--space-5); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }
.card-head p { margin-top: 2px; }
.link { display: inline-flex; align-items: center; gap: 4px; font-weight: 550; font-size: var(--text-sm); white-space: nowrap; }
.link .icon { width: 15px; height: 15px; }

/* -------------------------------------------------------------- Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 16px;
  border-radius: 10px; border: 1px solid transparent; font-weight: 600; font-size: var(--text-sm);
  transition: background .15s var(--ease), border-color .15s var(--ease), transform .1s var(--ease);
  white-space: nowrap; text-decoration: none !important;
}
.btn .icon { width: 17px; height: 17px; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-block { width: 100%; height: 44px; }

.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.icon-btn .icon { width: 18px; height: 18px; }
.icon-btn.is-disabled { opacity: .4; pointer-events: none; }

.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-3); border-radius: 11px; }
.segmented a { padding: 6px 12px; border-radius: 8px; font-size: var(--text-sm); font-weight: 550; color: var(--text-2); white-space: nowrap; }
.segmented a:hover { color: var(--text); text-decoration: none; }
.segmented a.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: var(--radius-pill);
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2); font-size: var(--text-sm); font-weight: 550; white-space: nowrap;
}
.chip small { color: var(--muted); font-weight: 500; }
.chip:hover { border-color: var(--border-strong); text-decoration: none; color: var(--text); }
.chip.is-active { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.chip.is-active small { color: inherit; opacity: .8; }

/* --------------------------------------------------------------- Badges */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: 650; letter-spacing: .01em; white-space: nowrap; }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-success .dot { box-shadow: 0 0 0 0 currentColor; animation: pulse 2s infinite; }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-neutral { background: var(--neutral-soft); color: var(--muted); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 55%, transparent); } 70% { box-shadow: 0 0 0 6px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
@media (prefers-reduced-motion: reduce) { .badge-success .dot { animation: none; } }

/* --------------------------------------------------------------- Alerts */
.alert { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--radius); margin-bottom: var(--space-5); font-size: var(--text-sm); border: 1px solid transparent; }
.alert .icon { width: 20px; height: 20px; margin-top: 1px; }
.alert-success { background: var(--success-soft); color: var(--text); border-color: color-mix(in srgb, var(--success) 25%, transparent); }
.alert-success .icon { color: var(--success); }
.alert-danger { background: var(--danger-soft); color: var(--text); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert-danger .icon { color: var(--danger); }

/* ------------------------------------------------------------- Overview */
.overview { display: grid; grid-template-columns: minmax(0, 1.75fr) minmax(300px, 1fr); gap: var(--space-5); align-items: start; }
.overview > .card:not(.hero) { grid-column: 1 / -1; }
.hero { padding: 0; overflow: hidden; }
.hero-media { position: relative; display: block; width: 100%; padding: 0; border: 0; background: #0b1117; aspect-ratio: 16 / 9; cursor: zoom-in; }
.hero-media img { width: 100%; height: 100%; object-fit: cover; }
.hero-overlay {
  position: absolute; inset: auto 0 0 0; display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
  padding: 48px 20px 16px; color: #fff; text-align: left;
  background: linear-gradient(to top, rgba(4, 12, 18, .78), rgba(4, 12, 18, 0));
}
.hero-time { display: grid; gap: 2px; text-shadow: 0 1px 2px rgba(0, 0, 0, .4); }
.hero-time strong { font-size: var(--text-lg); }
.hero-time span { font-size: var(--text-sm); opacity: .85; }
.hero-zoom { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: rgba(255, 255, 255, .16); backdrop-filter: blur(6px); transition: background .15s; }
.hero-media:hover .hero-zoom { background: rgba(255, 255, 255, .3); }
.hero-zoom .icon { width: 18px; height: 18px; }

.media-empty { display: grid; place-items: center; align-content: center; gap: 8px; aspect-ratio: 16 / 9; color: var(--muted); background: var(--surface-2); }
.media-empty .icon { width: 32px; height: 32px; }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
.kpi { display: flex; flex-direction: column; gap: 6px; padding: var(--space-4); min-width: 0; }
.kpi-wide { grid-column: 1 / -1; }
.kpi-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.kpi-icon { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; }
.kpi-icon .icon { width: 17px; height: 17px; }
.kpi-label { font-size: var(--text-sm); font-weight: 600; color: var(--text-2); }
.kpi-value { font-size: var(--text-3xl); font-weight: 700; letter-spacing: -0.03em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi-value small { font-size: var(--text-base); font-weight: 600; color: var(--muted); margin-left: 4px; letter-spacing: 0; }
.kpi-value-text { font-size: var(--text-xl); letter-spacing: -0.015em; }
.kpi-note { font-size: var(--text-xs); color: var(--muted); }
.tone-battery { color: var(--tone-battery); } .kpi-icon.tone-battery { background: color-mix(in srgb, var(--tone-battery) 14%, transparent); }
.tone-signal { color: var(--tone-signal); }   .kpi-icon.tone-signal { background: color-mix(in srgb, var(--tone-signal) 14%, transparent); }
.tone-temp { color: var(--tone-temp); }       .kpi-icon.tone-temp { background: color-mix(in srgb, var(--tone-temp) 14%, transparent); }
.tone-time { color: var(--tone-time); }       .kpi-icon.tone-time { background: color-mix(in srgb, var(--tone-time) 14%, transparent); }
.tone-next { color: var(--tone-next); }       .kpi-icon.tone-next { background: color-mix(in srgb, var(--tone-next) 14%, transparent); }

.meter { height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; margin-top: 4px; }
.meter span { display: block; height: 100%; border-radius: inherit; background: var(--tone-battery); }
.meter.is-mid span { background: var(--warning); }
.meter.is-low span { background: var(--danger); }

.bars { display: flex; align-items: flex-end; gap: 4px; height: 22px; margin-top: 2px; }
.bars span { width: 8px; border-radius: 3px; background: var(--surface-3); }
.bars span:nth-child(1) { height: 30%; } .bars span:nth-child(2) { height: 55%; }
.bars span:nth-child(3) { height: 78%; } .bars span:nth-child(4) { height: 100%; }
.bars span.on { background: var(--tone-signal); }

.spark { height: 46px; margin-top: 6px; }

.strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--space-3); }

.err-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--space-3); }
.err { display: grid; gap: 2px; padding: 12px 14px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); }
.err-label { font-size: var(--text-xs); color: var(--muted); font-weight: 600; }
.err-val { font-size: var(--text-xl); font-weight: 700; font-variant-numeric: tabular-nums; }
.err-delta { font-size: var(--text-xs); color: var(--muted); }
.err.is-rising { background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 35%, transparent); }
.err.is-rising .err-delta { color: var(--warning); font-weight: 650; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin-top: var(--space-4); font-size: var(--text-sm); }
.kv dt { color: var(--muted); }

/* multi-camera grid */
.cam-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: var(--space-5); }
.cam-card { padding: 0; overflow: hidden; color: inherit; transition: transform .2s var(--ease), box-shadow .2s var(--ease); }
.cam-card:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow); }
.cam-card .media { position: relative; aspect-ratio: 16 / 9; background: #0b1117; }
.cam-card .media img { width: 100%; height: 100%; object-fit: cover; }
.media-caption { position: absolute; right: 10px; bottom: 10px; padding: 3px 8px; border-radius: 6px; font-size: var(--text-xs); color: #fff; background: rgba(0, 0, 0, .55); }
.cam-card-body { padding: var(--space-4) var(--space-5) var(--space-5); display: grid; gap: 4px; }
.mini-stats { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 8px; font-size: var(--text-sm); color: var(--text-2); }
.mini-stats > span { display: inline-flex; align-items: center; gap: 6px; }
.mini-stats .icon { width: 15px; height: 15px; color: var(--muted); }

/* --------------------------------------------------------------- Thumbs */
.thumb {
  position: relative; display: block; padding: 0; border: 0; border-radius: var(--radius); overflow: hidden;
  background: #0b1117; aspect-ratio: 16 / 9; cursor: zoom-in; isolation: isolate;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform .35s var(--ease), opacity .2s; }
.thumb:hover img { transform: scale(1.04); }
.thumb span {
  position: absolute; left: 8px; bottom: 8px; padding: 2px 8px; border-radius: 6px; font-size: var(--text-xs); font-weight: 600;
  color: #fff; background: rgba(0, 0, 0, .55); backdrop-filter: blur(4px); font-variant-numeric: tabular-nums;
}

/* -------------------------------------------------------------- Gallery */
.toolbar { display: flex; align-items: center; gap: var(--space-4); flex-wrap: wrap; padding: var(--space-3) var(--space-4); margin-bottom: var(--space-4); }
.day-nav { display: flex; align-items: center; gap: var(--space-3); }
.day-current { display: grid; min-width: 150px; text-align: center; line-height: 1.3; }
.day-pick { margin-left: auto; }
.day-chips { display: flex; gap: var(--space-2); overflow-x: auto; padding-bottom: 4px; margin-bottom: var(--space-5); scrollbar-width: thin; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--space-3); }

/* --------------------------------------------------------------- Charts */
.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-5); margin-bottom: var(--space-5); }
.chart-card .card-head { margin-bottom: var(--space-2); }
.chart-last { font-size: var(--text-xl); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chart-last small { font-size: var(--text-sm); color: var(--muted); margin-left: 3px; font-weight: 600; }
.chart { position: relative; height: 210px; }
.chart svg, .spark svg { width: 100%; height: 100%; overflow: visible; }
.chart-note { margin-top: 8px; font-size: var(--text-xs); color: var(--muted); }
.chart .axis text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .grid line { stroke: var(--border); stroke-dasharray: 3 4; }
.chart-tip {
  position: absolute; z-index: 5; pointer-events: none; transform: translate(-50%, -115%); padding: 6px 10px; border-radius: 8px;
  background: var(--text); color: var(--surface); font-size: var(--text-xs); white-space: nowrap; box-shadow: var(--shadow);
}
.chart-tip strong { display: block; font-size: var(--text-sm); }

/* ---------------------------------------------------------------- Table */
.table-card { padding: 0; overflow: hidden; }
.table-card > .card-head { padding: var(--space-5) var(--space-5) 0; align-items: baseline; }
.table-card > .empty { padding: var(--space-8); }
.table-wrap { overflow: auto; max-height: 70vh; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--text-sm); }
.table th {
  position: sticky; top: 0; z-index: 1; text-align: left; font-weight: 600; font-size: var(--text-xs); color: var(--muted);
  background: var(--surface-2); padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:hover td { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cell-up { color: var(--warning); font-weight: 700; background: var(--warning-soft); }
.sig { display: inline-flex; align-items: flex-end; gap: 2px; height: 12px; margin-right: 6px; vertical-align: -1px; }
.sig i { width: 3px; border-radius: 1px; background: var(--border-strong); }
.sig i:nth-child(1) { height: 30%; } .sig i:nth-child(2) { height: 55%; } .sig i:nth-child(3) { height: 78%; } .sig i:nth-child(4) { height: 100%; }
.sig i.on { background: var(--tone-signal); }

.stat-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-4); margin-bottom: var(--space-5); }
.stat { display: grid; gap: 4px; padding: var(--space-4) var(--space-5); }
.stat-label { font-size: var(--text-xs); color: var(--muted); font-weight: 600; }
.stat strong { font-size: var(--text-2xl); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat strong.stat-text { font-size: var(--text-lg); }

.raw-log { margin-top: var(--space-5); padding: 0; }
.raw-log summary, .add-cam summary { display: flex; align-items: center; gap: 10px; padding: var(--space-4) var(--space-5); cursor: pointer; font-weight: 600; list-style: none; }
.raw-log summary::-webkit-details-marker, .add-cam summary::-webkit-details-marker { display: none; }
.raw-log summary .icon, .add-cam summary .icon { width: 18px; height: 18px; color: var(--muted); }
.raw-log pre { margin: 0; padding: var(--space-4) var(--space-5); max-height: 420px; overflow: auto; font: 12px/1.6 var(--font-mono); color: var(--text-2); background: var(--surface-2); border-top: 1px solid var(--border); }

/* ---------------------------------------------------------------- Forms */
input[type="text"], input[type="password"], input[type="number"], input[type="time"], select {
  width: 100%; height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); transition: border-color .15s, box-shadow .15s;
}
select { appearance: none; padding-right: 36px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236a7987' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 16px; }
input:hover, select:hover { border-color: var(--muted); }
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); }

.field { display: grid; gap: 6px; margin-bottom: var(--space-5); align-content: start; }
.field > label { font-size: var(--text-sm); font-weight: 600; color: var(--text-2); display: flex; align-items: center; justify-content: space-between; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--space-4); }
.hint { font-size: var(--text-xs); color: var(--muted); display: flex; gap: 6px; align-items: flex-start; }
.hint .icon { width: 14px; height: 14px; margin-top: 1px; }
.input-group { display: flex; align-items: center; border: 1px solid var(--border-strong); border-radius: 10px; overflow: hidden; background: var(--surface); }
.input-group:focus-within { border-color: var(--primary); box-shadow: var(--focus); }
.input-group input { border: 0; border-radius: 0; box-shadow: none !important; }
.input-group span { padding: 0 12px; color: var(--muted); font-size: var(--text-sm); background: var(--surface-2); align-self: stretch; display: grid; place-items: center; border-left: 1px solid var(--border); }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.presets .chip { height: 30px; }

input[type="range"] { width: 100%; accent-color: var(--primary); height: 28px; }
output { font-variant-numeric: tabular-nums; padding: 1px 8px; border-radius: 6px; background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.range-legend { display: flex; justify-content: space-between; font-size: var(--text-xs); color: var(--muted); }

.field-row { padding: 12px 0; border-bottom: 1px solid var(--border); }
.field-row:first-of-type { padding-top: 0; }
.field-row + .field { margin-top: var(--space-5); }
.switch { display: flex; align-items: flex-start; gap: 14px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-ui { position: relative; flex: none; width: 42px; height: 24px; margin-top: 1px; border-radius: 99px; background: var(--border-strong); transition: background .2s var(--ease); }
.switch-ui::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .2s var(--ease); }
.switch input:checked + .switch-ui { background: var(--primary); }
.switch input:checked + .switch-ui::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-ui { box-shadow: var(--focus); }
.switch > span:last-child { display: grid; gap: 2px; }
.switch small { color: var(--muted); font-size: var(--text-xs); }

.settings { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: var(--space-5); align-items: start; }
.settings-main { display: grid; gap: var(--space-5); }
.settings-main .field:last-child, .settings-main .field-grid:last-child .field { margin-bottom: 0; }
.sticky { position: sticky; top: var(--space-6); }
.is-staging .sticky { top: calc(36px + var(--space-6)); }
.code { padding: 14px 16px; border-radius: var(--radius); background: #0d1820; color: #cfe3ec; font: 12.5px/1.6 var(--font-mono); overflow: auto; margin-bottom: var(--space-3); }
.code .k { color: #66d9e8; } .code .s { color: #b2f2bb; } .code .n { color: #ffd8a8; } .code .b { color: #d0bfff; }
.form-actions { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-4); }
.add-cam { margin-top: var(--space-5); padding: 0; }
.add-cam-form { padding: 0 var(--space-5) var(--space-5); align-items: end; grid-template-columns: 1fr 1fr auto; }
.add-cam-form .form-actions { margin: 0 0 var(--space-5); }

/* ---------------------------------------------------------------- Empty */
.empty { display: grid; justify-items: center; gap: 8px; padding: var(--space-8) var(--space-4); text-align: center; color: var(--muted); }
.empty .icon { width: 36px; height: 36px; color: var(--border-strong); }
.empty h3 { color: var(--text); font-size: var(--text-base); }

/* ------------------------------------------------------------- Lightbox */
.lightbox { position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: rgba(5, 10, 14, .96); color: #fff; }
.lightbox::backdrop { background: rgba(5, 10, 14, .9); }
.lightbox[open] { display: grid; grid-template-rows: auto 1fr auto; }
.lb-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; }
.lb-title { display: grid; line-height: 1.3; }
.lb-title strong { font-size: var(--text-base); }
.lb-title span { font-size: var(--text-xs); color: rgba(255, 255, 255, .6); font-variant-numeric: tabular-nums; }
.lb-actions { display: flex; gap: 8px; }
.lb-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; border: 0; color: #fff; background: rgba(255, 255, 255, .1); }
.lb-btn:hover { background: rgba(255, 255, 255, .2); text-decoration: none; }
.lb-btn .icon { width: 19px; height: 19px; }
.lb-btn.is-on { background: var(--primary); color: var(--primary-text); }
.lb-stage { position: relative; display: grid; place-items: center; min-height: 0; padding: 0 64px; touch-action: pan-y; }
.lb-stage img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; user-select: none; -webkit-user-drag: none; }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 48px; }
.lb-prev { left: 10px; } .lb-next { right: 10px; }
.lb-progress { height: 3px; background: rgba(255, 255, 255, .12); }
.lb-progress span { display: block; height: 100%; width: 0; background: var(--primary); transition: width .2s linear; }

/* orientation fallback (nur ohne GD) */
.orient-flip_v { transform: scaleY(-1); }
.orient-flip_h { transform: scaleX(-1); }
.orient-rotate_180 { transform: rotate(180deg); }
.thumb:hover img.orient-flip_v { transform: scaleY(-1) scale(1.04); }

/* ----------------------------------------------------------------- Auth */
.auth { min-height: 100vh; background:
  radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--primary) 18%, transparent), transparent 60%),
  radial-gradient(900px 500px at 110% 110%, color-mix(in srgb, var(--info) 14%, transparent), transparent 60%), var(--bg); }
.auth-wrap { min-height: calc(100vh - 36px); display: grid; place-content: center; gap: 16px; padding: 24px; }
.auth-card { width: min(420px, 100%); padding: var(--space-8); display: grid; gap: var(--space-4); box-shadow: var(--shadow-lg); }
.auth-card h1 { font-size: var(--text-xl); margin-top: var(--space-4); }
.auth-card .alert { margin: 0; }
.auth-form .field { margin-bottom: var(--space-4); }
.brand-lg .brand-mark { width: 44px; height: 44px; border-radius: 12px; }
.brand-lg .brand-mark .icon { width: 24px; height: 24px; }

/* ----------------------------------------------------------- Responsive */
@media (max-width: 1180px) {
  .overview { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .kpi-wide { grid-column: 1 / -1; }
  .settings { grid-template-columns: 1fr; }
  .sticky { position: static; }
}
@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; z-index: 50; top: 0; left: 0; bottom: 0; height: 100%; width: min(300px, 86vw);
    transform: translateX(-102%); transition: transform .25s var(--ease); box-shadow: var(--shadow-lg);
  }
  .is-staging .sidebar { top: 0; height: 100%; }
  .nav-open .sidebar { transform: none; }
  .icon-btn.sidebar-close { display: inline-grid; }
  .backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(5, 12, 18, .45); opacity: 0; pointer-events: none; transition: opacity .2s; display: block; }
  .nav-open .backdrop { opacity: 1; pointer-events: auto; }
  .topbar {
    position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px; height: 58px; padding: 0 16px;
    background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: saturate(1.4) blur(12px);
    border-bottom: 1px solid var(--border);
  }
  .is-staging .topbar { top: 36px; }
  .brand-compact .brand-mark { width: 30px; height: 30px; border-radius: 8px; }
  .brand-compact .brand-mark .icon { width: 17px; height: 17px; }
  .topbar-title { margin-left: auto; font-size: var(--text-sm); color: var(--muted); font-weight: 600; }
  .content { padding: var(--space-5) var(--space-4) var(--space-8); }
  .footer { padding: var(--space-4); }
  .chart-grid { grid-template-columns: 1fr; }
  .stat-row { grid-template-columns: 1fr 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  h1 { font-size: var(--text-xl); }
  .page-head { margin-bottom: var(--space-4); }
  .card { padding: var(--space-4); border-radius: var(--radius); }
  .card.hero, .card.cam-card, .card.table-card, .card.raw-log, .card.add-cam { padding: 0; }
  .kpi-value { font-size: var(--text-2xl); }
  .kpi-value-text { font-size: var(--text-lg); }
  .field-grid, .add-cam-form { grid-template-columns: 1fr; }
  .gallery { grid-template-columns: repeat(2, 1fr); gap: var(--space-2); }
  .strip { grid-template-columns: repeat(2, 1fr); }
  .toolbar { gap: var(--space-3); }
  .day-pick { margin-left: 0; flex: 1; }
  .toolbar .btn { flex: 1; }
  .hero-overlay { padding: 32px 14px 12px; }
  .hero-time strong { font-size: var(--text-base); }
  .lb-stage { padding: 0; }
  .lb-nav { display: none; }
  .table-card > .card-head { padding: var(--space-4) var(--space-4) 0; flex-direction: column; gap: 2px; }
  .cam-grid { grid-template-columns: 1fr; }
}

/* --------------------------------------------------------------- Storage */
.storage-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: var(--space-5); margin-top: var(--space-5); align-items: start; }
.table-card + .storage-grid { margin-top: var(--space-5); }
.stat-row + .table-card { margin-top: 0; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 85%, #000); }
.preview-box { padding: var(--space-4); border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); margin-bottom: var(--space-5); display: grid; gap: 8px; }
.preview-box.is-danger { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.plain { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.plain li { display: flex; align-items: center; gap: 8px; }
.plain .icon { width: 16px; height: 16px; color: var(--muted); }
.preview-total { font-size: var(--text-lg); }
.confirm-form { margin-top: 4px; }
.check { display: flex; align-items: flex-start; gap: 8px; font-size: var(--text-sm); cursor: pointer; }
.check input { margin-top: 3px; accent-color: var(--primary); width: 16px; height: 16px; }
.checks { display: grid; gap: 8px; padding-top: 4px; }
.chip-radio { cursor: pointer; }
.chip-radio input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chip-radio:has(input:checked) { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.chip-radio:has(input:focus-visible) { box-shadow: var(--focus); }
.date-input { width: auto; height: 36px; margin-top: 4px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface); }
.ret-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 var(--space-3); margin-top: var(--space-4); }
.ret-grid .field { margin-bottom: var(--space-2); }
.cron-hint { margin-top: var(--space-5); border-top: 1px solid var(--border); padding-top: var(--space-4); }
.cron-hint summary { cursor: pointer; font-size: var(--text-sm); font-weight: 600; color: var(--text-2); }
.cron-hint p, .cron-hint pre { margin-top: 8px; }
@media (max-width: 1180px) { .storage-grid { grid-template-columns: 1fr; } }
@media (max-width: 600px) { .ret-grid { grid-template-columns: 1fr; } }
