:root {
  --bg: #0f1419;
  --panel: #17212b;
  --panel-2: #1e2a36;
  --line: #2b3b4c;
  --text: #e8eef4;
  --muted: #8aa0b5;
  --accent: #3d9ee5;
  --ok: #3ecf8e;
  --warn: #e0a14a;
  --bad: #e05a5a;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", "Malgun Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.top h1 { margin: 0; font-size: 20px; letter-spacing: 0.04em; }
.sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.top-status { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--bad);
  display: inline-block;
}
.dot.on { background: var(--ok); }
.dot.off { background: var(--bad); }

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 300px;
  gap: 12px;
  padding: 12px;
  min-height: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  overflow: auto;
}
.panel h2 {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.cameras ul, .events { list-style: none; margin: 0; padding: 0; }
.cameras li, .events li {
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 6px;
  background: var(--panel-2);
  cursor: pointer;
}
.cameras li.active { outline: 1px solid var(--accent); }
.cameras .name { font-weight: 600; }
.cameras .meta { color: var(--muted); font-size: 12px; margin-top: 3px; }
.badge {
  display: inline-block;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #243444;
  color: var(--muted);
  margin-right: 4px;
}
.badge.ptz { color: var(--ok); }
.controls.is-disabled .pad { opacity: 0.55; pointer-events: none; }
#ptzHint.warn { color: var(--warn); }

.stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.video-wrap {
  position: relative;
  flex: 1;
  background: #000;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  min-height: 320px;
  touch-action: none;
}
.video-wrap.is-zoomed { cursor: grab; }
.video-wrap.is-dragging { cursor: grabbing; }
#live {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  transform-origin: center center;
  will-change: transform;
  user-select: none;
  pointer-events: none;
}
.zoom-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 4px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.55);
  color: var(--text);
  font-size: 12px;
  letter-spacing: 0.04em;
}
.zoom-badge.hidden { display: none; }
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  background: rgba(0,0,0,0.35);
}
.overlay.hidden { display: none; }
.stage-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
  flex-wrap: wrap;
}
select, input, button {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
.chk {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}
.chk input { accent-color: var(--accent); }

.pad {
  position: relative;
  width: 176px;
  height: 176px;
  margin: 10px 0 16px;
  border-radius: 50%;
  background: #070c10;
  box-shadow: inset 0 0 0 1px var(--line);
  overflow: hidden;
  flex-shrink: 0;
}
.pad .seg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0 !important;
  border-radius: 0;
  background: #2a3e52;
  color: #dbe6ef;
  font-size: 15px;
  line-height: 1;
  touch-action: none;
  user-select: none;
}
.pad .seg:hover {
  background: #37536d;
  border-color: transparent !important;
}
.pad .seg:active { background: #426482; }
.pad [data-action="up"] {
  clip-path: polygon(50% 50%, 0% 0%, 100% 0%);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 22px;
  background: #31485e;
}
.pad [data-action="right"] {
  clip-path: polygon(50% 50%, 100% 0%, 100% 100%);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 22px;
  background: #26384c;
}
.pad [data-action="down"] {
  clip-path: polygon(50% 50%, 100% 100%, 0% 100%);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 22px;
  background: #31485e;
}
.pad [data-action="left"] {
  clip-path: polygon(50% 50%, 0% 100%, 0% 0%);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding-left: 22px;
  background: #26384c;
}
.pad::before,
.pad::after {
  content: "";
  position: absolute;
  z-index: 1;
  pointer-events: none;
  left: 50%;
  top: 50%;
  width: 5px;
  height: 145%;
  background: #070c10;
  transform-origin: center;
}
.pad::before { transform: translate(-50%, -50%) rotate(45deg); }
.pad::after { transform: translate(-50%, -50%) rotate(-45deg); }
.pad .hub {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  width: 42px;
  height: 42px;
  margin: 0;
  padding: 0 !important;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 4px solid #070c10 !important;
  background: radial-gradient(circle at 34% 30%, #7ad0ff, var(--accent) 58%, #1f6ea8);
  box-shadow: 0 0 0 1px #15202a;
}
.pad .hub:hover {
  filter: brightness(1.1);
  border-color: #070c10 !important;
}
.pad .hub:active { transform: translate(-50%, -50%) scale(0.94); }
.zoom-row button {
  height: 48px;
  font-size: 16px;
}
.zoom-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  margin-bottom: 8px;
}

.mes-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}
.mes-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.events li { cursor: default; font-size: 12px; }
.events .type { color: var(--accent); }

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }
  .video-wrap { min-height: 420px; }
}
