:root {
  --bg: #0d1014; --panel: #151a21; --panel-2: #1b222b; --line: #262f3a;
  --accent: #3d8bfd; --ok: #2fbf71; --bad: #e5534b; --muted: #8b96a5;
}
html, body { height: 100%; }
body { background: var(--bg); font-size: 14px; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at top, #1a2533 0%, var(--bg) 60%); }
.login-card { width: 340px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 32px; }
.brand-lg { font-size: 1.5rem; font-weight: 700; }
.brand-lg i, .brand i { color: var(--accent); }

/* Shell */
.app { height: 100vh; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 24px; padding: 6px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.topbar .nav-link { padding: 5px 12px; font-size: 13.5px; }
.body { flex: 1; display: flex; min-height: 0; }
.sidebar { width: 270px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.view { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: auto; }
.toolbar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel-2); flex-wrap: wrap; }

/* Tree */
.tree { overflow-y: auto; flex: 1; padding: 4px 0; }
.site-h { display: flex; align-items: center; gap: 6px; padding: 7px 10px; cursor: pointer; font-weight: 600; user-select: none; }
.site-h:hover { background: var(--panel-2); }
.site-h .chev { transition: transform .15s; color: var(--muted); }
.site-h.closed .chev { transform: rotate(-90deg); }
.site-h .cnt { margin-left: auto; font-size: 11.5px; color: var(--muted); font-weight: 400; }
.site-h .play-site { font-size: 12px; padding: 0 6px; border: 0; background: none; color: var(--muted); }
.site-h .play-site:hover { color: var(--accent); }
.cam { display: flex; align-items: center; gap: 8px; padding: 5px 10px 5px 28px; cursor: pointer; font-size: 13px; }
.cam:hover { background: var(--panel-2); }
.cam.sel { background: rgba(61,139,253,.18); }
.cam .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cam .dv { margin-left: auto; font-size: 11px; color: var(--muted); white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: #5b6573; }
.dot.on { background: var(--ok); box-shadow: 0 0 6px rgba(47,191,113,.6); }
.dot.off { background: var(--bad); }

/* Live grid */
.grid { flex: 1; display: grid; gap: 3px; padding: 3px; background: #000; min-height: 0; }
.grid.n1 { grid-template: 1fr / 1fr; }
.grid.n4 { grid-template: repeat(2, 1fr) / repeat(2, 1fr); }
.grid.n9 { grid-template: repeat(3, 1fr) / repeat(3, 1fr); }
.grid.n16 { grid-template: repeat(4, 1fr) / repeat(4, 1fr); }
.tile { position: relative; background: #0a0c0f; border: 1px solid #1a1f26; overflow: hidden; min-height: 0; }
.tile.active { border-color: var(--accent); }
.tile.drop { border-color: var(--ok); background: #0f1a12; }
.tile video { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
.tile-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #4a5361; font-size: 13px; pointer-events: none; }
.tile-bar { position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: center; gap: 6px; padding: 4px 6px;
  background: linear-gradient(rgba(0,0,0,.75), rgba(0,0,0,0)); font-size: 12px; opacity: 1; transition: opacity .2s; }
.tile:not(:hover) .tile-actions { opacity: 0; }
.tile-name { font-weight: 600; text-shadow: 0 1px 2px #000; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tile-actions { margin-left: auto; display: flex; gap: 2px; transition: opacity .2s; }
.tile-actions button { border: 0; background: rgba(0,0,0,.55); color: #dfe6ee; border-radius: 4px; padding: 1px 6px; font-size: 12px; }
.tile-actions button:hover { background: var(--accent); }
.q-badge { font-size: 10px; padding: 1px 4px; border-radius: 3px; background: rgba(255,255,255,.15); }
.tile-msg { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); text-align: center; max-width: 85%;
  font-size: 12.5px; color: #c9d1db; background: rgba(0,0,0,.6); padding: 8px 12px; border-radius: 6px; }
.tile-msg.err { color: #ffb4ae; }
.tile:fullscreen { border: 0; }

/* Playback */
.timeline-wrap { padding: 10px 14px 0; background: var(--panel-2); border-bottom: 1px solid var(--line); }
.timeline { position: relative; height: 34px; background: #0b0e12; border: 1px solid var(--line); border-radius: 4px; cursor: crosshair; overflow: hidden; }
.tl-seg { position: absolute; top: 0; bottom: 0; background: linear-gradient(#2f7de1, #2463b8); }
.tl-pos { position: absolute; top: -2px; bottom: -2px; width: 2px; background: #ffcc33; box-shadow: 0 0 4px #ffcc33; pointer-events: none; }
.tl-sel { position: absolute; top: 0; bottom: 0; background: rgba(47,191,113,.28); border-left: 1px solid var(--ok); border-right: 1px solid var(--ok); pointer-events: none; }
.tl-hover { position: absolute; top: 0; bottom: 0; width: 1px; background: rgba(255,255,255,.5); pointer-events: none; }
.tl-tip { position: absolute; top: 2px; font-size: 11px; background: #000; padding: 0 4px; border-radius: 3px; pointer-events: none; transform: translateX(-50%); }
.tl-hint { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; }
.tl-ticks { position: relative; height: 18px; font-size: 10.5px; color: var(--muted); }
.tl-ticks span { position: absolute; transform: translateX(-50%); top: 2px; }
.pb-stage { flex: 1; position: relative; background: #000; min-height: 240px; }
.pb-stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.pb-controls { display: flex; flex-wrap: wrap; gap: 18px; align-items: center; padding: 10px 14px; background: var(--panel-2); border-top: 1px solid var(--line); }
.pb-clock { font-family: ui-monospace, Consolas, monospace; font-size: 1.05rem; color: #ffcc33; }

/* Admin */
.admin-body .card { background: var(--panel); border-color: var(--line); }
.admin-body table { font-size: 13px; }
.admin-body .table > :not(caption) > * > * { background: transparent; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
.status-pill { font-size: 11.5px; padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.status-pill.on { background: rgba(47,191,113,.15); color: var(--ok); }
.status-pill.off { background: rgba(229,83,75,.15); color: var(--bad); }
.status-pill.unk { background: rgba(139,150,165,.15); color: var(--muted); }
.inline-input { background: transparent; border: 1px solid transparent; color: inherit; padding: 2px 6px; border-radius: 4px; width: 100%; }
.inline-input:hover, .inline-input:focus { border-color: var(--line); background: var(--bg); outline: none; }

@media (max-width: 800px) {
  .sidebar { width: 200px; }
  .topbar { gap: 10px; flex-wrap: wrap; }
  #statusSummary { display: none; }
}
