:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1c2330;
  --line: #2b3441;
  --text: #e6edf3;
  --muted: #8b98a8;
  --accent: #2f81f7;
  --ok: #3fb950;
  --bad: #f85149;
  --warn: #d29922;
  --tile-gap: 4px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--bad); min-height: 1.2em; margin: 0; }

input[type="password"], input[type="search"], input[type="text"] {
  width: 100%;
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  outline: none;
}
input:focus { border-color: var(--accent); }

.text-btn, .icon-btn, .layouts button, .all-btn, .login-card button, .pw-row button, .code-row button {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 8px;
  padding: 6px 12px;
}
.icon-btn { padding: 4px 10px; font-size: 16px; line-height: 1.3; }
.text-btn:hover, .icon-btn:hover, .layouts button:hover, .all-btn:hover { border-color: var(--accent); }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(360px, 100%);
  display: grid;
  gap: 12px;
  justify-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px 22px;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; text-align: center; }
.login-card button { width: 100%; background: var(--accent); border-color: var(--accent); padding: 10px; font-weight: 600; }

/* ---------- app layout ---------- */
.app {
  height: 100%;
  display: grid;
  grid-template-columns: 300px 1fr;
  grid-template-rows: auto auto 1fr;
  grid-template-areas: "top top" "side bar" "side main";
}
.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; white-space: nowrap; }
.view-title { flex: 1; min-width: 0; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.layouts { display: flex; gap: 4px; }
.layouts button { padding: 4px 10px; }
.layouts button.active { background: var(--accent); border-color: var(--accent); }
.pager { display: flex; align-items: center; gap: 6px; white-space: nowrap; }

.sidebar {
  grid-area: side;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.all-btn { width: 100%; text-align: left; }
.all-btn.active { border-color: var(--accent); background: #1f6feb33; }
.nvr-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.nvr {
  border: 1px solid transparent;
  border-radius: 8px;
}
.nvr.active { border-color: var(--accent); background: #1f6feb1f; }
.nvr-row { display: flex; align-items: center; }
.nvr-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px;
  background: none;
  border: 0;
  text-align: left;
}
.nvr-head:hover { background: var(--panel-2); border-radius: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--muted); }
.dot.on { background: var(--ok); }
.dot.off { background: var(--bad); }
.nvr-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 11px; color: var(--muted); white-space: nowrap; }
.badge.lock { color: var(--warn); }
.cams { list-style: none; margin: 0 0 6px; padding: 0 0 0 24px; display: grid; }
.cams button {
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  padding: 4px 6px;
  border-radius: 6px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cams button:hover { background: var(--panel-2); color: var(--text); }
.account-error {
  border: 1px solid var(--bad);
  color: var(--bad);
  border-radius: 8px;
  padding: 8px;
  font-size: 12px;
}

/* ---------- grid ---------- */
.grid {
  grid-area: main;
  display: grid;
  gap: var(--tile-gap);
  padding: var(--tile-gap);
  min-height: 0;
  background: #000;
}
.grid[data-layout="1"] { grid-template: 1fr / 1fr; }
.grid[data-layout="4"] { grid-template: repeat(2, 1fr) / repeat(2, 1fr); }
.grid[data-layout="9"] { grid-template: repeat(3, 1fr) / repeat(3, 1fr); }
.grid[data-layout="16"] { grid-template: repeat(4, 1fr) / repeat(4, 1fr); }
.empty { grid-area: main; display: grid; place-items: center; text-align: center; padding: 24px; color: var(--muted); }

.tile {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: #0a0a0a;
  border-radius: 4px;
  overflow: hidden;
  cursor: zoom-in;
}
.tile nvr-player, .viewer-video nvr-player { position: absolute; inset: 0; display: block; }
.tile video, .viewer-video video { width: 100%; height: 100%; object-fit: contain; background: #000; }
/* Bottom bar of each camera: name + tools. */
.tile-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 6px 4px 8px;
  background: linear-gradient(transparent, #000d 45%);
  cursor: default;
}
.tile-label {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tile-tools, .zoom-bar { display: flex; gap: 3px; flex: none; }
.tool-btn {
  border: 1px solid #ffffff2e;
  background: #ffffff1a;
  color: #fff;
  border-radius: 6px;
  min-width: 28px;
  height: 26px;
  padding: 0 6px;
  font-size: 13px;
  line-height: 1;
}
.tool-btn:hover { background: var(--accent); border-color: var(--accent); }
/* Small tiles: tools appear when the mouse is over the camera. */
.tile .tile-tools { opacity: 0; transition: opacity 0.15s; }
.tile:hover .tile-tools, .tile:focus-within .tile-tools, .tile.zoomed .tile-tools, .tile:fullscreen .tile-tools, .tile.maxed .tile-tools { opacity: 1; }
@media (hover: none) { .tile .tile-tools { opacity: 1; } }
.tile.zoomed { cursor: grab; }
.tile.zoomed:active { cursor: grabbing; }
.tile:fullscreen, .tile.maxed { border-radius: 0; background: #000; }
.tile.maxed { position: fixed; inset: 0; z-index: 15; }
.tile:fullscreen .tile-bar, .tile.maxed .tile-bar { padding: 20px 14px 10px; }
.tile:fullscreen .tile-label, .tile.maxed .tile-label { font-size: 16px; }
.tile:fullscreen .tool-btn, .tile.maxed .tool-btn { height: 32px; min-width: 36px; font-size: 15px; }
.viewer-video { overflow: hidden; }
.viewer-video.zoomed { cursor: grab; }
.viewer-bar .zoom-bar .tool-btn { border-color: var(--line); background: var(--panel-2); color: var(--text); height: 31px; min-width: 34px; }
.viewer-bar .zoom-bar .tool-btn:hover { background: var(--accent); color: #fff; }
.tile-note {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 10px;
  color: var(--muted);
  font-size: 13px;
  pointer-events: none;
}
.tile.blank { cursor: default; }

/* ---------- big view ---------- */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: #000;
  display: grid;
  grid-template-rows: auto 1fr;
}
.viewer-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.viewer-bar > span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.viewer-actions { display: flex; gap: 6px; }
.viewer-video { position: relative; min-height: 0; }

/* ---------- settings ---------- */
.settings {
  width: min(560px, calc(100% - 32px));
  max-height: calc(100% - 32px);
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 20px 20px;
}
.settings::backdrop { background: #0009; }
.settings-head { display: flex; align-items: center; justify-content: space-between; }
.settings h2 { margin: 0; font-size: 18px; }
.settings h3 { margin: 18px 0 6px; font-size: 14px; }
.code-list { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 6px; }
.code-row { display: grid; grid-template-columns: 1fr 120px auto; gap: 6px; align-items: center; }
.code-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.code-row .ok { color: var(--ok); font-size: 12px; }
.code-row .msg { grid-column: 1 / -1; font-size: 12px; min-height: 0; }
.pw-row { display: grid; grid-template-columns: 1fr auto; gap: 6px; margin-bottom: 10px; }
.pw-row label { grid-column: 1 / -1; }

/* ---------- phone ---------- */
.only-mobile { display: none; }
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-areas: "top" "bar" "main"; }
  .only-mobile { display: inline-block; }
  .brand { display: none; }
  .sidebar {
    position: fixed;
    top: 50px;
    left: 0;
    bottom: 0;
    width: min(300px, 85%);
    z-index: 10;
    transform: translateX(-100%);
    transition: transform 0.2s;
  }
  .app.menu-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax #0008; }
  .layouts button[data-layout="16"] { display: none; }
  .topbar { gap: 6px; padding: 8px; }
  #logout { padding: 6px 8px; }
  .code-row { grid-template-columns: 1fr 100px auto; }
}

.player-status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 12px;
  color: var(--muted);
  font-size: 13px;
  pointer-events: none;
}

/* ---------- open NVRs bar + multi-select list ---------- */
.nvr-head { flex: 1; min-width: 0; }
.check {
  width: 16px;
  height: 16px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 4px;
  display: grid;
  place-items: center;
  font-size: 11px;
  line-height: 1;
}
.nvr.active .check { background: var(--accent); border-color: var(--accent); color: #fff; }
.expand {
  flex: none;
  background: none;
  border: 0;
  color: var(--muted);
  padding: 6px 8px;
  border-radius: 6px;
}
.expand:hover { background: var(--panel-2); color: var(--text); }
.open-bar {
  grid-area: bar;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.open-label { color: var(--muted); font-size: 12px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px 2px 10px;
  border-radius: 999px;
  background: #1f6feb33;
  border: 1px solid var(--accent);
  font-size: 13px;
  max-width: 100%;
}
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button {
  border: 0;
  background: none;
  color: var(--text);
  border-radius: 50%;
  width: 22px;
  height: 22px;
  line-height: 1;
  flex: none;
}
.chip button:hover { background: var(--bad); }
.close-all { margin-left: auto; padding: 3px 10px; }

/* ---------- hiding camera lists ---------- */
.expand { font-size: 16px; min-width: 34px; padding: 6px 10px; }
.expand.on { color: var(--accent); }
.cams .hide-cams { color: var(--accent); font-size: 12px; }
.cams .hide-cams:hover { color: var(--text); }
.hide-all { width: 100%; text-align: left; font-size: 12px; color: var(--muted); padding: 5px 12px; }
.sidebar { overflow-x: hidden; }
.nvr-summary { margin: 0; }
.empty p { margin: 0 0 10px; }

/* ---------- playback ---------- */
.viewer { grid-template-rows: auto 1fr auto; }
.mode-btn.on { background: var(--accent); border-color: var(--accent); }
.pb-bar {
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding: 8px 12px 6px;
  display: grid;
  gap: 6px;
}
.pb-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.pb-controls input[type="date"] {
  padding: 5px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
}
.pb-time { flex: 1; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; min-width: 90px; }
.pb-timeline {
  position: relative;
  height: 34px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  overflow: hidden;
}
.pb-clips { position: absolute; inset: 0; }
.pb-clip { position: absolute; top: 6px; bottom: 6px; min-width: 2px; background: var(--accent); border-radius: 2px; opacity: 0.85; }
.pb-clip.alarm { background: #e3b341; }
.pb-cursor { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; box-shadow: 0 0 0 1px #000a; pointer-events: none; }
.pb-hover {
  position: absolute;
  top: 2px;
  padding: 1px 6px;
  font-size: 11px;
  background: #000c;
  border-radius: 4px;
  pointer-events: none;
  transform: translateX(-50%);
  white-space: nowrap;
}
.pb-hours { position: relative; height: 15px; font-size: 11px; color: var(--muted); }
.pb-hours span { position: absolute; top: 0; transform: translateX(-50%); white-space: nowrap; font-variant-numeric: tabular-nums; }
.pb-msg { margin: 0; min-height: 1.2em; }

/* ---------- Live view / Playback mode switch ---------- */
.modes { display: flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; flex: none; }
.modes button { border: 0; background: var(--panel-2); padding: 6px 12px; white-space: nowrap; }
.modes button + button { border-left: 1px solid var(--line); }
.modes button.active { background: var(--accent); color: #fff; font-weight: 600; }
.pb-screen { grid-area: main; overflow-y: auto; padding: 16px; background: var(--bg); }
.pb-screen h2 { margin: 0 0 4px; font-size: 16px; }
.pb-screen .hint { margin: 0 0 14px; }
.pb-nvr + .pb-nvr { margin-top: 18px; }
.pb-cams { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.pb-cam {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  text-align: left;
  min-width: 0;
}
.pb-cam:hover { border-color: var(--accent); background: var(--panel-2); }
.pb-cam .icon { font-size: 18px; flex: none; color: var(--accent); }
.pb-cam .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pb-cam:disabled { opacity: 0.5; cursor: not-allowed; }
@media (max-width: 760px) {
  .modes button { padding: 6px 8px; font-size: 13px; }
  .view-title { display: none; }
}

/* ---------- playback time box ---------- */
.pb-time-form { display: flex; gap: 4px; }
.pb-time-form input[type="time"] {
  padding: 5px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  font-variant-numeric: tabular-nums;
}
.go-btn { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* ---------- light theme ---------- */
:root[data-theme="light"] {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --panel-2: #eef1f6;
  --line: #d3dae4;
  --text: #1a2330;
  --muted: #5b6878;
  --accent: #1f6feb;
  --ok: #1a7f37;
  --bad: #cf222e;
  --warn: #9a6700;
  color-scheme: light;
}
:root[data-theme="light"] .all-btn.active,
:root[data-theme="light"] .nvr.active { background: #1f6feb14; }
:root[data-theme="light"] .chip { background: #1f6feb1a; }
:root[data-theme="light"] .settings::backdrop { background: #0005; }
/* Camera grid follows the theme; the big single-camera view stays dark for the video. */
:root[data-theme="light"] .grid { background: var(--bg); }
:root[data-theme="light"] .empty { color: var(--muted); }
:root[data-theme="light"] .tile { background: #dfe4eb; border: 1px solid var(--line); }
:root[data-theme="light"] .tile.blank { background: #e9edf2; }
:root[data-theme="light"] .tile video { background: #dfe4eb; }
:root[data-theme="light"] .tile-note,
:root[data-theme="light"] .tile .player-status { color: #3d4a5a; }
:root[data-theme="light"] .viewer,
:root[data-theme="light"] .viewer-video { background: #000; }
:root[data-theme="light"] .viewer-video .player-status { color: #b8c2cf; }

/* ---------- branding ---------- */
.brand-logo { width: 28px; height: 28px; object-fit: cover; border-radius: 50%; }
.login-logo { height: 120px; width: auto; background: #fff; border-radius: 14px; padding: 8px; }
.theme-btn { min-width: 36px; }
.login-theme {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 5;
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 16px;
}
@media (max-width: 760px) {
  .brand { display: flex; }
  .brand span { display: none; }
}
.login-card button { color: #fff; }
.go-btn, .modes button.active, .layouts button.active { color: #fff; }

.tile-label { color: #fff; }
#logout { white-space: nowrap; }

/* ---------- Lebanon clock ---------- */
.clock {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  flex: none;
}
.clock-time { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: 0.5px; }
.clock-date { font-size: 10px; color: var(--muted); white-space: nowrap; }
.viewer-bar .clock { flex: none; }
@media (max-width: 760px) {
  .clock { padding: 2px 6px; }
  .clock-time { font-size: 14px; }
  .clock-date { display: none; }
}

/* ---------- hideable NVR list (desktop) ---------- */
.hide-side-btn { align-self: flex-start; font-size: 12px; padding: 4px 10px; color: var(--muted); }
@media (min-width: 761px) {
  .app.side-hidden { grid-template-columns: 0 1fr; }
  .app.side-hidden .sidebar { display: none; }
}
@media (max-width: 760px) {
  .hide-side-btn { display: none; }
}
.choose-btn { display: none; }
.app.side-hidden .choose-btn { display: inline-block; }
@media (max-width: 760px) { .choose-btn { display: inline-block; } }

/* ---------- whole-grid full screen ---------- */
.grid-full-btn { white-space: nowrap; }
.app.grid-full { grid-template-columns: 1fr !important; grid-template-rows: 1fr !important; grid-template-areas: "main" !important; }
.app.grid-full .topbar,
.app.grid-full .sidebar,
.app.grid-full .open-bar { display: none !important; }
.app.grid-full .grid { --tile-gap: 2px; }
.grid-full-exit {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 16;
  border: 1px solid #ffffff40;
  background: #000a;
  color: #fff;
  border-radius: 8px;
  padding: 6px 12px;
  opacity: 0;
  transition: opacity 0.2s;
}
.app.grid-full .grid-full-exit:not([hidden]) { display: block; }
.app.grid-full:hover .grid-full-exit, .grid-full-exit:focus { opacity: 1; }
@media (max-width: 760px) { .grid-full-btn { display: none; } }
/* Narrower screens: let the top bar wrap instead of pushing buttons off the edge. */
.topbar { flex-wrap: wrap; row-gap: 6px; }
@media (max-width: 1400px) { .view-title { display: none; } }
/* Small camera boxes: drop the name while the tools are shown and make the buttons compact. */
.tile { container-type: size; }
@container (max-width: 300px) {
  .tile-bar { gap: 2px; padding-left: 4px; padding-right: 4px; }
  .tool-btn { min-width: 22px; height: 22px; padding: 0 3px; font-size: 11px; }
}
@container (max-width: 230px) {
  .tile:hover .tile-label { display: none; }
}

/* ---------- playback: choose several cameras ---------- */
.pb-actions {
  position: sticky;
  top: -16px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0 -16px 14px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.pb-count { flex: 1; font-weight: 600; }
.pb-actions button:disabled { opacity: 0.5; cursor: not-allowed; }
.pb-cam { cursor: pointer; }
.pb-cam .check { flex: none; }
.pb-cam.selected { border-color: var(--accent); background: #1f6feb22; }
.pb-cam.selected .check { background: var(--accent); border-color: var(--accent); color: #fff; }
.pb-cam .name { flex: 1; }
.pb-cam.disabled { opacity: 0.5; cursor: not-allowed; }
.alone-btn { flex: none; color: var(--text); background: var(--panel-2); border-color: var(--line); font-size: 11px; height: 24px; }
.alone-btn:hover { color: #fff; }

/* ---------- several cameras played together ---------- */
.mpb { z-index: 21; }
.mpb-grid { grid-area: auto; min-height: 0; }
:root[data-theme="light"] .mpb-grid { background: #000; }
:root[data-theme="light"] .mpb .tile { background: #0a0a0a; border: 0; }
:root[data-theme="light"] .mpb .tile video { background: #000; }
:root[data-theme="light"] .mpb .tile-note { color: #b8c2cf; }

/* ---------- tick boxes on single cameras ---------- */
.cams .cam-row { display: flex; align-items: center; }
.cams .cam-pick { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; }
.cams .cam-pick .check { width: 14px; height: 14px; font-size: 10px; }
.cams .cam-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cams .cam-row.on .cam-pick { color: var(--text); }
.cams .cam-row.on .check { background: var(--accent); border-color: var(--accent); color: #fff; }
.cams .cam-open { flex: none; width: auto; padding: 2px 8px; opacity: 0; }
.cams .cam-row:hover .cam-open, .cams .cam-open:focus { opacity: 1; }
@media (hover: none) { .cams .cam-open { opacity: 1; } }
.check.partial { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
/* The NVR's "selected" colour must not fill the boxes of cameras that are not ticked. */
.nvr.active .cams .cam-row:not(.on) .check { background: none; border-color: var(--line); color: inherit; }
.tool-btn.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- picture adjustments (🎚) ---------- */
/* Zoom (--zt) moves the video; the adjustments (--vf) apply on the player around it, after the
   zoom, so the zoomed picture keeps its real detail and sharpening doesn't grow with the zoom. */
.tile nvr-player video, .viewer-video nvr-player video { transform: var(--zt, none); transform-origin: center center; }
.tile nvr-player, .viewer-video nvr-player { filter: var(--vf, none); overflow: hidden; }
.adjust-panel {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 3;
  width: 250px;
  max-width: calc(100% - 16px);
  max-height: calc(100% - 56px);
  overflow: auto;
  padding: 10px 12px;
  border-radius: 8px;
  background: #101318e6;
  border: 1px solid #ffffff26;
  color: #fff;
  font-size: 12px;
  cursor: default;
  box-shadow: 0 6px 20px #0008;
}
.adjust-row { display: grid; grid-template-columns: 70px 1fr 46px; align-items: center; gap: 6px; margin-bottom: 6px; }
.adjust-row input { width: 100%; min-width: 0; accent-color: var(--accent); }
.adjust-value { text-align: right; color: #cfd6df; font-variant-numeric: tabular-nums; }
.adjust-presets { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.adjust-presets .tool-btn { height: 24px; font-size: 11px; }
.tile.adjusting .tile-tools { opacity: 1; }
.tile:fullscreen .adjust-panel, .tile.maxed .adjust-panel, .viewer-video .adjust-panel { top: 12px; right: 12px; width: 290px; font-size: 13px; }
@container (max-width: 300px) {
  .adjust-panel { top: 4px; right: 4px; padding: 6px 8px; }
  .adjust-row { grid-template-columns: 54px 1fr 38px; gap: 4px; margin-bottom: 3px; }
}

/* ---------- live quality: badge on cameras playing HD (zoomed, full screen, alone) ---------- */
.tile.hd .tile-label::before {
  content: 'HD';
  margin-right: 6px;
  padding: 1px 4px;
  border-radius: 3px;
  background: var(--accent);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  vertical-align: 1px;
}
:root[data-theme="light"] .tile.maxed, :root[data-theme="light"] .tile:fullscreen { background: #000; border: 0; }

/* ---------- playback timeline: drag to move, wheel / ＋－ to zoom ---------- */
.pb-timeline { cursor: ew-resize; touch-action: none; user-select: none; }
.pb-cursor { width: 2px; background: #ff3b30; box-shadow: 0 0 0 1px #0006; }
.pb-cursor::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ff3b30;
  border: 2px solid #fff;
  transform: translate(-50%, -50%);
  box-shadow: 0 1px 3px #0008;
}
.pb-timeline.dragging .pb-cursor::after { width: 16px; height: 16px; }
.pb-hover { color: #fff; font-weight: 600; z-index: 1; }
.tl-zoom { display: flex; gap: 2px; }
.tl-zoom .text-btn { min-width: 32px; padding-left: 6px; padding-right: 6px; font-weight: 700; }

/* ---------- playback calendar (recorded days in blue) ---------- */
.date-btn { white-space: nowrap; }
.cal-pop {
  position: fixed;
  z-index: 40;
  width: 270px;
  padding: 10px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 30px #0007;
}
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; font-weight: 700; }
.cal-head .icon-btn:disabled { opacity: 0.3; cursor: default; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; text-align: center; }
.cal-wd { font-size: 11px; color: var(--muted); padding-bottom: 2px; }
.cal-day {
  height: 32px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: none;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.cal-day:hover:not(:disabled) { border-color: var(--accent); }
.cal-day:disabled { opacity: 0.3; cursor: default; }
.cal-day.rec { background: var(--accent); color: #fff; font-weight: 700; }
.cal-day.today { text-decoration: underline; text-underline-offset: 3px; }
.cal-day.sel { box-shadow: 0 0 0 2px var(--text); }
.cal-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
.cal-key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--accent); vertical-align: -1px; }

/* ---------- settings: tabs, tables, forms ---------- */
.settings { width: min(860px, calc(100% - 32px)); }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin: 12px 0 10px; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; background: none; padding: 8px 12px; border-bottom: 2px solid transparent; color: var(--muted); }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.settings [data-panel] { display: none; }
.settings [data-panel].shown { display: block; }
.table-wrap { max-height: 46vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; margin: 8px 0; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { position: sticky; top: 0; background: var(--panel-2); font-size: 12px; color: var(--muted); font-weight: 600; z-index: 1; }
.table tr:last-child td { border-bottom: 0; }
.table td.actions { white-space: nowrap; text-align: right; }
.table td.actions .text-btn { padding: 3px 9px; font-size: 12px; }
.table tr.warn td { background: #d2992218; }
.table .nowrap { white-space: nowrap; }
#user-table td:nth-child(3) { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-btn.danger:hover:not(:disabled) { border-color: var(--bad); color: var(--bad); }
.text-btn:disabled { opacity: 0.45; cursor: default; }
.user-form { display: grid; gap: 10px; margin-top: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.user-form h3 { margin: 0; }
.user-form label { display: grid; gap: 4px; font-size: 13px; }
.user-form select, .activity-filters select, .tour select {
  padding: 7px 9px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.user-form fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 0; }
.user-form legend { font-size: 13px; padding: 0 4px; }
label.inline { display: flex !important; align-items: center; gap: 6px; cursor: pointer; }
.nvr-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 4px 12px; margin: 6px 0 0 22px; }
.nvr-checks.off { opacity: 0.45; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.activity-filters { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.activity-filters a.text-btn { text-decoration: none; color: inherit; }
#settings-msg { margin: 10px 0 0; min-height: 1.2em; }

/* ---------- saved groups (sidebar) ---------- */
.groups { margin: 4px 0 8px; display: grid; gap: 6px; }
.groups-head { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.group-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.group-chips:empty { display: none; }
.group-chip { display: inline-flex; align-items: stretch; border: 1px solid var(--line); border-radius: 999px; background: var(--panel-2); overflow: hidden; }
.group-chip.on { border-color: var(--accent); background: #1f6feb22; }
.group-chip button { border: 0; background: none; padding: 4px 10px; font-size: 13px; }
.group-chip .group-del { padding: 4px 8px 4px 2px; color: var(--muted); font-size: 11px; }
.group-chip .group-del:hover { color: var(--bad); }
.group-chip .group-open:hover { color: var(--accent); }
.group-save { font-size: 12px; padding: 5px 10px; justify-self: start; }
.group-form { display: flex; gap: 5px; }
.group-form input { padding: 6px 9px; }
.group-form .text-btn { padding: 5px 10px; }

/* ---------- auto tour ---------- */
.tour { display: flex; gap: 4px; align-items: center; flex: none; }
.tour select { padding: 5px 6px; }
#tour.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.open-bar.off { display: none; }

/* ---------- health ---------- */
.health-screen h2 { margin: 0 0 12px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; background: var(--panel); display: grid; }
.stat b { font-size: 24px; color: var(--ok); }
.stat span { color: var(--muted); font-size: 12px; }
.stat.bad { border-color: var(--bad); }
.stat.bad b { color: var(--bad); }
.health-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 14px; }
.progress { height: 6px; border-radius: 3px; background: var(--panel-2); overflow: hidden; flex: 1 1 160px; min-width: 120px; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.4s; }
.health-card { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); margin-bottom: 12px; overflow: hidden; }
.health-card.has-problems { border-color: #f8514966; }
.health-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; padding: 10px 14px; }
.health-head b { font-size: 15px; }
.health-head .badge { margin-left: auto; padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.badge.bad { background: #f8514922; color: var(--bad); }
.badge.ok { background: #3fb95022; color: var(--ok); }
.health-table { border-top: 1px solid var(--line); }
.health-table td.ok { color: var(--ok); }
.health-table td.bad { color: var(--bad); font-weight: 600; }
.health-table td:first-child { width: 34%; }
.link-btn { border: 0; background: none; padding: 0; color: var(--text); text-align: left; }
.link-btn:hover:not(:disabled) { color: var(--accent); text-decoration: underline; }
.link-btn:disabled { cursor: default; }

/* ---------- playback: pause, fast, save clip ---------- */
.pause-btn.on, #pb-fast.on { background: var(--accent); border-color: var(--accent); color: #fff; }
#pb-fast { min-width: 92px; }
.viewer-video .pb-still, .tile .pb-still { position: absolute; inset: 0; overflow: hidden; filter: var(--vf, none); }
.pb-still canvas { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; transform: var(--zt, none); transform-origin: center center; }
.clip-pop { width: 330px; }
.clip-pop form { display: grid; gap: 8px; }
.clip-pop p { margin: 0; }
.clip-row { display: flex; align-items: center; gap: 6px; }
.clip-row label { display: flex; align-items: center; gap: 6px; flex: 1; justify-content: space-between; }
.clip-row input[type="time"], .pb-time-form input[type="time"] { padding: 5px 7px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; }
.clip-row .text-btn, .clip-lengths .text-btn { padding: 4px 9px; font-size: 12px; }
.clip-lengths { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.clip-status { display: grid; gap: 6px; min-height: 1.2em; }
.clip-status .text-btn { justify-self: start; padding: 3px 9px; font-size: 12px; }
.health-table td.warn { color: var(--warn); }

/* ---------- internet use (📶) ---------- */
.net-btn { white-space: nowrap; font-variant-numeric: tabular-nums; }
.net-btn.on { border-color: var(--warn); color: var(--warn); }
.net-pop { width: 330px; display: grid; gap: 8px; }
.net-pop p { margin: 4px 0 0; }
.net-choice { display: flex; gap: 10px; align-items: flex-start; padding: 8px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.net-choice:has(input:checked) { border-color: var(--accent); background: #1f6feb18; }
.net-choice input { margin-top: 3px; }
.net-choice > span { display: grid; gap: 2px; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(560px, calc(100% - 32px));
  padding: 12px 16px;
  border-radius: 10px;
  background: #1c2330f2;
  color: #fff;
  border: 1px solid var(--warn);
  box-shadow: 0 8px 24px #0008;
  font-size: 13px;
}

/* The NVR / camera lists never grow wider than the sidebar: long names end in "…" and the
   camera count, lock and ▸ always stay visible. */
.nvr-list, .cams { grid-template-columns: minmax(0, 1fr); }
.nvr, .cam-row { min-width: 0; }
.nvr-head .badge { flex: none; }
.cam-pick { min-width: 0; }
.cam-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Long NVR names use up to two lines instead of being cut short. */
.nvr-head .nvr-name {
  white-space: normal;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow-wrap: anywhere;
}

/* ---------- "All NVRs" box and saved views ---------- */
.nvr-all { border-bottom: 1px solid var(--line); border-radius: 8px 8px 0 0; margin-bottom: 2px; }
.nvr-all .nvr-name { font-weight: 600; }
.view-pick {
  padding: 5px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  max-width: 180px;
}
.view-pick:hover { border-color: var(--accent); }
.save-view { padding: 3px 10px; margin-left: auto; }
.save-view + .close-all { margin-left: 0; }

/* Camera boxes: the tool buttons take no room until the mouse is over the box, so the name shows in full. */
@media (hover: hover) {
  .tile:not(:hover):not(:focus-within):not(.zoomed):not(.maxed):not(:fullscreen):not(.adjusting) .tile-tools { display: none; }
}

/* Pages of cameras: clear buttons, highlighted (shown only when there is more than one page). */
.pager { border: 1px solid var(--accent); border-radius: 10px; padding: 2px; background: #1f6feb1a; gap: 4px; }
.pager .text-btn { padding: 4px 10px; font-weight: 600; }
.pager .text-btn:not(:disabled) { background: var(--accent); border-color: var(--accent); color: #fff; }
.pager #page-label { padding: 0 4px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- inside OneApp: one shop at a time (option A of the 2026-10-10 sketch) ---------- */
.shop-pick { display: none; }
.app.oneapp { --accent: #00775b; }
.app.oneapp .brand,
.app.oneapp .clock,
.app.oneapp .tour,
.app.oneapp #net,
.app.oneapp [data-theme-toggle],
.app.oneapp #logout,
.app.oneapp #view-pick,
.app.oneapp .layouts button[data-layout="1"],
.app.oneapp .layouts button[data-layout="0"],
.app.oneapp #open-bar,
.app.oneapp #nvr-summary,
.app.oneapp #groups,
.app.oneapp #hide-all-lists { display: none !important; }
.app.oneapp .view-title { display: block; flex: 1; color: var(--text); font-weight: 600; font-size: 15px; }
.app.oneapp .grid-full-btn { margin-left: auto; }
.app.oneapp #search { margin-top: 2px; }
.app.oneapp #search::placeholder { color: var(--muted); }
.shop-btn {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font: inherit;
}
.shop-btn:hover { border-color: var(--line); }
.shop-btn.sel { background: color-mix(in srgb, var(--accent) 18%, transparent); border-color: var(--accent); font-weight: 600; }
.shop-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shop-count { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.shop-count.off { color: var(--bad); }
@media (max-width: 760px) {
  /* Phone: the shop list is a drop-down at the top; no sliding panel. */
  .app.oneapp #menu-toggle,
  .app.oneapp .sidebar { display: none !important; }
  .app.oneapp .shop-pick {
    display: block;
    flex: 1;
    min-width: 0;
    padding: 6px 8px;
    border-radius: 6px;
    border: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--text);
    font: inherit;
    font-weight: 600;
  }
  .app.oneapp .view-title { display: none; }
  /* One camera per row, full width, scrolling down the page (asked for 2026-10-11). */
  .app.oneapp .grid { grid-template-columns: minmax(0, 1fr) !important; grid-template-rows: none !important; grid-auto-rows: max-content; align-content: start; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  /* Width-only containment: full "size" containment gives the tile no height of its own, so a
     grid row sized by its content collapses and the cameras overlap. */
  .app.oneapp .grid .tile { aspect-ratio: 16 / 9; container-type: inline-size; }
}
@media (max-width: 760px) { .app.oneapp .grid .tile.blank { display: none; } }

/* ---------- a receipt's footage (clip.js): every camera on one clock ---------- */
.clip { padding: 10px 12px 16px; max-width: 1400px; margin: 0 auto; outline: none; }
.clip-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; margin-bottom: 8px; font-size: 15px; }
.clip-head b { font-size: 17px; }
.clip-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 6px; }
.clip-track { position: relative; flex: 1 1 220px; height: 28px; display: flex; align-items: center; }
.clip-slider { width: 100%; margin: 0; }
/* The receipt, marked on the slider where it falls in the window. */
.clip-mark { position: absolute; top: 2px; bottom: 2px; width: 3px; margin-left: -1px; background: #e5534b; border-radius: 2px; pointer-events: none; }
.clip-clock { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 68px; text-align: right; }
.clip-status:empty { display: none; }
.clip-status { margin: 0 0 6px; }
/* Every camera on screen at once, equal size (answered "A", 2026-10-12): the screen fills its
   frame, the controls take what they need and the cameras share the rest. clip.js sets --cols
   and --rows from the number of cameras (gridShape). Each camera's cell is a size container and
   its tile is the largest 16:9 box that fits in it, so nothing is cropped and the name and
   buttons stay on the picture rather than floating in black bands. */
.clip { height: 100%; display: flex; flex-direction: column; }
.clip-grid { flex: 1 1 auto; min-height: 0; display: grid; gap: 8px; grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr)); grid-template-rows: repeat(var(--rows, 1), minmax(0, 1fr)); }
.clip-cell { min-width: 0; min-height: 0; container-type: size; display: grid; place-items: center; }
.clip-tile { position: relative; background: #000; border-radius: 8px; overflow: hidden; aspect-ratio: 16 / 9; width: min(100cqw, calc(100cqh * 16 / 9)); }
/* One camera tapped: it fills the screen; the others keep playing out of sight. */
.clip-grid.focus { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
.clip-grid.focus .clip-cell:not(.big) { display: none; }
.clip-video { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; cursor: pointer; }
.clip-tile.nofilm .clip-video, .clip-tile.outside .clip-video { opacity: 0.25; }
.clip-tile .tile-bar { position: absolute; left: 0; right: 0; top: 0; bottom: auto; display: flex; justify-content: space-between; align-items: center; gap: 6px; padding: 4px 8px; background: linear-gradient(#000a, #0000); }
.clip-tile .tile-tools { opacity: 1; }
.clip-tile .tile-tools a, .clip-tile .tile-tools button { text-decoration: none; font-size: 12px; padding: 3px 8px; }
.clip-note { position: absolute; left: 10px; right: 10px; bottom: 10px; background: #000c; color: #fff; padding: 6px 10px; border-radius: 6px; font-size: 13px; }
.clip-note[hidden] { display: none; }
.clip-foot { margin: 8px 0 0; font-size: 12px; flex: none; }
@media (max-width: 700px) {
  /* A phone: one camera per row, full width, scrolling down. */
  .clip { height: auto; display: block; }
  .clip-grid { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; }
  .clip-cell { container-type: normal; display: block; }
  .clip-tile { width: 100%; }
  .clip-bar { position: sticky; top: 0; background: var(--bg); padding: 6px 0; z-index: 2; }
}
