:root {
  color-scheme: dark;
  --bg: #111315;
  --panel: #1b1f22;
  --panel-soft: #242a2f;
  --text: #edf2f4;
  --muted: #9aa7ad;
  --accent: #4fb477;
  --border: #374047;
  --danger: #e56b6f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app {
  width: min(1120px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 20px 0;
  display: grid;
  gap: 14px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto minmax(118px, auto) minmax(74px, auto);
  gap: 10px;
  align-items: center;
}

.auth-panel {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) minmax(140px, 1fr) auto auto minmax(118px, auto);
  gap: 10px;
  align-items: center;
}

.auth-panel[hidden] {
  display: none;
}

.vod-panel {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.url-input,
.auth-input,
.policy-select,
.timeline-scale,
button {
  height: 40px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font: inherit;
}

.url-input,
.auth-input,
.policy-select,
.timeline-scale {
  min-width: 0;
  padding: 0 12px;
  background: var(--panel);
  color: var(--text);
}

.policy-select {
  width: 96px;
}

.timeline-scrubber {
  position: relative;
  min-width: 0;
  height: 58px;
  border-radius: 4px;
  background: #161a1d;
  border: 1px solid rgba(255, 255, 255, 0.07);
  cursor: grab;
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

.timeline-scrubber:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.timeline-scrubber.is-dragging {
  cursor: grabbing;
}

.timeline-scrubber.is-disabled {
  cursor: default;
  opacity: 0.62;
}

.timeline-canvas {
  display: block;
  width: 100%;
  height: 58px;
}

.timeline-controls {
  display: grid;
  grid-template-columns: auto auto auto auto auto auto auto auto auto minmax(180px, 1fr) minmax(118px, auto);
  gap: 10px;
  align-items: center;
}

.timeline-scale {
  width: 94px;
}

.timeline-selected {
  min-width: 180px;
  color: var(--text);
  font: 13px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-align: center;
  white-space: nowrap;
}

.live-button {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
}

.snapshot-button {
  min-width: 64px;
}

.live-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 180, 119, 0.15);
}

.ptz-panel {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  justify-content: flex-end;
}

.motion-controls,
.privacy-controls {
  width: 150px;
  min-height: 32px;
  padding: 5px 7px 7px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: #171c1f;
}

.motion-controls summary,
.privacy-controls summary {
  cursor: pointer;
  color: var(--text);
  font-size: 12px;
  font-weight: 650;
  line-height: 20px;
  list-style-position: inside;
}

.motion-toggle,
.motion-sensitivity,
.privacy-toggle {
  display: grid;
  gap: 4px;
  margin-top: 7px;
  color: var(--muted);
  font-size: 11px;
}

.motion-toggle,
.privacy-toggle {
  grid-template-columns: auto 1fr;
  align-items: center;
}

.motion-sensitivity input {
  width: 100%;
}

.motion-apply,
.privacy-button {
  width: 42px;
  height: 26px;
  min-height: 26px;
  margin-top: 7px;
  padding: 0 8px;
  border-radius: 5px;
  font-size: 12px;
}

.motion-status,
.privacy-status {
  margin-left: 6px;
  color: var(--muted);
  font-size: 11px;
}

.privacy-region-select {
  width: 100%;
  height: 28px;
  margin-top: 7px;
  padding: 0 6px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font: 12px/1 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.privacy-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.privacy-actions .privacy-button {
  width: 100%;
  padding: 0 5px;
}

.ptz-pad {
  display: grid;
  grid-template-columns: repeat(3, 34px);
  gap: 4px;
}

.ptz-zoom {
  display: grid;
  grid-template-columns: repeat(2, 38px);
  gap: 4px;
}

.ptz-side-controls {
  display: grid;
  gap: 8px;
  align-self: start;
}

.ptz-side-top {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.ptz-speed {
  display: grid;
  width: 92px;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
}

.ptz-speed input {
  width: 100%;
}

.ir-controls {
  display: grid;
  grid-template-columns: auto 66px 38px 38px minmax(28px, auto);
  justify-content: end;
  gap: 4px 6px;
  align-items: center;
}

.talkback-volume-controls {
  display: grid;
  grid-template-columns: 1fr 38px 38px;
  justify-content: end;
  gap: 4px 6px;
  align-items: center;
  width: 214px;
}

.talkback-volume-row {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 6px;
  align-items: center;
  color: var(--muted);
  font-size: 11px;
}

.talkback-volume-row span {
  display: inline-flex;
  justify-content: space-between;
  gap: 4px;
  white-space: nowrap;
}

.talkback-volume-row input {
  width: 100%;
  min-width: 0;
}

.talkback-volume-apply,
.talkback-volume-get {
  height: 28px;
  padding: 0 7px;
  border-radius: 5px;
  font-size: 12px;
}

.lte-controls {
  display: grid;
  grid-template-columns: 38px 48px 62px;
  justify-content: end;
  gap: 4px 6px;
  align-items: center;
}

.preset-controls {
  display: grid;
  grid-template-columns: 86px 30px 80px 38px 42px;
  justify-content: end;
  gap: 4px;
  align-items: center;
}

.preset-select,
.preset-id,
.preset-name {
  min-width: 0;
  height: 28px;
  padding: 0 6px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font: 12px/1 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.preset-button {
  height: 28px;
  padding: 0 7px;
  border-radius: 5px;
  font-size: 12px;
}

.preset-danger {
  border-color: #7e3b3b;
  color: #ffd8d8;
}

.preset-status {
  grid-column: 1 / -1;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ir-label,
.ir-status,
.talkback-volume-status,
.lte-data-usage-status {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
}

.ir-select {
  min-width: 0;
  width: 66px;
  height: 28px;
  padding: 0 6px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font: 12px/1 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.ir-apply,
.ir-get {
  height: 28px;
  padding: 0 7px;
  border-radius: 5px;
  font-size: 12px;
}

.lte-data-usage,
.lte-data-usage-reset {
  height: 28px;
  padding: 0 7px;
  border-radius: 5px;
  font-size: 12px;
}

.lte-data-usage-reset {
  background: #20272b;
  border-color: var(--border);
  color: var(--text);
}

.lte-data-usage-status {
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lens-calibrate {
  justify-self: end;
  width: 114px;
  height: 28px;
  padding: 0 8px;
  border-radius: 5px;
  background: #20272b;
  border-color: var(--border);
  color: var(--text);
  font-size: 12px;
  font-weight: 650;
}

.ir-status {
  display: none;
}

.ptz-button {
  width: 34px;
  height: 32px;
  padding: 0;
  border-color: var(--border);
  background: var(--panel-soft);
  color: var(--text);
  font-size: 16px;
  line-height: 1;
  touch-action: none;
}

.ptz-zoom .ptz-button {
  width: 38px;
}

.ptz-button.is-active,
.ptz-button:active {
  background: var(--accent);
  border-color: var(--accent);
  color: #07110b;
}

.ptz-button:disabled {
  opacity: 0.42;
}

.ptz-stop {
  color: var(--danger);
}

button {
  padding: 0 16px;
  background: var(--accent);
  border-color: var(--accent);
  color: #07110b;
  font-weight: 700;
  cursor: pointer;
}

button:disabled {
  cursor: default;
  opacity: 0.55;
}

.status {
  min-width: 118px;
  color: var(--muted);
  font-size: 14px;
  text-align: right;
}

.wan-status {
  min-width: 74px;
  color: var(--muted);
  font: 13px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-align: right;
  white-space: nowrap;
}

.wan-status.is-lte {
  color: #8ed7ff;
}

.wan-status.is-wifi {
  color: #ffd37a;
}

.wan-status.is-ether {
  color: #9ee6b8;
}

.video-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #050607;
  border: 1px solid var(--border);
  overflow: hidden;
}

video {
  width: 100%;
  height: 100%;
  display: block;
  background: #050607;
}

.motion-grid-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  background: rgba(10, 10, 10, 0.14);
  touch-action: none;
  user-select: none;
  cursor: crosshair;
  z-index: 2;
}

.motion-grid-overlay[hidden] {
  display: none;
}

.privacy-mask-overlay {
  position: absolute;
  inset: 0;
  background: rgba(5, 6, 7, 0.08);
  cursor: crosshair;
  touch-action: none;
  user-select: none;
  z-index: 2;
}

.privacy-mask-overlay[hidden] {
  display: none;
}

.privacy-mask-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.privacy-mask-region {
  fill: rgba(0, 0, 0, 0.58);
  stroke: rgba(255, 180, 76, 0.95);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
}

.privacy-mask-region.is-selected {
  stroke: rgba(255, 255, 255, 0.96);
  stroke-width: 3;
  filter: drop-shadow(0 0 3px rgba(255, 152, 45, 0.9));
}

.privacy-mask-draft {
  fill: rgba(255, 152, 45, 0.22);
  stroke: rgba(255, 236, 204, 0.96);
  stroke-width: 2;
  stroke-dasharray: 5 4;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.privacy-mask-point,
.privacy-mask-draft-point {
  position: absolute;
  width: 9px;
  height: 9px;
  border: 1px solid rgba(0, 0, 0, 0.88);
  border-radius: 999px;
  background: #ffb44c;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.22);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.privacy-mask-point {
  background: #ffffff;
  pointer-events: auto;
}

.privacy-mask-point-0,
.privacy-mask-point-2 {
  cursor: nwse-resize;
}

.privacy-mask-point-1,
.privacy-mask-point-3 {
  cursor: nesw-resize;
}

.motion-grid-cell {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border-radius: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.24);
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  border-left: 0;
  border-top: 0;
  background: rgba(128, 136, 140, 0.34);
  cursor: crosshair;
}

.motion-grid-cell.is-active {
  background: rgba(255, 152, 45, 0.46);
}

.motion-grid-cell.is-edited {
  outline: 1px solid rgba(255, 236, 204, 0.82);
  outline-offset: -1px;
}

.fullscreen-button {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 3;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 5px;
  background: rgba(17, 19, 21, 0.78);
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.24);
  font-size: 19px;
  line-height: 1;
}

.unmute-button {
  min-width: 82px;
}

.unmute-button.is-on {
  background: rgba(79, 180, 119, 0.86);
  border-color: rgba(79, 180, 119, 0.95);
  color: #07110b;
}

.ptt-button.is-on {
  background: rgba(237, 145, 43, 0.9);
  border-color: rgba(237, 145, 43, 0.95);
  color: #130b03;
}

.debug-panel {
  min-height: 220px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.stats-panel {
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.stats-log {
  min-height: 82px;
  padding: 10px;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  color: var(--text);
}

.debug-log {
  height: 260px;
  overflow: auto;
  padding: 10px;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

.entry {
  padding: 7px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.entry.rx {
  color: #b7d7ff;
}

.entry.tx {
  color: #b7f7cf;
}

.entry.info {
  color: var(--muted);
}

.entry.error {
  color: var(--danger);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.68);
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  width: min(420px, 100%);
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
}

.modal h2 {
  margin: 0 0 10px;
  font-size: 20px;
}

.modal p {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.6;
}

.mp4-modal {
  width: min(720px, calc(100vw - 28px));
}

.mp4-range {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-top: 12px;
}

.mp4-range label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.mp4-range input {
  min-width: 0;
  height: 34px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  background: #111518;
}

.mp4-status {
  min-height: 20px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.mp4-results {
  max-height: min(360px, 45vh);
  margin-top: 10px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #111518;
}

.mp4-empty {
  padding: 16px;
  color: var(--muted);
  font-size: 13px;
}

.mp4-file {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 9px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.mp4-file:last-child {
  border-bottom: 0;
}

.mp4-file-main {
  min-width: 0;
}

.mp4-file-name {
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mp4-file-time {
  margin-top: 3px;
  color: var(--muted);
  font: 11px/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.mp4-file-size {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.mp4-progress {
  grid-column: 1 / -1;
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: #20282c;
}

.mp4-progress span {
  display: block;
  width: 0%;
  height: 100%;
  background: var(--accent);
}

.mp4-progress.is-indeterminate span {
  width: 35%;
  animation: mp4-indeterminate 1.1s ease-in-out infinite;
}

@keyframes mp4-indeterminate {
  0% {
    transform: translateX(-120%);
  }
  50% {
    transform: translateX(120%);
  }
  100% {
    transform: translateX(-120%);
  }
}

.mp4-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 12px;
}

@media (max-width: 720px) {
  .toolbar {
    grid-template-columns: 1fr;
  }

  .timeline-controls {
    grid-template-columns: 1fr;
  }

  .mp4-range {
    grid-template-columns: 1fr;
  }

  .timeline-selected {
    text-align: left;
  }

  .status {
    text-align: left;
  }

  .ptz-panel {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .motion-controls {
    width: 100%;
  }
}
