@font-face {
  font-family: "DM Sans";
  src: url("/static/fonts/dm-sans-400.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "DM Sans";
  src: url("/static/fonts/dm-sans-500.ttf") format("truetype");
  font-style: normal;
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: "DM Sans";
  src: url("/static/fonts/dm-sans-600.ttf") format("truetype");
  font-style: normal;
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: "DM Sans";
  src: url("/static/fonts/dm-sans-700.ttf") format("truetype");
  font-style: normal;
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("/static/fonts/jetbrains-mono-500.ttf") format("truetype");
  font-style: normal;
  font-weight: 500;
  font-display: swap;
}

:root {
  --bg: #080b0f;
  --panel: #0e1319;
  --panel-2: #121922;
  --line: #222c37;
  --text: #edf4f2;
  --muted: #7f8c99;
  --mint: #4adec4;
  --red: #ff4b35;
  --amber: #ffb443;
  --surface-input: #090d12;
  --surface-raised: #151c24;
}

[data-theme="light"] {
  --bg: #edf2f3;
  --panel: #ffffff;
  --panel-2: #f4f7f8;
  --line: #d4dde0;
  --text: #152026;
  --muted: #687780;
  --mint: #087f70;
  --red: #d63c2a;
  --amber: #a96500;
  --surface-input: #ffffff;
  --surface-raised: #edf2f3;
}

* { box-sizing: border-box; }

html {
  touch-action: manipulation;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 70% -20%, rgba(74, 222, 196, .08), transparent 33%),
    var(--bg);
  color: var(--text);
  font-family: "DM Sans", sans-serif;
  transition: background-color .3s ease, color .3s ease;
}
body.modal-open { overflow: hidden; }

button,
a,
.event-item,
.theme-toggle,
.gallery-nav,
.silence-button {
  touch-action: manipulation;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 15;
  height: 74px;
  padding: 0 36px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 11, 15, .88);
  backdrop-filter: blur(16px);
}
[data-theme="light"] .topbar { background: rgba(255, 255, 255, .9); }

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 34px; height: 34px; display: grid; place-items: center;
  border: 1px solid rgba(74, 222, 196, .5); transform: rotate(45deg);
}
.brand-mark span { width: 10px; height: 10px; background: var(--mint); }
.brand strong, .brand small { display: block; letter-spacing: .17em; }
.brand strong { font-size: 13px; }
.brand small { color: var(--mint); font-size: 8px; margin-top: 3px; }

.connection { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 9px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: #66717d; }
.dot.online { background: var(--mint); box-shadow: 0 0 12px var(--mint); }
.theme-toggle {
  justify-self: end; display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 36px; padding: 0; border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel-2); color: var(--text); cursor: pointer;
  font: 600 10px "DM Sans"; transition: transform .18s ease, background-color .25s ease, border-color .25s ease;
}
.theme-toggle:hover { transform: translateY(-1px); border-color: var(--mint); }
.theme-toggle svg { width: 16px; height: 16px; fill: none; stroke: var(--mint); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

main { max-width: 1560px; margin: auto; padding: 34px 36px 50px; }
.hero-row { display: flex; justify-content: space-between; align-items: end; margin-bottom: 24px; }
.eyebrow { color: var(--mint); font: 500 10px "JetBrains Mono"; letter-spacing: .14em; margin: 0 0 7px; }
h1 { margin: 0; font-size: clamp(28px, 4vw, 44px); letter-spacing: -.04em; }
h2 { margin: 0; font-size: 17px; }

.alert-pill {
  padding: 11px 16px; border: 1px solid; border-radius: 3px;
  font: 600 11px "JetBrains Mono"; letter-spacing: .08em;
  display: flex; align-items: center; gap: 9px;
}
.alert-pill.safe { color: var(--mint); border-color: rgba(74, 222, 196, .35); background: rgba(74, 222, 196, .06); }
.alert-pill.danger { color: var(--red); border-color: rgba(255, 75, 53, .5); background: rgba(255, 75, 53, .1); }
.pulse { width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 10px currentColor; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.camera-card, .side-panel {
  background: rgba(14, 19, 25, .9);
  border: 1px solid var(--line);
  box-shadow: 0 18px 60px rgba(0, 0, 0, .25);
  animation: panelEnter .55s cubic-bezier(.2, .75, .2, 1) both;
}
[data-theme="light"] .camera-card,
[data-theme="light"] .side-panel { background: rgba(255, 255, 255, .94); }
.side-panel { animation-delay: .08s; }
.camera-toolbar { min-height: 64px; padding: 13px 17px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); }
.camera-title, .toolbar-actions, .editor-actions { display: flex; align-items: center; gap: 9px; }
.camera-title { color: var(--muted); font-size: 12px; }
.view-mode-switch {
  display: flex; padding: 2px; border: 1px solid var(--line); border-radius: 4px;
  background: var(--surface-input);
}
.view-mode-option {
  padding: 7px 9px; border: 0; border-radius: 2px; color: var(--muted);
  background: transparent; font: 600 10px "DM Sans"; cursor: pointer;
  transition: color .18s ease, background-color .18s ease, box-shadow .18s ease;
}
.view-mode-option.active {
  color: #04100e; background: var(--mint);
  box-shadow: 0 3px 12px rgba(74, 222, 196, .18);
}
.live-badge { color: #fff; background: var(--red); border-radius: 2px; padding: 4px 7px; font: 600 9px "JetBrains Mono"; letter-spacing: .08em; }
.live-badge { transition: background-color .25s ease, color .25s ease, box-shadow .25s ease; }
.live-badge.offline {
  color: #aab4bd; background: #28313a; box-shadow: inset 0 0 0 1px #3a4651;
}

.button {
  border: 1px solid transparent; border-radius: 3px; padding: 9px 13px;
  color: var(--text); background: transparent; font: 600 11px "DM Sans"; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  transition: transform .18s ease, filter .18s ease, border-color .18s ease, background-color .18s ease;
}
.button-icon { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
.button.primary { background: var(--mint); color: #04100e; }
.button.secondary { border-color: var(--line); background: var(--surface-raised); }
.button.ghost { color: var(--muted); }
.button.danger { border-color: rgba(255, 75, 66, .55); background: rgba(255, 75, 66, .12); color: var(--red); }
.button.warning { border-color: rgba(255, 180, 67, .55); background: rgba(255, 180, 67, .1); color: #ffb443; }
.button.warning.active { background: #ffb443; color: #201305; }
.button:hover { filter: brightness(1.12); transform: translateY(-1px); }
.button:active { transform: translateY(0) scale(.98); }
.button:disabled { cursor: wait; opacity: .55; filter: none; }
.button.compact { padding: 5px 7px; font-size: 9px; }

.video-stage { position: relative; background: #030506; aspect-ratio: 16 / 9; overflow: hidden; }
.video-stage img, .video-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.video-stage img { object-fit: contain; }
.video-stage canvas { z-index: 2; cursor: default; pointer-events: none; }
.camera-offline-panel {
  position: absolute; inset: 0; z-index: 5;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 28px; text-align: center;
  background:
    radial-gradient(circle at center, rgba(74, 222, 196, .07), transparent 38%),
    #05080b;
}
.camera-offline-panel strong {
  margin-top: 20px; color: var(--text); font-size: clamp(20px, 3vw, 30px);
}
.camera-offline-panel > span {
  margin-top: 8px; color: var(--muted); font-size: 12px;
}
.camera-offline-icon {
  position: relative; width: 70px; height: 70px; border: 1px solid #35414c;
  border-radius: 50%; background: #10161d; box-shadow: 0 0 40px rgba(0, 0, 0, .4);
}
.offline-lens {
  position: absolute; width: 26px; height: 20px; left: 19px; top: 24px;
  border: 2px solid #8a97a2; border-radius: 4px;
}
.offline-lens::after {
  content: ""; position: absolute; width: 8px; height: 8px; right: -8px; top: 4px;
  border: 2px solid #8a97a2; border-left: 0; border-radius: 0 3px 3px 0;
}
.offline-slash {
  position: absolute; width: 44px; height: 2px; left: 13px; top: 34px;
  border-radius: 2px; background: #8a97a2; transform: rotate(-45deg);
  box-shadow: 0 0 0 3px #10161d;
}
.video-stage.editing canvas { cursor: crosshair; }
.video-stage.editing canvas { pointer-events: auto; }
.draw-hint {
  position: absolute; z-index: 3; top: 15px; left: 50%; transform: translateX(-50%);
  padding: 9px 13px; border-radius: 3px; background: rgba(3, 7, 9, .84);
  border: 1px solid rgba(74, 222, 196, .35); color: var(--mint); font-size: 11px;
  pointer-events: none;
}
.hidden { display: none !important; }

.camera-corner { display: none; position: absolute; z-index: 3; width: 20px; height: 20px; pointer-events: none; }
.video-stage.editing .camera-corner { display: block; }
.top-left { top: 12px; left: 12px; border-top: 1px solid var(--mint); border-left: 1px solid var(--mint); }
.top-right { top: 12px; right: 12px; border-top: 1px solid var(--mint); border-right: 1px solid var(--mint); }
.bottom-left { bottom: 12px; left: 12px; border-bottom: 1px solid var(--mint); border-left: 1px solid var(--mint); }
.bottom-right { bottom: 12px; right: 12px; border-bottom: 1px solid var(--mint); border-right: 1px solid var(--mint); }

.editor-bar { padding: 14px 17px; display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--line); }
.editor-bar strong, .editor-bar span { display: block; }
.editor-bar strong { font-size: 13px; }
.editor-bar span { margin-top: 3px; font-size: 11px; color: var(--muted); }

.side-panel { padding: 16px; }
.panel-section { padding: 22px 2px; border-bottom: 1px solid var(--line); }
.panel-section:last-child { border-bottom: 0; padding-bottom: 4px; }
.section-heading { display: flex; align-items: start; justify-content: space-between; margin-bottom: 14px; }
.count-badge { border: 1px solid #31404d; padding: 5px 7px; border-radius: 3px; color: var(--muted); font: 500 9px "JetBrains Mono"; }
.zone-preview { height: 116px; background: #080c10; border: 1px solid var(--line); }
[data-theme="light"] .zone-preview { background: #eaf0f1; }
.zone-preview canvas { width: 100%; height: 100%; }
.muted { color: var(--muted); font-size: 11px; line-height: 1.6; margin: 12px 0 0; }

.event-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.event-item { display: grid; grid-template-columns: 56px 1fr auto; align-items: center; gap: 10px; padding: 8px; background: var(--panel-2); border: 1px solid var(--line); }
.event-item { transition: transform .2s ease, border-color .2s ease, background-color .2s ease; }
.event-item:hover { transform: translateX(3px); border-color: #3a4957; background: #16202a; }
[data-theme="light"] .event-item:hover { border-color: #a9b8bd; background: #eaf0f2; }
.event-item img { width: 56px; height: 40px; object-fit: cover; cursor: zoom-in; }
.event-item strong { display: block; font-size: 11px; }
.event-item span { color: var(--muted); font-size: 9px; }
.event-count { color: var(--red) !important; font: 500 10px "JetBrains Mono" !important; }
.event-actions { display: grid; justify-items: end; gap: 7px; }
.event-delete-btn {
  appearance: none;
  border: 1px solid rgba(255, 75, 66, .62);
  background: transparent;
  color: var(--red);
  width: 26px; height: 26px; padding: 0; display: grid; place-items: center;
  border-radius: 3px;
  cursor: pointer;
}
.event-delete-btn svg, .image-delete svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.event-delete-btn:hover {
  color: white;
  background: var(--red);
}
.event-delete-btn:disabled { cursor: wait; opacity: .55; }
.event-load-more { width: 100%; margin-top: 10px; }
.empty-state { color: var(--muted); font-size: 11px; text-align: center; padding: 25px 8px; border: 1px dashed #2a3540; }

.toast {
  position: fixed; left: 50%; top: 24px; bottom: auto; z-index: 100;
  width: min(calc(100% - 32px), 540px);
  transform: translate(-50%, -20px); text-align: center;
  opacity: 0; transition: .2s;
  padding: 15px 18px; border-radius: 4px; font-size: 13px; font-weight: 600;
  box-shadow: 0 18px 60px rgba(0, 0, 0, .55);
}
.toast.success { background: #d9fff7; color: #05201a; border: 1px solid #4adec4; }
.toast.error { background: #ffded9; color: #3a0903; border: 1px solid #ff4b35; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }

.warning-overlay {
  position: fixed; top: 92px; left: 50%; z-index: 60;
  width: min(calc(100% - 28px), 760px); padding: 16px 18px;
  overflow: hidden; color: #fff;
  border: 1px solid rgba(255, 91, 67, .78); border-radius: 6px;
  background: linear-gradient(110deg, rgba(77, 12, 7, .98), rgba(27, 8, 7, .98));
  box-shadow: 0 20px 70px rgba(0, 0, 0, .62), 0 0 30px rgba(255, 75, 53, .16);
  animation: warningToastEnter .28s ease both;
}
.warning-overlay::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  border-top: 3px solid #ff4b35;
  animation: warningBorderPulse 1.4s ease-in-out infinite;
}
.warning-scanline { display: none; }
.warning-content {
  position: relative; z-index: 1; width: 100%;
  display: grid; grid-template-columns: auto 1fr auto; align-items: center;
  column-gap: 16px; text-align: left;
}
.warning-icon {
  grid-row: 1 / 5; width: 48px; height: 48px; margin: 0; display: grid; place-items: center;
  border: 2px solid #ff4b35; transform: rotate(45deg);
  color: #fff; background: rgba(255, 75, 53, .14); font: 700 27px "DM Sans";
  box-shadow: 0 0 28px rgba(255, 75, 53, .25);
  animation: warningIconPulse 1.1s ease-in-out infinite;
}
.warning-icon { line-height: 1; }
.warning-icon > * { transform: rotate(-45deg); }
.warning-eyebrow {
  grid-column: 2; margin: 0 0 3px; color: #ff7664;
  font: 600 9px "JetBrains Mono"; letter-spacing: .2em;
}
.warning-content h2 {
  grid-column: 2; margin: 0; color: #fff; font-size: clamp(20px, 3vw, 30px);
  line-height: 1; letter-spacing: -.025em; text-shadow: 0 0 30px rgba(255, 75, 53, .35);
}
.warning-people {
  grid-column: 2; margin: 6px 0 0; color: #ff7a67;
  font: 700 12px "JetBrains Mono"; letter-spacing: .06em;
}
.warning-sound-status { grid-column: 2; min-height: 0; margin: 3px 0 0; color: #c7b8b5; font-size: 10px; }
.silence-button {
  grid-column: 3; grid-row: 1 / 5; min-width: 170px;
  padding: 11px 14px; border: 1px solid #ff6e59; border-radius: 3px;
  color: #fff; background: rgba(255, 75, 53, .16); cursor: pointer;
  font: 700 12px "DM Sans"; letter-spacing: .04em;
  transition: transform .18s ease, background-color .18s ease;
}
.silence-button:hover { transform: translateY(-2px); background: rgba(255, 75, 53, .28); }
.silence-button:active { transform: translateY(0) scale(.98); }
.silence-button:disabled {
  cursor: default; transform: none; color: #bcaeab;
  border-color: #69504c; background: rgba(255, 255, 255, .05);
}
.silence-countdown {
  position: fixed; right: 20px; bottom: 20px; z-index: 45;
  min-width: 180px; padding: 12px 15px; border: 1px solid #8b5a21; border-radius: 4px;
  background: rgba(28, 19, 8, .94); color: #ffba55;
  box-shadow: 0 14px 45px rgba(0, 0, 0, .38);
  animation: panelEnter .25s ease both;
}
.silence-countdown span { display: block; font: 600 9px "JetBrains Mono"; letter-spacing: .12em; }
.silence-countdown strong { display: block; margin-top: 4px; color: #fff; font: 600 20px "JetBrains Mono"; }

.modal {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center;
  padding: 18px; overflow-y: auto; overscroll-behavior: contain;
  touch-action: pan-y; -webkit-overflow-scrolling: touch;
  background: rgba(2, 5, 7, .76); backdrop-filter: blur(12px);
  animation: modalBackdropIn .22s ease both;
}
.modal-card {
  width: min(100%, 510px); max-height: calc(100dvh - 36px);
  margin: auto; padding: 24px; overflow-y: auto; overscroll-behavior: contain;
  touch-action: pan-y; -webkit-overflow-scrolling: touch;
  scrollbar-width: thin; scrollbar-color: #3d4c59 #0b1015;
  background: #10161d;
  border: 1px solid #2a3642; box-shadow: 0 30px 100px rgba(0, 0, 0, .55);
  animation: modalCardIn .32s cubic-bezier(.2, .8, .2, 1) both;
}
.modal.is-loading .settings-grid,
.modal.is-loading .current-url,
.modal.is-loading .modal-card > label,
.modal.is-loading .modal-card > input,
.modal.is-loading .modal-card > .muted {
  opacity: .38; pointer-events: none; transition: opacity .18s ease;
}
[data-theme="light"] .modal-card { background: #fff; }
.modal-card::-webkit-scrollbar { width: 8px; }
.modal-card::-webkit-scrollbar-track { background: #0b1015; }
.modal-card::-webkit-scrollbar-thumb { background: #3d4c59; border-radius: 8px; }
.sound-permission-card {
  width: min(100%, 440px);
  text-align: center;
}
.sound-permission-icon {
  display: grid; width: 64px; height: 64px; margin: 0 auto 18px; place-items: center;
  border: 1px solid rgba(74, 222, 196, .45); border-radius: 50%;
  background: rgba(74, 222, 196, .1); box-shadow: 0 0 30px rgba(74, 222, 196, .15);
  font-size: 28px; animation: soundPermissionPulse 2.2s ease-in-out infinite;
}
.sound-permission-copy {
  max-width: 360px; margin: 12px auto 24px; color: var(--muted); line-height: 1.65;
}
.sound-permission-actions {
  display: flex; justify-content: center; gap: 10px;
}
.modal-head {
  position: sticky; top: -24px; z-index: 3;
  display: flex; justify-content: space-between; align-items: start;
  margin: -24px -24px 24px; padding: 24px;
  background: linear-gradient(#10161d 82%, rgba(16, 22, 29, 0));
}
[data-theme="light"] .modal-head { background: linear-gradient(#fff 82%, rgba(255, 255, 255, 0)); }
.icon-button {
  position: relative; z-index: 10; flex: 0 0 44px;
  width: 44px; height: 44px; margin: -10px -10px 0 0;
  border: 0; border-radius: 50%; background: transparent; color: var(--muted);
  font-size: 25px; line-height: 1; cursor: pointer; touch-action: manipulation;
}
.icon-button:active { background: rgba(127, 140, 153, .16); }
.modal label { display: block; margin-bottom: 8px; color: var(--muted); font-size: 11px; }
.field-help {
  display: block; margin-top: 7px; color: var(--muted);
  font-size: 9px; line-height: 1.45;
}
.modal input, .modal select {
  width: 100%; padding: 13px 14px; border: 1px solid #34414e; border-radius: 3px;
  outline: 0; background: var(--surface-input); color: var(--text); font: 12px "JetBrains Mono";
}
.modal input:focus, .modal select:focus { border-color: var(--mint); box-shadow: 0 0 0 3px rgba(74, 222, 196, .08); }
.current-url { color: var(--mint); font: 10px "JetBrains Mono"; overflow-wrap: anywhere; }
.modal-actions {
  position: sticky; bottom: -24px; z-index: 3;
  margin: 22px -24px -24px; padding: 18px 24px 24px;
  display: flex; justify-content: end; gap: 9px;
  background: linear-gradient(rgba(16, 22, 29, 0), #10161d 22%);
}
[data-theme="light"] .modal-actions { background: linear-gradient(rgba(255, 255, 255, 0), #fff 22%); }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 18px; }
.settings-wide { grid-column: 1 / -1; }
.login-card { width: min(100%, 400px); }
.image-modal { cursor: zoom-out; }
.image-modal img {
  max-width: min(94vw, 1400px); max-height: 90vh; object-fit: contain;
  border: 1px solid #34414e; box-shadow: 0 30px 100px rgba(0, 0, 0, .75);
  animation: imageZoomIn .3s cubic-bezier(.2, .8, .2, 1) both;
}
.image-modal img.gallery-swap { animation: gallerySwap .22s ease both; }
.image-close {
  position: fixed; top: 18px; right: 24px; z-index: 10;
  width: 42px; height: 42px; border-radius: 50%; border: 1px solid #536170;
  background: rgba(8, 12, 16, .9); color: white; font-size: 25px; cursor: pointer;
}
.image-delete {
  position: fixed; top: 18px; right: 76px; z-index: 10;
  width: 42px; height: 42px; border-radius: 50%; border: 1px solid rgba(255, 75, 66, .75);
  background: rgba(44, 13, 13, .92); color: var(--red); cursor: pointer;
  display: grid; place-items: center;
}
.image-delete:hover { background: var(--red); color: white; }
.gallery-nav {
  position: fixed; top: 50%; z-index: 2; transform: translateY(-50%);
  width: 52px; height: 68px; border: 1px solid #536170; border-radius: 4px;
  background: rgba(8, 12, 16, .82); color: #fff; font-size: 38px;
  cursor: pointer; transition: background-color .18s ease, transform .18s ease;
}
.gallery-nav:hover { background: rgba(74, 222, 196, .16); }
.gallery-nav:active { transform: translateY(-50%) scale(.96); }
.gallery-prev { left: 24px; }
.gallery-next { right: 24px; }
.gallery-counter {
  position: fixed; left: 50%; bottom: 22px; z-index: 2;
  transform: translateX(-50%); padding: 8px 12px; border-radius: 3px;
  background: rgba(8, 12, 16, .88); border: 1px solid #3b4854;
  color: #dbe5e2; font: 500 10px "JetBrains Mono";
}

@keyframes panelEnter {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes modalBackdropIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes modalCardIn {
  from { opacity: 0; transform: translateY(18px) scale(.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes imageZoomIn {
  from { opacity: 0; transform: scale(.94); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes gallerySwap {
  from { opacity: .35; transform: scale(.985); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes warningEnter {
  from { opacity: 0; transform: scale(1.015); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes warningToastEnter {
  from { opacity: 0; transform: translate(-50%, -14px) scale(.98); }
  to { opacity: 1; transform: translate(-50%, 0) scale(1); }
}
@keyframes warningBorderPulse {
  0%, 100% { opacity: .55; }
  50% { opacity: 1; }
}
@keyframes warningIconPulse {
  0%, 100% { transform: rotate(45deg) scale(1); }
  50% { transform: rotate(45deg) scale(1.06); }
}
@keyframes warningScan {
  from { transform: translateY(-100%); }
  to { transform: translateY(460%); }
}
@keyframes soundPermissionPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

.camera-list-link {
  display: inline-block; margin-bottom: 12px; color: var(--mint);
  font: 700 10px/1 var(--mono); letter-spacing: .08em; text-decoration: none;
}
.camera-index-main { max-width: 1240px; padding-top: 64px; }
.camera-index-hero { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 32px; }
.camera-index-copy { color: var(--muted); margin: 8px 0 0; }
.camera-list-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 22px; }
.camera-list-card {
  overflow: hidden; border: 1px solid var(--border); background: var(--panel);
  box-shadow: 0 18px 48px rgba(0, 0, 0, .16);
  transition: transform .22s ease, border-color .22s ease, box-shadow .22s ease;
}
.camera-list-card:hover { transform: translateY(-4px); border-color: rgba(74, 222, 196, .52); box-shadow: 0 24px 60px rgba(0, 0, 0, .24); }
.camera-list-card.danger { border-color: rgba(255, 75, 66, .62); }
.camera-card-preview { position: relative; display: block; aspect-ratio: 16 / 9; overflow: hidden; background: #05090c; color: inherit; }
.camera-card-preview img { position: relative; z-index: 2; width: 100%; height: 100%; object-fit: cover; transition: transform .4s ease; }
.camera-list-card:hover .camera-card-preview img { transform: scale(1.025); }
.camera-card-preview img.unavailable { display: none; }
.camera-card-preview.is-offline img { display: none; }
.camera-preview-fallback { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; color: var(--muted); gap: 5px; }
.camera-preview-fallback span { color: var(--text); font-weight: 700; }
.camera-state, .camera-area-state { position: absolute; z-index: 3; top: 14px; padding: 6px 9px; font: 700 10px/1 var(--mono); letter-spacing: .08em; }
.camera-state { left: 14px; }
.camera-area-state { right: 14px; }
.camera-state.live, .camera-area-state.danger { color: white; background: #ff4b42; }
.camera-state.offline { color: var(--muted); background: rgba(12, 20, 27, .9); border: 1px solid var(--border); }
.camera-area-state.safe { color: var(--mint); background: rgba(5, 20, 20, .88); border: 1px solid rgba(74, 222, 196, .42); }
.camera-list-body { padding: 18px; }
.camera-list-body h2 { margin: 5px 0 0; font-size: 20px; }
.camera-list-body > p { color: var(--muted); font: 10px/1.6 var(--mono); margin: 12px 0 18px; }
.camera-list-body .button { display: flex; width: 100%; text-decoration: none; }
.camera-card-actions { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; }
.camera-card-actions .delete-camera-btn,
.camera-card-actions .toggle-camera-btn { width: auto; }
.camera-list-card.disabled { opacity: .82; }
.camera-list-card.disabled .camera-card-preview { filter: saturate(.2); }
.camera-empty { grid-column: 1 / -1; min-height: 260px; display: grid; place-content: center; text-align: center; gap: 8px; border: 1px dashed var(--border); color: var(--muted); }
.camera-empty strong { color: var(--text); font-size: 20px; }
.camera-form-card { width: min(520px, calc(100vw - 28px)); }
.camera-form-card label { margin-top: 15px; }
.camera-index-actions { display: flex; flex-wrap: wrap; justify-content: end; gap: 9px; }

.login-page { min-height: 100dvh; }
.error-page {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  overflow-x: hidden;
}
.error-shell {
  position: relative;
  width: min(100% - 32px, 760px);
  padding: 24px 0;
}
.error-theme-toggle {
  position: absolute;
  z-index: 2;
  top: 42px;
  right: 24px;
}
.error-card {
  position: relative;
  overflow: hidden;
  min-height: 560px;
  padding: 48px;
  border: 1px solid var(--line);
  background:
    radial-gradient(circle at 86% 18%, rgba(74, 222, 196, .12), transparent 29%),
    var(--panel);
  box-shadow: 0 30px 100px rgba(0, 0, 0, .35);
  animation: panelEnter .55s cubic-bezier(.2, .75, .2, 1) both;
}
.error-card::after {
  content: "";
  position: absolute;
  width: 240px;
  height: 240px;
  right: -105px;
  bottom: -115px;
  border: 1px solid rgba(74, 222, 196, .22);
  transform: rotate(45deg);
  pointer-events: none;
}
.error-brand { margin-bottom: 66px; }
.error-visual {
  position: relative;
  width: fit-content;
  margin-bottom: 28px;
}
.error-code {
  display: block;
  color: var(--text);
  font: 700 clamp(78px, 17vw, 136px)/.82 "DM Sans";
  letter-spacing: -.08em;
}
.error-scan-line {
  position: absolute;
  left: 3px;
  right: -8px;
  bottom: -9px;
  height: 3px;
  background: linear-gradient(90deg, var(--mint), transparent);
  box-shadow: 0 0 18px rgba(74, 222, 196, .45);
  transform-origin: left;
  animation: errorScan 2.8s ease-in-out infinite;
}
.error-card h1 {
  max-width: 600px;
  font-size: clamp(28px, 5vw, 44px);
}
.error-message {
  max-width: 590px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.7;
}
.error-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 28px;
}
.error-actions .button {
  min-width: 148px;
  text-align: center;
  text-decoration: none;
}
.login-theme-toggle { position: absolute; z-index: 5; top: 24px; right: 24px; }
.login-shell {
  position: relative;
  width: min(1040px, calc(100% - 32px)); min-height: 620px;
  display: grid; grid-template-columns: 1.15fr .85fr; padding: 0;
  margin: max(30px, 8vh) auto; border: 1px solid var(--border);
  background: var(--panel); box-shadow: 0 32px 100px rgba(0, 0, 0, .35);
}
.login-hero-panel {
  min-height: 620px; padding: 42px; display: flex; flex-direction: column;
  justify-content: space-between; border-right: 1px solid var(--border);
  background:
    linear-gradient(135deg, rgba(74, 222, 196, .09), transparent 48%),
    repeating-linear-gradient(90deg, transparent 0 59px, rgba(74, 222, 196, .025) 60px);
}
.login-hero-panel h1 { margin: 12px 0 18px; font-size: clamp(42px, 6vw, 68px); line-height: .98; }
.login-hero-panel > div:last-child > p:last-child { max-width: 430px; color: var(--muted); line-height: 1.7; }
.portal-login-card { align-self: center; padding: 48px; }
.portal-login-card h2 { margin: 9px 0; font-size: 30px; }
.portal-login-card label { display: block; margin: 30px 0 9px; color: var(--muted); font-size: 11px; }
.portal-login-card input { width: 100%; padding: 15px; border: 1px solid #34414e; background: var(--surface-input); color: var(--text); }
.portal-login-card input:focus { outline: 0; border-color: var(--mint); box-shadow: 0 0 0 3px rgba(74, 222, 196, .08); }
.portal-login-card .button { width: 100%; margin-top: 18px; }
.login-error { margin: 12px 0 0; color: var(--red); font-size: 11px; }

.user-admin-card { width: min(760px, calc(100vw - 28px)); }
.user-create-form { padding-bottom: 24px; border-bottom: 1px solid var(--border); }
.user-create-form h3, .user-list-section h3 { margin: 0 0 15px; }
.user-create-form > .button { margin-top: 16px; }
.camera-access-options { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.camera-access-check {
  display: flex !important; align-items: center; gap: 8px; margin: 0 !important;
  padding: 9px 11px; border: 1px solid var(--border); background: var(--surface-input);
  color: var(--text) !important; cursor: pointer;
}
.camera-access-check input { width: auto; accent-color: var(--mint); }
.user-list-section { padding-top: 24px; }
.admin-user-list { display: grid; gap: 12px; }
.active-streams-section .section-heading { align-items: center; }
.active-streams-list { display: grid; gap: 8px; max-height: 220px; overflow-y: auto; }
.active-stream-item { display: grid; grid-template-columns: 1fr 1fr auto; align-items: center; gap: 12px; padding: 10px; border: 1px solid var(--line); background: var(--panel-2); }
.active-stream-item strong, .active-stream-item span { display: block; }
.active-stream-item strong { font-size: 11px; }
.active-stream-item span { margin-top: 4px; color: var(--muted); font: 9px var(--mono); word-break: break-word; }
@media (max-width: 720px) {
  .active-stream-item { grid-template-columns: 1fr auto; }
  .active-stream-item > div:nth-child(2) { grid-column: 1 / -1; }
}
.admin-user-item { padding: 16px; border: 1px solid var(--border); background: rgba(0, 0, 0, .08); }
.admin-user-heading { display: flex; justify-content: space-between; align-items: center; gap: 15px; }
.admin-user-heading strong, .admin-user-heading span { display: block; }
.admin-user-heading span { margin-top: 5px; color: var(--mint); font: 700 9px var(--mono); letter-spacing: .09em; }
.user-row-actions { display: grid; grid-template-columns: 1fr auto; gap: 9px; margin-top: 14px; }

@keyframes errorScan {
  0%, 100% { transform: scaleX(.2); opacity: .45; }
  50% { transform: scaleX(1); opacity: 1; }
}

@media (max-width: 980px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .side-panel { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
  .panel-section { border: 0; }
}

@media (max-width: 650px) {
  .error-shell { width: 100%; padding: 0; }
  .error-card {
    min-height: 100dvh;
    padding: 34px 22px;
    border: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
  .error-theme-toggle { top: 22px; right: 18px; }
  .error-brand { position: absolute; top: 28px; left: 22px; margin: 0; }
  .error-visual { margin-top: 32px; }
  .error-actions { display: grid; grid-template-columns: 1fr; }
  .error-actions .button { width: 100%; }
  .topbar { padding: 0 16px; grid-template-columns: 1fr auto; }
  .camera-index-main { padding: 34px 14px; }
  .camera-index-hero { align-items: stretch; flex-direction: column; }
  .camera-index-hero .button { width: 100%; }
  .camera-index-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .camera-index-actions .button { width: auto; }
  .camera-list-grid { grid-template-columns: 1fr; }
  .camera-card-actions { grid-template-columns: 1fr 1fr; }
  .camera-card-actions > .button:first-child { grid-column: 1 / -1; }
  .login-shell { width: 100%; min-height: 100dvh; margin: 0; grid-template-columns: 1fr; border: 0; }
  .login-hero-panel { min-height: 235px; padding: 25px 22px; border: 0; border-bottom: 1px solid var(--border); }
  .login-hero-panel h1 { font-size: 38px; }
  .login-hero-panel > div:last-child > p:last-child { display: none; }
  .portal-login-card { width: 100%; padding: 34px 22px; }
  .user-row-actions { grid-template-columns: 1fr; }
  .connection { display: none; }
  main { padding: 24px 14px; }
  .hero-row { align-items: start; }
  .dashboard-grid { gap: 12px; }
  .camera-toolbar, .editor-bar { align-items: stretch; flex-direction: column; }
  .toolbar-actions, .editor-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .view-mode-switch { grid-column: 1 / -1; }
  .view-mode-option { flex: 1; }
  .toolbar-actions .button:first-child { grid-column: 1 / -1; }
  .editor-actions { grid-template-columns: repeat(3, 1fr); }
  .side-panel { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .modal-actions { display: grid; grid-template-columns: 1fr; }
  .sound-permission-actions { flex-direction: column-reverse; }
  .sound-permission-actions .button { width: 100%; }
  .modal { padding: 0; place-items: stretch; }
  .modal-card {
    width: 100%; max-height: 100dvh; min-height: 100dvh;
    border-width: 0; padding: 20px;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }
  .modal-head {
    top: -20px; margin: -20px -20px 20px;
    padding: max(20px, env(safe-area-inset-top)) 20px 20px;
  }
  .modal-actions { bottom: -20px; margin: 20px -20px -20px; padding: 18px 20px 20px; }
  .settings-wide { grid-column: auto; }
  .image-modal {
    place-items: center; padding: 58px 10px 78px; min-height: 100dvh;
  }
  .image-modal img {
    width: 100%; max-width: 100%; max-height: calc(100dvh - 150px);
    object-fit: contain; border-radius: 3px;
  }
  .gallery-nav { width: 42px; height: 56px; font-size: 30px; }
  .gallery-prev, .gallery-next { top: 50%; bottom: auto; transform: translateY(-50%); }
  .gallery-prev { left: 12px; }
  .gallery-next { right: 12px; }
  .gallery-nav:active { transform: translateY(-50%) scale(.96); }
  .gallery-counter { bottom: 24px; }
  .image-close { top: 10px; right: 10px; }
  .image-delete { top: 10px; right: 62px; }
  .warning-overlay { top: 82px; padding: 14px; }
  .warning-content { grid-template-columns: auto 1fr; column-gap: 13px; }
  .warning-icon { width: 40px; height: 40px; font-size: 23px; }
  .silence-button {
    grid-column: 1 / -1; grid-row: auto; width: 100%; min-width: 0; margin-top: 12px;
  }
  .silence-countdown { left: 12px; right: 12px; bottom: 12px; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
