/* Видеонаб — интерфейс оператора.
   Тёмная схема не декоративная: пост охраны работает в затемнённом
   помещении круглосуточно, и светлый фон рядом с видеоокнами утомляет
   глаза и мешает различать детали в тёмных сценах. */

/* Палитра общая с остальными изделиями КВВАСЮ (СКУД): пост оператора
   и проходная должны выглядеть одной системой, а не двумя разными. */
:root {
  --bg:        #0f1419;
  --bg-panel:  #1a2129;
  --bg-raised: #222b35;
  --bg-hover:  #2d3845;
  --line:      #2d3845;
  --text:      #e6edf3;
  --text-dim:  #8b98a5;
  --accent:    #2f81f7;
  --ok:        #2ea043;
  --warn:      #d29922;
  --alarm:     #f85149;
  --rec:       #f85149;
  --gold:      #d8b45a;

  --topbar-h:  48px;
  --sidebar-w: 260px;
  --alarms-w:  300px;
}

/* Фирменная надпись «КВВАСЮ» — рукописный шрифт бренда. Файла шрифта
   в поставке нет, поэтому подхватывается системный рукописный. */
@font-face {
  font-family: 'Saint Amour Script';
  src: url('fonts/SaintAmourScript.woff2') format('woff2'),
       url('fonts/SaintAmourScript.woff') format('woff');
  font-display: swap;
}
.kv-brand {
  font-family: 'Saint Amour Script', 'Segoe Script', 'Brush Script MT', cursive;
  text-transform: uppercase; letter-spacing: 1px; color: var(--text);
}

* { box-sizing: border-box; }

/* Атрибут hidden задаёт display:none лишь стилями браузера, а любое
   авторское правило с display его перебивает. Ниже такие правила есть
   почти у каждого переключаемого блока — экранов входа, разделов,
   модального окна, — поэтому скрытие перестало бы работать. Это
   объявление возвращает атрибуту его смысл. */
[hidden] { display: none !important; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 14px/1.45 "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
}

button, input, select { font: inherit; color: inherit; }

/* --- кнопки --- */

.btn-primary, .btn-ghost {
  border: 1px solid var(--line); border-radius: 4px;
  background: var(--bg-raised); padding: 6px 12px; cursor: pointer;
  transition: background .12s, border-color .12s;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-ghost:hover { background: var(--bg-hover); }
.btn-small { padding: 2px 7px; font-size: 12px; }
/* Необратимые действия должны выглядеть необратимыми, а не как
   соседняя кнопка «Правка». */
.btn-ghost.danger { color: var(--alarm); border-color: rgba(248,81,73,.45); }
.btn-ghost.danger:hover { background: var(--alarm); color: #fff; border-color: var(--alarm); }
button:disabled { opacity: .45; cursor: default; }

input[type=text], input[type=password], input[type=search],
input[type=datetime-local], input[type=number], select, textarea {
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 4px; padding: 6px 9px; width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
}

/* --- вход --- */

.login-screen {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: var(--bg); z-index: 100;
}
.login-box {
  width: 340px; padding: 28px; background: var(--bg-panel);
  border: 1px solid var(--line); border-radius: 14px;
}
.login-logo { display: block; width: 160px; margin: 0 auto 10px; }
.login-box h1 { margin: 0; font-size: 24px; letter-spacing: .5px; text-align: center; }
.login-sub { margin: 4px 0 22px; color: var(--text-dim); font-size: 13px; text-align: center; }
.login-box label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--text-dim); }
.login-box input { margin-top: 5px; }
.login-box .btn-primary { width: 100%; margin-top: 6px; padding: 9px; }
.login-error {
  background: rgba(248,81,73,.14); border: 1px solid var(--alarm);
  color: #ffb3ae; border-radius: 4px; padding: 8px 10px;
  margin-bottom: 14px; font-size: 13px;
}

/* --- каркас --- */

.app { display: flex; flex-direction: column; height: 100%; }

.topbar {
  height: var(--topbar-h); flex: none; display: flex; align-items: center;
  gap: 18px; padding: 0 14px; background: var(--bg-panel);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 600; letter-spacing: .6px; display: flex; align-items: center; gap: 8px; }
/* Монограмма тонкая: на рекомендованных бренд-книгой 22px она сливается
   в штрих, поэтому в шапке (48px) даём 28px. */
.brand-mark { height: 28px; display: block; }

/* Подпись правообладателя в шапке — ведёт к окну контактов. */
.contacts-link { text-decoration: none; font-size: 13px; }
.contacts-link .kv-brand { font-size: 1.45em; vertical-align: -2px; }
.contacts-link:hover .kv-brand { color: var(--gold); }

/* Подвал экранов входа. */
#brand-footer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 101;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: rgba(15,20,25,.92); border-top: 1px solid var(--line);
  backdrop-filter: blur(6px);
  padding: 8px 18px; text-align: center; font-size: 12px; color: var(--text-dim);
}
#brand-footer .brand-mark { height: 22px; }
#brand-footer .kv-brand { font-size: 1.5em; vertical-align: -2px; padding: 0 2px; }
#brand-footer .copy { font-size: 1.25em; vertical-align: -1px; }
#brand-footer a { color: var(--accent); text-decoration: none; margin-left: 6px; }
#brand-footer a:hover { text-decoration: underline; }
/* В рабочем режиме подвал не нужен: место отдаётся окнам камер. */
body.in-app #brand-footer { display: none; }

/* Страница состояния узла: плитки показателей и полосы заполнения. */
.health-row { display: flex; gap: 10px; flex-wrap: wrap; }
.health-tile {
  flex: 1 1 130px; background: var(--bg-raised); border: 1px solid var(--line);
  border-radius: 6px; padding: 10px 12px;
}
.health-value { font-size: 22px; font-variant-numeric: tabular-nums; }
.health-label { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
/* Цветом помечаем только то, что требует внимания: раскрашенная
   целиком страница перестаёт что-либо выделять. */
.health-tile.ok    .health-value { color: var(--ok); }
.health-tile.warn  .health-value { color: var(--warn); }
.health-tile.alarm .health-value { color: var(--alarm); }

/* Плитка, за которой прячется список, должна выглядеть нажимаемой:
   иначе о том, что по числу можно щёлкнуть, никто не узнает. */
.health-tile.clickable { cursor: pointer; }
.health-tile.clickable:hover { border-color: var(--accent); }
.health-tile.clickable .health-label::after { content: ' ▸'; }

.cam-detail { margin-top: 10px; }
.cam-detail:empty { margin-top: 0; }
.cam-detail-title { font-size: 12px; color: var(--text-dim); margin-bottom: 4px; }

.bar {
  display: inline-block; width: 120px; height: 8px; vertical-align: middle;
  background: var(--bg); border: 1px solid var(--line); border-radius: 4px;
  overflow: hidden;
}
.bar-fill { display: block; height: 100%; background: var(--ok); }
.bar-fill.warn { background: var(--warn); }
.bar-fill.alarm { background: var(--alarm); }

/* Ключ второго фактора: вводится вручную, поэтому крупно, моноширинно
   и с разрядкой — так его труднее прочитать с ошибкой. */
.totp-secret {
  display: inline-block; margin: 6px 0; padding: 8px 12px;
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: 4px;
  font-family: ui-monospace, Consolas, monospace; font-size: 16px;
  letter-spacing: 2px; user-select: all;
}

/* Привязка второго фактора: слева QR-код, справа шаги. На узком экране
   колонки складываются одна под другую. */
.totp-setup { display: flex; gap: 20px; flex-wrap: wrap; align-items: flex-start; }
.totp-setup .totp-steps { flex: 1 1 320px; min-width: 280px; }
.totp-setup ol { margin: 0; padding-left: 20px; }
.totp-setup li { margin-bottom: 10px; }
/* Белая подложка обязательна: код читается по контрасту, а на тёмной
   теме прозрачный SVG слился бы с фоном панели. */
.totp-qr {
  flex: 0 0 auto; background: #fff; padding: 8px; border-radius: 4px;
  border: 1px solid var(--line); line-height: 0;
}
.totp-qr img { width: 200px; height: 200px; display: block; }

/* Всплывающее меню по правому щелчку. */
.ctx-menu {
  position: fixed; z-index: 300; min-width: 170px;
  background: var(--bg-panel); border: 1px solid var(--line);
  border-radius: 6px; padding: 4px; box-shadow: 0 8px 24px rgba(0,0,0,.55);
}
.ctx-title {
  padding: 4px 10px 6px; font-size: 11px; color: var(--text-dim);
  border-bottom: 1px solid var(--line); margin-bottom: 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ctx-item {
  display: block; width: 100%; text-align: left; border: none;
  background: none; color: var(--text); padding: 6px 10px;
  border-radius: 4px; cursor: pointer; font-size: 13px;
}
.ctx-item:hover { background: var(--bg-hover); }
.ctx-item.danger { color: var(--alarm); }
.ctx-item.danger:hover { background: var(--alarm); color: #fff; }

/* Контакты — всплывающее окно. */
.contacts-popover {
  position: fixed; right: 16px; bottom: 46px; z-index: 200;
  background: var(--bg-panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 16px 18px; text-align: left; width: 320px; max-width: calc(100vw - 32px);
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
body.in-app .contacts-popover { top: calc(var(--topbar-h) + 8px); bottom: auto; }
.contacts-logo { display: block; width: 150px; margin: 0 auto 10px; }
.contacts-row { font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }
.contacts-row a { color: var(--accent); text-decoration: none; }
.contacts-row a:hover { text-decoration: underline; }
.contacts-close {
  position: absolute; top: 6px; right: 8px; background: none; border: none;
  color: var(--text-dim); cursor: pointer; font-size: 14px; line-height: 1;
}
.contacts-close:hover { color: var(--text); }

.tabs { display: flex; gap: 2px; }
.tab {
  background: none; border: none; padding: 6px 14px; cursor: pointer;
  color: var(--text-dim); border-radius: 4px;
}
.tab:hover { background: var(--bg-hover); color: var(--text); }
.tab.active { background: var(--bg-raised); color: var(--text); }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user-name { color: var(--text-dim); font-size: 13px; }

.conn-state {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--text-dim); transition: background .2s;
}
.conn-state.online { background: var(--ok); }
.conn-state.offline { background: var(--alarm); }

.alarm-indicator {
  background: var(--alarm); color: #fff; border-radius: 10px;
  padding: 1px 9px; font-size: 12px; font-weight: 600;
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: .55; } }
@media (prefers-reduced-motion: reduce) {
  .alarm-indicator { animation: none; }
}

.body { flex: 1; display: flex; min-height: 0; }

/* --- дерево камер --- */

.sidebar {
  width: var(--sidebar-w); flex: none; background: var(--bg-panel);
  border-right: 1px solid var(--line); display: flex; flex-direction: column;
}
.sidebar-head {
  padding: 8px; border-bottom: 1px solid var(--line);
  display: flex; gap: 6px; align-items: center;
}
.sidebar-head #camera-filter { flex: 1; }
.camera-tree { flex: 1; overflow-y: auto; padding: 4px 0; }

.tree-group {
  padding: 7px 12px 4px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .7px; color: var(--text-dim);
}
/* Папка группы: сворачивается, принимает перетаскивание камер. */
.tree-group.folder {
  display: flex; align-items: center; gap: 6px; cursor: pointer;
  text-transform: none; letter-spacing: normal; font-size: 12px;
  padding: 6px 10px; user-select: none;
}
.tree-group.folder:hover { background: var(--bg-hover); }
.tree-group.folder.drop-target { background: #16273d; outline: 1px dashed var(--accent); outline-offset: -2px; }
.tree-group .caret { width: 10px; color: var(--text-dim); }
.tree-group .folder-name {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text);
}
.tree-group .folder-actions { display: none; gap: 2px; }
.tree-group.folder:hover .folder-actions { display: flex; }
.tree-group .folder-actions button {
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  padding: 0 4px; font-size: 12px; border-radius: 3px;
}
.tree-group .folder-actions button:hover { background: var(--bg-raised); color: var(--text); }

.tree-item {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 12px 5px 24px; cursor: pointer; user-select: none;
}
.tree-item:hover { background: var(--bg-hover); }
/* Выделенная камера отмечается и щелчком по окну на стене, поэтому
   подсветка должна читаться сразу: на сотне строк оттенок серого
   рядом с наведением не различить. */
.tree-item.selected {
  background: rgba(76, 141, 255, .16);
  box-shadow: inset 2px 0 0 var(--accent);
}
.tree-item.selected .name { color: #fff; }
.tree-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Переименование камеры — по наведению, как у папок. */
.tree-item .item-actions { display: none; }
.tree-item:hover .item-actions { display: flex; }
.tree-item .item-actions button {
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  padding: 0 4px; font-size: 12px; border-radius: 3px;
}
.tree-item .item-actions button:hover { background: var(--bg-raised); color: var(--text); }

.state-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--text-dim); }
.state-dot.online { background: var(--ok); }
.state-dot.offline { background: var(--alarm); }

.rec-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--rec); flex: none; }

/* --- рабочая область --- */

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.toolbar {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: var(--bg-panel);
  border-bottom: 1px solid var(--line);
}
.toolbar select, .toolbar input { width: auto; }
.toolbar-spacer { flex: 1; }
.toolbar-sep { width: 1px; height: 22px; background: var(--line); }
.hint { color: var(--text-dim); font-size: 12px; }
/* Итог проверки пути должен читаться как ответ «годится / не годится»,
   а не сливаться с обычной подсказкой. */
.hint.ok { color: var(--ok); }
.hint.error { color: var(--alarm); }
.check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-dim); }
.check input { width: auto; }

.layout-picker { display: flex; gap: 2px; }
.layout-picker button {
  width: 32px; height: 30px; border: 1px solid var(--line);
  background: var(--bg-raised); border-radius: 4px; cursor: pointer;
}
.layout-picker button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* --- сетка окон --- */

.grid {
  flex: 1; min-height: 0; display: grid; gap: 2px; padding: 2px;
  background: #0b0f13;
}

/* Стена во весь экран (Ctrl+Shift+A): остаются только окна камер.
   Панели убираются целиком, а не сжимаются, — на посту дорог каждый
   пиксель изображения. Уведомления не прячем: сообщение о тревоге
   оператор должен увидеть и здесь. */
body.wall-mode .topbar,
body.wall-mode .sidebar,
body.wall-mode .alarms,
body.wall-mode #view-live .toolbar { display: none; }
body.wall-mode .grid { padding: 0; gap: 1px; }
.cell {
  position: relative; background: #000; overflow: hidden;
  border: 1px solid transparent; min-height: 0;
}
.cell.selected { border-color: var(--accent); }
.cell.empty { background: #131a21; display: grid; place-items: center; }
.cell.empty::after {
  content: "Перетащите камеру"; color: #4a5563; font-size: 12px;
}
.cell.drop-target { border-color: var(--accent); background: #16273d; }
/* Окно с камерой можно тянуть в другое окно; перетаскиваемое — приглушаем. */
.cell:not(.empty) { cursor: grab; }
.cell.dragging { opacity: 0.45; cursor: grabbing; }

.cell video,
.cell-snapshot {
  width: 100%; height: 100%; object-fit: contain;
  background: #000; display: block;
}
/* Снимок лежит в том же месте, что и видео: показывается одно из двух. */
.cell-snapshot { position: absolute; inset: 0; }

.cell-overlay {
  position: absolute; left: 0; right: 0; top: 0;
  display: flex; align-items: center; gap: 7px;
  padding: 5px 8px; font-size: 12px;
  background: linear-gradient(rgba(0,0,0,.72), rgba(0,0,0,0));
  pointer-events: none;
}
.cell-overlay .cam-name {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  text-shadow: 0 1px 3px #000;
}
.cell-overlay .badge {
  background: rgba(0,0,0,.55); border-radius: 3px; padding: 0 5px;
  font-size: 11px; color: var(--text-dim);
}
.cell-overlay .badge.rec { background: var(--rec); color: #fff; }
.cell-overlay .badge.motion { background: var(--warn); color: #000; }
.cell-overlay .badge.snapshot { background: #3a6ea5; color: #fff; }
/* Серверное время поверх кадра. Отступ справа уводит метку из-под
   кнопки закрытия и значка архива, всплывающих в углу при наведении. */
.cell-clock {
  margin-left: auto; margin-right: 26px;
  font-variant-numeric: tabular-nums; font-size: 12px;
  color: #fff; text-shadow: 0 1px 3px #000; white-space: nowrap;
}

.cell-status {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--text-dim); font-size: 13px; text-align: center; padding: 12px;
}
.cell-status.error { color: #ffb3ae; }

.cell-close {
  position: absolute; top: 4px; right: 4px; z-index: 2;
  width: 20px; height: 20px; border: none; border-radius: 3px;
  background: rgba(0,0,0,.55); color: var(--text-dim); cursor: pointer;
  opacity: 0; transition: opacity .12s;
}
.cell:hover .cell-close { opacity: 1; }
.cell-close:hover { background: var(--alarm); color: #fff; }

/* Управление поворотом поверх окна */
.ptz-pad {
  position: absolute; right: 10px; bottom: 10px; z-index: 3;
  display: grid; grid-template-columns: repeat(3, 30px); grid-auto-rows: 30px;
  gap: 2px; opacity: 0; transition: opacity .15s;
}
.cell:hover .ptz-pad { opacity: 1; }
.ptz-pad button {
  border: 1px solid var(--line); background: rgba(20,23,28,.85);
  border-radius: 3px; cursor: pointer; font-size: 13px;
}
.ptz-pad button:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.ptz-zoom { position: absolute; right: 106px; bottom: 10px; z-index: 3;
  display: flex; flex-direction: column; gap: 2px; opacity: 0; transition: opacity .15s; }
.cell:hover .ptz-zoom { opacity: 1; }
.ptz-zoom button {
  width: 30px; height: 30px; border: 1px solid var(--line);
  background: rgba(20,23,28,.85); border-radius: 3px; cursor: pointer;
}

/* Пресеты PTZ — ряд кнопок снизу слева, показываются при наведении. */
.ptz-presets {
  position: absolute; left: 10px; bottom: 10px; z-index: 3;
  display: flex; flex-wrap: wrap; gap: 3px; max-width: 55%;
  opacity: 0; transition: opacity .15s;
}
.cell:hover .ptz-presets { opacity: 1; }
.ptz-presets button {
  border: 1px solid var(--line); background: rgba(20,23,28,.85);
  border-radius: 3px; cursor: pointer; font-size: 11px; padding: 2px 7px; color: var(--text);
}
.ptz-presets button:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Цифровое увеличение: масштаб и панорама картинки внутри окна. */
.cell video, .cell .cell-snapshot {
  transform: translate(var(--panx, 0), var(--pany, 0)) scale(var(--zoom, 1));
  transform-origin: center center;
}
.cell.zoomed { cursor: move; }

/* Угловые значки окна — показываются при наведении. */
.cell-icons { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
.cell-corner {
  position: absolute; display: flex; gap: 3px;
  opacity: 0; transition: opacity .15s; pointer-events: auto;
}
.cell:hover .cell-corner { opacity: 1; }
.cell-corner.tr { top: 6px; right: 6px; }
.cell-corner.bl { left: 6px; bottom: 6px; }
.cell-icon {
  width: 24px; height: 24px; border: 1px solid var(--line);
  background: rgba(20,23,28,.82); color: var(--text); border-radius: 3px;
  cursor: pointer; font-size: 14px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.cell-icon:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.cell-icon.ic-arch.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Переключатель потока нужен только в развёрнутом окне: в сетке всегда
   дополнительный поток, и выбора там нет. */
.cell-icon.ic-stream { display: none; width: auto; padding: 0 7px; font-size: 11px; }
.cell.fullscreen .cell-icon.ic-stream { display: flex; }
.cell-icon.ic-stream.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Звук с микрофона камеры. Включённый звук помечаем заметно: оператор
   должен видеть, какое окно сейчас звучит. */
.cell-icon.ic-audio.on { background: var(--ok); border-color: var(--ok); color: #fff; }

/* Панель управления архивом внизу окна: сверху шкала времени с полосами
   записей, снизу — органы управления. */
.cell-archbar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; flex-direction: column; gap: 4px; padding: 6px 8px 5px;
  background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,.85));
}
.cell-archctl { display: flex; align-items: center; gap: 6px; }
.cell-archbar button, .cell-archbar select {
  background: rgba(20,23,28,.9); color: var(--text); border: 1px solid var(--line);
  border-radius: 3px; cursor: pointer; font-size: 12px; padding: 2px 6px;
}
.cell-archbar .arch-live { color: var(--rec); font-weight: 700; }
.cell-archbar .arch-time {
  font-size: 12px; color: var(--text); font-variant-numeric: tabular-nums;
  min-width: 62px; text-align: right; margin-left: auto;
}

/* Шкала: полотно с записями и подписи часов под ним. */
.cell-archline-box { position: relative; overflow: hidden; }
.cell-archline {
  display: block; width: 100%; height: 22px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 2px;
}
.cell-archlabels { position: relative; height: 13px; }
.cell-archlabels span {
  position: absolute; top: 0; transform: translateX(-50%);
  font-size: 10px; color: var(--text-dim); font-variant-numeric: tabular-nums;
  white-space: nowrap; pointer-events: none;
}
/* В мелких окнах шкала съедает картинку — оставляем только управление. */
.cell.small .cell-archline-box { display: none; }

/* --- архив (мультикамерный, как у регистраторов) --- */

.archive-time { font-variant-numeric: tabular-nums; color: var(--text-dim); }

/* Сетка окон архива. */
.arch-grid {
  flex: 1; min-height: 0; display: grid; gap: 2px; padding: 2px; background: #0b0f13;
}
.arch-cell {
  position: relative; background: #000; overflow: hidden; min-height: 0;
  border: 1px solid transparent;
}
.arch-cell.focused { border-color: var(--accent); }
.arch-cell.drop-target { border-color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); }
.arch-cell video { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
.arch-cell.empty video { display: none; }
.arch-cell-overlay {
  position: absolute; left: 0; right: 0; top: 0; padding: 4px 8px; font-size: 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: linear-gradient(rgba(0,0,0,.7), rgba(0,0,0,0)); pointer-events: none;
  text-shadow: 0 1px 3px #000;
}
.arch-cell-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.arch-cell-clock { font-variant-numeric: tabular-nums; white-space: nowrap; color: #fff; }
.arch-cell-empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); font-size: 13px; text-align: center; padding: 10px;
}
.arch-cell:not(.empty) .arch-cell-empty { display: none; }
.arch-cell.unsupported::after {
  content: 'H.265 — браузер не проигрывает (десктоп играет)';
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #ffb3ae; font-size: 12px; text-align: center; padding: 12px; background: rgba(0,0,0,.4);
}

/* Низ: календарь слева, дорожки времени справа. */
.arch-bottom {
  flex: none; display: flex; gap: 10px; background: var(--bg-panel);
  border-top: 1px solid var(--line); padding: 8px 12px 10px;
}
.arch-calendar { flex: none; width: 210px; }
.arch-timelines { flex: 1; min-width: 0; }

/* Линейка времени над дорожками. Ширины подобраны так, чтобы полотно
   линейки начиналось и заканчивалось ровно там же, где полотна дорожек:
   иначе метка времени под линейкой не совпала бы с записью под ней. */
.timeline-axis {
  display: flex; align-items: stretch; margin-bottom: 3px;
  font-variant-numeric: tabular-nums;
}

.axis-nav {
  flex: none; width: 24px; padding: 0; cursor: pointer;
  background: var(--bg-raised); border: 1px solid var(--line);
  border-radius: 3px; color: var(--text-dim); font-size: 14px; line-height: 1;
}
.axis-nav:hover { background: var(--bg-hover); color: var(--text); }
.axis-ruler {
  flex: 1; min-width: 0; height: 30px; display: block; cursor: crosshair;
}
.arch-lanes { display: flex; flex-direction: column; gap: 2px; }
/* Отступы равны ширине стрелок линейки: так полотно дорожки начинается
   и заканчивается ровно под полотном линейки, и метка времени совпадает
   с записью под ней. */
.arch-lane { display: flex; align-items: center; padding: 0 24px; }
/* Имя камеры на дорожке не дублируем: оно написано в самом окне,
   а место лучше отдать шкале. */
.arch-lane-label { display: none; }
.arch-lane canvas {
  flex: 1; min-width: 0; height: 26px; display: block; cursor: crosshair;
  border: 1px solid var(--line); border-radius: 2px;
}
.arch-legend {
  display: flex; align-items: center; gap: 14px; margin-top: 6px;
  font-size: 11px; color: var(--text-dim);
}
.arch-legend .lg { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.arch-legend .lg-cont { background: #3fbf6f; }
.arch-legend .lg-motion { background: #e0a53a; }

/* Календарь. */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 5px; font-size: 12px; }
.cal-head button {
  border: 1px solid var(--line); background: var(--bg-raised); color: var(--text);
  border-radius: 3px; cursor: pointer; width: 22px; height: 22px;
}
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-wd { text-align: center; font-size: 10px; color: var(--text-dim); padding-bottom: 2px; }
.cal-day {
  position: relative; text-align: center; font-size: 11px; padding: 4px 0; cursor: pointer;
  border-radius: 3px; color: var(--text);
}
.cal-day:hover { background: var(--bg-hover); }
.cal-day.selected { background: var(--accent); color: #fff; }
.cal-day.today { outline: 1px solid var(--accent); }
.cal-dot { position: absolute; left: 50%; bottom: 1px; transform: translateX(-50%); width: 5px; height: 5px; border-radius: 50%; }
.cal-dot.cont { background: #3fbf6f; }
.cal-dot.motion { background: #e0a53a; }

/* --- журнал --- */

.events-table-wrap { flex: 1; overflow: auto; }
.events-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.events-table th {
  position: sticky; top: 0; z-index: 1; text-align: left;
  padding: 8px 12px; background: var(--bg-panel);
  border-bottom: 1px solid var(--line); font-weight: 500; color: var(--text-dim);
}
.events-table td { padding: 6px 12px; border-bottom: 1px solid #23282f; }
.events-table tr:hover td { background: var(--bg-panel); }
.events-table .time { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--text-dim); }

.sev { padding: 1px 8px; border-radius: 3px; font-size: 11px; white-space: nowrap; }
.sev.debug   { background: #2a2f38; color: var(--text-dim); }
.sev.info    { background: #24313f; color: #9fc4ea; }
.sev.warning { background: #3a3220; color: #e8c47c; }
.sev.alarm   { background: #3d2222; color: #ffb3ae; }

.row-unacked td { background: rgba(248,81,73,.06); }

/* --- лента тревог --- */

.alarms {
  width: var(--alarms-w); flex: none; background: var(--bg-panel);
  border-left: 1px solid var(--line); display: flex; flex-direction: column;
}

/* Язычок сворачивания боковой панели — по образцу привычных операторам
   систем. Узкая полоса во всю высоту: в свёрнутом виде она остаётся
   единственным следом панели, и вернуть ленту можно одним щелчком. */
.panel-toggle {
  flex: none; width: 12px; padding: 0; cursor: pointer;
  background: var(--bg-panel); border: none;
  border-left: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim);
}
.panel-toggle:hover { background: var(--bg-hover); color: var(--text); }
.panel-toggle-arrow { font-size: 14px; line-height: 1; }
/* Стрелка показывает, куда уедет панель: вправо — спрятать, влево — вернуть. */
body.alarms-hidden .panel-toggle-arrow { transform: none; }
body:not(.alarms-hidden) .panel-toggle-arrow { transform: rotate(180deg); }
body.alarms-hidden .alarms { display: none; }
/* Пока есть неподтверждённые тревоги, свёрнутый язычок подсвечен:
   иначе за спрятанной лентой события уходили бы незамеченными. */
body.alarms-hidden .panel-toggle.has-alarms {
  background: var(--alarm); color: #fff;
}
.alarms-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; border-bottom: 1px solid var(--line);
  font-size: 12px; color: var(--text-dim);
}
.alarms-list { flex: 1; overflow-y: auto; }
.alarm-item {
  padding: 7px 12px; border-bottom: 1px solid #23282f;
  cursor: pointer; font-size: 13px;
}
.alarm-item:hover { background: var(--bg-hover); }
.alarm-item .meta {
  display: flex; gap: 8px; align-items: center;
  font-size: 11px; color: var(--text-dim); margin-bottom: 2px;
}
.alarm-item.alarm { border-left: 3px solid var(--alarm); }
.alarm-item.warning { border-left: 3px solid var(--warn); }

/* --- план объекта --- */

.map-wrap {
  flex: 1; min-height: 0; overflow: auto; background: #0b0f13;
  display: grid; place-items: center; padding: 12px; position: relative;
}
.map-stage { position: relative; max-width: 100%; max-height: 100%; }
.map-stage img { display: block; max-width: 100%; max-height: calc(100vh - 200px); }
.map-markers { position: absolute; inset: 0; }
.map-empty { position: absolute; color: var(--text-dim); text-align: center; padding: 20px; }

.map-marker {
  position: absolute; transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  cursor: pointer;
}
.map-marker-dot {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid #fff; box-shadow: 0 0 5px rgba(0,0,0,.8);
  background: var(--text-dim);
}
.map-marker.online .map-marker-dot { background: var(--ok); }
.map-marker.offline .map-marker-dot { background: var(--alarm); }
/* Сработавший детектор должен быть виден на плане сразу: ради этого
   план и открывают при тревоге. */
.map-marker.motion .map-marker-dot {
  background: var(--warn);
  box-shadow: 0 0 0 5px rgba(224,165,58,.35);
  animation: pulse 1.2s ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce) {
  .map-marker.motion .map-marker-dot { animation: none; }
}
.map-marker-label {
  font-size: 11px; background: rgba(13,15,18,.82); padding: 1px 5px;
  border-radius: 3px; white-space: nowrap; pointer-events: none;
}

/* --- настройка --- */

.setup-body { flex: 1; overflow-y: auto; padding: 14px; }
.cam-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.cam-table th {
  text-align: left; padding: 8px 12px; color: var(--text-dim);
  font-weight: 500; border-bottom: 1px solid var(--line);
}
.cam-table td { padding: 7px 12px; border-bottom: 1px solid #23282f; }
.cam-table tr:hover td { background: var(--bg-panel); }

.form-row { display: flex; gap: 12px; margin-bottom: 12px; }
.form-row > label { flex: 1; font-size: 13px; color: var(--text-dim); }
.form-row input, .form-row select { margin-top: 4px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
fieldset {
  border: 1px solid var(--line); border-radius: 5px;
  padding: 12px; margin: 0 0 14px;
}
legend { padding: 0 6px; color: var(--text-dim); font-size: 12px; }

/* --- модальное окно --- */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: grid; place-items: center; z-index: 200;
}
.modal {
  width: min(720px, 92vw); max-height: 86vh; display: flex; flex-direction: column;
  background: var(--bg-panel); border: 1px solid var(--line); border-radius: 8px;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 500;
}
.modal-body { padding: 16px; overflow-y: auto; }

/* --- уведомления --- */

.toasts {
  position: fixed; right: 16px; bottom: 16px; z-index: 300;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--bg-raised); border: 1px solid var(--line);
  border-left-width: 3px; border-radius: 5px;
  padding: 9px 14px; font-size: 13px; max-width: 380px;
  animation: slide-in .18s ease-out;
}
.toast.error { border-left-color: var(--alarm); }
.toast.ok { border-left-color: var(--ok); }
.toast.warn { border-left-color: var(--warn); }
@keyframes slide-in { from { transform: translateX(16px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; }
}

/* --- полноэкранный режим окна --- */

.cell.fullscreen {
  position: fixed; inset: 0; z-index: 150; border: none;
}

/* На узком экране боковые панели убираются: планшет дежурного
   не должен показывать три колонки на 900 точках. */
@media (max-width: 1100px) {
  .alarms { display: none; }
}
@media (max-width: 820px) {
  .sidebar { position: absolute; z-index: 50; height: calc(100% - var(--topbar-h)); }
  .sidebar:not(.open) { display: none; }
}

/* Итог обхода сети: короткий список, который читают взглядом. */
ul.summary {
  margin: 6px 0 0; padding-left: 18px; line-height: 1.7;
}
ul.summary li { color: var(--text); }

/* Строка результата обхода с подобранным паролем: такую камеру можно
   заводить не глядя. Подсветка слева полосой, а не заливкой всей строки —
   на полутора сотнях строк заливка режет глаза. */
.cam-table tr.pass-known td:first-child {
  box-shadow: inset 3px 0 0 var(--warn);
}
.cam-table tr.pass-known { background: rgba(224, 165, 58, .10); }
.cam-table tr.dimmed { opacity: .5; }

/* Форма роли: права и камеры сеткой, чтобы длинный список не тянулся
   в один столбец на весь экран. */
.perm-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2px 14px; margin-top: 4px;
}
/* Выбор камер по группам: группы стопкой, камеры внутри — с отступом. */
.scope-cams {
  max-height: 260px; overflow-y: auto; margin-top: 4px;
  border: 1px solid var(--line); border-radius: 4px; padding: 6px 8px;
}
.scope-group { margin-bottom: 8px; }
.scope-grouphead { position: sticky; top: -6px; background: var(--bg-panel); padding: 3px 0; z-index: 1; }
.scope-cam { padding-left: 24px; }
.check { cursor: pointer; }
.check input { margin-right: 6px; }

/* --- конструктор раскладки --- */
.layout-builder { width: min(560px, 88vw); }
.le-board {
  display: grid; gap: 3px; height: 380px; margin: 10px 0;
  background: #0d1b2e; padding: 3px; border: 1px solid var(--line);
  border-radius: 4px; user-select: none;
}
.le-cell {
  position: relative; background: #16324f; border: 1px solid #2f5c86;
  border-radius: 2px; cursor: pointer; display: flex;
  align-items: center; justify-content: center;
}
.le-cell:hover { background: #1d4066; }
.le-cell.merged { background: #274b73; border-color: var(--accent); }
.le-num { color: #9db8d6; font-size: 12px; pointer-events: none; }
.le-highlight {
  background: rgba(76,141,255,.30); border: 2px solid var(--accent);
  border-radius: 2px; pointer-events: none; z-index: 2;
}

/* Справка. Разделы идут в две колонки на широком экране: справочник
   листают глазами, а не прокруткой, и всё должно быть видно разом. */
.help-body {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  align-content: start;
}
.help-body fieldset { margin: 0; }

.help-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.help-table td {
  padding: 5px 8px; border-bottom: 1px solid #23282f; vertical-align: top;
}
.help-table tr:last-child td { border-bottom: none; }
/* Первый столбец — что нажать: узкий и не переносится посреди слова. */
.help-table td:first-child { width: 1%; white-space: nowrap; }
.help-act { color: var(--text-dim); }
.help-where { color: var(--text-dim); text-align: right; white-space: nowrap; }

kbd {
  display: inline-block; min-width: 20px; text-align: center;
  padding: 1px 6px; border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 4px; background: var(--bg-raised); color: var(--text);
  font: 12px/1.5 "Segoe UI", system-ui, sans-serif;
}

/* Метки в справке: в окне камеры они раскрашены правилами .cell-overlay,
   здесь нужен тот же вид без накладки. */
.help-table .badge {
  display: inline-block; border-radius: 3px; padding: 0 5px;
  font-size: 11px; background: rgba(0,0,0,.55); color: var(--text-dim);
}
.help-table .badge.rec { background: var(--rec); color: #fff; }
.help-table .badge.motion { background: var(--warn); color: #000; }
.help-table .badge.snapshot { background: #3a6ea5; color: #fff; }
