/* VA Hub viewer. Self-contained: no external fonts, images or scripts. */
:root {
  color-scheme: light dark;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f0f2f6;
  --surface-3: #e7eaf0;
  --border: #e1e5ec;
  --border-strong: #cdd3dd;
  --text: #111827;
  --text-2: #374151;
  --muted: #6b7280;
  --accent: #2f5bea;
  --accent-hover: #2449c7;
  --accent-soft: #e8eefe;
  --accent-text: #ffffff;
  --ok: #15803d;
  --ok-soft: #e4f6ea;
  --warn: #b45309;
  --warn-soft: #fdf1df;
  --danger: #c62828;
  --danger-soft: #fde8e8;
  --neutral-soft: #eceff3;
  --box: #ffb020;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 4px 12px rgba(16, 24, 40, .05);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, .18);
  --radius: 12px;
  --radius-sm: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f16;
    --surface: #131a25;
    --surface-2: #1a2230;
    --surface-3: #222c3d;
    --border: #252f40;
    --border-strong: #34405a;
    --text: #e8ecf2;
    --text-2: #c7cfdb;
    --muted: #8d99ab;
    --accent: #6d8dff;
    --accent-hover: #87a1ff;
    --accent-soft: #1c2747;
    --accent-text: #0b0f16;
    --ok: #4ade80;
    --ok-soft: #12301f;
    --warn: #fbbf24;
    --warn-soft: #33270f;
    --danger: #f87171;
    --danger-soft: #3a1717;
    --neutral-soft: #222b3a;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 1px 3px rgba(0, 0, 0, .45), 0 4px 14px rgba(0, 0, 0, .25);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, .6);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { display: block; max-width: 100%; }
svg.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mono { font-family: var(--mono); font-size: .86em; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.break { overflow-wrap: anywhere; word-break: break-word; }
[hidden] { display: none !important; }

/* ---------- buttons & form controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-weight: 550; font-size: 14px; cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s, box-shadow .12s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn.icon-only { padding: 0; width: 36px; }
.btn.sm.icon-only { width: 30px; }
.btn .spinner { width: 14px; height: 14px; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .field-label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--muted); line-height: 1.4; }
.field .hint.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.input, select.input, textarea.input {
  width: 100%; min-height: 38px; padding: 7px 11px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  transition: border-color .12s, box-shadow .12s;
}
select.input { padding-right: 28px; }
textarea.input { min-height: 96px; font-family: var(--mono); font-size: 13px; resize: vertical; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.input-wrap { display: flex; align-items: stretch; }
.input-wrap .input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-wrap .unit { display: flex; align-items: center; padding: 0 10px; border: 1px solid var(--border-strong); border-left: 0; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; background: var(--surface-2); color: var(--muted); font-size: 13px; }
.check { display: inline-flex; gap: 8px; align-items: center; font-size: 14px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.form-error { color: var(--danger); font-size: 13px; min-height: 1em; }
.form-error:empty { display: none; }

/* ---------- pills / badges ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; line-height: 1.6; white-space: nowrap;
  background: var(--neutral-soft); color: var(--text-2);
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.danger { background: var(--danger-soft); color: var(--danger); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.dot.pulse { box-shadow: 0 0 0 0 currentColor; animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 55%, transparent); } 70% { box-shadow: 0 0 0 6px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
@media (prefers-reduced-motion: reduce) { .dot.pulse { animation: none; } .spinner { animation-duration: 2s !important; } }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid color-mix(in srgb, currentColor 25%, transparent); border-top-color: currentColor; animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- app shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { max-width: 1440px; margin: 0 auto; display: flex; align-items: center; gap: 18px; height: 58px; padding: 0 24px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: var(--text); letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), #7c4dff); display: grid; place-items: center; color: #fff; }
.brand-mark svg { width: 18px; height: 18px; stroke: #fff; }
.brand small { display: block; font-size: 11px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.nav { display: flex; gap: 4px; }
.nav a { display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; font-size: 14px; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.spacer { flex: 1; }
.live { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.live.ok { color: var(--ok); }
.live.warn { color: var(--warn); }
.live .live-text { color: var(--muted); }
.user { display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--surface-3); color: var(--text-2); display: grid; place-items: center; font-weight: 700; font-size: 13px; text-transform: uppercase; flex: none; }
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-meta strong { font-size: 13px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-meta span { font-size: 11px; color: var(--muted); text-transform: capitalize; }

.page { max-width: 1440px; margin: 0 auto; padding: 24px 24px 64px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 24px; letter-spacing: -.02em; line-height: 1.2; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.crumbs { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.crumbs a { color: var(--muted); }
.banner { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--warn); font-size: 14px; margin-bottom: 16px; }
.banner.danger { background: var(--danger-soft); color: var(--danger); }
.banner.info { background: var(--accent-soft); color: var(--accent); }
.banner svg { margin-top: 2px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.section { margin-top: 22px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.section-head h2 { margin: 0; font-size: 16px; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; }
.count { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-3); padding: 1px 8px; border-radius: 999px; }

.empty { text-align: center; padding: 56px 20px; color: var(--muted); }
.empty .empty-icon { width: 52px; height: 52px; border-radius: 14px; background: var(--surface-2); display: grid; place-items: center; margin: 0 auto 14px; color: var(--muted); }
.empty .empty-icon svg { width: 26px; height: 26px; }
.empty h3 { margin: 0 0 6px; color: var(--text); font-size: 16px; }
.empty p { margin: 0 auto; max-width: 420px; font-size: 14px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background:
  radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 60%),
  radial-gradient(900px 500px at 110% 110%, color-mix(in srgb, #7c4dff 14%, transparent), transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 400px; padding: 32px 28px 26px; box-shadow: var(--shadow-lg); }
.login-card .brand { margin-bottom: 22px; }
.login-card h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.02em; }
.login-card > p { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
.login-card form { display: grid; gap: 14px; }
.login-card .btn { min-height: 42px; width: 100%; font-size: 15px; }
.login-foot { margin-top: 18px; font-size: 12px; color: var(--muted); text-align: center; }

/* ---------- filters ---------- */
.toolbar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; padding: 12px; margin-bottom: 18px; }
.toolbar .field { flex: 1 1 160px; }
.toolbar .field > label { font-size: 12px; color: var(--muted); font-weight: 600; }
.toolbar .actions { display: flex; gap: 8px; align-items: center; }

/* ---------- event grid ---------- */
.events-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(272px, 1fr)); }
.event-card { display: flex; flex-direction: column; overflow: hidden; color: inherit; transition: box-shadow .15s, transform .15s, border-color .15s; }
.event-card:hover { text-decoration: none; box-shadow: var(--shadow); border-color: var(--border-strong); transform: translateY(-1px); }
.event-card.fresh { animation: fresh 2.4s ease-out; }
@keyframes fresh { from { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 55%, transparent); } to { box-shadow: var(--shadow-sm); } }
.event-body { padding: 12px 14px 14px; display: grid; gap: 6px; }
.event-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.event-title strong { font-size: 15px; text-transform: capitalize; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score { font-variant-numeric: tabular-nums; }
.meta-row { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); min-width: 0; }
.meta-row svg.icon { width: 14px; height: 14px; }
.meta-row .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.meta-row .sep { opacity: .5; }

/* media stage: wrapper aspect matches the image so normalized boxes align exactly */
.stage { position: relative; width: 100%; aspect-ratio: 16 / 9; background: var(--surface-3); overflow: hidden; }
.stage > img.frame { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; opacity: 0; transition: opacity .25s; }
.stage > img.frame.loaded { opacity: 1; }
.stage .bbox { position: absolute; border: 2px solid var(--box); border-radius: 3px; box-shadow: 0 0 0 1px rgba(0,0,0,.45), inset 0 0 0 1px rgba(0,0,0,.3); pointer-events: none; }
.stage .bbox-label { position: absolute; left: -2px; bottom: 100%; margin-bottom: 2px; background: var(--box); color: #1a1200; font-size: 11px; font-weight: 700; padding: 0 5px; border-radius: 3px; white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.stage .bbox.below .bbox-label { bottom: auto; top: 100%; margin: 2px 0 0; }
.stage .placeholder { position: absolute; inset: 0; display: grid; place-items: center; align-content: center; gap: 6px; color: var(--muted); font-size: 12px; text-align: center; padding: 10px; }
.stage .placeholder svg { width: 22px; height: 22px; }
.stage .tag { position: absolute; top: 8px; left: 8px; z-index: 2; }
.stage .tag .pill { background: rgba(10, 14, 22, .72); color: #fff; backdrop-filter: blur(4px); text-transform: capitalize; }
.stage .crop { position: absolute; right: 8px; bottom: 8px; z-index: 2; width: 27%; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--surface-3); border: 2px solid rgba(255,255,255,.92); box-shadow: 0 2px 10px rgba(0,0,0,.35); }
.stage .crop img { width: 100%; height: 100%; object-fit: contain; background: #000; opacity: 0; transition: opacity .25s; }
.stage .crop img.loaded { opacity: 1; }
.stage .crop .placeholder svg { width: 16px; height: 16px; }
.stage .crop .placeholder { font-size: 10px; padding: 4px; }

.more-row { display: flex; justify-content: center; margin-top: 22px; }
.feed-status { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }

/* ---------- event rows ---------- */
.ev-list { overflow: clip; }
.ev-head, .ev-row {
  display: grid; align-items: center; column-gap: 14px; padding: 5px 16px;
  grid-template-columns: 44px 104px 104px minmax(110px, 1.3fr) 52px minmax(90px, 1fr) minmax(90px, 1fr) minmax(90px, 1fr) 92px;
}
.ev-head { position: sticky; top: 58px; z-index: 5; padding-top: 9px; padding-bottom: 9px; background: var(--surface-2); border-bottom: 1px solid var(--border);
  font-size: 11px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.ev-row { min-height: 54px; color: inherit; border-bottom: 1px solid var(--border); font-size: 14px; transition: background .12s; }
.ev-row:last-child { border-bottom: 0; }
.ev-row:hover { background: var(--surface-2); text-decoration: none; }
.ev-row:focus-visible { outline-offset: -2px; }
.ev-row > span, .ev-head > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-row.fresh { animation: fresh-row 2.6s ease-out; }
@keyframes fresh-row { from { background: var(--accent-soft); } }
.stage.ev-thumb { width: 44px; height: 44px; aspect-ratio: auto; border-radius: 8px; background: var(--surface-3); }
.stage.ev-thumb > img.frame { object-fit: cover; }
.stage.ev-thumb .placeholder { padding: 0; }
.stage.ev-thumb .placeholder svg { width: 18px; height: 18px; }
.c-time { display: flex; flex-direction: column; line-height: 1.25; }
.c-time b { font-weight: 600; font-variant-numeric: tabular-nums; }
.c-time time { font-size: 12px; color: var(--muted); }
.ev-row .c-type .pill { text-transform: capitalize; }
.c-label { font-weight: 600; }
.ev-row .c-conf { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--accent); }
.ev-row .c-cam, .ev-row .c-dev { color: var(--text-2); }
.ev-row .c-inst { color: var(--muted); font-size: 12px; }
.c-sm { display: none; }
.day-sep { padding: 7px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); font-size: 12px; font-weight: 700; color: var(--text-2); letter-spacing: .02em; }
.skel-row { height: 54px; border-radius: 0; border-bottom: 1px solid var(--border); }
.sentinel { height: 1px; }
.cap-note { font-size: 13px; text-align: center; margin: 0; }
.new-pill { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); z-index: 30; display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 16px; border: 0; border-radius: 999px; background: var(--accent); color: var(--accent-text); font-weight: 650; font-size: 14px; box-shadow: var(--shadow-lg); cursor: pointer; }
.new-pill svg.icon { width: 16px; height: 16px; }
.settle-hint { color: var(--warn); }
@media (max-width: 1180px) {
  .ev-head, .ev-row { grid-template-columns: 44px 100px 96px minmax(110px, 1.3fr) 52px minmax(90px, 1fr) minmax(90px, 1fr) 88px; }
  .c-inst { display: none; }
}
@media (max-width: 900px) {
  .ev-head, .ev-row { grid-template-columns: 44px 96px minmax(100px, 1.3fr) 52px minmax(90px, 1fr) 88px; }
  .c-type, .c-dev { display: none; }
}

/* ---------- dialogs ---------- */
dialog { border: 0; padding: 0; background: transparent; color: var(--text); max-width: calc(100vw - 24px); max-height: calc(100dvh - 24px); }
dialog::backdrop { background: rgba(8, 12, 20, .55); backdrop-filter: blur(2px); }
.dlg { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg); width: 560px; max-width: 100%; max-height: calc(100dvh - 24px); display: flex; flex-direction: column; overflow: hidden; }
.dlg.wide { width: 1180px; }
.dlg.mid { width: 720px; }
.dlg-head { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.dlg-head h2 { margin: 0; font-size: 17px; flex: 1; min-width: 0; letter-spacing: -.01em; }
.dlg-body { padding: 18px; overflow: auto; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--border); background: var(--surface-2); flex-wrap: wrap; }

/* event detail */
.detail { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; }
.detail .stage { border-radius: 10px; }
.detail-side { display: grid; gap: 14px; align-content: start; min-width: 0; }
.kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 7px 14px; font-size: 13px; margin: 0; }
.kv dt { color: var(--muted); white-space: nowrap; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.crops { display: flex; gap: 10px; flex-wrap: wrap; }
.crop-tile { width: 96px; display: grid; gap: 4px; font-size: 12px; }
.crop-tile .stage { aspect-ratio: 1; border-radius: 8px; }
.crop-tile .stage > img.frame { object-fit: contain; background: #000; }
.media-list { display: grid; gap: 6px; font-size: 12px; }
.media-item { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 6px 9px; background: var(--surface-2); border-radius: 7px; }
details.raw summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text-2); }
pre.json { margin: 8px 0 0; padding: 10px 12px; background: var(--surface-2); border-radius: 8px; font: 12px/1.5 var(--mono); overflow: auto; max-height: 300px; white-space: pre-wrap; overflow-wrap: anywhere; }
.subhead { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 0 0 8px; }

/* ---------- devices ---------- */
.device-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.device-card { padding: 16px; display: grid; gap: 12px; color: inherit; transition: box-shadow .15s, border-color .15s; }
.device-card:hover { text-decoration: none; box-shadow: var(--shadow); border-color: var(--border-strong); }
.device-top { display: flex; align-items: flex-start; gap: 12px; }
.device-ico { width: 40px; height: 40px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.device-ico svg { width: 22px; height: 22px; }
.device-name { font-weight: 650; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-id { font-family: var(--mono); font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.stat b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.device-hero { padding: 18px; display: grid; gap: 16px; }
.device-hero .device-top h1 { margin: 0; font-size: 22px; letter-spacing: -.02em; overflow-wrap: anywhere; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.fact { background: var(--surface-2); border-radius: 9px; padding: 9px 12px; min-width: 0; }
.fact span { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.fact b { display: block; font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }

.instance-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.instance { padding: 16px; display: grid; gap: 12px; align-content: start; }
.instance-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.instance-head h3 { margin: 0; font-size: 15px; overflow-wrap: anywhere; }
.instance-head .sub { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.state-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-size: 13px; }
.state-row .lbl { color: var(--muted); }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.metrics .stat b { font-size: 14px; }
.exit-reason { font-size: 12px; color: var(--warn); background: var(--warn-soft); border-radius: 7px; padding: 6px 9px; overflow-wrap: anywhere; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn-row .push { margin-left: auto; }
.filter-toggle { display: none; }
.pending-cmd { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--accent); }

.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; background: var(--surface-2); }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td.url { font-family: var(--mono); font-size: 12px; color: var(--text-2); overflow-wrap: anywhere; min-width: 160px; }

.activity { display: grid; }
.cmd { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
.cmd:last-child { border-bottom: 0; }
.cmd .cmd-ico { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); }
.cmd .cmd-ico svg { width: 16px; height: 16px; }
.cmd .cmd-main { min-width: 0; }
.cmd .cmd-main b { font-weight: 600; }
.cmd .cmd-sub { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.cmd .cmd-err { font-size: 12px; color: var(--danger); overflow-wrap: anywhere; }
.steps { display: flex; gap: 4px; align-items: center; }
.steps i { width: 18px; height: 4px; border-radius: 2px; background: var(--surface-3); }
.steps i.on { background: var(--accent); }
.steps.ok i.on { background: var(--ok); }
.steps.bad i.on { background: var(--danger); }

.danger-zone { padding: 16px; display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; border-color: color-mix(in srgb, var(--danger) 30%, var(--border)); }
.danger-zone h3 { margin: 0 0 2px; font-size: 15px; }
.danger-zone p { margin: 0; color: var(--muted); font-size: 13px; max-width: 640px; }

/* instance form */
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .span-2 { grid-column: 1 / -1; }
.param-group { border: 1px solid var(--border); border-radius: 10px; padding: 14px; display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.param-group > .subhead { grid-column: 1 / -1; margin: 0; }
details.adv { border: 1px solid var(--border); border-radius: 10px; }
details.adv > summary { cursor: pointer; padding: 12px 14px; font-weight: 600; font-size: 14px; list-style: none; display: flex; align-items: center; gap: 8px; }
details.adv > summary::-webkit-details-marker { display: none; }
details.adv > summary svg { transition: transform .15s; }
details.adv[open] > summary svg { transform: rotate(90deg); }
details.adv > .adv-body { padding: 0 14px 14px; display: grid; gap: 14px; }
details.adv .param-group { border: 0; padding: 0; }
.param-name { font-family: var(--mono); font-size: 11px; color: var(--muted); font-weight: 400; margin-left: 6px; }

/* pairing */
.code-box { font-family: var(--mono); font-size: 15px; letter-spacing: .04em; background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: 10px; padding: 14px; overflow-wrap: anywhere; user-select: all; line-height: 1.7; }
.copy-row { display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-top: 10px; }
.countdown { font-variant-numeric: tabular-nums; font-weight: 600; }
.steps-list { margin: 0 0 16px; padding-left: 20px; color: var(--text-2); font-size: 14px; display: grid; gap: 4px; }

/* toasts */
.toasts { position: fixed; z-index: 100; right: 16px; bottom: 16px; display: grid; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 14px; display: flex; gap: 10px; align-items: flex-start; animation: toast-in .2s ease-out; overflow-wrap: anywhere; }
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: var(--radius); }
@keyframes shimmer { to { background-position: -200% 0; } }
.skel-card { height: 268px; }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .detail { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 720px) {
  .topbar-inner { padding: 0 14px; gap: 10px; height: 54px; }
  .brand small, .user-meta, .live .live-text { display: none; }
  .nav a { padding: 7px 9px; }
  .page { padding: 16px 14px 48px; }
  .page-head h1 { font-size: 21px; }
  .filter-toggle { display: inline-flex; }
  .page-head { align-items: center; }
  .toolbar { display: none; grid-template-columns: 1fr 1fr; gap: 10px; }
  .toolbar.open { display: grid; }
  .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar .actions { grid-column: 1 / -1; justify-content: space-between; }
  .ev-head { display: none; }
  .ev-row { grid-template-columns: 44px minmax(0, 1fr) auto; grid-template-areas: "thumb label conf" "thumb sm sm"; row-gap: 1px; column-gap: 12px; padding: 8px 12px; min-height: 60px; }
  .ev-row .ev-thumb { grid-area: thumb; }
  .ev-row .c-label { grid-area: label; }
  .ev-row .c-conf { grid-area: conf; }
  .ev-row .c-sm { grid-area: sm; display: block; font-size: 13px; color: var(--muted); }
  .ev-row .c-time, .ev-row .c-type, .ev-row .c-cam, .ev-row .c-inst, .ev-row .c-dev, .ev-row .c-media { display: none; }
  .ev-head { top: 54px; }
  .day-sep { padding: 6px 12px; }
  .new-pill { top: 64px; }
  .form-grid, .param-group { grid-template-columns: minmax(0, 1fr); }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .instance-grid, .device-grid { grid-template-columns: minmax(0, 1fr); }
  .dlg-body { padding: 14px; }
  dialog { max-width: 100vw; max-height: 100dvh; margin: auto auto 0; }
  .dlg { border-radius: 16px 16px 0 0; max-height: 92dvh; }
  .cmd { grid-template-columns: auto minmax(0, 1fr); }
  .cmd > .steps { grid-column: 2; }
  .hide-sm { display: none !important; }
  .tbl th, .tbl td { padding: 9px 10px; }
}
@media (max-width: 430px) {
  .brand-text { display: none; }
  .nav a { padding: 7px 8px; gap: 5px; }
}
