:root {
  --bg: #0f1115;
  --panel: #181b22;
  --panel2: #222631;
  --line: #2c313d;
  --text: #e6e8ec;
  --muted: #8b93a3;
  --accent: #3d8bfd;
  --ok: #2fbf71;
  --rec: #2fbf71;
  --err: #ef5350;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, select, input { font: inherit; color: var(--text); background: var(--panel2);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; }
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.link { background: none; border: none; color: var(--muted); }
button.link:hover { color: var(--text); }
code { background: var(--panel2); padding: 2px 6px; border-radius: 4px; }
.spacer { flex: 1; }

/* Шапка */
.top { display: flex; align-items: center; gap: 16px; padding: 8px 16px;
  background: var(--panel); border-bottom: 1px solid var(--line); height: 52px; }
.brand { font-weight: 600; white-space: nowrap; }
.brand::first-letter { color: var(--err); }
.top nav { display: flex; gap: 4px; }
.top nav a { color: var(--muted); text-decoration: none; padding: 6px 12px; border-radius: 6px; }
.top nav a.active, .top nav a:hover { color: var(--text); background: var(--panel2); }
.tool { color: var(--muted); display: flex; align-items: center; gap: 6px; }
main { height: calc(100% - 52px); }
.login-page main { height: 100%; }

/* Вход */
.login-box { width: 320px; margin: 12vh auto 0; background: var(--panel); padding: 28px;
  border-radius: 10px; border: 1px solid var(--line); display: flex; flex-direction: column; gap: 14px; }
.login-box h1 { margin: 0 0 6px; font-size: 20px; }
.login-box label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); }
.login-box input { padding: 9px 10px; }
.login-box .error { color: var(--err); }

/* Сетка камер */
.grid { --cols: 3; display: grid; grid-template-columns: repeat(var(--cols), 1fr);
  gap: 4px; padding: 4px; height: 100%; grid-auto-rows: 1fr; }
.focused .grid { display: none; }
.tile { position: relative; background: #000; border-radius: 4px; overflow: hidden; cursor: pointer; min-height: 120px; }
.tile video { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
.tile-bar { position: absolute; left: 0; right: 0; bottom: 0; display: flex; gap: 8px; align-items: center;
  padding: 4px 8px; background: linear-gradient(transparent, rgba(0,0,0,.75)); font-size: 13px; }
.tile-bar .name { font-weight: 600; text-shadow: 0 1px 2px #000; }
.tile-tools { position: absolute; top: 6px; right: 6px; display: none; gap: 4px; }
.tile:hover .tile-tools { display: flex; }
.tile-tools button { padding: 2px 7px; background: rgba(0,0,0,.6); }
.tile:hover { outline: 2px solid var(--accent); }

.state { font-size: 12px; color: var(--muted); }
.state.error { color: var(--err); }
.state.live::before { content: "● онлайн"; color: var(--ok); }

/* Одна камера крупно */
.focus { display: flex; flex-direction: column; height: 100%; }
.focus[hidden] { display: none; }
.focus-head { display: flex; align-items: center; gap: 8px; padding: 6px 10px;
  background: var(--panel); border-bottom: 1px solid var(--line); }
.focus-video { flex: 1; background: #000; min-height: 0; }
.focus-video video { width: 100%; height: 100%; object-fit: contain; display: block; }

.empty { padding: 40px; text-align: center; color: var(--muted); line-height: 2; }

/* Архив */
.archive { display: flex; flex-direction: column; gap: 8px; padding: 10px; height: 100%; }
.archive-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.archive-controls select { min-width: 200px; }
.timeline { position: relative; height: 46px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 6px; cursor: pointer; user-select: none; flex: none; }
.timeline .segments { position: absolute; left: 0; right: 0; top: 6px; height: 18px; }
.timeline .seg { position: absolute; top: 0; height: 100%; background: var(--rec); opacity: .8; border-radius: 2px; }
.timeline .cursor { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--err); pointer-events: none; }
.timeline .hover { position: absolute; top: -22px; transform: translateX(-50%); background: var(--panel2);
  padding: 1px 6px; border-radius: 4px; font-size: 12px; pointer-events: none; white-space: nowrap; }
.timeline .ticks { position: absolute; left: 0; right: 0; bottom: 2px; height: 16px; pointer-events: none; }
.timeline .ticks span { position: absolute; bottom: 0; transform: translateX(-50%); font-size: 11px;
  color: var(--muted); border-left: 1px solid var(--line); padding-left: 2px; height: 100%; }
.timeline .ticks span.minor { height: 5px; top: 0; }
.info { color: var(--muted); font-size: 13px; min-height: 18px; }
.archive-video { position: relative; flex: 1; background: #000; border-radius: 6px; overflow: hidden; min-height: 240px; }
.archive-video video { width: 100%; height: 100%; object-fit: contain; display: block; }
.archive-video .overlay { position: absolute; top: 8px; left: 10px; display: flex; gap: 12px; align-items: center; }
.archive-video .clock { font-variant-numeric: tabular-nums; font-size: 15px; font-weight: 600;
  background: rgba(0,0,0,.55); padding: 2px 8px; border-radius: 4px; }
.archive-video .clock:empty { display: none; }

@media (max-width: 720px) {
  .grid { --cols: 1 !important; height: auto; grid-auto-rows: 56vw; }
  .top { gap: 8px; padding: 6px 8px; }
  .brand, .tool { display: none; }
  main { height: auto; min-height: calc(100% - 52px); }
  .archive-video { min-height: 56vw; }
}
