:root {
  --bg: #0f1720; --panel: #17212c; --panel2: #1f2b38; --line: #2c3a49;
  --text: #e8eef4; --muted: #8fa1b3; --accent: #3fb68b; --accent-ink: #062016;
  --info: #5aa9ff; --warn: #f0b429; --bad: #ef5d5d; --radius: 12px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f6f8; --panel: #ffffff; --panel2: #eef2f5; --line: #d5dde4;
    --text: #13202b; --muted: #5b6b7a; --accent: #1f8f68; --accent-ink: #ffffff;
    --info: #1d6fd1; --warn: #a86a00; --bad: #c62f2f; color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column; height: 100dvh; overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
[hidden] { display: none !important; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px; background: var(--panel); border-bottom: 1px solid var(--line); }
.site { background: none; border: 0; padding: 4px 0; text-align: left; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-size: 12px; background: var(--panel2); white-space: nowrap; }
.pill.private { border-color: var(--accent); color: var(--accent); }
.pill.cloud { border-color: var(--warn); color: var(--warn); }

main { flex: 1; min-height: 0; position: relative; }
.view { position: absolute; inset: 0; display: flex; flex-direction: column; }
.view.pad { padding: 16px; overflow-y: auto; gap: 12px; display: block; }
.view.pad > * + * { margin-top: 12px; }

.tabs { display: flex; background: var(--panel); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs button { flex: 1; background: none; border: 0; padding: 12px 0; color: var(--muted); font-weight: 600; }
.tabs button.on { color: var(--accent); }

/* look */
.stage { position: relative; flex: 1; min-height: 0; background: #000; overflow: hidden; }
.stage video { width: 100%; height: 100%; object-fit: cover; display: block; }
#overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.cam-msg { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px; color: #fff; background: #000c; }
.status { position: absolute; left: 8px; right: 8px; top: 8px; font-size: 12px; color: #fff; text-shadow: 0 1px 2px #000; pointer-events: none; }
.watch { position: absolute; left: 8px; right: 8px; bottom: 8px; background: #0f1720e6; color: #e8eef4; border: 1px solid #2c3a49; border-radius: var(--radius); padding: 10px 12px; }
.watch.alarm { border-color: var(--bad); box-shadow: 0 0 0 2px var(--bad); }
.watch .muted { color: #8fa1b3; }
.watch-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.w-name { font-weight: 700; }
.w-val { font-size: 32px; font-weight: 800; font-variant-numeric: tabular-nums; }
.w-chart { width: 100%; height: 56px; display: block; margin: 6px 0; }

.card { background: var(--panel); border-top: 1px solid var(--line); padding: 12px 16px; max-height: 38vh; overflow-y: auto; }
.card h2 { margin: 0; font-size: 20px; }
.card .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.card .actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { border: 1px solid var(--line); background: var(--panel2); border-radius: 999px; padding: 3px 10px; font-size: 13px; }
button.chip { cursor: pointer; }
.chip.ok { border-color: var(--accent); }
.big { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.up { color: var(--warn); } .down { color: var(--info); }

.controls { display: flex; gap: 8px; padding: 10px 16px; background: var(--panel); border-top: 1px solid var(--line); }
.controls .btn { flex: 1; }

.btn { border: 1px solid var(--line); background: var(--panel2); border-radius: 10px; padding: 10px 14px; font-weight: 600; min-height: 44px; }
.btn.sm { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: none; }
.btn.ghost[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.btn.danger { border-color: var(--bad); color: var(--bad); background: none; }
.btn:disabled { opacity: .5; }

/* lists + forms */
.row { display: flex; gap: 8px; align-items: center; }
.row > input[type=search] { flex: 1; min-width: 0; }
input, select, textarea { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; }
textarea { min-height: 70px; resize: vertical; }
label.f { display: block; font-size: 13px; color: var(--muted); }
label.f > input, label.f > select, label.f > textarea { margin-top: 4px; color: var(--text); }
.check { display: flex; gap: 8px; align-items: center; padding: 4px 0; }
.check input { width: auto; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.list img, .thumb-ph { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; background: var(--panel2); flex: none; }
.list .name { font-weight: 700; }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }
.box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.box h3 { margin: 0 0 8px; font-size: 15px; }
.photo { width: 100%; max-height: 260px; object-fit: cover; border-radius: var(--radius); background: var(--panel2); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats div { background: var(--panel2); border-radius: 10px; padding: 8px; }
.stats b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.chart { width: 100%; height: 160px; display: block; }
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
td, th { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.note { font-size: 13px; color: var(--muted); }

.sheet { border: 0; border-radius: 16px 16px 0 0; padding: 0; width: 100%; max-width: 560px; margin: auto auto 0; background: var(--panel); color: var(--text); max-height: 90dvh; }
.sheet::backdrop { background: #0008; }
.sheet form { padding: 16px; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; max-height: 90dvh; }
.sheet h2 { margin: 0; font-size: 18px; }
.sheet .actions { display: flex; gap: 8px; justify-content: flex-end; position: sticky; bottom: 0; background: var(--panel); padding-top: 8px; }

.print-area { display: none; }
@media print {
  body { display: block; height: auto; overflow: visible; background: #fff; color: #000; }
  body > *:not(.print-area) { display: none !important; }
  .print-area { display: grid !important; grid-template-columns: repeat(3, 1fr); gap: 6mm; padding: 6mm; }
  .label { border: 1px dashed #999; padding: 3mm; text-align: center; break-inside: avoid; font: 11pt system-ui, sans-serif; }
  .label svg { width: 30mm; height: 30mm; }
  .label b { display: block; margin-top: 1mm; }
}
.watch .btn { background: #1f2b38; color: #e8eef4; border-color: #3a4b5c; }
