:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #2a2f3a;
  --text: #e7e9ee;
  --muted: #9aa2b1;
  --accent: #3d8bfd;
  --accent-2: #2f6fd0;
  --ok: #2fbf71;
  --warn: #f0b429;
  --bad: #ef5350;
  --cone: rgba(61, 139, 253, .22);
  --cone-line: rgba(61, 139, 253, .65);
  --radius: 10px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-weight: 600; margin: 0 0 12px; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- шапка ---------- */
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 10px 18px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.topbar .brand { font-weight: 650; color: var(--text); font-size: 16px; white-space: nowrap; }
.topbar .brand .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent); margin-right: 8px; vertical-align: 1px; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; }
.topbar nav a { color: var(--muted); padding: 6px 10px; border-radius: 8px; }
.topbar nav a:hover, .topbar nav a.active { color: var(--text); background: var(--panel-2); text-decoration: none; }
.topbar .who { color: var(--muted); font-size: 13px; white-space: nowrap; }

/* ---------- кнопки и поля ---------- */
button, .btn {
  font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 13px; cursor: pointer; line-height: 1.2; display: inline-flex;
  align-items: center; gap: 6px; white-space: nowrap;
}
button:hover, .btn:hover { border-color: #3a4150; text-decoration: none; }
button:disabled { opacity: .5; cursor: default; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-2); }
button.danger { color: #ffb4b0; border-color: #5a2a2a; }
button.ghost { background: transparent; border-color: transparent; }
button.small { padding: 4px 9px; font-size: 13px; }
button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: transparent; }
.seg button.on { background: var(--accent); }

input, select, textarea {
  font: inherit; color: var(--text); background: #0c0e12; border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
label { display: block; margin: 0 0 12px; }
label > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
label.check { display: flex; align-items: center; gap: 8px; }
label.check > span { display: inline; margin: 0; color: var(--text); font-size: 15px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.msg { padding: 10px 12px; border-radius: 8px; margin: 0 0 12px; font-size: 14px; }
.msg.err { background: #3a1d1d; color: #ffc9c5; }
.msg.ok { background: #183325; color: #b9f0d0; }
.msg.info { background: #1b2740; color: #c8dafc; }

.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.badge.ok { color: #b9f0d0; border-color: #2a5a41; }
.badge.bad { color: #ffc9c5; border-color: #6a3030; }
.badge.warn { color: #ffe3a3; border-color: #6b5520; }

/* ---------- вход ---------- */
.auth-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.auth-box { width: 100%; max-width: 380px; }
.auth-box h1 { margin-bottom: 4px; }
.auth-box .sub { color: var(--muted); margin-bottom: 20px; }
.auth-box button.primary { width: 100%; justify-content: center; padding: 10px; margin-top: 4px; }
.qr { background: #fff; border-radius: 8px; padding: 8px; width: 200px; height: 200px; display: block; margin: 8px auto 12px; }
.secret { font-family: ui-monospace, Menlo, Consolas, monospace; word-break: break-all; font-size: 13px;
  background: #0c0e12; padding: 8px; border-radius: 6px; text-align: center; }

/* ---------- схема ---------- */
.page { padding: 18px; max-width: 1600px; margin: 0 auto; }
.plan-wrap { position: relative; width: 100%; margin: 0 auto; user-select: none; }
.plan-wrap > img.plan-img { display: block; width: 100%; height: auto; border-radius: var(--radius); }
.plan-wrap > svg.cones { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.plan-empty { aspect-ratio: 16/9; background: repeating-linear-gradient(45deg, #151820, #151820 12px, #181c25 12px, #181c25 24px);
  border: 1px dashed var(--line); border-radius: var(--radius); }
.cam-rect {
  position: absolute; border: 2px solid var(--accent); border-radius: 6px; overflow: hidden;
  background: #000; cursor: pointer; box-shadow: 0 4px 16px rgba(0,0,0,.5);
  transition: transform .12s ease, box-shadow .12s ease;
}
.cam-rect:hover { transform: scale(1.03); box-shadow: 0 8px 26px rgba(0,0,0,.6); z-index: 5; }
.cam-rect img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-rect .label {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 3px 6px; font-size: 12px;
  background: linear-gradient(transparent, rgba(0,0,0,.85)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cam-rect .dir {
  position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%;
  background: rgba(0,0,0,.65); display: grid; place-items: center;
}
.cam-rect .dir svg { width: 14px; height: 14px; }
.cam-rect .age { position: absolute; top: 4px; left: 4px; font-size: 11px; padding: 1px 5px; border-radius: 4px;
  background: rgba(0,0,0,.65); color: #ddd; }
.cam-rect .noimg { width: 100%; height: 100%; display: grid; place-items: center; color: var(--muted); font-size: 12px; }

.cam-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; margin-top: 16px; }
.cam-card { position: relative; aspect-ratio: 16/9; }
.cam-card .cam-rect { position: absolute; inset: 0; }

/* ---------- просмотр ---------- */
body.viewer { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.wall { flex: 1; display: grid; gap: 4px; padding: 4px; min-height: 0; background: #000; }
.tile { position: relative; background: #000; min-height: 0; min-width: 0; overflow: hidden; border-radius: 4px; }
.tile video { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
.tile .t-top { position: absolute; top: 0; left: 0; right: 0; display: flex; gap: 6px; align-items: center;
  padding: 6px 8px; background: linear-gradient(rgba(0,0,0,.75), transparent); font-size: 13px; }
.tile .t-top .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .t-top button { padding: 3px 7px; font-size: 13px; background: rgba(20,20,20,.6); border-color: rgba(255,255,255,.15); }
.tile .overlay { position: absolute; inset: 0; display: grid; place-items: center; color: #cfd3db; font-size: 14px;
  background: rgba(0,0,0,.55); text-align: center; padding: 10px; pointer-events: none; }
.tile .live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--bad); box-shadow: 0 0 6px var(--bad); }
.tile .tstamp { position: absolute; bottom: 6px; right: 8px; font-size: 12px; background: rgba(0,0,0,.6);
  padding: 1px 6px; border-radius: 4px; font-variant-numeric: tabular-nums; }

.controls { background: var(--panel); border-top: 1px solid var(--line); padding: 8px 12px; }
.controls .row { gap: 8px; }
.controls .clock { font-variant-numeric: tabular-nums; font-size: 17px; font-weight: 600; min-width: 170px; }
.controls input[type=date], .controls input[type=time] { width: auto; padding: 5px 8px; }
.controls select { width: auto; padding: 5px 8px; }
.timeline { position: relative; height: 64px; margin-top: 8px; cursor: grab; touch-action: none; }
.timeline:active { cursor: grabbing; }
.timeline canvas { width: 100%; height: 100%; display: block; border-radius: 6px; }
.sel-info { font-size: 13px; color: var(--muted); }

/* ---------- админка ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { background: transparent; border: 0; border-bottom: 2px solid transparent; border-radius: 0; padding: 10px 14px; color: var(--muted); }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); background: transparent; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
tr:hover td { background: rgba(255,255,255,.02); }
.table-wrap { overflow-x: auto; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.cam-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px 14px;
  max-height: 260px; overflow: auto; padding: 8px; border: 1px solid var(--line); border-radius: 8px; }
.cam-checks label { margin: 0; }
.bar { height: 10px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.bar > div { height: 100%; background: var(--accent); }
.bar.warn > div { background: var(--warn); } .bar.bad > div { background: var(--bad); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 14px; }
.kv > div:nth-child(odd) { color: var(--muted); }
.events { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; max-height: 360px; overflow: auto; }
.events div { padding: 3px 0; border-bottom: 1px solid #1d212a; }
.events .error { color: #ffb4b0; } .events .warn { color: #ffe3a3; }

/* редактор схемы */
.editor { display: grid; grid-template-columns: 1fr 300px; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .editor { grid-template-columns: 1fr; } }
.editor .cam-rect { cursor: move; }
.editor .cam-rect.sel { border-color: var(--warn); box-shadow: 0 0 0 2px var(--warn); }
.editor .cam-rect:hover { transform: none; }
.handle { position: absolute; width: 14px; height: 14px; right: -2px; bottom: -2px; background: var(--warn);
  cursor: nwse-resize; border-radius: 3px; }
.rot-handle { position: absolute; width: 16px; height: 16px; border-radius: 50%; background: var(--warn);
  border: 2px solid #000; cursor: grab; z-index: 6; transform: translate(-50%, -50%); }

/* модалка */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal { width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; }
.modal h2 { margin-bottom: 16px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }

.toast { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast div { background: var(--panel-2); border: 1px solid var(--line); padding: 10px 14px; border-radius: 8px;
  max-width: 380px; box-shadow: 0 6px 20px rgba(0,0,0,.5); }
.toast .err { border-color: #6a3030; } .toast .ok { border-color: #2a5a41; }

@media (max-width: 700px) {
  .topbar { padding: 8px 10px; gap: 8px; flex-wrap: wrap; }
  .topbar .who { display: none; }
  .page { padding: 10px; }
  .controls .clock { min-width: 0; font-size: 15px; }
}
