/* Infinite NVR, light theme */
:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --line: #e3e7ed;
  --line-soft: #eef1f5;
  --text: #0f1729;
  --muted: #5b6678;
  --brand: #1d5bff;
  --brand-hover: #1449d6;
  --brand-soft: #edf2ff;
  --ok: #0f9d58;
  --ok-bg: #e6f6ee;
  --ok-text: #0a6b3b;
  --warn: #e08a00;
  --warn-bg: #fff4df;
  --warn-text: #8a4d00;
  --bad: #d92d20;
  --bad-bg: #fdecea;
  --bad-text: #a8251b;
  --idle-bg: #f0f2f5;
  --video: #0b1120;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
/* Elements toggled with the hidden attribute must stay hidden even when a class sets display. */
[hidden] { display: none !important; }
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
a { color: var(--brand); text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
svg { display: block; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100vh; }
.side {
  width: 248px; flex: none; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 20px 14px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 22px; color: var(--text); }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px; background: var(--brand);
  display: grid; place-items: center; flex: none;
}
.brand-mark svg { width: 24px; height: 24px; fill: none; stroke: #fff; stroke-width: 2.3; stroke-linecap: round; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand-site { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 12px; height: 44px; padding: 0 12px; border-radius: 10px;
  color: var(--muted); font-weight: 500;
}
.nav a svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav a:hover { background: var(--line-soft); color: var(--text); }
.nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.health {
  display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: 12px;
  background: var(--bg); font-size: 13px; font-weight: 500;
}
.version { font-size: 12px; color: var(--muted); padding: 0 12px; }
.main { flex: 1; min-width: 0; padding: 28px 32px 48px; outline: none; }

/* ---------- page header ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px; margin-bottom: 22px; }
.page-head h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.page-actions { margin-left: auto; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--line-soft); }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-hover); }
.btn.danger { color: var(--bad-text); }
.btn.icon { width: 40px; padding: 0; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.seg { display: inline-flex; padding: 3px; background: var(--panel); border: 1px solid var(--line); border-radius: 11px; gap: 2px; }
.seg button {
  min-width: 44px; min-height: 34px; padding: 0 10px; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--text); color: #fff; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; }
.field .hint { font-size: 12px; color: var(--muted); }
.input, select.input {
  min-height: 42px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); width: 100%;
}
.input:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }

/* ---------- status pills ---------- */
.dot { width: 8px; height: 8px; border-radius: 50%; background: #9aa4b2; flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(15, 157, 88, .15); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px;
  border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--idle-bg); color: var(--muted);
}
.pill.ok { background: var(--ok-bg); color: var(--ok-text); }
.pill.warn { background: var(--warn-bg); color: var(--warn-text); }
.pill.bad { background: var(--bad-bg); color: var(--bad-text); }
.pill .dot { width: 7px; height: 7px; box-shadow: none; }
.chip {
  display: inline-flex; align-items: center; height: 24px; padding: 0 8px; border-radius: 6px;
  background: var(--line-soft); color: var(--muted); font-size: 12px; font-weight: 600;
}

/* ---------- cards ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.card h2 { margin: 0; font-size: 16px; font-weight: 650; }
.card-head { display: flex; align-items: center; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--line-soft); }
.empty { text-align: center; padding: 56px 24px; }
.empty .empty-icon {
  width: 56px; height: 56px; border-radius: 16px; background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center; margin: 0 auto 16px;
}
.empty .empty-icon svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.empty h2 { margin: 0 0 6px; font-size: 18px; }
.empty p { margin: 0 auto 20px; color: var(--muted); max-width: 420px; }

/* ---------- live grid ---------- */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr)); }
.tile { overflow: hidden; display: flex; flex-direction: column; cursor: pointer; transition: box-shadow .15s, transform .15s; }
.tile:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.tile .frame { position: relative; aspect-ratio: 16 / 9; background: var(--video); overflow: hidden; }
.tile .frame img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .frame .waiting {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  color: #c3cad6; font-size: 13px; text-align: center; padding: 16px;
}
.tile .frame .waiting svg { width: 30px; height: 30px; fill: none; stroke: #4b5568; stroke-width: 1.6; }
.tile .badges { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; gap: 6px; align-items: center; }
.tile .badges .live {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px; border-radius: 7px;
  background: rgba(11, 17, 32, .62); color: #fff; font-size: 11px; font-weight: 700; letter-spacing: .04em;
  backdrop-filter: blur(6px);
}
.tile .badges .live .dot { width: 7px; height: 7px; box-shadow: none; }
.tile .badges .codec { margin-left: auto; }
.tile .badges .codec .live { font-weight: 600; letter-spacing: 0; }
.tile .meta { display: flex; align-items: center; gap: 10px; padding: 12px 14px; }
.tile .meta .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .meta .sub { font-size: 12px; color: var(--muted); }
.tile .meta .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }

/* ---------- timeline ---------- */
.tl-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 20px; align-items: start; }
.cam-list { padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.cam-list button {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px; padding: 0 12px; border: 0;
  border-radius: 10px; background: transparent; text-align: left; cursor: pointer; font-weight: 500;
}
.cam-list button:hover { background: var(--line-soft); }
.cam-list button[aria-current="true"] { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.cam-list .label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player { overflow: hidden; }
.player .screen { position: relative; aspect-ratio: 16 / 9; background: var(--video); }
.player video { width: 100%; height: 100%; display: block; background: var(--video); }
.player .clock {
  position: absolute; top: 14px; left: 14px; padding: 6px 12px; border-radius: 8px;
  background: rgba(11, 17, 32, .62); color: #fff; font-weight: 600; font-size: 14px;
  font-variant-numeric: tabular-nums; backdrop-filter: blur(6px); pointer-events: none;
}
.player .screen .waiting { position: absolute; inset: 0; display: grid; place-items: center; color: #c3cad6; text-align: center; padding: 24px; }
.player .bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 14px 16px; border-top: 1px solid var(--line-soft); }
.player .screen .preview { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: var(--video); pointer-events: none; }
.player .bar .day-label { font-weight: 600; }
.player .bar .speed { width: auto; min-width: 72px; }
.scrub-wrap { padding: 12px 16px 14px; border-top: 1px solid var(--line-soft); }
.scrub { display: block; width: 100%; height: 72px; cursor: grab; touch-action: none; user-select: none; border-radius: 10px; }
.scrub.dragging { cursor: grabbing; }
.scrub:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.scrub-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 10px; }
.scrub-foot .seg button { min-width: 52px; }
.tl-summary { margin-left: auto; font-size: 13px; color: var(--muted); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 12px 20px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 14px 20px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td .strong { font-weight: 600; }
td .muted { color: var(--muted); font-size: 13px; }
td.actions { text-align: right; white-space: nowrap; }
/* The devices table scrolls sideways on narrow screens instead of squeezing names and buttons. */
.devices table { min-width: 820px; }
.devices td:first-child .strong { white-space: nowrap; }
.devices td:nth-child(3) { min-width: 170px; max-width: 260px; }
.devices .err-line { max-width: 260px; }
td.actions .btn { margin-left: 6px; }
.err-line { color: var(--bad-text); font-size: 12px; margin-top: 4px; max-width: 360px; }
.info-row td { background: var(--bg); }
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px 24px; }
.info-grid dt { font-size: 12px; color: var(--muted); }
.info-grid dd { margin: 2px 0 0; font-weight: 600; word-break: break-all; }

/* ---------- storage ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat .k { font-size: 13px; color: var(--muted); font-weight: 500; }
.stat .v { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin-top: 6px; }
.stat .v small { font-size: 15px; font-weight: 600; color: var(--muted); margin-left: 4px; }
.meter { height: 10px; border-radius: 999px; background: var(--line-soft); overflow: hidden; margin-top: 14px; }
.meter > div { height: 100%; background: var(--brand); border-radius: 999px; }
.meter.warn > div { background: var(--warn); }
.meter.bad > div { background: var(--bad); }
.inline-form { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.inline-form .input { width: 96px; }

/* ---------- dialog ---------- */
dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(560px, calc(100vw - 32px));
  box-shadow: var(--shadow-lg); color: var(--text);
}
dialog::backdrop { background: rgba(15, 23, 41, .35); backdrop-filter: blur(2px); }
.dlg-head { display: flex; align-items: center; padding: 20px 24px 0; }
.dlg-head h2 { margin: 0; font-size: 19px; }
.dlg-head .btn { margin-left: auto; border: 0; }
.dlg-body { padding: 18px 24px; display: flex; flex-direction: column; gap: 16px; max-height: 70vh; overflow: auto; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px 22px; border-top: 1px solid var(--line-soft); }
.brand-pick { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.brand-pick label {
  display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer;
}
.brand-pick label:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); box-shadow: 0 0 0 1px var(--brand); }
.brand-pick input { position: absolute; opacity: 0; pointer-events: none; }
.brand-pick b { font-size: 14px; }
.brand-pick span { font-size: 12px; color: var(--muted); }
.row2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.row3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; }
details.adv summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted); }
details.adv[open] summary { margin-bottom: 12px; }
.form-error { color: var(--bad-text); background: var(--bad-bg); padding: 10px 12px; border-radius: 10px; font-size: 13px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--text); color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow-lg); transition: opacity .2s, transform .2s; pointer-events: none; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- small screens ---------- */
@media (max-width: 1100px) { .grid { --cols: 2 !important; } }
@media (max-width: 900px) {
  .tl-layout { grid-template-columns: 1fr; }
  .cam-list { flex-direction: row; overflow-x: auto; }
  .cam-list button { width: auto; flex: none; }
}
@media (max-width: 820px) {
  .shell { flex-direction: column; }
  .side {
    width: 100%; height: auto; position: sticky; top: 0; z-index: 10; flex-direction: row; align-items: center;
    padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--line);
  }
  .brand { padding: 0; }
  .brand-mark { width: 34px; height: 34px; }
  .side-foot { display: none; }
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; flex-direction: row; justify-content: space-around;
    background: var(--panel); border-top: 1px solid var(--line); padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); z-index: 10;
  }
  .nav a { flex-direction: column; gap: 2px; height: 54px; padding: 6px 4px; font-size: 11px; flex: 1; justify-content: center; }
  .main { padding: 20px 16px 96px; }
  .page-head h1 { font-size: 22px; }
  .grid { --cols: 1 !important; gap: 12px; }
  .row2, .row3, .brand-pick { grid-template-columns: 1fr; }
}

/* ---------- cloud ---------- */
.cloud-card { max-width: 720px; display: flex; flex-direction: column; gap: 16px; }
.cloud-row { display: flex; align-items: center; gap: 12px; }
.cloud-row .pill { margin-left: auto; }
.cloud-lead { margin: 0; color: var(--muted); }
.cloud-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.cloud-form .field { flex: 1; min-width: 240px; }
.cloud-info { margin: 0; }
.claim { background: var(--brand-soft); border-radius: 12px; padding: 18px 20px; text-align: center; }
.claim-k { font-size: 13px; font-weight: 600; color: #173a99; }
.claim-code { font-size: 34px; font-weight: 800; letter-spacing: .14em; margin: 6px 0; font-variant-numeric: tabular-nums; color: var(--text); }
.claim-hint { font-size: 13px; color: var(--muted); }
.cloud-actions { display: flex; gap: 10px; }

/* ---------- add NVR ---------- */
dialog.wide { width: min(680px, calc(100vw - 32px)); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.brand-pick.two-up { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.found { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; padding: 12px 14px; border-radius: 10px; background: var(--bg); }
.found span { color: var(--muted); font-size: 13px; }
.chan-table { border: 1px solid var(--line); border-radius: 12px; max-height: 46vh; overflow: auto; }
.chan-table th, .chan-table td { padding: 8px 12px; }
.chan-table th:first-child, .chan-table td:first-child { width: 36px; }
.chan-table td.num { width: 44px; color: var(--muted); font-variant-numeric: tabular-nums; }
.chan-table input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--brand); }
.small-input { min-height: 36px; }
.muted-line { font-size: 12px; color: var(--muted); margin-top: 3px; }
.hint { font-size: 12px; color: var(--muted); }
