/* ════════════════════════════════════════════════════════════════
   CamPlus — Drive M3 Expressive Light  ⇄  Nothing Dark
   ════════════════════════════════════════════════════════════════ */

:root,
[data-theme="light"] {
  --bg: #f8f9fc;
  --bg-2: #f0f4f9;
  --card: #ffffff;
  --line: #e3e8f0;
  --text: #1f1f1f;
  --text-2: #5f6368;
  --primary: #1a73e8;
  --on-primary: #ffffff;
  --accent-2: #5e5ce6;
  --tonal: #e8f0fe;
  --tonal-2: #eef2ff;
  --on-tonal: #0b57d0;
  --danger: #d93025;
  --danger-bg: #fce8e6;
  --ok: #188038;
  --warn: #e37400;
  --track: #dfe3eb;
  --bar: rgba(248, 249, 252, .78);
  --scrim: rgba(32, 33, 36, .45);
  --shadow: 0 1px 2px rgba(60, 64, 67, .08), 0 2px 8px rgba(60, 64, 67, .06);
  --shadow-2: 0 4px 12px rgba(60, 64, 67, .14), 0 12px 32px rgba(60, 64, 67, .12);
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0a0a0a;
  --bg-2: #101010;
  --card: #141414;
  --line: #262626;
  --text: #ffffff;
  --text-2: #9b9b9b;
  --primary: #ffffff;
  --on-primary: #0a0a0a;
  --accent-2: #0a0a0a;
  --tonal: #222222;
  --tonal-2: #1a1a1a;
  --on-tonal: #ffffff;
  --danger: #ff3b30;
  --danger-bg: #2b0e0c;
  --ok: #ffffff;
  --warn: #ffffff;
  --track: #333333;
  --bar: rgba(10, 10, 10, .78);
  --scrim: rgba(0, 0, 0, .7);
  --shadow: none;
  --shadow-2: 0 0 0 1px #262626;
  color-scheme: dark;
}

:root {
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --r: 20px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Google Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --nav-h: 68px;
  --bar-h: 60px;
}

/* ───────────── Base ───────────── */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  overscroll-behavior-y: none;
  transition: background-color .3s var(--ease), color .3s var(--ease);
}
h1, h2, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button { border: 0; background: none; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
small { font-size: 12.5px; color: var(--text-2); }
.grow { flex: 1 1 auto; min-width: 0; }
.muted { color: var(--text-2); }
.ic { width: 24px; height: 24px; fill: currentColor; flex: none; display: block; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ───────────── App bar ───────────── */
.appbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--bar);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.appbar-in {
  height: var(--bar-h); max-width: 1180px; margin: 0 auto;
  padding: 0 12px 0 16px; display: flex; align-items: center; gap: 8px;
}
.logo { width: 30px; height: 30px; flex: none; }
.appbar h1 { font-size: 20px; font-weight: 600; letter-spacing: -.2px; margin-right: 4px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px;
  border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap;
  background: var(--tonal); color: var(--on-tonal);
  transition: background-color .25s var(--ease), color .25s var(--ease);
}
.pill .ic { width: 16px; height: 16px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.status[data-state="live"] { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.status[data-state="live"] .dot { animation: pulse 2s infinite; }
.status[data-state="connecting"] .dot { animation: blink 1s infinite; }
.status[data-state="offline"] { background: var(--danger-bg); color: var(--danger); }
.pill.privacy { background: var(--danger-bg); color: var(--danger); }
[data-theme="dark"] .pill { border: 1px solid var(--line); background: transparent; }
[data-theme="dark"] .status[data-state="offline"],
[data-theme="dark"] .pill.privacy { border-color: var(--danger); }

.iconbtn {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  display: grid; place-items: center; color: var(--text-2);
  transition: background-color .2s var(--ease), transform .2s var(--ease), color .2s var(--ease);
}
.iconbtn:hover { background: var(--bg-2); }
.iconbtn:active { transform: scale(.9); background: var(--tonal); }
.iconbtn.tonal { background: var(--tonal); color: var(--on-tonal); }
#themeBtn .ic { transition: transform .5s var(--ease); }
[data-theme="dark"] #themeBtn .ic { transform: rotate(180deg); }

/* ───────────── Layout ───────────── */
main {
  max-width: 1180px; margin: 0 auto;
  padding: 12px 12px calc(var(--nav-h) + env(safe-area-inset-bottom) + 20px);
}
.tab { display: none; }
.tab.active { display: block; animation: tabIn .35s var(--ease); }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow); overflow: hidden;
  transition: background-color .3s var(--ease), border-color .3s var(--ease);
}
.card-head { display: flex; align-items: center; gap: 12px; padding: 16px 16px 8px; }
.card-head > div:nth-child(2) { flex: 1; min-width: 0; }
.card-head h2 { font-size: 16px; font-weight: 600; }
.card-head p { font-size: 12.5px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-ic {
  width: 40px; height: 40px; border-radius: 14px; flex: none; display: grid; place-items: center;
  background: var(--tonal-2); color: var(--accent-2);
}
[data-theme="dark"] .card-ic { color: #fff; border: 1px solid var(--line); }
.card-ic .ic { width: 22px; height: 22px; }
.pad { padding: 8px 16px 16px; display: grid; gap: 12px; }

.cols { display: grid; gap: 12px; }

/* ───────────── Buttons / inputs ───────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 20px; border-radius: 999px; white-space: nowrap;
  background: var(--primary); color: var(--on-primary); font-weight: 600; font-size: 14px;
  transition: transform .2s var(--ease), filter .2s var(--ease), background-color .2s var(--ease), border-radius .2s var(--ease);
}
.btn .ic { width: 20px; height: 20px; }
.btn:active { transform: scale(.96); border-radius: 14px; }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn.small { height: 36px; padding: 0 14px; font-size: 13px; }
.btn.small .ic { width: 18px; height: 18px; }
.btn.tonal { background: var(--tonal); color: var(--on-tonal); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger-outline { background: transparent; color: var(--danger); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--danger) 50%, transparent); }
.btn.block { width: 100%; }

.input {
  height: 44px; width: 100%; min-width: 0; padding: 0 14px; border-radius: 14px;
  background: var(--bg-2); border: 1px solid transparent; outline: none;
  transition: border-color .2s var(--ease), background-color .2s var(--ease);
}
.input:focus { border-color: var(--primary); background: var(--card); }
.input::placeholder { color: var(--text-2); opacity: .8; }
.field.search {
  display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 14px; border-radius: 999px;
  background: var(--bg-2); color: var(--text-2);
}
.field.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; color: var(--text); }
.field.search .ic { width: 20px; height: 20px; }

/* ───────────── LIVE — player ───────────── */
.live-grid { display: grid; gap: 12px; }
.live-main { display: grid; gap: 12px; min-width: 0; }

.player { background: #000; border-color: transparent; }
.stage {
  position: relative; aspect-ratio: 16 / 9; width: 100%; overflow: hidden; background: #000;
  touch-action: pan-y; user-select: none; -webkit-user-select: none;
}
.stage.zoomed { touch-action: none; cursor: grab; }
.zoomer { position: absolute; inset: 0; transform-origin: 50% 50%; transition: transform .16s var(--ease); will-change: transform; }
.stage.gesturing .zoomer { transition: none; }
.zoomer video, .zoomer img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; display: block; pointer-events: none; }

.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.flash.go { animation: flash .45s var(--ease); }

.badges { position: absolute; top: 10px; left: 10px; display: flex; gap: 6px; flex-wrap: wrap; pointer-events: none; }
.tbadge {
  display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 999px;
  background: rgba(0, 0, 0, .55); color: #fff; font-size: 11.5px; font-weight: 700; letter-spacing: .4px;
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.tbadge .dot { width: 7px; height: 7px; }
.tbadge[data-state="live"] .dot { background: #34d058; }
.tbadge[data-state="connecting"] .dot { background: #ffd33d; animation: blink 1s infinite; }
.tbadge[data-state="offline"] .dot { background: #ff3b30; }
.tbadge.rec { background: #ff3b30; }
.tbadge.rec .dot { background: #fff; animation: blink 1s infinite; }

.hud {
  position: absolute; top: 10px; right: 10px; display: grid; grid-template-columns: auto auto; gap: 2px 10px;
  padding: 8px 10px; border-radius: 12px; background: rgba(0, 0, 0, .55); color: #fff;
  font: 600 11px/1.4 var(--mono); pointer-events: none;
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.hud span { opacity: .65; letter-spacing: .5px; }
.hud b { text-align: right; font-weight: 600; }

.stage-msg {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  color: #fff; background: rgba(0, 0, 0, .35); text-align: center; padding: 16px 16px 56px; font-size: 13.5px;
}
.stage-msg .btn { background: #fff; color: #000; }
.spinner { width: 30px; height: 30px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .25); border-top-color: #fff; animation: spin .9s linear infinite; }

.vctl {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: 6px; padding: 24px 8px 8px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .6));
}
.vbtn {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; flex: none;
  color: #fff; background: rgba(255, 255, 255, .14);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  transition: transform .2s var(--ease), background-color .2s var(--ease);
}
.vbtn .ic { width: 20px; height: 20px; }
.vbtn:active { transform: scale(.88); }
.vbtn.on { background: #fff; color: #000; }
.vbtn.text { width: auto; min-width: 46px; padding: 0 12px; border-radius: 999px; font-size: 12.5px; font-weight: 800; letter-spacing: .4px; }
.vbtn.spin .ic { animation: spin .9s linear infinite; }

.player:fullscreen { border-radius: 0; border: 0; width: 100vw; height: 100vh; }
.player:fullscreen .stage { aspect-ratio: auto; height: 100%; }
.player:-webkit-full-screen { border-radius: 0; border: 0; width: 100vw; height: 100vh; }
.player:-webkit-full-screen .stage { aspect-ratio: auto; height: 100%; }

/* banner */
.banner {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: var(--r);
  background: var(--danger-bg); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  animation: tabIn .35s var(--ease);
}
.banner > div { flex: 1; min-width: 0; display: grid; }
.banner small { color: inherit; opacity: .8; }
.banner .btn { background: var(--danger); color: #fff; }

/* quick actions */
.qa { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.qa-pill {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  height: 68px; border-radius: 22px; background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow);
  font-size: 12px; font-weight: 600; color: var(--text); min-width: 0;
  transition: transform .2s var(--ease), background-color .25s var(--ease), color .25s var(--ease), border-radius .25s var(--ease), border-color .25s var(--ease);
}
.qa-pill span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; padding: 0 4px; }
.qa-pill .ic { width: 22px; height: 22px; color: var(--primary); }
.qa-pill:active { transform: scale(.94); border-radius: 16px; }
.qa-pill.busy { opacity: .6; pointer-events: none; }
.qa-pill.on { background: var(--tonal); color: var(--on-tonal); border-color: transparent; }
.qa-pill.danger .ic, #qaRec .ic { color: var(--danger); }
#qaRec.on, .qa-pill.danger.on { background: var(--danger); color: #fff; border-color: transparent; }
#qaRec.on .ic, .qa-pill.danger.on .ic { color: #fff; }
#qaRec.on .ic { animation: blink 1s infinite; }
#qaSiren.on .ic { animation: wiggle .5s infinite; color: inherit; }
[data-theme="dark"] .qa-pill.on { background: #fff; color: #000; }
[data-theme="dark"] .qa-pill.on .ic { color: #000; }
[data-theme="dark"] #qaRec.on, [data-theme="dark"] .qa-pill.danger.on { background: var(--danger); color: #fff; }
[data-theme="dark"] #qaRec.on .ic, [data-theme="dark"] .qa-pill.danger.on .ic { color: #fff; }

/* PTZ */
.ptz-body { display: flex; align-items: center; justify-content: center; gap: 16px; padding: 8px 16px 18px; flex-wrap: wrap; }
.dpad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; width: 192px; height: 192px; padding: 8px;
  border-radius: 50%; background: var(--bg-2); border: 1px solid var(--line); flex: none;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.dpad button, .hold-pill { touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.dpad button {
  border-radius: 50%; display: grid; place-items: center; color: var(--text-2);
  transition: transform .15s var(--ease), background-color .15s var(--ease), color .15s var(--ease);
}
.dpad button.main { background: var(--card); color: var(--primary); box-shadow: var(--shadow); border: 1px solid var(--line); }
.dpad button .ic { width: 26px; height: 26px; pointer-events: none; }
.dpad button:not(.main) .ic { width: 20px; height: 20px; }
.dpad button.held { background: var(--primary); color: var(--on-primary); transform: scale(.9); }
.dpad-mid { display: grid; place-items: center; }
.dpad-mid i { width: 14px; height: 14px; border-radius: 50%; background: var(--track); }
.ptz-side { display: grid; gap: 8px; flex: 1 1 110px; max-width: 200px; }
.hold-pill {
  display: flex; align-items: center; justify-content: center; gap: 6px; height: 48px; border-radius: 999px;
  background: var(--bg-2); border: 1px solid var(--line); font-weight: 600; font-size: 13.5px;
  transition: transform .15s var(--ease), background-color .15s var(--ease), color .15s var(--ease), border-radius .2s var(--ease);
}
.hold-pill .ic { width: 20px; height: 20px; pointer-events: none; }
.hold-pill.tonal { background: var(--tonal); color: var(--on-tonal); border-color: transparent; }
.hold-pill.held, .hold-pill:active { background: var(--primary); color: var(--on-primary); transform: scale(.96); border-radius: 16px; }

/* ───────────── TOGGLES ───────────── */
.rows { padding: 0 0 8px; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; min-height: 56px; cursor: pointer;
  transition: background-color .2s var(--ease);
}
.row + .row { border-top: 1px solid color-mix(in srgb, var(--line) 60%, transparent); }
.row.col { flex-direction: column; align-items: stretch; gap: 8px; cursor: default; }
.row.sub { padding-left: 28px; }
.row-txt { flex: 1; min-width: 0; display: grid; }
.row-txt b { font-weight: 500; font-size: 14.5px; }
.row-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row-top b { font-weight: 500; font-size: 14.5px; }
.row-top output { font: 600 12.5px var(--mono); color: var(--on-tonal); background: var(--tonal); padding: 2px 8px; border-radius: 999px; }
.group-title { padding: 14px 16px 2px; font-size: 12px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; color: var(--text-2); border-top: 1px solid var(--line); }

/* M3 switch */
.switch { position: relative; width: 52px; height: 32px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; width: 100%; height: 100%; z-index: 1; }
.switch i {
  position: absolute; inset: 0; border-radius: 999px; background: var(--bg-2); border: 2px solid var(--track);
  transition: background-color .25s var(--ease), border-color .25s var(--ease);
}
.switch i::after {
  content: ""; position: absolute; top: 50%; left: 6px; width: 16px; height: 16px; margin-top: -8px; border-radius: 50%;
  background: var(--text-2);
  transition: transform .3s var(--ease), width .3s var(--ease), height .3s var(--ease), margin .3s var(--ease), left .3s var(--ease), background-color .25s var(--ease);
}
.switch input:active + i::after { width: 26px; }
.switch input:checked + i { background: var(--primary); border-color: var(--primary); }
.switch input:checked + i::after { width: 24px; height: 24px; margin-top: -12px; left: 2px; transform: translateX(20px); background: var(--on-primary); }
.switch input:checked:active + i::after { width: 28px; transform: translateX(16px); }
.switch.danger input:checked + i { background: var(--danger); border-color: var(--danger); }
.switch.danger input:checked + i::after { background: #fff; }

/* segmented */
.seg { display: flex; padding: 3px; gap: 2px; border-radius: 999px; background: var(--bg-2); border: 1px solid var(--line); }
.seg button {
  flex: 1 1 0; min-width: 0; height: 34px; padding: 0 6px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background-color .25s var(--ease), color .25s var(--ease), box-shadow .25s var(--ease);
}
.seg button.on { background: var(--card); color: var(--on-tonal); box-shadow: var(--shadow); }
[data-theme="light"] .seg button.on { background: var(--tonal); box-shadow: none; }
[data-theme="dark"] .seg button.on { background: #fff; color: #000; }

/* range */
input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 28px; margin: 0; background: transparent; cursor: pointer;
  --pct: 50%;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 12px; border-radius: 999px;
  background: linear-gradient(to right, var(--primary) var(--pct), var(--track) var(--pct));
}
input[type="range"]::-moz-range-track { height: 12px; border-radius: 999px; background: var(--track); }
input[type="range"]::-moz-range-progress { height: 12px; border-radius: 999px; background: var(--primary); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 6px; height: 28px; margin-top: -8px; border-radius: 4px; background: var(--primary);
  box-shadow: 0 0 0 4px var(--card); transition: width .15s var(--ease);
}
input[type="range"]::-moz-range-thumb { width: 6px; height: 28px; border: 0; border-radius: 4px; background: var(--primary); box-shadow: 0 0 0 4px var(--card); }
input[type="range"]:active::-webkit-slider-thumb { width: 4px; }

.row-btn { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* ───────────── GALLERY ───────────── */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 12px 12px; margin: 0 -12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  height: 36px; padding: 0 16px; border-radius: 12px; flex: none; font-weight: 600; font-size: 13.5px;
  background: var(--card); border: 1px solid var(--line); color: var(--text-2);
  transition: background-color .25s var(--ease), color .25s var(--ease), border-radius .25s var(--ease), border-color .25s var(--ease);
}
.chip.on { background: var(--tonal); color: var(--on-tonal); border-color: transparent; border-radius: 999px; }
[data-theme="dark"] .chip.on { background: #fff; color: #000; }

.disk { padding: 14px 16px 16px; margin-bottom: 12px; }
.disk-top { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.disk-txt { flex: 1; min-width: 0; display: grid; }
.disk-txt b { font-weight: 600; }
.bar { height: 10px; border-radius: 999px; background: var(--track); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, var(--primary), var(--accent-2)); transition: width .6s var(--ease); }
[data-theme="dark"] .bar i { background: #fff; }
.bar.hot i { background: var(--danger); }

.mgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.mcard {
  display: block; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden;
  box-shadow: var(--shadow); min-width: 0; transition: transform .2s var(--ease), border-color .2s var(--ease);
}
.mcard:active { transform: scale(.97); }
.mcard:hover { border-color: var(--primary); }
.thumb { position: relative; aspect-ratio: 16 / 10; background: var(--bg-2); display: grid; place-items: center; color: var(--text-2); overflow: hidden; }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.thumb .ic { width: 40px; height: 40px; opacity: .7; }
.thumb .tag { position: absolute; left: 8px; top: 8px; padding: 2px 8px; border-radius: 999px; background: rgba(0, 0, 0, .6); color: #fff; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; }
.minfo { padding: 8px 12px 10px; display: grid; gap: 1px; }
.minfo b { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.minfo small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { display: grid; place-items: center; gap: 8px; padding: 48px 16px; color: var(--text-2); text-align: center; }
.empty .ic { width: 48px; height: 48px; opacity: .5; }

/* ───────────── LAB ───────────── */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 8px 16px 12px; }
.stat { padding: 12px 14px; border-radius: 16px; background: var(--bg-2); display: grid; gap: 2px; min-width: 0; }
.stat.wide { grid-column: 1 / -1; }
.stat b { font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat b.ok { color: var(--ok); }
.stat b.bad { color: var(--danger); }
.badgerow { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 16px; }
.badgerow:empty { display: none; }
.badge { height: 26px; padding: 0 10px; border-radius: 999px; display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; background: var(--tonal); color: var(--on-tonal); }
.badge.off { background: var(--bg-2); color: var(--text-2); }
[data-theme="dark"] .badge { border: 1px solid var(--line); }
[data-theme="dark"] .badge:not(.off) { background: #fff; color: #000; }

.dptable { max-height: 300px; overflow: auto; border: 1px solid var(--line); border-radius: 14px; }
.dptable table { width: 100%; border-collapse: collapse; font: 12px var(--mono); table-layout: fixed; }
.dptable th:first-child { width: 62%; }
.dptable th { position: sticky; top: 0; background: var(--bg-2); text-align: left; padding: 8px 10px; font: 700 11px var(--font); letter-spacing: .5px; text-transform: uppercase; color: var(--text-2); }
.dptable td { padding: 8px 10px; border-top: 1px solid var(--line); word-break: break-all; vertical-align: top; }
.dptable td i { font-style: normal; color: var(--text-2); margin-left: 6px; }
.dptable tbody tr { cursor: pointer; transition: background-color .15s var(--ease); }
.dptable tbody tr:hover, .dptable tbody tr:active { background: var(--tonal-2); }
.dptable td.t { color: var(--ok); } .dptable td.f { color: var(--text-2); }
.dpform { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.dpform .btn { grid-column: 1 / -1; }
.dpform .input { font: 13px var(--mono); }
.pinform { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.pinform .btn { grid-column: 1 / -1; }

.events { list-style: none; margin: 0; padding: 4px 16px 14px; max-height: 280px; overflow: auto; display: grid; gap: 0; }
.events li { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; padding: 8px 0; font-size: 13px; border-top: 1px solid color-mix(in srgb, var(--line) 60%, transparent); }
.events li:first-child { border-top: 0; }
.events time { font: 11.5px var(--mono); color: var(--text-2); padding-top: 1px; white-space: nowrap; }
.events span { word-break: break-word; }
.events li.muted { display: block; }

/* ───────────── Bottom nav ───────────── */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around; padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  background: var(--bar); border-top: 1px solid var(--line);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
}
.bottomnav button {
  flex: 1 1 0; max-width: 120px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 12px; font-weight: 600; color: var(--text-2); transition: color .25s var(--ease);
}
.nav-ic { width: 60px; height: 30px; border-radius: 999px; display: grid; place-items: center; transition: background-color .3s var(--ease), width .3s var(--ease), color .3s var(--ease); }
.nav-ic .ic { width: 22px; height: 22px; }
.bottomnav button:active .nav-ic { width: 68px; }
.bottomnav button.on { color: var(--text); }
.bottomnav button.on .nav-ic { background: var(--tonal); color: var(--on-tonal); }
[data-theme="dark"] .bottomnav button.on .nav-ic { background: #fff; color: #000; }

/* ───────────── Modals ───────────── */
.modal {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 12px;
  background: var(--scrim); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  animation: fade .2s var(--ease);
}
.sheet {
  width: 100%; max-width: 400px; max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px); overflow: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: 28px; box-shadow: var(--shadow-2);
  animation: pop .3s var(--ease);
}
.sheet.wide { max-width: 760px; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 16px 12px 4px 20px; min-height: 56px; }
.sheet-head h2 { flex: 1; min-width: 0; font-size: 18px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vtitle { flex: 1; min-width: 0; display: grid; }
.sheet-sub { padding: 0 20px 12px; color: var(--text-2); font-size: 13.5px; }
.sheet-foot { display: flex; align-items: center; gap: 8px; padding: 12px 16px 16px; flex-wrap: wrap; }

.zone-wrap {
  position: relative; margin: 0 12px; aspect-ratio: 16 / 9; background: #000 ; border-radius: 14px; overflow: hidden;
  touch-action: none; user-select: none; -webkit-user-select: none; cursor: crosshair;
}
.zone-wrap img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; pointer-events: none; -webkit-user-drag: none; }
.zone-box {
  position: absolute; border: 2px solid #fff; border-radius: 6px; pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .5), inset 0 0 0 1px rgba(0, 0, 0, .5);
  background: color-mix(in srgb, #1a73e8 18%, transparent);
}
.viewer-body { margin: 0 12px; border-radius: 14px; overflow: hidden; background: #000; display: grid; place-items: center; min-height: 120px; }
.viewer-body img, .viewer-body video { display: block; width: 100%; max-height: 62vh; object-fit: contain; background: #000; }

/* ───────────── PIN lock ───────────── */
.lock {
  position: fixed; inset: 0; z-index: 100; background: var(--bg); display: grid; place-items: center; overflow: auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  animation: fade .25s var(--ease);
}
.lock-in { width: 100%; max-width: 320px; display: grid; justify-items: center; gap: 6px; text-align: center; }
.lock-logo { width: 76px; height: 76px; margin-bottom: 8px; filter: drop-shadow(0 6px 16px color-mix(in srgb, var(--primary) 30%, transparent)); }
[data-theme="dark"] .lock-logo { filter: none; }
.lock h2 { font-size: 26px; font-weight: 600; letter-spacing: -.3px; }
.lock p { color: var(--text-2); min-height: 21px; transition: color .2s var(--ease); }
.lock p.err { color: var(--danger); }
.dots { display: flex; gap: 14px; margin: 18px 0 22px; }
.dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--track); transition: transform .25s var(--ease), background-color .2s var(--ease), border-color .2s var(--ease); }
.dots i.on { background: var(--primary); border-color: var(--primary); transform: scale(1.15); }
.dots.shake { animation: shake .45s var(--ease); }
.dots.shake i { border-color: var(--danger); background: var(--danger); }
.dots.busy i.on { animation: blink .8s infinite; }
.keypad { display: grid; grid-template-columns: repeat(3, 72px); gap: 14px 22px; justify-content: center; }
.keypad button {
  width: 72px; height: 72px; border-radius: 50%; display: grid; place-items: center; font-size: 26px; font-weight: 500;
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow);
  transition: transform .15s var(--ease), border-radius .2s var(--ease), background-color .15s var(--ease), color .15s var(--ease);
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.keypad button:active { transform: scale(.92); border-radius: 22px; background: var(--tonal); color: var(--on-tonal); }
.keypad button.alt { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-2); }
.keypad button.go { background: var(--primary); color: var(--on-primary); border-color: transparent; }
.keypad .ic { width: 28px; height: 28px; }

/* ───────────── Toasts ───────────── */
.toasts {
  position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px); z-index: 120;
  display: grid; justify-items: center; gap: 8px; padding: 0 12px; pointer-events: none;
}
.toast {
  max-width: min(440px, 100%); padding: 12px 18px; border-radius: 16px; font-size: 13.5px; font-weight: 500;
  background: #303134; color: #fff; box-shadow: var(--shadow-2); animation: toastIn .3s var(--ease);
  transition: opacity .25s var(--ease), transform .25s var(--ease); word-break: break-word;
}
[data-theme="dark"] .toast { background: #fff; color: #000; }
.toast.err { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; transform: translateY(8px); }

/* ───────────── Keyframes ───────────── */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 50% { opacity: .25; } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 50%, transparent); } 100% { box-shadow: 0 0 0 7px transparent; } }
@keyframes flash { 0% { opacity: .9; } 100% { opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(16px) scale(.96); } }
@keyframes tabIn { from { opacity: 0; transform: translateY(8px); } }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px) scale(.96); } }
@keyframes shake { 15% { transform: translateX(-10px); } 30% { transform: translateX(9px); } 45% { transform: translateX(-7px); } 60% { transform: translateX(5px); } 75% { transform: translateX(-3px); } }
@keyframes wiggle { 25% { transform: rotate(-12deg); } 75% { transform: rotate(12deg); } }

/* ───────────── Small phones (360px) ───────────── */
@media (max-width: 399px) {
  .pill.privacy span { display: none; }
  .pill.privacy { padding: 0 7px; }
  .appbar h1 { font-size: 18px; }
  .keypad { grid-template-columns: repeat(3, 68px); gap: 12px 20px; }
  .keypad button { width: 68px; height: 68px; }
  .dpad { width: 176px; height: 176px; }
}

/* ───────────── Desktop ≥ 840px ───────────── */
@media (min-width: 840px) {
  main { padding: 20px 24px calc(var(--nav-h) + 48px); }
  .appbar-in { padding: 0 24px; }
  .live-grid { grid-template-columns: minmax(0, 1.75fr) minmax(300px, 1fr); align-items: start; gap: 16px; }
  .ptz-body { flex-direction: column; padding-bottom: 22px; }
  .ptz-side { flex: none; width: 100%; max-width: 260px; grid-template-columns: 1fr 1fr; }
  .ptz-side .tonal { grid-column: 1 / -1; }
  .dpad { width: 216px; height: 216px; }
  .cols { display: block; columns: 2; column-gap: 16px; }
  .cols > .card { break-inside: avoid; margin-bottom: 16px; }
  .mgrid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
  .chips { flex-wrap: wrap; overflow: visible; }
  .bottomnav {
    left: 50%; right: auto; bottom: 18px; transform: translateX(-50%); width: 440px; height: var(--nav-h);
    padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow-2);
  }
  .toasts { bottom: calc(var(--nav-h) + 34px); }
  .qa-pill { height: 76px; }
}
@media (min-width: 1200px) {
  #tab-toggles .cols { columns: 3; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
