:root {
  /* Ряды графиков: проверенная палитра (синий, оранжевый, бирюзовый) на фоне --panel. */
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --bg: #0f1115;
  --panel: #171a21;
  --line: #262b36;
  --text: #e6e8ee;
  --muted: #8a93a6;
  --accent: #3b82f6;
  --rec: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --empty: #0b0c10;
  color-scheme: dark;
}

/* Светлая тема: по настройке системы (если не выбрана тёмная) или выбранная вручную (☀/☾ в шапке). */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --line: #d9dee7;
  --text: #1b2230;
  --muted: #5f6b7d;
  --accent: #2563eb;
  --rec: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --empty: #e9edf3;
  color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --line: #d9dee7;
  --text: #1b2230;
  --muted: #5f6b7d;
  --accent: #2563eb;
  --rec: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --empty: #e9edf3;
  color-scheme: light;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  height: 52px;
  box-sizing: border-box;
  white-space: nowrap;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
/* Шапка — одной высоты на всех экранах: элементы не переносятся и не сжимаются, лишнее в «крошках» — многоточием. */
header > * { flex-shrink: 0; }
header > #crumbs { flex: 1 1 auto; min-width: 120px; overflow: hidden; display: flex; align-items: center; gap: 12px; }
/* Не помещаются показатели сервера — лишние уходят целиком (перенос на скрытую строку), а не обрезаются посередине. */
header > .rec-state { flex-shrink: 1; min-width: 60px; overflow: hidden; text-overflow: ellipsis; }
header > .sys-chips { flex: 0 1 auto; min-width: 0; flex-wrap: wrap; height: 18px; line-height: 18px; overflow: hidden; }

.brand { color: var(--text); font-weight: 600; text-decoration: none; }
.obj-switch { max-width: 14em; }
#crumbs { color: var(--muted); flex: 1; font-size: 13px; }
#crumbs a { color: var(--muted); }
#crumbs span { color: var(--text); }
.rec-state { color: var(--muted); font-size: 13px; }
.rec-state.ok { color: var(--rec); }
.rec-state.bad { color: var(--bad); }

main { padding: 12px 16px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 2px; /* плитки вплотную: между ними — тонкая линия фона */
}

.tile {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  overflow: hidden;
  cursor: pointer;
}

.tile video { width: 100%; height: 100%; object-fit: contain; display: block; }
.tile.off { opacity: .55; }

.tile .name {
  position: absolute;
  left: 8px;
  bottom: 6px;
  padding: 2px 6px;
  background: rgba(0, 0, 0, .6);
  border-radius: 4px;
  font-size: 13px;
}

.tile .dot {
  position: absolute;
  right: 8px;
  top: 8px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
}
.tile .dot.ok { background: var(--rec); }
.tile .dot.bad { background: var(--bad); }

.tile .msg, .player-msg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  color: var(--muted);
  text-align: center;
  padding: 16px;
}

.empty { color: var(--muted); }

.player {
  position: relative;
  background: #000;
  overflow: hidden;
  min-height: 160px;
  flex: 1 1 auto; /* видео — всё, что осталось от кнопок и шкалы: страница камеры без прокрутки */
}
/* Страница камеры — ровно в окно: шапка 52 px, отступы main 12 px сверху и снизу. */
#camera-view:not([hidden]) { display: flex; flex-direction: column; height: calc(100vh - 52px); box-sizing: border-box; }
#camera-view > :not(.player-row) { flex: none; }
/* Видео и панель аналитики — рядом: панель справа колонкой с прокруткой, видео — вся высота (рисовать зоны удобнее). */
.player-row { display: flex; gap: 8px; flex: 1 1 auto; min-height: 0; }
.player-row > .player { flex: 1 1 auto; min-width: 0; }
.player-row > .an-panel { flex: none; width: 340px; overflow-y: auto; margin: 0; }

.player video { width: 100%; height: 100%; object-fit: contain; display: block; }
/* Цифровой зум (app.js): видео и рамки аналитики увеличиваются вместе — от левого верхнего угла плеера. */
.player video, .player .an-canvas { transform-origin: 0 0; }
.player.zoomed { cursor: grab; }
.player.zoomed.panning { cursor: grabbing; }
.vzoom { pointer-events: auto; padding: 2px 8px; border-radius: 4px; border: 1px solid rgba(255, 255, 255, .45);
  background: rgba(0, 0, 0, .6); color: #fff; font: inherit; font-variant-numeric: tabular-nums; cursor: pointer; }

.overlay {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}

.badge, .clock {
  padding: 2px 8px;
  border-radius: 4px;
  background: rgba(0, 0, 0, .6);
  font-variant-numeric: tabular-nums;
}
.badge.live { background: var(--bad); }
.badge.archive { background: var(--accent); }

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin: 10px 0 6px;
}

button, input, select {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 5px 10px;
}
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
label { color: var(--muted); display: flex; gap: 6px; align-items: center; }
.hint { color: var(--muted); font-size: 12px; }
.hint.warn { color: var(--warn); }

/* Клавиатура: видимый фокус на кнопках, полях, ссылках (вкладки, плеер) — пост охраны работает без мыши. */
:is(button, input, select, textarea, a, summary):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Вкладки: отклик и без активной мыши. */
.tabs a:hover { color: var(--text); }

/* Плавность отключается по системной настройке (post с вестибулярной чувствительностью).
   Тревога остаётся заметной: красная рамка без мигания. */
@media (prefers-reduced-motion: reduce) {
  .vctl { transition: none; }
  .progress div { transition: none; }
  #alarm-box { animation: none; }
}

.timeline-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px;
  position: relative;
}
#timeline { width: 100%; display: block; cursor: crosshair; touch-action: none; }
/* Подсказка над шкалой: время под курсором, запись, события рядом. */
.tl-tip { position: absolute; bottom: 100%; margin-bottom: 4px; padding: 4px 8px; border-radius: 4px; font-size: 12px;
  line-height: 1.4; white-space: nowrap; pointer-events: none; z-index: 5; background: rgba(0, 0, 0, .85); color: #fff; }
.tl-legend .lg { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: -1px; margin-left: 6px; }
.lg.rec { background: var(--rec); } .lg.mot { background: var(--warn); } .lg.ev-a { background: var(--bad); }
.lg.ev-p { background: var(--accent); } .lg.ev-o { background: var(--muted); }

/* Кнопки на видео: пауза посередине, ±10 с — рядом с ней на 72 px. Видео уже — ±10 подходят к паузе (не дальше
   18 px от края), места нет и между ними меньше 8 px — скрываются. */
.vctl { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 0 18px;
  gap: clamp(8px, calc((100% - 68px - 96px) / 2), 72px); container-type: inline-size;
  pointer-events: none; opacity: 0; transition: opacity .2s; z-index: 3; }
@container (max-width: 180px) { .vctl .vctl-side { visibility: hidden; } }
.vctl.show, .vctl.paused.inside, .vctl:focus-within { opacity: 1; }
.vctl.show button, .vctl.paused.inside button, .vctl:focus-within button,
.vctl.show .vbar, .vctl.paused.inside .vbar, .vctl:focus-within .vbar { pointer-events: auto; }
.vctl.editing .vctl-play, .vctl.editing .vctl-side { display: none; } /* рисуют зоны: панель — да, пауза и ±10 — нет */
/* Правка зон: панель кнопок не закрывает низ кадра — щелчки ловят только сами кнопки (не затемнение и не промежутки),
   а пока рисуют зону или тащат угол — панели нет совсем. */
.vctl.editing .vbar { pointer-events: none !important; }
.vctl.editing:is(.show, .paused.inside, :focus-within) .vbar :is(button, select, input, a) { pointer-events: auto; }
.vctl.an-busy .vbar { display: none; }
.vctl button { border: 2px solid rgba(255, 255, 255, .45); color: #fff; background-color: rgba(0, 0, 0, .55); cursor: pointer; }
.vctl button:hover { background-color: rgba(0, 0, 0, .8); }
.vctl button:disabled { opacity: .35; cursor: default; }
.vctl .vctl-play { width: 68px; height: 68px; border-radius: 50%; flex: none; font-size: 0; padding: 0;
  background-repeat: no-repeat; background-position: center; background-size: 28px 28px;
  /* значок рисуется (символы шрифта ⏸ ▶ садятся не по центру): пауза — две полосы, на паузе — треугольник,
     смещённый вправо на 2 px (центр тяжести треугольника — левее середины) */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 28 28'%3E%3Crect x='6' y='4' width='5.5' height='20' rx='1.5' fill='white'/%3E%3Crect x='16.5' y='4' width='5.5' height='20' rx='1.5' fill='white'/%3E%3C/svg%3E"); }
.vctl.paused .vctl-play {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 28 28'%3E%3Cpath d='M8 4.5v19a1 1 0 0 0 1.5.9l15-9.5a1 1 0 0 0 0-1.8l-15-9.5A1 1 0 0 0 8 4.5z' fill='white'/%3E%3C/svg%3E"); }
.vctl .vctl-side { width: 48px; height: 48px; flex: none; border-radius: 50%; font-size: 13px; font-weight: 600; white-space: nowrap; padding: 0;
  display: flex; align-items: center; justify-content: center; font-variant-numeric: tabular-nums; box-sizing: border-box; }
.vctl .vctl-side[hidden] { display: flex; visibility: hidden; }
/* Внизу архива: дни слева, масштаб справа, ещё правее через отступ — «Выгрузить…». */
.tl-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; position: relative; }
.tl-bar-fill { flex: 1; }
.tl-days-list { display: flex; gap: 6px; flex-wrap: wrap; }
.tl-days-list button, .tl-bar .tl-cal { padding: 4px 12px; border-radius: 8px; font-size: 13px; }
.tl-days-list button.active, .tl-bar .tl-cal.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.tl-bar .tl-cal { padding: 4px 8px; display: inline-flex; align-items: center; }
.tl-bar .tl-cal .ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.tl-bar .tl-date { position: absolute; left: 0; bottom: 100%; width: 1px; height: 1px; opacity: 0; pointer-events: none; border: 0; padding: 0; }
.zoom { display: flex; gap: 4px; flex-wrap: wrap; }
.tl-bar .tl-export { margin-left: 28px; }
#archive-box #export-panel { margin: 6px 0 0; justify-content: center; }
.tl-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 16px; margin-top: 4px; }
.tl-foot p { margin: 0; }
.zoom button { padding: 2px 10px; font-size: 13px; }
.zoom button.active { border-color: var(--accent); color: var(--text); background: var(--line); }

.tabs { display: flex; gap: 4px; }
.user { color: var(--muted); font-size: 13px; white-space: nowrap; }
.user button { padding: 2px 8px; font-size: 12px; margin-left: 4px; }
.login { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }
.login-box { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 24px 28px;
  display: flex; flex-direction: column; gap: 12px; width: min(340px, calc(100vw - 32px)); }
.login-box h1 { font-size: 20px; margin: 0 0 8px; }
.login-box label { flex-direction: column; align-items: stretch; }
.login-box label.check { flex-direction: row; align-items: center; gap: 8px; }
.login-box label.check input { width: auto; }
.subtabs { display: flex; gap: 4px; margin-bottom: 12px; }
.grid.layout { display: grid; gap: 2px; aspect-ratio: var(--ratio); width: min(100%, calc((100vh - 80px) * var(--ratio))); margin: 0 auto; }
.grid.layout .tile { aspect-ratio: auto; min-height: 0; }
.grid.layout .tile.empty-cell { background: var(--empty); cursor: default; }
#grid-view.fullscreen { padding: 0; background: #000; }
#grid-view.fullscreen .layout-bar { display: none; }
#grid-view.fullscreen .grid { height: 100vh; gap: 2px; }
#grid-view.fullscreen .grid.layout { height: auto; width: min(100vw, calc(100vh * var(--ratio))); }
#grid-view.fullscreen .grid:not(.layout) { grid-template-columns: repeat(auto-fill, minmax(25vw, 1fr)); }
.l-grid { display: grid; gap: 4px; margin: 8px 0; min-height: 200px; }
.l-cell { background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 4px;
  display: flex; align-items: center; justify-content: center; }
.l-cell select { max-width: 100%; font-size: 12px; }
.subtabs button.active { border-color: var(--accent); background: var(--line); }
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 4px 0 10px; }
.checks.tree-checks { display: block; max-height: 40vh; overflow: auto; }
.tabs a { color: var(--muted); text-decoration: none; padding: 4px 10px; border-radius: 4px; }
.tabs a.active { color: var(--text); background: var(--line); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px 16px;
  margin-bottom: 16px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel h2, dialog h2 { font-size: 16px; margin: 0 0 8px; }

.row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 10px 0; }
.row.end { justify-content: flex-end; }

table.list { width: 100%; border-collapse: collapse; margin-top: 8px; }
table.list th, table.list td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { color: var(--muted); font-weight: 500; font-size: 13px; }
table.list td .sub { color: var(--muted); font-size: 12px; }

button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger:hover { border-color: var(--bad); color: var(--bad); }
button:disabled { opacity: .5; cursor: default; }

.ok { color: var(--rec); }
#ss-st-list .warn, #ss-lic-state.warn { color: var(--warn); }
.error { color: var(--bad); min-height: 1em; }
.tag { display: inline-block; padding: 0 6px; border-radius: 3px; background: var(--line); font-size: 12px; }

.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 8px 0; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .3s; }

dialog {
  width: min(860px, calc(100vw - 32px));
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px 20px;
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }

.alerts-badge {
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 13px;
  text-decoration: none;
  color: #fff;
  white-space: nowrap;
}
.alerts-badge.critical { background: var(--bad); }
.alerts-badge.warning { background: #b7791f; }

.alert-card {
  border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
  border-radius: 4px;
  padding: 8px 12px;
  margin: 8px 0;
}
.alert-card.critical { border-left-color: var(--bad); }
.alert-card.warning { border-left-color: var(--warn); }
.alert-card .title { font-weight: 500; }
.alert-card .meta, .alert-card .detail { color: var(--muted); font-size: 13px; }
.level { white-space: nowrap; }
.level.critical { color: var(--bad); }
.level.warning { color: var(--warn); }

.sys-chips {
  display: flex;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.sys-chips b { color: var(--text); font-weight: 500; }
.sys-chips .warn b, .sys-chips .warn { color: var(--warn); }

.sys-tiles { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 12px; align-items: stretch; }
/* Группы плиток «Мониторинга»: нагрузка, температуры, диски */
.sys-group { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px 10px; }
.sys-group > h3 { margin: 0 0 8px 2px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.sys-group .tiles { display: flex; flex-wrap: wrap; gap: 10px; }
.sys-group .tile-stat { min-width: 150px; }
/* Сворачиваемая панель */
details.fold-panel > summary { cursor: pointer; list-style: none; display: flex; align-items: baseline; gap: 10px; }
details.fold-panel > summary::-webkit-details-marker { display: none; }
details.fold-panel > summary h2 { margin: 0; }
details.fold-panel > summary::before { content: '▸'; color: var(--muted); transition: transform .15s; display: inline-block; }
details.fold-panel[open] > summary::before { transform: rotate(90deg); }
details.fold-panel[open] > summary { margin-bottom: 8px; }
.tile-stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 14px;
  min-width: 180px;
}
.tile-stat .label { color: var(--muted); font-size: 12px; }
.tile-stat .value { font-size: 22px; font-variant-numeric: tabular-nums; }
.tile-stat .sub { color: var(--muted); font-size: 12px; }
.list.hw td:first-child { color: var(--muted); white-space: nowrap; width: 1%; padding-right: 24px; }
.list.hw td.warn { color: var(--warn); }
.meter { height: 6px; background: var(--line); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.meter div { height: 100%; background: var(--series-1); border-radius: 3px; }
.meter.warn div { background: var(--warn); }

.sys-charts { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 12px; margin-bottom: 16px; }
.chart-card {
  margin: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
}
.chart-card figcaption { color: var(--text); font-size: 13px; margin-bottom: 4px; display: flex; gap: 12px; flex-wrap: wrap; }
.chart-card .legend { color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.chart-card .legend i { display: inline-block; width: 14px; height: 2px; border-radius: 1px; }
.chart { position: relative; height: 150px; }
.chart canvas { width: 100%; height: 100%; display: block; }
.chart .tip {
  position: absolute;
  top: 4px;
  pointer-events: none;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 12px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.chart .tip .row { display: flex; align-items: center; gap: 6px; }
.chart .tip .row i { width: 10px; height: 2px; display: inline-block; }
.chart .tip b { color: var(--text); }
.chart .tip span { color: var(--muted); }

@media (max-width: 900px) { .sys-chips { display: none; } }

@media (max-width: 600px) {
  .grid { grid-template-columns: 1fr; }
}

/* Управление поворотом (PTZ) */
.ptz { display: flex; gap: 16px; align-items: flex-start; margin: 8px 0; }
.ptz-pad { display: grid; grid-template-columns: repeat(3, 40px); gap: 4px; }
.ptz-pad button { height: 36px; padding: 0; font-size: 16px; touch-action: none; user-select: none; }
.ptz-side { display: flex; flex-direction: column; gap: 6px; }
.ptz-side button { touch-action: none; user-select: none; }

/* Встроенный режим (плеер в Битрикс24): только просмотр, без администрирования и выхода */
.embed #tab-admin, .embed #tab-system, .embed #tab-alerts, .embed #btn-logout,
.embed #sys-chips, .embed #alerts-badge, .embed .brand, .embed #user-name, .embed #to-center,
.embed #tab-view, .embed #rec-state, .embed #btn-theme, .embed #obj-switch { display: none !important; }
.embed header:not(:has(#crumbs a)):not(:has(#layout-bar:not([hidden]))) { display: none; }
.embed header { padding-top: 4px; padding-bottom: 4px; }

.theme-btn { background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 4px; padding: 2px 8px; cursor: pointer; }

/* Индикатор ожидания (проверка камеры и т. п.) */
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Псевдо-полноэкранный режим (фрейм, где настоящий запрещён): на всю область окна */
.pseudo-fs { position: fixed !important; inset: 0; z-index: 1000; margin: 0; background: #000; overflow: auto; }
#camera-view .player.pseudo-fs, #camera-view .player:fullscreen { display: flex; align-items: center; justify-content: center; border-radius: 0; }
#camera-view .player.pseudo-fs video, #camera-view .player:fullscreen video { width: 100%; height: 100%; max-height: none; object-fit: contain; }
/* Страница камеры во весь экран: видео — всё место, под ним (если открыты) шкала архива, сбоку — панель аналитики. */
#camera-view.pseudo-fs, #camera-view:fullscreen { height: 100vh; padding: 0; box-sizing: border-box; background: #000; }
#camera-view:fullscreen .player, #camera-view.pseudo-fs .player { border-radius: 0; }
#fs-exit { display: none; position: fixed; top: 8px; right: 8px; z-index: 1001; width: 36px; height: 36px; border-radius: 50%;
  border: 0; background: rgba(0, 0, 0, .6); color: #fff; font-size: 18px; cursor: pointer; }
.has-pseudo-fs #fs-exit { display: block; }

/* Подписи поверх видео — светлые в любой теме (подложка тёмная) */
.tile .name, .badge, .clock { color: #fff; }

/* Плеер на телефоне (мобильное приложение Битрикс24): во весь экран — только отдельная камера */
.embed.mobile #btn-fullscreen, .embed.mobile #btn-popout, .embed.mobile #btn-cam-popout { display: none !important; }

/* Дерево камер (Управление → Камеры) */
.ct { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 16px; align-items: start; }
.ct-left { display: flex; flex-direction: column; gap: 8px; position: sticky; top: 8px; max-height: calc(100vh - 140px); }
.ct-left input[type=search] { width: 100%; }
.ct-links { display: flex; gap: 16px; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; font-size: 13px; }
.tree { overflow: auto; flex: 1; min-height: 120px; border: 1px solid var(--line); border-radius: 4px; padding: 4px 0; user-select: none; }
/* Строка дерева; --d — глубина. Линии уровней рисуются фоном: вертикальная направляющая под шевроном каждого
   предка (шаг 18 px, центр шеврона — 11 px) и горизонтальный отвод от последней к самому элементу (├─). */
.tr-row {
  --guide: color-mix(in srgb, var(--muted) 38%, transparent);
  display: flex; align-items: center; gap: 6px; padding: 4px 8px 4px calc(var(--d, 0) * 18px + 4px);
  cursor: pointer; white-space: nowrap; border-radius: 4px;
  background-image: linear-gradient(var(--guide), var(--guide)),
    repeating-linear-gradient(90deg, transparent 0 10.5px, var(--guide) 10.5px 11.5px, transparent 11.5px 18px);
  background-size: calc(min(var(--d, 0), 1) * 8px) 1px, calc(var(--d, 0) * 18px) 100%;
  background-position: calc(var(--d, 0) * 18px - 7px) 50%, 0 0;
  background-repeat: no-repeat;
}
.tr-row:hover { background-color: color-mix(in srgb, var(--accent) 10%, transparent); }
.tr-row.sel { background-color: color-mix(in srgb, var(--accent) 22%, transparent); }
.tr-row.drop { outline: 2px dashed var(--accent); }
.tr-row.disabled .tn { color: var(--muted); text-decoration: line-through; }
.rename-cam { flex: none; padding: 2px 8px; font-size: 14px; }
#crumbs .cam-head { flex: 1; min-width: 0; display: flex; justify-content: center; align-items: center; gap: 6px; }
#crumbs .cam-head .cam-title { flex: 0 1 auto; }
/* Расстановка камер пользователем */
.arrange-bar { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; padding: 8px 10px; margin-bottom: 8px;
  border: 1px solid var(--accent); border-radius: 6px; background: color-mix(in srgb, var(--accent) 8%, transparent); }
.grid.arranging .tile { outline: 1px dashed color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: -1px; }
.grid.arranging .tile[draggable="true"] { cursor: grab; }
.grid.arranging .tile.dragging { opacity: .4; }
.grid .tile .arr-btn { position: absolute; z-index: 5; border-radius: 50%; border: 0; cursor: pointer; font-size: 18px; line-height: 1;
  background: color-mix(in srgb, #000 65%, transparent); color: #fff; }
.grid .tile .arr-x { top: 6px; right: 6px; width: 30px; height: 30px; }
.grid .tile .arr-x:hover { background: var(--bad); }
.grid .tile .arr-plus { top: 50%; left: 50%; transform: translate(-50%, -50%); width: 56px; height: 56px; font-size: 32px; background: var(--accent); }
.grid .tile.empty-cell { position: relative; }
.arr-list { display: flex; flex-direction: column; gap: 4px; max-height: 55vh; overflow: auto; margin: 8px 0; min-width: 380px; }
.arr-list .arr-cam { text-align: left; }
.arr-list .arr-cam.placed { opacity: .55; }
.ico { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }
/* Папка — в цвет акцента с лёгкой заливкой, как в современных файловых менеджерах */
.ico.fold { color: var(--accent); fill: color-mix(in srgb, var(--accent) 18%, transparent); }
details.manual-url { margin: 4px 0 8px; }
details.manual-url > summary { cursor: pointer; color: var(--accent); font-size: 13px; }
details.manual-url label { display: block; margin: 6px 0; }
.tr-row .tw { width: 14px; height: 14px; display: inline-flex; color: var(--muted); }
.tr-row .tw .ico { width: 14px; height: 14px; stroke-width: 2; transition: transform .15s ease; }
.tr-row .tw.open .ico { transform: rotate(90deg); }
.tr-row .tw:hover { color: var(--text); }
.tr-row.folder .tn { font-weight: 500; }
.ico.cam { color: var(--muted); width: 15px; height: 15px; }
.tr-row.sel .ico.cam { color: var(--text); }
.sub .ico { width: 13px; height: 13px; vertical-align: -2px; }
h2 .ico.fold { width: 20px; height: 20px; vertical-align: -4px; margin-right: 4px; }
.tr-row .sub { font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.tr-row .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.tr-row .dot.ok { background: var(--rec); }
.tr-row .dot.bad { background: var(--bad); }
.tr-row .dot.off { background: transparent; border: 1px solid var(--muted); }
.ct-tools { display: flex; gap: 8px; }
table.kv { border-collapse: collapse; margin: 8px 0 16px; }
table.kv td { padding: 6px 12px 6px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
table.kv td:first-child { color: var(--muted); white-space: nowrap; }
@media (max-width: 900px) { .ct { grid-template-columns: 1fr; } .ct-left { position: static; max-height: none; } }

/* Редактор видов (Управление → Раскладки) */
.vw { display: grid; grid-template-columns: 260px 1fr; gap: 16px; align-items: start; }
.vw-list { display: flex; flex-direction: column; gap: 8px; }
.vw-list .tree { max-height: 60vh; }
.vw-editor { display: flex; flex-direction: column; gap: 12px; }
.vw-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.vw-body { display: grid; grid-template-columns: minmax(260px, 340px) 1fr; gap: 12px; align-items: start; }
.vw-cams { display: flex; flex-direction: column; gap: 6px; }
.vw-cams .tree { max-height: 60vh; }
.vw-right { display: flex; flex-direction: column; gap: 12px; }
.vw h3 { margin: 0 0 6px; font-size: 15px; }
.l-ico { display: inline-grid; width: 22px; height: 18px; gap: 1px; flex: none; }
.l-ico i { background: var(--muted); opacity: .55; border-radius: 1px; }
.l-templates { display: flex; flex-wrap: wrap; gap: 6px; }
.l-tpl { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 8px; font-size: 11px; }
.l-tpl .l-ico { width: 30px; height: 24px; }
.l-tpl.sel { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 15%, transparent); }
.l-grid { display: grid; gap: 2px; background: var(--line); border: 1px solid var(--line); aspect-ratio: 16 / 9; max-height: 60vh; }
.l-cell { position: relative; display: flex; align-items: center; justify-content: center; background: var(--empty);
  color: var(--text); overflow: hidden; cursor: grab; text-align: center; padding: 4px; }
.l-cell.empty { cursor: default; }
.l-cell .l-x { position: absolute; top: 2px; right: 2px; padding: 0 6px; font-size: 14px; line-height: 18px; opacity: .6; }
.l-cell .l-x:hover { opacity: 1; }
@media (max-width: 1100px) { .vw, .vw-body { grid-template-columns: 1fr; } }

#ct-folder-list tr.off td { opacity: .55; }
#ct-folder-list tfoot td { border-top: 2px solid var(--line); padding-top: 8px; }

/* Список видов (обычный пользователь при открытии) */
.grid.view-picker { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.view-card { display: flex; flex-direction: column; gap: 6px; align-items: stretch; text-align: left; padding: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px; cursor: pointer; font: inherit; color: var(--text); }
.view-card:hover { border-color: var(--accent); }
.vc-scheme { display: grid; gap: 2px; width: 100%; }
.vc-scheme span { background: var(--empty); border-radius: 2px; }
.vc-scheme span.on { background: color-mix(in srgb, var(--accent) 45%, transparent); }
#btn-fullscreen.picker-hide { display: none; }

/* Свёрнутые панели камеры: «Архив», «Поворот (PTZ)» */
.toggles { display: inline-flex; gap: 8px; margin-left: auto; }
button.toggle::after { content: ' ▸'; color: var(--muted); }
button.toggle[aria-pressed]::after { content: none; } /* переключатель (Рамки), а не раскрывающаяся панель */
button.toggle[aria-expanded="true"] { border-color: var(--accent); }
button.toggle[aria-expanded="true"]::after { content: ' ▾'; }

/* Страница камеры: «Назад» — кнопкой, название камеры — посередине шапки, пауза и «Во весь экран» — справа в шапке */
#crumbs a.btn-back { flex: none; color: var(--text); text-decoration: none; background: var(--panel); border: 1px solid var(--line);
  border-radius: 4px; padding: 5px 12px; font-size: 14px; font-weight: 500; }
#crumbs a.btn-back:hover { border-color: var(--accent); }
#crumbs .cam-title { flex: 1; min-width: 0; text-align: center; font-size: 15px; font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; }
body:has(#camera-view:not([hidden])) #sys-chips { display: none; }
/* Сетка: выбор вида — слева в шапке, название — посередине, «Во весь экран» — справа, как на странице камеры */
.layout-bar, .grid-actions { display: none; gap: 8px; align-items: center; }
body:has(#grid-view:not([hidden])) .layout-bar, body:has(#grid-view:not([hidden])) .grid-actions { display: flex; }
.layout-bar select { width: 190px; }
body:has(#grid-view:not([hidden])) #sys-chips { display: none; }
button.eye { padding: 2px 6px; line-height: 1; }

/* Видеостена (клиент охранника): вид во весь монитор без шапки */
html.wall header { display: none; }
html.wall body { background: #000; }
.grid .tile.solo { position: fixed; inset: 0; z-index: 60; border-radius: 0; border: 0; aspect-ratio: auto; }
.grid .tile.solo video { object-fit: contain !important; }
/* Клиент охранника: «На монитор», сообщения о выгрузке */
.to-monitor { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 4px); z-index: 70; background: var(--panel); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px; display: flex; flex-direction: column; gap: 4px; min-width: 260px; box-shadow: 0 6px 20px rgba(0,0,0,.18); }
.menu button { text-align: left; white-space: nowrap; }
.menu button.sub { color: var(--muted); font-size: 12px; }
.toast { position: fixed; right: 16px; bottom: 16px; z-index: 80; background: var(--panel); border: 1px solid var(--line);
  border-left: 4px solid var(--rec); border-radius: 6px; padding: 10px 14px; box-shadow: 0 6px 20px rgba(0,0,0,.18); max-width: 520px; }
.toast.bad { border-left-color: var(--bad); }
html.wall .grid.layout .tile.empty-cell { background: #111; border-color: #111; }
html.client #btn-theme { display: none; }

/* Логотип: значок в шапке, полный — на входе */
.brand { display: inline-flex; align-items: center; gap: 8px; }
.brand img { height: 30px; width: auto; } /* значок по куполу (icon-brand.svg), без пустых полей квадрата */
.login-logo { display: block; width: 200px; max-width: 100%; margin: 0 auto 4px; }
.login-icon { display: block; width: 72px; height: 72px; margin: 0 auto 8px; }
.login-box h1 { text-align: center; }
.login-dev { margin-top: 22px; text-align: center; font-size: 12px; color: var(--muted); }
.login-dev img { display: block; width: 150px; max-width: 100%; margin: 6px auto 0; opacity: .75; }
.about-dev { color: var(--muted); font-size: 12px; margin: 10px 0 0; }
.about-dev img { display: block; width: 170px; max-width: 100%; margin: 6px 0 0; opacity: .8; }
/* Клиент поста: окна и так во весь экран, сессия — поста (выход — меню клиента администратором) */
html.client #btn-logout, html.client #btn-fullscreen, html.client #btn-cam-fs, html.client #btn-popout, html.client #btn-cam-popout { display: none !important; }
/* Видеостена: на развёрнутой камере — «Архив» и «К виду» */
.tile .solo-bar { display: none; position: absolute; right: 16px; bottom: 16px; gap: 8px; z-index: 2; }
.tile.solo .solo-bar { display: flex; }
.tile .solo-bar button { background: rgba(15,17,21,.75); color: #fff; border: 1px solid rgba(255,255,255,.3); padding: 8px 16px; font-size: 15px; }
/* Загрузка видео: крутящийся значок с подписью вместо чёрного экрана */
.tile .msg, .player-msg { gap: 10px; flex-direction: column; }
.spinner.big { width: 32px; height: 32px; border-width: 3px; border-color: rgba(255,255,255,.18); border-top-color: var(--accent); }
table.usage tr.group-row td { font-weight: 600; background: color-mix(in srgb, var(--accent) 8%, transparent); }
td.warn { color: var(--warn); }
.cen-paste { display: block; margin: 8px 0; }
.cen-paste textarea { display: block; width: 100%; margin-top: 4px; font: 12px Consolas, monospace; }

/* Видеоаналитика: зоны и линии поверх видео (рисование — щелчками), панель правил камеры. */
.an-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#an-live { z-index: 1; }
button.toggle[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.an-fb { max-width: calc(100vw - 32px); }
.an-fb canvas { display: block; max-width: 100%; cursor: crosshair; touch-action: none; background: #000; margin: 6px 0; }
.an-fb .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 6px 0; }
.an-canvas.drawing { pointer-events: auto; cursor: crosshair; }
.an-canvas.editing { pointer-events: auto; touch-action: none; }
.an-panel .row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 6px; }
.an-list { list-style: none; padding: 0; margin: 6px 0; display: flex; flex-direction: column; gap: 6px; }
.an-list:empty { display: none; }
/* Панель аналитики: шапка (вкл., поток, сохранить) и разделы по модулям. */
.an-head { padding-bottom: 6px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.an-head .row:first-child { justify-content: space-between; }
.an-head p { margin: 2px 0; }
.an-head p:empty { display: none; }
.an-sec { border-bottom: 1px solid var(--line); padding: 4px 0; }
.an-sec > summary { cursor: pointer; padding: 6px 0; font-weight: 600; display: flex; gap: 8px; align-items: baseline; }
.an-sec > summary::before { content: '▸'; font-weight: 400; }
.an-sec[open] > summary::before { content: '▾'; }
.an-sec > summary::-webkit-details-marker { display: none; }
.an-sec > summary { list-style: none; }
.an-sum { margin-left: auto; font-weight: 400; font-size: 12px; color: var(--muted); }
.an-sec > .hint { margin: 0 0 6px; }
.an-card { border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; display: flex; flex-direction: column; gap: 4px; }
.an-card-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.an-card-name input { width: 11em; }
.an-card-opts { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.an-del { border: none; background: none; font-size: 18px; line-height: 1; padding: 0 4px; color: var(--muted); cursor: pointer; }
.an-del:hover { color: var(--bad); }
#an-edit-hint:empty { display: none; }
/* Страница «События»: карточки со снимком */
.ev-modes { margin: 0 0 10px; gap: 6px; }
.ev-modes button.active { border-color: var(--accent); color: var(--accent); }
.cnt-sum { display: flex; flex-wrap: wrap; gap: 10px; margin: 6px 0 10px; }
.cnt-sum div { border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; background: var(--panel); }
.cnt-sum b { font-size: 18px; }
#cnt-chart svg { width: 100%; height: 180px; display: block; }
.cnt-table { overflow-x: auto; max-height: 420px; overflow-y: auto; }
#cnt-table td.n, #cnt-table th.n { text-align: right; }
.ev-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.ev-card { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; color: var(--text); text-decoration: none; background: var(--panel); }
.ev-card:hover { border-color: var(--accent); }
.ev-card.gone:hover { border-color: var(--line); }
.ev-img { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; background: #000; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; }
.ev-cap { display: flex; flex-direction: column; gap: 2px; padding: 6px 8px; font-size: 13px; }
/* Спецтранспорт (мусоровоз, скорая, …) — заметная плашка на карточке события. */
.ev-veh { align-self: flex-start; padding: 0 6px; border-radius: 4px; background: var(--accent); color: #fff; font-weight: 600; }
.ev-crop { max-width: 160px; max-height: 48px; object-fit: contain; align-self: flex-start; border-radius: 3px; }
.ev-filters { margin: 0 0 10px; gap: 12px; flex-wrap: wrap; }
.ev-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; border: 1px solid var(--line); margin-right: 4px; vertical-align: -1px; }

/* Тревоги охраннику (alarm.js): поверх всего, в том числе видеостены. */
#alarm-box { position: fixed; top: 12px; right: 12px; z-index: 1000; width: 340px; max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px); overflow: auto; background: #1a0f10; color: #fff; border: 2px solid var(--bad);
  border-radius: 8px; box-shadow: 0 6px 24px rgba(0, 0, 0, .6); animation: alarm-pulse 1.2s ease-in-out infinite; }
@keyframes alarm-pulse { 50% { border-color: #ff9a9a; } }
#alarm-box .alarm-head { display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 8px 10px; background: var(--bad); }
#alarm-box .alarm-card { padding: 8px 10px; border-top: 1px solid rgba(255, 255, 255, .15); }
#alarm-box img { display: block; width: 100%; border-radius: 4px; margin-bottom: 6px; }
#alarm-box .alarm-what { font-weight: 600; }
#alarm-box .alarm-meta { opacity: .8; font-size: 90%; margin: 2px 0 6px; }
#alarm-box .alarm-btns { display: flex; justify-content: flex-end; gap: 6px; }

/* Номер машины в событиях — как на табличке. */
b.plate { font-family: "DejaVu Sans Mono", Consolas, monospace; letter-spacing: .04em; border: 1px solid var(--line);
  border-radius: 3px; padding: 0 4px; background: var(--bg); }
/* Номера на проверку: вырезка крупно, номер, верно / неверно. */
.lpr-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
.lpr-card { border: 1px solid var(--line); border-radius: 6px; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.lpr-card img { width: 100%; height: 90px; object-fit: contain; background: #000; border-radius: 4px; image-rendering: auto; }
.lpr-info { display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.lpr-watch { align-self: flex-start; color: var(--accent); text-decoration: none; }
.lpr-watch:hover { text-decoration: underline; }
.lpr-card .row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.lpr-plate { font-size: 16px; font-weight: 600; letter-spacing: 1px; }
/* Списки номеров: вид записи и решение на карточке события. */
.pl-kind { display: inline-block; padding: 0 6px; border-radius: 3px; font-size: 12px; border: 1px solid var(--line); }
.pl-resident { color: var(--rec); border-color: var(--rec); }
.pl-guest { color: var(--accent); border-color: var(--accent); }
.pl-deny { color: #fff; background: var(--bad); border-color: var(--bad); }
.pl-expired { color: var(--warn); border-color: var(--warn); }
.pl-none { color: var(--muted); }
.pl-table tr.pl-off td { opacity: .55; }
.pl-btns { white-space: nowrap; text-align: right; }
#pl-import-text { width: 100%; box-sizing: border-box; font-family: "DejaVu Sans Mono", Consolas, monospace; }
#ev-mode-lpr .badge { background: var(--accent); color: #fff; margin-left: 4px; }
/* Синхронный архив сетки. */
.sa-panel { position: sticky; bottom: 0; z-index: 4; margin-top: 8px; padding: 8px; background: var(--bg); border-top: 1px solid var(--line); }
.sa-panel .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 6px; }
.sa-clock { margin-left: auto; font-variant-numeric: tabular-nums; }
#sa-timeline { width: 100%; display: block; cursor: crosshair; touch-action: none; }
#btn-grid-archive.active { border-color: var(--accent); background: var(--accent); color: #fff; }
.tile.sa-wait video { opacity: .35; }

/* Панель кнопок на видео (звук, поток, архив, во весь экран…): внизу кадра, с затемнением. */
.vctl .vbar { position: absolute; left: 0; right: 0; bottom: 0; margin: 0; padding: 28px 10px 8px; gap: 6px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .75)); pointer-events: none; }
.vctl .vbar button, .vctl .vbar select, .vctl .vbar input { color: #fff; background-color: rgba(0, 0, 0, .45);
  border: 1px solid rgba(255, 255, 255, .3); border-radius: 4px; padding: 3px 8px; font-size: 13px; }
.vctl .vbar button:hover { background-color: rgba(0, 0, 0, .75); border-color: #fff; }
.vctl .vbar select option { color: #000; }
.vctl .vbar input[type=date] { color-scheme: dark; }
.vctl .vbar label { color: #ddd; font-size: 13px; }
.vctl .vbar .toggles { gap: 6px; }
.vctl .vbar button.toggle::after { color: #bbb; }
.vctl .vbar button.toggle[aria-expanded="true"], .vctl .vbar button.toggle[aria-pressed="true"] { border-color: #6fa8ff; color: #9cc4ff; }

/* Сворачиваемая панель (details.fold): заголовок со стрелкой; раскрыта ли — помнит браузер (data-fold, app.js). */
.fold > summary { cursor: pointer; list-style: none; }
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary h2 { display: inline-flex; gap: 8px; align-items: baseline; margin: 0; }
.fold > summary h2::before { content: '▸'; font-weight: 400; }
.fold[open] > summary h2::before { content: '▾'; }
.fold[open] > summary { margin-bottom: 8px; }

/* Меню ☰ шапки и прочее только для телефона (mobile.js переносит в меню объект, запись, тему и вход). */
.m-menu-btn, .m-only { display: none; }

/* Телефон и приложение на главном экране: шапка — одна строка (значок, название, проблемы, ☰), разделы — панелью
   внизу, кнопки видео — под кадром (mobile.js), видео — во всю ширину. Кнопки — под палец (не меньше 36 px). */
@media (max-width: 700px) {
  body { padding-bottom: calc(58px + env(safe-area-inset-bottom)); }
  header { height: auto; min-height: 48px; flex-wrap: wrap; gap: 8px 10px; padding: 6px 10px;
    padding-top: max(6px, env(safe-area-inset-top)); position: sticky; top: 0; z-index: 50; }
  header > #crumbs { min-width: 0; flex: 1 1 0; }
  .brand { font-size: 0; gap: 0; }
  .brand img { height: 28px; }
  .m-menu-btn { display: block; width: 40px; height: 36px; padding: 0; font-size: 20px; line-height: 1; }
  .m-menu { position: absolute; right: 8px; top: calc(100% + 4px); z-index: 60; display: flex; flex-direction: column;
    align-items: stretch; gap: 10px; min-width: 240px; max-width: calc(100vw - 16px); padding: 12px; white-space: normal;
    background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, .35); }
  .m-menu .obj-switch { max-width: none; width: 100%; }
  .m-menu .theme-btn { align-self: flex-start; padding: 6px 12px; }
  .m-menu .theme-btn::after { content: ' Тема'; }
  .m-menu .user { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 14px; }
  .m-menu .user button { padding: 6px 14px; font-size: 14px; }
  .alerts-badge { padding: 4px 10px; }
  .alerts-badge .ab-word { display: none; }
  /* Страница камеры: слева «← Назад» вместо значка; переименование — на компьютере. */
  body:has(#camera-view:not([hidden])) .brand, #crumbs .rename-cam { display: none; }
  #crumbs a.btn-back { padding: 7px 12px; }
  #crumbs .cam-head { justify-content: flex-start; }
  /* Разделы — панелью внизу экрана, как в приложениях. */
  header > .tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; gap: 0; background: var(--panel);
    border-top: 1px solid var(--line); padding: 0 0 env(safe-area-inset-bottom); }
  .tabs a { flex: 1 1 0; min-width: 0; height: 56px; display: flex; align-items: center; justify-content: center;
    padding: 0 2px; border-radius: 0; font-size: 12px; text-align: center; overflow: hidden; text-overflow: ellipsis; }
  .tabs a.active { background: none; color: var(--accent); box-shadow: inset 0 2px 0 var(--accent); font-weight: 600; }
  /* Сетка: выбор вида — второй строкой во всю ширину; расстановка, синхронный архив и «во весь экран» —
     для больших экранов. */
  .layout-bar { order: 10; flex-basis: 100%; }
  .layout-bar select { width: 100%; }
  #btn-arrange, #btn-fullscreen, #btn-popout, #btn-grid-archive { display: none !important; }
  body:has(#grid-view:not([hidden])) .grid-actions { display: none; }
  main { padding: 8px; }
  .panel { padding: 10px 12px; }
  button, select, input { min-height: 36px; }
  .grid { gap: 6px; }
  /* Страница камеры листается: видео во всю ширину (16:9), под ним кнопки, шкала архива, панели. */
  #camera-view:not([hidden]) { height: auto; display: block; }
  .player-row { flex-direction: column; }
  .player-row > .an-panel { width: auto; overflow: visible; }
  #camera-view .player { flex: none; height: auto; aspect-ratio: 16 / 9; margin: -8px -8px 0; min-height: 0; touch-action: pan-y; }
  #camera-view .player.zoomed { touch-action: none; }
  #camera-view > .vbar { margin: 8px 0; gap: 8px; }
  #camera-view > .vbar .toggles { margin-left: 0; flex-wrap: wrap; }
  #camera-view > .vbar #v-speed, #camera-view > .vbar #stream { min-height: 36px; }
  #camera-view:fullscreen > .vbar, #camera-view.pseudo-fs > .vbar { padding: 0 8px; }
  .tl-foot p:last-child { display: none; } /* щелчок, колесо — про мышь */
  .tl-bar .tl-export { margin-left: 0; }
  .zoom button { padding: 4px 8px; }
  #export-panel { justify-content: flex-start; }
  .toast { left: 8px; right: 8px; bottom: calc(66px + env(safe-area-inset-bottom)); max-width: none; }
  #alarm-box { top: auto; bottom: calc(66px + env(safe-area-inset-bottom)); right: 8px; left: 8px; width: auto; }
  dialog { width: calc(100vw - 16px); padding: 12px; }
  .m-only { display: inline-block; }
  .panel-head { flex-wrap: wrap; }
  /* Таблицы шире экрана — листаются вбок внутри себя, а не всей страницей. */
  table.list { display: block; overflow-x: auto; }
  /* События: фильтры — под кнопкой «Фильтры», каждый во всю ширину; карточки — одна колонка. */
  #ev-filters:not(.open) { display: none; }
  .ev-filters label, #ev-panel .panel-head label { flex: 1 1 100%; }
  .ev-filters label > :is(select, input), #ev-panel .panel-head label > select { flex: 1; min-width: 0; }
  #ev-panel .panel-head .row { flex: 1 1 100%; }
  #ev-filt-btn { margin: 4px 0; }
  .ev-list { grid-template-columns: 1fr; }
  /* Битрикс24 (встроенный режим): всё из меню ☰ там скрыто, из разделов — «Просмотр» и «События»: ссылками
     в шапке, без меню и нижней панели. */
  .embed .m-menu-btn { display: none; }
  .embed body { padding-bottom: env(safe-area-inset-bottom); }
  .embed header > .tabs { position: static; background: none; border: 0; padding: 0; }
  .embed .tabs a { flex: none; height: auto; padding: 8px 10px; font-size: 14px; }
  .embed .tabs a.active { box-shadow: none; }
  .embed .tabs #tab-view { display: flex !important; } /* из «Событий» — обратно к камерам */
}
