:root {
  --bg: #0b0d10; --panel: #15181d; --panel2: #1c2027; --line: #2a2f38;
  --text: #e8eaed; --muted: #9aa3ae; --accent: #3b82f6; --accent2: #2563eb;
  --ok: #22c55e; --warn: #f59e0b; --bad: #ef4444; --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: #7fb0ff; }
h1 { font-size: 1.15rem; margin: 0; }
h2 { font-size: 1rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); font-size: .85rem; }
.small { font-size: .8rem; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.row > .grow { flex: 1 1 180px; }
.stack > * + * { margin-top: .6rem; }
.hidden { display: none !important; }

/* ---- layout ---- */
header.top { position: sticky; top: 0; z-index: 20; background: rgba(11,13,16,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); padding: .6rem 1rem; display: flex; align-items: center; gap: .75rem; }
header.top .who { margin-left: auto; color: var(--muted); font-size: .85rem; }
nav.tabs { display: flex; gap: .25rem; overflow-x: auto; padding: .5rem 1rem; border-bottom: 1px solid var(--line);
  position: sticky; top: 49px; z-index: 19; background: var(--bg); scrollbar-width: none; }
nav.tabs button { background: transparent; color: var(--muted); border: 0; padding: .45rem .8rem; border-radius: 999px;
  white-space: nowrap; margin: 0; font-weight: 500; }
nav.tabs button.active { background: var(--panel2); color: var(--text); }
nav.tabs .badge { margin-left: .3rem; }
main { max-width: 1100px; margin: 0 auto; padding: 1rem; }
.grid2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1rem; }
@media (max-width: 820px) { .grid2 { grid-template-columns: 1fr; } }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }

/* ---- controls ---- */
button, .btn { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: .5rem .9rem;
  font: inherit; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: .35rem;
  text-decoration: none; }
button:hover { background: var(--accent2); }
button:disabled { opacity: .5; cursor: default; }
button.secondary { background: var(--panel2); color: var(--text); border: 1px solid var(--line); }
button.danger { background: #b91c1c; }
button.ok { background: #15803d; }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
button.big { padding: .75rem 1.2rem; font-size: 1rem; }
input, select, textarea { background: #0e1115; color: var(--text); border: 1px solid var(--line); border-radius: 8px;
  padding: .5rem .6rem; font: inherit; width: 100%; }
textarea { resize: vertical; min-height: 60px; }
label.field { display: block; font-size: .8rem; color: var(--muted); }
label.field > input, label.field > select, label.field > textarea { margin-top: .2rem; }
.switch { display: flex; align-items: center; gap: .55rem; cursor: pointer; font-size: .9rem; user-select: none; }
.switch input { appearance: none; width: 38px; height: 22px; border-radius: 999px; background: #3a404b; position: relative;
  flex: none; padding: 0; border: 0; cursor: pointer; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; transition: left .15s; }
.switch input:checked { background: var(--ok); }
.switch input:checked::after { left: 19px; }

.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .72rem; font-weight: 600;
  background: var(--panel2); color: var(--muted); border: 1px solid var(--line); }
.badge.ok { background: #14532d; color: #bbf7d0; border-color: #166534; }
.badge.warn { background: #78350f; color: #fde68a; border-color: #92400e; }
.badge.bad { background: #7f1d1d; color: #fecaca; border-color: #991b1b; }
.badge.info { background: #1e3a8a; color: #bfdbfe; border-color: #1e40af; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--muted); }
.dot.ok { background: var(--ok); box-shadow: 0 0 8px var(--ok); } .dot.bad { background: var(--bad); }

/* ---- live view ---- */
.live-wrap { position: relative; background: #000; border-radius: 10px; overflow: hidden; aspect-ratio: 16 / 9; }
.live-wrap video, .live-wrap img.live { width: 100%; height: 100%; object-fit: contain; display: block; }
.live-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.live-wrap .placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted);
  text-align: center; padding: 1rem; }
.live-status { font-size: .82rem; color: var(--muted); margin: .45rem 0; min-height: 1.2em; }
.rec-pill { position: absolute; top: .5rem; left: .5rem; background: rgba(0,0,0,.6); padding: .15rem .55rem;
  border-radius: 999px; font-size: .75rem; }

/* ---- lists ---- */
.list > .item { display: flex; gap: .75rem; padding: .7rem 0; border-bottom: 1px solid var(--line); align-items: flex-start; }
.list > .item:last-child { border-bottom: 0; }
.item .thumb { width: 92px; height: 70px; object-fit: cover; border-radius: 8px; background: #000; flex: none; cursor: zoom-in; }
.item .body { flex: 1; min-width: 0; }
.item .title { font-weight: 600; }
.item.k-watchlist_pending .title, .item.k-watchlist_alert_sent .title { color: #fca5a5; }
.item.k-arrival .title, .item.k-doorbell .title { color: #93c5fd; }
.item.k-unknown .title { color: #fcd34d; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .8rem; }
.pcard { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: .75rem; }
.pcard img.face { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; background: #000; }
.clip { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; cursor: pointer; }
.clip img { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; background: #000; }
.clip .meta { padding: .5rem .6rem; font-size: .82rem; }
.chips { display: flex; gap: .3rem; flex-wrap: wrap; margin-top: .3rem; }

/* ---- photo picker ---- */
.picker .src-tabs { display: flex; gap: .3rem; margin-bottom: .5rem; }
.picker .src-tabs button { padding: .35rem .7rem; font-size: .85rem; }
.picker video { width: 100%; max-width: 320px; border-radius: 8px; background: #000; }
.picker .frames, .picker .selected { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; }
.picker .frames img { width: 96px; height: 72px; object-fit: cover; border-radius: 6px; cursor: pointer; border: 2px solid transparent; }
.picker .selected .sel { position: relative; }
.picker .selected img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; }
.picker .selected button { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; padding: 0;
  border-radius: 50%; font-size: .75rem; justify-content: center; background: var(--bad); }

/* ---- modal + toast ---- */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 50; display: grid; place-items: center; padding: 1rem; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; width: min(640px, 100%);
  max-height: 92vh; overflow: auto; padding: 1rem; }
.modal img.snap { width: 100%; border-radius: 10px; background: #000; }
.modal video { width: 100%; border-radius: 10px; background: #000; }
.modal .compare { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.modal .compare img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; background: #000; }
.modal.alert-urgent { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,.25); }
#toasts { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); z-index: 60; display: grid; gap: .4rem; width: min(92vw, 420px); }
.toast { background: var(--panel2); border: 1px solid var(--line); border-left: 4px solid var(--accent); padding: .6rem .8rem;
  border-radius: 8px; font-size: .9rem; box-shadow: 0 6px 20px rgba(0,0,0,.4); }
.toast.bad { border-left-color: var(--bad); } .toast.ok { border-left-color: var(--ok); }
table.plain { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.plain th, table.plain td { text-align: left; padding: .45rem .4rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.plain th { color: var(--muted); font-weight: 500; }
.empty { color: var(--muted); text-align: center; padding: 1.5rem; }
@media (max-width: 600px) {
  header.top { gap: .5rem; padding: .55rem .75rem; }
  header.top h1 { font-size: 1rem; white-space: nowrap; }
  header.top .who, #camText { display: none; }
  main { padding: .75rem; }
  .card { padding: .8rem; }
}
