/* =====================================================================
   ИНВАРИАНТ ЖИВОГО ВИДЕО (сборки 13–14; нарушать нельзя)
   ---------------------------------------------------------------------
   На <video>, <video-stream> и на ЛЮБОМ их предке (.media, .tile, #liveGrid,
   #view-live, #app, body, html) никогда не ставим:
     transform, translate, scale, rotate, will-change, filter, backdrop-filter,
     opacity < 1, perspective, contain, isolation, clip-path, mask,
     position: fixed / absolute / sticky.
   Между режимами (поворот, размер окна, «во весь экран», открытие панелей)
   НЕ переключаем у них overflow, border-radius, border, display, z-index.
   Меняются ТОЛЬКО width, height, шаблоны сетки, gap, padding, margin.
   Видео не переносится в другого родителя, плеер не пересоздаётся при
   повороте/ресайзе/полном экране — только при смене источника или сбросе сторожем.
   Почему: всё перечисленное выносит видео в отдельный слой композитора, а
   Safari на iPhone на этом замораживает живую картинку (история — CLAUDE.md §5).
   Поэтому, например, у плиток нет скруглений вовсе (скругление + overflow — маска),
   а зум делается размером и отступами видео, не transform.
   Проверка: ?debug=1 — app.js сверяет вычисленные стили (checkInvariant) и пишет
   нарушения в консоль и в отладочную строку (inv=N).
   Поверх картинки — ничего (правило владельца): управление рядом или ниже.
   Разрешены только подпись «нет сигнала» (.note) и прозрачный слой жестов —
   соседи видео внутри .media.
   ===================================================================== */

:root {
  --bg: #0f1216; --panel: #171b21; --panel2: #1f242c; --border: #2a303a;
  --text: #e6e9ee; --muted: #8b94a3; --accent: #3b82f6; --ok: #22c55e; --warn: #f59e0b; --err: #ef4444;
  --tap: 44px;          /* минимальная цель касания (Apple HIG) */
  --label-h: 32px;      /* высота подписи плитки — app.js (fitGrid) считает на неё */
  --side-w: clamp(300px, 28vw, 380px);   /* боковая панель «Файлы за день» на компьютере */
  --sat: env(safe-area-inset-top, 0px);    --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);   --sar: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
/* overscroll-behavior: none — без «резинки» и без потягивания на обновление: в кабинете
   с жестами по шкале и по картинке это только мешает. */
html, body { margin: 0; background: var(--bg); color: var(--text); overscroll-behavior: none;
  font: 15px/1.45 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--err); min-height: 1.2em; font-size: 14px; }
code { background: var(--panel2); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
svg { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; }
svg .fill { fill: currentColor; stroke: none; }

.screen { min-height: 100vh; min-height: 100dvh; }
#login { display: flex; align-items: center; justify-content: center;
  padding: max(16px, var(--sat)) max(16px, var(--sar)) max(16px, var(--sab)) max(16px, var(--sal)); }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 20px; }
.login-card { width: min(380px, 92vw); display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { font-size: 20px; margin: 4px 0 0; }
.logo { font-weight: 700; letter-spacing: .3px; white-space: nowrap; }
.logo::first-letter { color: var(--ok); }

/* Поля: 16 px текста — меньше iOS приближает страницу при фокусе; высота под палец. */
input, select { background: var(--panel2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; font-size: 16px; min-height: var(--tap); width: 100%; }
input:focus, select:focus { outline: none; border-color: var(--accent); }
input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; margin: 0; }
.btn { border: 1px solid var(--border); background: var(--panel2); color: var(--text); border-radius: 8px;
  padding: 0 14px; font-size: 14px; cursor: pointer; min-height: var(--tap); min-width: var(--tap);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
  white-space: nowrap; font-family: inherit; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--err); }
.btn.sm { padding: 0 10px; font-size: 13px; }
.btn.icon-btn { padding: 0; width: var(--tap); }
.btn:focus-visible, .tab:focus-visible, .seg button:focus-visible, .chip:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; }
/* Подсветка при наведении — только там, где наведение есть. На iPhone :hover «залипает»
   после касания, и кнопка выглядит нажатой, пока не ткнёшь в другое место. */
@media (hover: hover) {
  .btn:hover { filter: brightness(1.15); }
  .tab:hover { color: var(--text); }
  .seg button:hover:not(.active) { color: var(--text); }
  .chip:hover:not(.active) { border-color: var(--muted); }
  .fr-play:hover { background: rgba(255,255,255,.04); }
}
.btn:disabled { opacity: .4; cursor: default; }

/* ---- Шапка: одна строка 44 px ---- */
.topbar { display: flex; align-items: center; gap: 16px; background: var(--panel);
  border-bottom: 1px solid var(--border); flex: none; flex-wrap: nowrap; min-height: calc(var(--tap) + 8px);
  /* status-bar-style black-translucent: страница под строкой состояния — отступаем. */
  padding: var(--sat) max(12px, var(--sar)) 0 max(12px, var(--sal)); }
.topbar nav { display: flex; gap: 2px; min-width: 0; }
.tab { background: transparent; border: 0; color: var(--muted); padding: 0 12px; border-radius: 8px;
  cursor: pointer; font-size: 15px; min-height: var(--tap); white-space: nowrap; font-family: inherit; }
.tab.active { background: var(--panel2); color: var(--text); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; min-width: 0; }
.disk { font-size: 13px; color: var(--muted); white-space: nowrap; }
/* Раскладка в шапке — только на сетке «Онлайн». Путь видео теперь в строке состояния. */
body:not([data-view="live"]) #gridSel, body.single #gridSel { display: none; }

.view { padding: 16px; max-width: 1400px; margin: 0 auto; width: 100%; flex: 1 1 auto; min-height: 0; overflow: auto; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; flex: none; }
.seg button { background: var(--panel2); border: 0; color: var(--muted); padding: 0 12px; cursor: pointer;
  min-height: var(--tap); min-width: var(--tap); font-size: 14px; font-family: inherit; }
.seg button.active { background: var(--accent); color: #fff; }

/* =====================================================================
   КАБИНЕТ И «ОНЛАЙН»: постоянная часть (одинакова во ВСЕХ режимах)
   ===================================================================== */
/* #app — колонка на высоту окна. overflow не задаём нигде: он должен быть одним
   и тем же в любом режиме (инвариант), а длинная сетка просто прокручивает документ. */
#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
/* #view-live — ВСЕГДА сетка (display не переключается между режимами); режимы
   меняют только шаблон областей. gap 0 — пустые (скрытые) строки не дают зазоров,
   отступы у самих элементов. */
#view-live { display: grid; overflow: visible; gap: 0;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto auto auto auto auto auto auto auto;
  grid-template-areas: "video" "status" "note" "debug" "chips" "tl" "ticks" "more" "bar"; }
#liveGrid, #liveEmpty { grid-area: video; }
#statusRow { grid-area: status; }
#noteRow { grid-area: note; }
#debugRow { grid-area: debug; }
#camChips { grid-area: chips; }
#playerTl { grid-area: tl; }
#playerTicks { grid-area: ticks; }
#moreRow { grid-area: more; }
#playerBar { grid-area: bar; }

.grid { display: grid; gap: 10px; min-height: 0; overflow: visible;
  justify-content: center; align-content: start; grid-auto-rows: 1fr; }
.grid.cols-1 { grid-template-columns: minmax(0, 1fr); }
.grid.cols-2, .grid.cols-auto { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
/* Раскладка «1+N»: первая камера крупно, остальные полосой справа.
   Первая занимает квадрат 2x2 из трёх колонок, прочие выстраиваются в третьей. */
.grid.cols-hero { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-hero > .tile:first-child { grid-column: span 2; grid-row: span 2; }

/* Плитка: колонка «видео + подпись». Без скруглений и рамок — ни в одном режиме
   (скругление с overflow: hidden = маска поверх видео, переключать его нельзя). */
.tile { background: #000; border: 0; border-radius: 0; overflow: hidden; position: relative;
  display: flex; flex-direction: column; min-height: 0; height: 100%; cursor: pointer; }
body.single .tile { cursor: default; }
/* .media — контейнер под видео, 16:9 по умолчанию. Там, где у плитки задана высота
   (компьютер, разворот), он тянется flex'ом и соотношение не мешает; где высота
   плитки auto (телефон) — даёт честные 16:9. */
.tile .media { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; background: #000;
  aspect-ratio: 16 / 9; }
.tile .media > video-stream { display: block; width: 100%; height: 100%; }
/* Плеер go2rtc рисует рядом с <video> свою плашку режима/ошибки — поверх картинки.
   Она соседка видео, а не обёртка, поэтому прятать её безопасно. */
video-stream .info { display: none !important; }
.tile .media > video { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
/* Подпись НЕ поверх видео, а отдельной строкой под ним. Любая плашка на картинке
   рано или поздно налезает на управление плеером. fitGrid() считает плитку как
   «16:9 + подпись высотой --label-h». */
.tile .label { flex: none; min-height: var(--label-h); padding: 0 10px; display: flex; gap: 8px;
  align-items: center; background: var(--panel); font-size: 13.5px; overflow: hidden; }
.tile .label > span:not(.dot) { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .label .live-msg { color: var(--warn); }
/* «Запустить» в подписи плитки сетки: цель касания 44 px, поэтому подпись на это
   время вырастает с 32 до 44 (min-height, не height) — видео чуть ужимается, это
   только размер. Выступать за подпись кнопке нельзя: overflow её обрежет, и
   обрезанная часть перестанет ловить касания. */
.tile .label .play-btn { margin-left: auto; min-height: var(--tap); flex: none; padding: 0 10px; }
.tile .label .play-btn svg { width: 16px; height: 16px; }
/* В развороте подпись не нужна — её роль играет строка состояния. Подпись — соседка
   .media, а не предок видео: прятать её можно. */
body.single .tile .label { display: none; }
.tile .note { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); text-align: center; padding: 20px; font-size: 14px; pointer-events: none; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.online { background: var(--ok); }
.dot.connecting, .dot.reconnecting, .dot.starting { background: var(--warn); }
.dot.error { background: var(--err); }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
/* Слой жестов зума: прозрачный СОСЕД видео внутри .media (не обёртка, ничего не рисует).
   touch-action: none — щипок и двойное касание достаются нам, а не масштабу страницы;
   -webkit-touch-callout — без меню «Сохранить видео» по долгому касанию на iPhone.
   В сетке его нет: касание уходит плитке (открыть камеру), лента прокручивается. */
.tile .media > .gesture { position: absolute; inset: 0; touch-action: none; -webkit-touch-callout: none;
  -webkit-user-select: none; user-select: none; }
body:not(.single) .tile .media > .gesture { display: none; }
.gesture.zoomed { cursor: grab; }
.gesture.panning { cursor: grabbing; }

/* ---- Разворот одной камеры: строки под видео ---- */
/* Строка состояния переносится, а не обрезается: ошибка камеры важнее красоты. */
.status-row { display: flex; align-items: center; flex-wrap: wrap; column-gap: 10px; row-gap: 2px;
  min-height: var(--tap); padding: 4px 12px; font-size: 14px; }
.status-row > span { white-space: nowrap; }
.st-mode { font-weight: 700; font-size: 12.5px; letter-spacing: .6px; padding: 3px 8px; border-radius: 6px;
  flex: none; display: inline-flex; align-items: center; gap: 6px; }
.st-mode::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.st-mode.live { color: #fff; background: var(--err); }
.st-mode.arc { color: var(--text); background: var(--panel2); }
.st-time { font-variant-numeric: tabular-nums; flex: none; }
.st-tr { font-size: 13px; }
.st-stall { color: var(--warn); font-size: 13px; }
.status-row > .st-cam { color: var(--warn); font-size: 13px; white-space: normal; overflow-wrap: anywhere; min-width: 0; }
.status-row .js-play { margin-left: auto; flex: none; }
.note-row { display: flex; flex-wrap: wrap; gap: 4px 12px; padding: 4px 12px; font-size: 13.5px; color: var(--warn); }
.debug-row { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 2px 12px; }
.debug-row .btn { flex: none; }
.debug-row code { flex: 1 1 auto; min-width: 0; overflow-x: auto; white-space: nowrap;
  font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace; padding: 3px 6px; }
.chips { display: flex; gap: 8px; padding: 6px 12px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 8px; min-height: var(--tap);
  padding: 0 14px; border-radius: 22px; border: 1px solid var(--border); background: var(--panel2);
  color: var(--text); font-size: 14px; cursor: pointer; font-family: inherit; white-space: nowrap; }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.active .dot { box-shadow: 0 0 0 2px rgba(255,255,255,.6); }

/* Шкала: лента (#tlStrip) шириной в три окна, центральная треть — видимое окно;
   двигается transform'ом (шкала — не предок видео). Бегунок неподвижен в центре. */
#playerTl { margin: 8px 12px 0; height: var(--tap); touch-action: none; cursor: grab; }
#playerTl:active { cursor: grabbing; }
/* Долгое нажатие на шкалу — тоже касание (14.1). Без этого iOS на удержании начинает
   выделять текст подписей или показывает меню, забирает касание (pointercancel) —
   и касание молча теряется. */
#playerTl, #playerTicks { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.tl-strip { position: absolute; top: 0; bottom: 0; left: -100%; width: 300%; }
#playerTl .seg-block.broken { background: var(--muted); opacity: .45; }
.tl-now { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--err); }
.day-mark { position: absolute; top: 0; bottom: 0; border-left: 1px dashed rgba(255,255,255,.45);
  padding: 2px 0 0 3px; font-size: 10px; line-height: 1; color: var(--text); white-space: nowrap;
  pointer-events: none; }
#playhead { position: absolute; top: 0; bottom: 0; left: 50%; width: 2px; margin-left: -1px; background: #fff;
  z-index: 2; pointer-events: none; box-shadow: 0 0 4px rgba(0,0,0,.8); }
#playhead::before, #playhead::after { content: ''; position: absolute; left: -5px; border: 6px solid transparent; }
#playhead::before { top: 0; border-top-color: #fff; border-bottom-width: 0; }
#playhead::after { bottom: 0; border-bottom-color: #fff; border-top-width: 0; }
/* Подписи: каждая стоит под своим моментом (left в %, центр подписи — на моменте).
   Прозрачные боковые рамки 1 px — как рамка у шкалы, чтобы проценты совпали. */
#playerTicks { display: block; position: relative; overflow: hidden; height: 18px; padding: 0;
  margin: 0 12px; border: solid transparent; border-width: 0 1px; }
#playerTicks .tick { position: absolute; top: 2px; transform: translateX(-50%); white-space: nowrap;
  font-variant-numeric: tabular-nums; }
#playerTicks .tick.mid { color: var(--text); font-weight: 600; }
#playerTicks .tick.edge { visibility: hidden; }
/* Отметка полуночи у края окна: текст «Пт 26» обрезался бы — прячем текст, линия остаётся (14.1). */
.day-mark.edge { color: transparent; }
.timeline .gap { position: absolute; top: 4px; bottom: 4px; background: repeating-linear-gradient(
  45deg, transparent, transparent 4px, rgba(255,255,255,.07) 4px, rgba(255,255,255,.07) 8px); }

.more-row { display: flex; align-items: center; gap: 10px; padding: 6px 12px; flex-wrap: nowrap;
  overflow-x: auto; scrollbar-width: none; }
.zoom-box { display: flex; align-items: center; gap: 4px; }
/* «К дате…», «Скачать фрагмент», «Файлы за день…» — бывшая вкладка «Архив». */
.more-acts { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
/* Прозрачное поле даты поверх кнопки: касание попадает прямо в родной выбор даты
   (на iPhone — колесо). Значок календаря Chrome растянут на всё поле — щелчок в любом
   месте открывает календарь (плюс showPicker() в app.js). */
.date-btn { position: relative; overflow: hidden; }
.date-btn input { position: absolute; inset: 0; width: 100%; height: 100%; min-height: 0; margin: 0; padding: 0;
  border: 0; opacity: 0; font-size: 16px; cursor: pointer; -webkit-appearance: none; appearance: none; }
.date-btn input::-webkit-calendar-picker-indicator { position: absolute; inset: 0; width: auto; height: auto;
  margin: 0; padding: 0; cursor: pointer; }
.zoom-box #zoomLevel { min-width: 42px; text-align: center; }

/* Панель управления. По умолчанию — строка; в альбомном телефоне — полоса. */
.ctrl-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; flex-wrap: nowrap; }
/* Распорка без собственных зазоров: gap с обеих сторон съедал 16 px — на 390 px
   строка «Сетка · В эфир · звук · экран · ⋯» переносилась. */
.ctrl-bar .bar-gap { flex: 1 1 auto; margin: 0 -4px; }
.xport { display: flex; align-items: center; gap: 4px; }
#btnPause .i-play, #btnPause.paused .i-pause { display: none; }
#btnPause.paused .i-play { display: block; }
#btnSound .i-on, #btnSound.on .i-off { display: none; }
#btnSound.on .i-on { display: block; }
.speed-btn, .hd-btn { font-weight: 700; font-variant-numeric: tabular-nums; padding: 0 8px; min-width: 52px; }
#btnSound.on, #btnHd[aria-pressed="true"] { background: var(--panel2); }
.btn svg text { stroke: none; font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
.ctrl-bar .rail-only { display: none; }
.live-btn .live-dot { width: 10px; height: 10px; border-radius: 50%; background: #fff; flex: none; }
.live-btn { font-weight: 700; letter-spacing: .5px; min-width: 88px; }
/* В эфире и шкала следует за «сейчас» — кнопка красная: «вы в эфире». */
.ctrl-bar .btn.primary.live-on { background: var(--err); border-color: var(--err); }
#btnFull .i-off, #btnFull.on .i-on { display: none; }
#btnFull.on .i-off { display: block; }
.rail-time { font-size: 11px; line-height: 1.2; text-align: center; color: var(--muted);
  white-space: pre; font-variant-numeric: tabular-nums; }
.rail-time.live { color: var(--err); font-weight: 700; }
.rail-time.stall { color: var(--warn); }
#btnTl[aria-pressed="true"], #btnMore[aria-expanded="true"] { background: var(--panel2); }

/* =====================================================================
   РЕЖИМЫ. Три раскладки по ориентации, не по устройству:
     телефон-портрет  = (max-width: 599px) and (orientation: portrait)
     телефон-альбом   = (orientation: landscape) and (max-height: 500px)
     компьютер        = всё остальное (и iPad)
   Меняются ТОЛЬКО шаблоны сетки, размеры и отступы (см. инвариант вверху).
   ===================================================================== */

/* ---- Компьютер ---- */
/* Разворот: редкое («⋯») на компьютере видно всегда — справа от кнопок. */
@media not all and (max-width: 599px) and (orientation: portrait) {
  @media not all and (orientation: landscape) and (max-height: 500px) {
    body.single #moreRow.hidden { display: flex !important; }
    body.single #btnMore { display: none; }
    body.single #moreRow { flex-wrap: nowrap; padding-left: 0; padding-right: 0; }
    body.single .ctrl-bar { padding-left: 0; padding-right: 0; }
    body.single #statusRow, body.single #noteRow, body.single #debugRow,
    body.single #camChips { padding-left: 0; padding-right: 0; }
    body.single #playerTl, body.single #playerTicks { margin-left: 0; margin-right: 0; }
  }
}
/* Боковая панель на компьютере — отдельная колонка справа: видео сужается, но ничем
   не накрыто. Меняется только шаблон колонок (инвариант). */
@media not all and (max-width: 599px) and (orientation: portrait) {
  @media not all and (orientation: landscape) and (max-height: 500px) {
    #view-live.panel-open { column-gap: 16px;
      grid-template-columns: minmax(0, 1fr) var(--side-w);
      grid-template-areas: "video side" "status side" "note side" "debug side" "chips side"
        "tl side" "ticks side" "more side" "bar side"; }
    .sheet-backdrop { display: none !important; }
    /* В развороте на компьютере подписи «К дате…» и т. п. не нужны — есть подсказка. */
    body.single .more-acts .lbl2 { display: none; }
    body.single .more-acts .btn { padding: 0; width: var(--tap); }
  }
}
/* Широкое окно: редкое («⋯») справа от панели в одну строку; уже — строкой ниже. */
@media (min-width: 1100px) and (min-height: 501px) {
  body.single #view-live {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "video video" "status status" "note note" "debug debug"
      "chips chips" "tl tl" "ticks ticks" "bar more"; }
  /* С открытой панелью места на две колонки кнопок нет — снова одна под другой. */
  body.single #view-live.panel-open {
    grid-template-columns: minmax(0, 1fr) var(--side-w);
    grid-template-areas: "video side" "status side" "note side" "debug side" "chips side"
      "tl side" "ticks side" "more side" "bar side"; }
}
@media (max-width: 1100px) { #diskBadge { display: none; } }
@media (max-width: 860px) { .topbar .logo { display: none; } }

/* ---- «Во весь экран» (CSS-режим; на iOS в эфире вместо него родной полный экран) ----
   Видео НЕ переносится и НЕ позиционируется: прячем лишнее вокруг, плитка
   вырастает сама. Первая версия делала плитку position: fixed — и Safari на iPhone
   терял живой поток. Меняются только отступы и размеры. */
body.fullwin .topbar, body.fullwin #camChips { display: none; }
body.fullwin #view-live { padding: var(--sat) var(--sar) 0 var(--sal); max-width: none; }
body.fullwin #liveGrid { gap: 0; }

/* ---- Телефон, портрет ---- */
@media (max-width: 599px) and (orientation: portrait) {
  /* Одна строка шапки: только вкладки и выход. Логотип, место на диске и раскладка —
     лишнее на узком экране (раскладка тут всё равно одна: колонка). */
  .topbar { gap: 6px; min-height: calc(var(--tap) + var(--sat)); }
  .topbar .logo, #gridSel, #diskBadge { display: none; }
  /* Строка «⋯» не должна переноситься: процент зума и подпись «Скачать» прячем —
     остаются кнопки 44×44. */
  #zoomLevel, #btnDownload span { display: none; }
  #btnDownload { padding: 0; width: var(--tap); }
  .topbar-right { gap: 4px; }
  .tab { padding: 0 10px; }
  /* Сетка: плитки от края до края, по одной в ряд, высота по 16:9 — лента прокручивает
     документ. */
  #app { height: auto; min-height: 100vh; min-height: 100dvh; }
  #view-live { padding: 0 0 var(--sab); max-width: none;
    grid-template-rows: auto auto auto auto auto minmax(0, 1fr) auto auto auto;
    grid-template-areas: "video" "status" "note" "debug" "chips" "." "tl" "ticks" "bar"; }
  #liveGrid.grid { grid-template-columns: minmax(0, 1fr); grid-auto-rows: auto; gap: 6px; }
  .grid.cols-hero > .tile:first-child { grid-column: auto; grid-row: auto; }
  .tile { height: auto; }
  /* Разворот: окно ровно в экран. Видео сверху, под ним состояние и камеры,
     шкала и кнопки — в нижней половине, под большим пальцем. «⋯» раскрывает строку
     редкого прямо над кнопками. */
  body.single #app, body.fullwin #app { height: 100vh; height: 100dvh; }
  body.single #view-live { padding-bottom: 0;
    grid-template-areas: "video" "status" "note" "debug" "chips" "." "more" "tl" "ticks" "bar";
    grid-template-rows: auto auto auto auto auto minmax(0, 1fr) auto auto auto auto; }
  /* gap 6 и поля 10: на 375 px (iPhone SE/mini) «Сетка · ЭФИР · звук · экран · ⋯» иначе
     не влезали, и «⋯» уезжала на вторую строку. */
  body.single .ctrl-bar { padding: 8px 10px max(8px, var(--sab)); gap: 6px; flex-wrap: wrap; row-gap: 8px; }
  /* Архив: перемотка и пауза — отдельной строкой по центру над «Сетка / В эфир»,
     крупно и под большим пальцем. order меняет только порядок показа, узлы на месте. */
  body.single .xport { order: -1; flex: 1 0 100%; justify-content: center; gap: 16px; }
  /* «⋯» на узком экране — в две строки, а не прокруткой вбок: скрытое за краем не найти. */
  body.single .more-row { flex-wrap: wrap; row-gap: 6px; overflow-x: visible; }
  /* «Файлы за день» — лист снизу на 85 % высоты. */
  .side-panel { position: fixed; left: 0; right: 0; bottom: 0; height: 85vh; height: 85dvh; z-index: 30;
    border-radius: 14px 14px 0 0; border-bottom: 0; padding-bottom: var(--sab); }
  /* Во весь экран в портрете (Android, архив на iPhone): видео забирает всю свободную
     высоту и центрируется сам (object-fit: contain) — размер, а не позиция. */
  body.fullwin #view-live { grid-template-rows: minmax(0, 1fr) auto auto auto auto 0 auto auto auto auto; }
  body.fullwin .tile { height: 100%; }
  body.fullwin #liveGrid.grid { grid-auto-rows: minmax(0, 1fr); }
  .view:not(#view-live) { padding: 12px max(12px, var(--sal)) max(12px, var(--sab)) max(12px, var(--sar)); }
}

/* ---- Телефон, альбом ---- */
@media (orientation: landscape) and (max-height: 500px) {
  .topbar { gap: 8px; min-height: calc(var(--tap) + var(--sat)); }
  .topbar .logo, #gridSel, #diskBadge { display: none; }
  #zoomLevel, #btnDownload span { display: none; }
  #btnDownload { padding: 0; width: var(--tap); }
  .topbar-right { gap: 4px; }
  #app { height: auto; min-height: 100vh; min-height: 100dvh; }
  /* Сетка: по две 16:9 в ряд (одна камера — одна), вырез и полоса «домой» не закрывают
     картинку. */
  #view-live { padding: 8px var(--sar) var(--sab) var(--sal); max-width: none; }
  #liveGrid.grid:not(.cols-1) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #liveGrid.grid { grid-auto-rows: auto; gap: 6px; }
  .grid.cols-hero > .tile:first-child { grid-column: auto; grid-row: auto; }
  .tile { height: auto; }
  /* Разворот: видео во всю высоту, справа полоса 64 px с кнопками 44×44. Шапка,
     строка состояния и камеры спрятаны — картинка важнее. Шкала — по кнопке
     (или сама, пока смотрим архив: иначе не видно, где мы). */
  body.single .topbar, body.single #statusRow, body.single #camChips { display: none; }
  body.single #app { height: 100vh; height: 100dvh; }
  body.single #view-live { padding: 0 0 var(--sab) var(--sal);
    grid-template-columns: minmax(0, 1fr) calc(100px + var(--sar));
    grid-template-rows: minmax(0, 1fr) auto auto auto auto auto;
    grid-template-areas: "video bar" "note bar" "debug bar" "more bar" "tl bar" "ticks bar"; }
  body.single .tile { height: 100%; }
  body.single #liveGrid.grid { grid-auto-rows: minmax(0, 1fr); }
  body.single #view-live:not(.tl-open):not(.arc) #playerTl,
  body.single #view-live:not(.tl-open):not(.arc) #playerTicks { display: none; }
  body.single #playerTl { margin: 6px 8px 0; }
  body.single #playerTicks { margin: 0 8px; }
  body.single .note-row, body.single .debug-row, body.single .more-row { padding-left: 8px; padding-right: 8px; }
  /* Полоса: две колонки кнопок 44×44 (кнопок архива много, а по ширине место есть:
     видео 16:9 в альбоме упирается в высоту, не в ширину). Отступ справа — под вырез. */
  body.single .ctrl-bar { display: grid; grid-template-columns: repeat(2, var(--tap));
    grid-auto-rows: min-content; gap: 6px; justify-content: center; align-content: start;
    padding: 6px var(--sar) 6px 0; overflow-y: auto; }
  body.single .ctrl-bar .xport { display: contents; }
  body.single .ctrl-bar .rail-only { display: inline-flex; }
  body.single .ctrl-bar .rail-only.hidden { display: none; }
  body.single .ctrl-bar .lbl, body.single .ctrl-bar .bar-gap { display: none; }
  body.single .ctrl-bar .btn { width: var(--tap); padding: 0; min-width: 0; }
  body.single .live-btn { min-width: 0; }
  body.single .rail-time { display: block; grid-column: 1 / -1; }
  body.fullwin #view-live { padding-top: 0; }
  .view:not(#view-live) { padding: 12px max(12px, var(--sar)) max(12px, var(--sab)) max(12px, var(--sal)); }
  /* «Файлы за день» — панель справа во всю высоту. */
  .side-panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 75vw); z-index: 30;
    border-radius: 14px 0 0 14px; border-right: 0; padding-right: var(--sar); padding-bottom: var(--sab); }
}

/* ---- Шкала (класс .timeline у #playerTl) и подписи ---- */
.timeline { position: relative; height: 34px; background: var(--panel2); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; cursor: crosshair; }
.timeline .seg-block { position: absolute; top: 4px; bottom: 4px; background: var(--accent); opacity: .85; border-radius: 2px; }
.timeline .seg-block.recording { background: var(--err); }
.ticks { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); padding: 2px 0; }

/* ---- Боковая панель: «Файлы за день» / «Клавиши» ----
   Соседка сетки в #view-live, НЕ предок видео (ей position: fixed на телефоне можно).
   Компьютер — колонка «side» (см. «Режимы»), телефон — лист поверх, с подложкой. */
#sidePanel { grid-area: side; }
.side-panel { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--panel);
  border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.sp-head { display: flex; align-items: center; gap: 2px; padding: 4px; border-bottom: 1px solid var(--border); flex: none; }
.sp-head h2 { flex: 1 1 auto; min-width: 0; margin: 0; font-size: 16px; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#sidePanel[data-kind="help"] #spPrev, #sidePanel[data-kind="help"] #spNext { visibility: hidden; }
.sp-summary { padding: 6px 12px; flex: none; border-bottom: 1px solid var(--border); }
.sp-summary:empty { display: none; }
.sp-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-bottom: 8px; }
.sp-empty { padding: 16px 12px; margin: 0; }
.sp-hour { position: sticky; top: 0; z-index: 1; background: var(--panel); padding: 8px 12px 4px;
  font-size: 12.5px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
/* Строка файла — 48 px: касание по времени — смотреть, справа скачать и удалить. */
.file-row { display: flex; align-items: center; min-height: 48px; padding-right: 4px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.05); }
.file-row.current { background: rgba(59,130,246,.18); }
.fr-play { flex: 1 1 auto; min-width: 0; min-height: 48px; display: flex; flex-direction: column;
  justify-content: center; align-items: flex-start; padding: 0 12px; background: transparent; border: 0;
  color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.fr-time { font-variant-numeric: tabular-nums; font-size: 14.5px; white-space: nowrap; }
.fr-meta { font-size: 12px; color: var(--muted); white-space: nowrap; }
.file-row.recording .fr-meta { color: var(--err); }
.sheet-backdrop { position: fixed; inset: 0; z-index: 29; background: rgba(0,0,0,.55); }
/* Подсказка по клавишам */
.keys { display: grid; grid-template-columns: auto 1fr; gap: 8px 12px; margin: 12px; font-size: 14px; }
.keys dt { white-space: nowrap; }
.keys dd { margin: 0; color: var(--muted); }
#sidePanel .sp-body > p { margin: 0 12px 12px; }
kbd { display: inline-block; min-width: 22px; padding: 1px 6px; border: 1px solid var(--border); border-bottom-width: 2px;
  border-radius: 5px; background: var(--panel2); color: var(--text); text-align: center;
  font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace; }

/* ---- Настройки: камеры карточками ---- */
.cam-list { display: grid; gap: 10px; margin-top: 12px; }
.cam-card { background: var(--panel2); border: 1px solid var(--border); border-radius: 10px; padding: 12px;
  display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.cc-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cc-name { font-size: 15.5px; }
.cc-off { color: var(--warn); }
.cc-addr, .cc-stats, .cc-err, .cc-hist li { overflow-wrap: anywhere; min-width: 0; }
.cc-err { color: var(--warn); white-space: pre-wrap; background: rgba(245,158,11,.08); border-radius: 6px; padding: 6px 8px; }
.cc-hist summary { min-height: var(--tap); line-height: var(--tap); cursor: pointer; color: var(--muted); font-size: 13.5px; }
.cc-hist ol { margin: 0 0 4px; padding-left: 22px; font-size: 12.5px; display: flex; flex-direction: column; gap: 6px; }
.cc-ht { font-variant-numeric: tabular-nums; }
.cc-acts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.cc-acts .btn { flex: 1 1 auto; }

.two-col { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card h2 { font-size: 17px; margin: 0 0 12px; }
.card-head h2 { margin: 0; }
.form { display: flex; flex-direction: column; gap: 10px; margin: 12px 0 20px; }
.form label, .modal label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); min-height: var(--tap); }
label.check input { width: 22px; flex: none; }   /* длинная подпись не должна сжимать галочку */
.bar { height: 10px; background: var(--panel2); border-radius: 5px; overflow: hidden; margin: 6px 0; }
.bar > div { height: 100%; background: var(--accent); width: 0; }
/* «Выйти» — внизу настроек, после всех карточек. */
.logout-wide { margin-top: 16px; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 10;
  padding: max(16px, var(--sat)) max(16px, var(--sar)) max(16px, var(--sab)) max(16px, var(--sal)); }
.modal form { width: min(560px, 100%); display: flex; flex-direction: column; gap: 10px; max-height: 100%; overflow: auto; }
.modal .row { display: flex; gap: 8px; }
.two-inputs { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.two-inputs > label { min-width: 0; }

/* Сборка 22: уведомления */
.push-acts { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 10px; }
.push-acts .btn { flex: 1 1 auto; }
#pushState { margin: 0 0 8px; }
#pushState.ok { color: var(--ok); }
#pushState.warn { color: var(--warn); }
.cc-motion { font-size: 13px; color: var(--muted); }
.cc-motion .bad { color: var(--err); }
.notify-box { border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px 10px; margin: 4px 0; min-width: 0;
  display: flex; flex-direction: column; gap: 10px; }
.notify-box legend { color: var(--muted); font-size: 14px; padding: 0 4px; }
.notify-opts { display: flex; flex-direction: column; gap: 10px; }
.notify-box.off .notify-opts { opacity: .45; pointer-events: none; }
.days { display: flex; flex-wrap: wrap; gap: 6px; }
.modal .days label { flex-direction: row; align-items: center; justify-content: center; gap: 0; min-height: var(--tap);
  min-width: var(--tap); padding: 0 8px; border: 1px solid var(--border); border-radius: 8px; color: var(--text);
  cursor: pointer; user-select: none; position: relative; }
.days input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.days label:has(input:checked) { background: var(--accent); border-color: var(--accent); color: #fff; }
.days label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Сборка 26: зона детекции */
#zoneModal { z-index: 11; }
.modal form.zone-card { width: min(900px, 100%); }
.zone-stage { flex: none; position: relative; background: #000; border-radius: 6px; overflow: hidden; aspect-ratio: 16 / 9;
  touch-action: none; user-select: none; -webkit-user-select: none; }
.zone-stage img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; pointer-events: none; }
.zone-grid { position: absolute; inset: 0; display: grid; cursor: crosshair; }
.zone-grid > i { border-right: 1px solid rgba(255,255,255,.18); border-bottom: 1px solid rgba(255,255,255,.18); }
.zone-grid > i.on { background: rgba(239, 68, 68, .42); }
.zone-tools { flex-wrap: wrap; }
#zoneMsg.ok { color: var(--ok); }
#zoneMsg.err { color: var(--err); }
#zoneBtn { align-self: flex-start; }

@media (max-width: 800px) {
  .two-col { grid-template-columns: 1fr; }
  .two-col > .card { min-width: 0; }
}
@media (max-width: 520px) {
  #view-settings .card { padding: 14px; }
  .logout-wide { width: 100%; }
  .two-inputs { grid-template-columns: minmax(0, 1fr); }
}
