:root {
  --forest: #1b3a2f;
  --moss: #2f5d4a;
  --danger: #b3261e;
  --danger-fill: #7a1a14;
  --water: #1565c0;
  --water-fill: #0d47a1;
  --mist: #e8f0e9;
  --live: #3ddc84;
  --amber: #ffc107;
  --stuck: #b3261e;
  --bg: #000;
  --dialog: #1c1c1c;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--mist);
  font-family: "Roboto", "Segoe UI", system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

.app, .screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #000;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 64px;
  padding: 8px 8px 8px 16px;
  background: var(--forest);
  color: var(--mist);
  flex-shrink: 0;
}
.topbar.frozen { background: var(--stuck); }
.topbar-title { flex: 1; min-width: 0; }
.title-row { display: flex; align-items: center; gap: 8px; }
.topbar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}
#status-text {
  margin: 2px 0 0;
  font-size: 13px;
  opacity: 0.85;
}
.topbar-actions { display: flex; }

.icon-btn, .text-btn, .outline-btn, .fill-btn, .hold-btn, .chip {
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.icon-btn {
  background: none;
  border: 0;
  width: 44px;
  height: 44px;
  border-radius: 22px;
  color: var(--mist);
}
.icon-btn:disabled { opacity: 0.4; cursor: default; }
.icon-btn:active { background: rgba(255,255,255,0.08); }

.pulse {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #888;
  flex-shrink: 0;
}
.pulse.green { background: var(--live); }
.pulse.amber { background: var(--amber); }
.pulse.red { background: var(--stuck); }
.pulse.gray { background: #888; }

.video-pane {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #000;
  overflow: hidden;
}
.video-pane.frozen-bg { background: var(--stuck); }
.video-fit {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}
#live-video {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  background: #000;
  transform-origin: center center;
}

.connect-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  pointer-events: none;
}
.connect-overlay .outline-btn { pointer-events: auto; }
.connect-overlay[hidden], [hidden] { display: none !important; }

.frozen-banner {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  background: var(--stuck);
  color: #fff;
  font-weight: 700;
  font-size: 22px;
  text-align: center;
  padding: 10px 8px;
  letter-spacing: 0.04em;
  z-index: 5;
}

.overlay-panel {
  position: absolute;
  z-index: 4;
  background: rgba(0,0,0,0.62);
  border: 1px solid rgba(232,240,233,0.35);
  border-radius: 10px;
  padding: 8px 10px;
  min-width: 140px;
}
.overlay-panel h2 {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.panel-strong { margin: 0; font-weight: 600; font-size: 14px; }
.panel-dim { margin: 4px 0 0; font-size: 12px; opacity: 0.85; }
.network-card { top: 12px; left: 12px; }
.motion-card { top: 12px; right: 12px; width: 180px; }
.motion-card input[type="range"] { width: 100%; margin: 6px 0 0; }
.meter {
  position: relative;
  height: 8px;
  border-radius: 4px;
  background: rgba(232,240,233,0.2);
  overflow: hidden;
  margin-top: 6px;
}
.meter-fill { height: 100%; width: 0%; background: var(--live); }
.meter-mark {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #fff;
}

.action-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background: rgba(0,0,0,0.45);
}
.hold-btn {
  position: relative;
  overflow: hidden;
  height: 56px;
  border: 0;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  touch-action: none;
}
.hold-btn.danger { background: var(--danger); }
.hold-btn.water { background: var(--water); }
.hold-btn:disabled { opacity: 0.4; cursor: default; }
.hold-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  pointer-events: none;
}
.hold-btn.danger .hold-fill { background: var(--danger-fill); }
.hold-btn.water .hold-fill { background: var(--water-fill); }
.hold-label { position: relative; z-index: 1; }
.hold-btn.busy .hold-label { visibility: hidden; }
.hold-btn .spinner { position: absolute; inset: 0; margin: auto; }

.zone-canvas {
  position: absolute;
  inset: 0;
  z-index: 6;
  width: 100%;
  height: 100%;
  touch-action: none;
}
.zone-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 7;
  background: rgba(0,0,0,0.7);
  padding: 12px;
}
.zone-bar p { margin: 0 0 8px; font-size: 13px; }
.zone-actions { display: flex; gap: 8px; margin-top: 8px; }
.zone-actions > * { flex: 1; }

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  border: 1px solid rgba(232,240,233,0.35);
  background: transparent;
  color: var(--mist);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
}
.chip.selected {
  background: var(--moss);
  border-color: var(--moss);
  color: #fff;
}
.chip-approach.selected { background: var(--amber); color: #000; border-color: var(--amber); }
.chip-inside.selected { background: var(--live); color: #000; border-color: var(--live); }

.outline-btn, .fill-btn, .text-btn {
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 600;
}
.outline-btn {
  background: transparent;
  border: 1px solid rgba(232,240,233,0.55);
  color: var(--mist);
}
.fill-btn {
  background: var(--moss);
  border: 0;
  color: #fff;
}
.text-btn {
  background: none;
  border: 0;
  color: var(--mist);
}
.wide { width: 100%; }

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(232,240,233,0.25);
  border-top-color: var(--mist);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.spinner.small { width: 22px; height: 22px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

.recordings-screen { background: #000; }
.recordings-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  line-height: 1.4;
}
.recordings-list {
  flex: 1;
  overflow: auto;
  padding: 12px;
}
.recording-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
}
.recording-row .meta { flex: 1; min-width: 0; }
.recording-row h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}
.recording-row p {
  margin: 2px 0 0;
  font-size: 12px;
  opacity: 0.75;
}
.recording-row .icon-btn { color: var(--mist); }
.recording-row .icon-btn.delete { color: #ef9a9a; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 20;
}
.dialog {
  background: #2b2b2b;
  color: #eee;
  border-radius: 16px;
  width: min(520px, 100%);
  max-height: min(92vh, 820px);
  display: flex;
  flex-direction: column;
  padding: 18px 18px 12px;
}
.dialog h2 { margin: 0 0 12px; font-size: 22px; }
.dialog-body {
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 4px;
}
.dialog label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: #bbb;
}
.dialog input[type="text"],
.dialog input[type="password"] {
  background: #1a1a1a;
  border: 1px solid #555;
  border-radius: 6px;
  color: #fff;
  padding: 10px;
  font: inherit;
}
.dialog h3 { margin: 8px 0 0; font-size: 16px; }
.hint { margin: 0; font-size: 12px; color: #aaa; line-height: 1.35; }
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 12px;
}
.switch-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.switch-row .hint { flex: 1; }
.switch { position: relative; width: 46px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute;
  inset: 0;
  background: #555;
  border-radius: 13px;
  transition: 0.15s;
}
.switch span::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.15s;
}
.switch input:checked + span { background: var(--moss); }
.switch input:checked + span::after { transform: translateX(20px); }

.playback-dialog video {
  width: 100%;
  background: #000;
  border-radius: 8px;
  aspect-ratio: 4 / 3;
}

.snackbar {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #323232;
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  z-index: 30;
  max-width: 90%;
}

input[type="range"] {
  accent-color: var(--moss);
}

@media (min-width: 720px) {
  .app { max-width: 480px; margin: 0 auto; box-shadow: 0 0 0 1px #111; }
}
