:root {
  --bg: #0e1116;
  --panel: #171b22;
  --panel-2: #1f242e;
  --line: #2a3038;
  --text: #e6e9ef;
  --muted: #8b95a5;
  --accent: #4aa3ff;
  --rec: #2f9e6a;
  --mot: #ff8c1a;
  --live: #e5484d;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
}
.hidden { display: none !important; }
button {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 12px; cursor: pointer; font-size: 13px;
}
button:hover { border-color: var(--accent); }
button.ghost { background: transparent; }
button.live { background: var(--live); border-color: var(--live); color: #fff; font-weight: 600; }
button.live.off { background: transparent; color: var(--live); }
input, select {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; font-size: 14px; width: 100%;
}
.muted { color: var(--muted); }
.spacer { flex: 1; }

/* ---------- логин ---------- */
.login-screen { height: 100%; display: flex; align-items: center; justify-content: center; }
.card {
  width: 320px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 24px; display: flex; flex-direction: column; gap: 12px;
}
.card h1 { margin: 0; font-size: 22px; letter-spacing: .5px; }
.card p { margin: 0 0 4px; }
.card button { padding: 10px; font-weight: 600; }
.error { color: #ff6b6b; min-height: 18px; font-size: 13px; }

/* ---------- каркас ---------- */
#app { height: 100%; display: flex; flex-direction: column; }
header {
  display: flex; align-items: center; gap: 12px; padding: 8px 14px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .5px; }
.status { color: var(--muted); font-size: 13px; }
main { flex: 1; overflow: auto; padding: 12px; }
footer#tl {
  background: var(--panel); border-top: 1px solid var(--line);
  padding: 6px 10px 8px; flex: 0 0 auto;
}
.tl-controls { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.tl-time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.legend { color: var(--muted); font-size: 12px; margin-right: 6px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin: 0 4px 0 8px; vertical-align: middle; }
.sw.rec { background: var(--rec); }
.sw.mot { background: var(--mot); }
#timeline { width: 100%; height: 108px; display: block; cursor: crosshair; }

/* ---------- сетка камер ---------- */
.grid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}
.tile {
  position: relative; background: #000; border: 1px solid var(--line);
  border-radius: 10px; overflow: hidden; aspect-ratio: 16 / 9; cursor: pointer;
}
.tile video { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
.tile .cap {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 6px 8px;
  background: linear-gradient(transparent, rgba(0,0,0,.8)); display: flex; gap: 8px;
  align-items: center; font-size: 12px; pointer-events: none;
}
.tile .dot { width: 8px; height: 8px; border-radius: 50%; background: #666; }
.tile .dot.on { background: var(--rec); }
.tile .dot.mot { background: var(--mot); }
.tile .res { color: var(--muted); }

/* ---------- страница камеры ---------- */
.cam-page { display: grid; grid-template-columns: 1fr 320px; gap: 12px; height: 100%; }
.cam-video {
  position: relative; background: #000; border: 1px solid var(--line);
  border-radius: 10px; overflow: hidden; min-height: 240px;
}
.cam-video video { width: 100%; height: 100%; object-fit: contain; display: block; }
.cam-video .hud { position: absolute; top: 8px; left: 8px; right: 8px; display: flex; gap: 6px; }
.cam-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; overflow: auto; }
.cam-panel h3 { margin: 0 0 10px; font-size: 15px; }
.field { margin-bottom: 10px; }
.field label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.row { display: flex; gap: 8px; align-items: center; }
.kv { display: grid; grid-template-columns: 96px 1fr; gap: 4px 8px; font-size: 13px; margin-bottom: 12px; }
.kv div:nth-child(odd) { color: var(--muted); }
.danger { border-color: #6b2b2b; color: #ff8080; }

/* ---------- модалка ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-box { width: min(720px, 92vw); max-height: 80vh; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--line); }
#modal-body { padding: 12px; overflow: auto; }
.found-row { display: grid; grid-template-columns: 130px 1fr 120px 90px; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.found-row .muted { font-size: 12px; }
