:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-2: #f6f7f9;
  --text: #111827;
  --muted: #64748b;
  --border: #e3e7ed;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --link: #4338ca;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #15803d;
  --success-soft: #ecfdf3;
  --warning: #b45309;
  --warning-bg: #fef3c7;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0d12; --surface: #151922; --surface-2: #1c212c; --text: #eceef3; --muted: #9aa3b5; --border: #252b38;
    --primary: #6366f1; --primary-hover: #7477f4; --link: #a5b4fc;
    --danger: #f87171; --danger-soft: #2a1416; --success: #4ade80; --success-soft: #11251a;
    --warning-bg: #33260a; --warning: #fbbf24;
    --shadow: 0 1px 2px rgba(0,0,0,.45); --shadow-lg: 0 8px 24px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
a { color: var(--link); text-decoration: none; }
.icon { flex: none; vertical-align: -.2em; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 .4rem; }
h2 { font-size: 1.2rem; margin: 1.8rem 0 .8rem; }
.card h2:first-child, .card h1:first-child { margin-top: 0; }
h3 { font-size: 1.05rem; margin: 0 0 .4rem; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88em; word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.warn { color: var(--warning); }
.hidden { display: none !important; }

/* Layout */
.topbar { display: flex; align-items: center; gap: 1.25rem; padding: .55rem 1.25rem; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.brand { display: flex; align-items: center; gap: .45rem; font-weight: 700; font-size: 1.12rem; letter-spacing: -.01em; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-logo { color: var(--primary); }
.brand-mark { color: var(--primary); }
.nav { display: flex; gap: .15rem; flex: 1; min-width: 0; }
.nav a { display: flex; align-items: center; gap: .45rem; padding: .5rem .75rem; border-radius: 10px; color: var(--muted); font-weight: 500; font-size: .92rem; position: relative; white-space: nowrap; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, transparent); }
@media (prefers-color-scheme: dark) { .nav a.active { color: var(--link); } }
.nav-user { display: flex; align-items: center; gap: .35rem; margin-left: auto; }
.bell { position: relative; display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--surface-2); color: var(--text); cursor: pointer; }
.bell:hover { background: var(--border); text-decoration: none; }
.bell.active { color: var(--primary); }
.bell .count { position: absolute; top: -3px; right: -3px; margin: 0; border: 2px solid var(--surface); }
.avatar-link { display: flex; align-items: center; gap: .5rem; color: var(--text); padding: .2rem .7rem .2rem .2rem; border-radius: 999px; font-weight: 500; font-size: .92rem; }
.avatar-link:hover { background: var(--surface-2); text-decoration: none; }
.avatar-sm { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
@media (max-width: 1150px) { .nav a span:not(.count) { display: none; } .nav a { padding: .55rem .7rem; } }
@media (max-width: 640px) { .nav-name { display: none; } .avatar-link { padding: .2rem; } }
.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem 16px 4rem; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.grid-2-1 { grid-template-columns: 2fr 1fr; }
@media (max-width: 800px) { .grid-2-1 { grid-template-columns: 1fr; } .topbar { padding: .75rem 16px; } }
.page-head, .section-head, .row-between { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.page-head { margin-bottom: 1.2rem; }
.section-head { align-items: baseline; }
.actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: .5rem; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); color: var(--text); display: block; }
a.card:hover { border-color: var(--primary); text-decoration: none; }
.narrow { max-width: 440px; margin: 2rem auto; }
.narrow-wide { max-width: 720px; margin: 0 auto; }
.empty { text-align: center; padding: 3rem 1rem; }
.stat { display: flex; flex-direction: column; }
.stat-num { font-size: 2rem; font-weight: 700; }
.stats { margin: 1rem 0; }
.hero { text-align: center; padding: 4rem 1rem 3rem; max-width: 760px; margin: 0 auto; }
.hero h1 { font-size: 2.4rem; }
.lead { font-size: 1.15rem; color: var(--muted); }
.hero .actions { justify-content: center; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: .4rem; padding: .55rem 1rem; border-radius: 8px; border: 1px solid var(--primary); background: var(--primary); color: #fff; font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--primary-hover); text-decoration: none; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: var(--danger); border-color: var(--danger); }
.danger { color: var(--danger) !important; }
.btn-sm { padding: .3rem .65rem; font-size: .85rem; }
.btn-lg { padding: .8rem 1.4rem; font-size: 1.05rem; }
.btn-block { width: 100%; justify-content: center; margin-top: .5rem; }
.btn[disabled] { opacity: .6; cursor: progress; }
button.link { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: 0; }
form.inline { display: inline; }

/* Forms */
.field { margin-bottom: 1rem; display: flex; flex-direction: column; gap: .3rem; }
.field label { font-weight: 500; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=number], input[type=search], select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; }
select[multiple] { padding: .25rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.help { color: var(--muted); }
.error { color: var(--danger); }
.has-error input, .has-error select { border-color: var(--danger); }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 400 !important; }
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 1.5rem; text-align: center; }
.dropzone.dragover { border-color: var(--primary); background: var(--bg); }
.file-list { list-style: none; padding: 0; margin: 0; text-align: left; }
.label-filter { margin-bottom: 1rem; }
.filters { display: flex; gap: .5rem; }
.filters select { width: auto; }
fieldset.category-picker { border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem 1rem; margin: 0 0 1rem; }
fieldset.category-picker legend { font-weight: 500; padding: 0 .3rem; }
.category-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .4rem; margin-bottom: .5rem; }
.category-option { display: flex; align-items: center; gap: .45rem; padding: .4rem .6rem; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; font-size: .9rem; }
.category-option:has(input:checked) { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, transparent); }

/* Bits */
.alert { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid var(--border); background: var(--surface); }
.alert-success { border-color: var(--success); }
.alert-error { border-color: var(--danger); color: var(--danger); }
.alert-warning { background: var(--warning-bg); border-color: var(--warning); }
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--bg); border: 1px solid var(--border); color: var(--muted); vertical-align: middle; white-space: nowrap; }
.badge-online, .badge-completed { color: var(--success); border-color: var(--success); }
.badge-offline, .badge-failed { color: var(--danger); border-color: var(--danger); }
.badge-running, .badge-pending, .badge-stopping { color: var(--primary); border-color: var(--primary); }
.chip { display: inline-block; padding: .1rem .5rem; margin: .1rem .2rem .1rem 0; border-radius: 6px; background: var(--bg); border: 1px solid var(--border); font-size: .78rem; }
.progress { height: 8px; background: var(--bg); border-radius: 999px; overflow: hidden; margin: .6rem 0; border: 1px solid var(--border); }
.progress-bar { height: 100%; background: var(--primary); transition: width .4s; }
.tabs { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.tabs a { padding: .4rem .8rem; color: var(--muted); }
.tabs a.active { background: var(--primary); color: #fff; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .6rem .8rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.table tr:last-child td { border-bottom: 0; }
.pagination { display: flex; gap: 1rem; justify-content: center; margin-top: 1.5rem; }
.plain { list-style: none; padding: 0; }
.plain li { padding: .4rem 0; border-bottom: 1px solid var(--border); }
.job-card { border: 1px solid var(--border); border-radius: 8px; padding: .8rem; margin-bottom: 1rem; }
.details { display: grid; grid-template-columns: auto 1fr; gap: .4rem 1rem; margin: 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; }
.help-card dt { font-weight: 600; margin-top: .8rem; }
.help-card dd { margin: .2rem 0 0; color: var(--muted); font-size: .9rem; }

/* Media */
.snapshot, .media-card video, .media-card img { width: 100%; border-radius: 8px; background: #000; display: block; }
.media-card video { max-height: 70vh; }
.snippet-card { padding: 0; overflow: hidden; }
.thumb { position: relative; aspect-ratio: 16 / 9; background: #111; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-empty { color: #888; display: grid; place-items: center; height: 100%; font-size: .85rem; }
.duration { position: absolute; right: 6px; bottom: 6px; background: rgba(0,0,0,.7); color: #fff; font-size: .75rem; padding: .05rem .4rem; border-radius: 4px; }
.snippet-meta { display: flex; flex-direction: column; padding: .7rem .8rem; gap: .1rem; }
.seek { margin-top: .4rem; width: 100%; justify-content: center; }
.profile-head { display: flex; gap: 1.2rem; align-items: center; margin-bottom: 1rem; }
.avatar-lg { width: 88px; height: 88px; border-radius: 50%; object-fit: cover; }
.avatar-placeholder { display: grid; place-items: center; background: var(--primary); color: #fff; font-size: 2rem; font-weight: 700; }

/* Home-page demo */
.try-card { max-width: 820px; margin: 0 auto 2.5rem; scroll-margin-top: 80px; }
.try-head h2 { margin-top: 0; }
.try-card .btn-lg { width: 100%; justify-content: center; }
.thumb video { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
.cta { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-top: 2rem; }
.cta h3 { margin: 0 0 .2rem; }
.cta p { margin: 0; }

/* Security: alerts, network, agencies */
.nav .count, .bell .count { display: inline-block; min-width: 1.3em; padding: 0 .35em; margin-left: .15rem; border-radius: 999px; background: var(--danger); color: #fff; font-size: .72rem; font-weight: 700; text-align: center; line-height: 1.5; }
.attention { border-color: var(--danger); border-left-width: 4px; margin-bottom: 1rem; }
.verified { color: var(--success); font-size: .85em; }
.badge-new, .badge-open { color: var(--danger); border-color: var(--danger); }
.badge-acknowledged, .badge-responding, .badge-pending { color: var(--warning); border-color: var(--warning); }
.badge-resolved, .badge-active, .badge-accepted { color: var(--success); border-color: var(--success); }
.badge-false_alarm, .badge-declined { color: var(--muted); }
.alert-feed { display: flex; flex-direction: column; gap: .6rem; }
.alert-item { display: grid; grid-template-columns: 120px 1fr; gap: 1rem; align-items: center; padding: .7rem; }
.alert-item.unread { border-left: 4px solid var(--danger); }
.alert-thumb { aspect-ratio: 4 / 3; background: #111; border-radius: 6px; overflow: hidden; }
.alert-thumb img, .table-thumb { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: 6px; }
.table-thumb { width: 110px; height: 70px; }
.row-new td { background: color-mix(in srgb, var(--danger) 6%, transparent); }
.field div:has(> div > label > input[type=checkbox]), .field div:has(> div > label > input[type=radio]) { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .35rem; }
.field div > div > label:has(input[type=checkbox]), .field div > div > label:has(input[type=radio]) { display: flex; gap: .45rem; align-items: center; padding: .35rem .6rem; border: 1px solid var(--border); border-radius: 8px; font-weight: 400; cursor: pointer; }
.field label:has(input:checked) { border-color: var(--primary); }
.filters input[type=search], .filters input[type=text] { flex: 1; min-width: 0; }
@media (max-width: 600px) { .alert-item { grid-template-columns: 80px 1fr; } .filters { flex-wrap: wrap; } }


/* Notification counts: fixed red so white text stays readable in both themes */
.nav .count, .bell .count, .pill-count { background: #dc2626; color: #fff; }
@media (max-width: 1150px) { .nav .count { position: absolute; top: 1px; right: 1px; margin: 0; font-size: .65rem; } }

/* ===== Dashboard feed ===== */
/* Avatars */
.av { display: inline-grid; place-items: center; flex: none; border-radius: 50%; object-fit: cover; color: #fff; font-weight: 600; }
.av-xs { width: 20px; height: 20px; font-size: .62rem; }
.av-sm { width: 34px; height: 34px; font-size: .85rem; }
.av-md { width: 42px; height: 42px; font-size: 1rem; }
.av-lg { width: 72px; height: 72px; font-size: 1.8rem; }
.av-agency { border-radius: 30%; color: var(--tint); background: color-mix(in srgb, var(--tint) 14%, var(--surface)); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--tint) 25%, transparent); }
.av-xs.av-agency { border-radius: 6px; }

/* Requests */
.requests-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.15rem .5rem; }
.requests-card h3 { display: flex; align-items: center; gap: .5rem; margin: 0 0 .4rem; font-size: 1rem; }
.requests-card h3 .pill-count { margin-left: 0; }
.request { display: flex; align-items: center; gap: .75rem; padding: .65rem 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.request .person-text { display: flex; flex-direction: column; flex: 1; min-width: 0; line-height: 1.35; }
.request .person-text strong { font-weight: 600; }
.request:first-of-type { border-top: 0; }
.request-actions { display: flex; gap: .4rem; margin-left: auto; }
.request-actions form { margin: 0; }

/* Posts */
.post { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.post-head { display: flex; gap: .7rem; align-items: center; padding: .95rem 1.1rem .55rem; }
.post-who { min-width: 0; flex: 1; }
.post-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.post-name strong { font-weight: 600; }
.post-meta { display: flex; gap: .6rem; flex-wrap: wrap; color: var(--muted); font-size: .8rem; }
.post-meta span { display: inline-flex; align-items: center; gap: .2rem; }
.unread-dot { display: inline-flex; align-items: center; gap: .35rem; font-size: .75rem; font-weight: 600; color: var(--primary); }
@media (prefers-color-scheme: dark) { .unread-dot { color: var(--link); } }
.unread-dot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.post-alert { display: flex; align-items: center; gap: .55rem; margin: 0 1.1rem .8rem; padding: .55rem .75rem; border-radius: 10px; background: var(--danger-soft); color: var(--text); flex-wrap: wrap; }
.post-alert-icon { color: var(--danger); display: grid; }
.post-alert strong { font-weight: 600; }
.post-closed .post-alert { background: var(--surface-2); }
.post-closed .post-alert-icon { color: var(--muted); }
.confidence { display: inline-flex; align-items: center; gap: .4rem; margin-left: auto; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.confidence-bar { width: 54px; height: 5px; border-radius: 999px; background: color-mix(in srgb, var(--muted) 25%, transparent); overflow: hidden; }
.confidence-bar span { display: block; height: 100%; background: var(--danger); border-radius: inherit; }
.post-closed .confidence-bar span { background: var(--muted); }
.post-media { display: block; position: relative; background: #000; }
.post-media video, .post-media img { display: block; width: 100%; aspect-ratio: 16 / 9; max-height: 460px; object-fit: contain; background: #000; }
.media-tag { position: absolute; left: 12px; top: 12px; display: inline-flex; align-items: center; gap: .35rem; background: rgba(0,0,0,.6); backdrop-filter: blur(4px); color: #fff; font-size: .75rem; font-weight: 500; padding: .15rem .55rem; border-radius: 999px; pointer-events: none; }
.rec-dot { width: 7px; height: 7px; border-radius: 50%; background: #ef4444; animation: blink 1.2s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }
@media (prefers-reduced-motion: reduce) { .rec-dot { animation: none; } }
.post-agencies { list-style: none; display: flex; flex-wrap: wrap; gap: .4rem; padding: 0; margin: .8rem 1.1rem 0; }
.post-agencies li { display: inline-flex; align-items: center; gap: .4rem; font-size: .82rem; font-weight: 500; padding: .2rem .3rem .2rem .25rem; background: var(--surface-2); border-radius: 999px; }
.post-actions { display: flex; gap: .25rem; border-top: 1px solid var(--border); margin: .8rem 0 0; padding: .3rem .5rem; }
.post-actions a { flex: 1; display: flex; align-items: center; justify-content: center; gap: .4rem; padding: .5rem; border-radius: 10px; color: var(--muted); font-weight: 500; font-size: .88rem; }
.post-actions a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.post-update .post-head { padding-bottom: .7rem; }
.verified { display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; background: var(--primary); color: #fff; vertical-align: -.15em; }
.post-quote { margin: 0 1.1rem .8rem; padding: .7rem .9rem; background: var(--surface-2); border-radius: 4px 12px 12px 12px; font-size: .95rem; }
.post-quote cite { display: block; margin-top: .3rem; font-size: .78rem; color: var(--muted); font-style: normal; }
.post-ref { display: flex; gap: .75rem; align-items: center; margin: 0 1.1rem 1rem; padding: .45rem; border: 1px solid var(--border); border-radius: 12px; color: var(--text); }
.post-ref:hover { text-decoration: none; background: var(--surface-2); }
.post-ref img { width: 84px; height: 52px; object-fit: cover; border-radius: 8px; background: #000; }
.post-ref > span { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.post-ref-arrow { color: var(--muted); margin-right: .3rem; }
/* Status badges used across the feed */
.badge { border-radius: 999px; }
.badge-acknowledged, .badge-responding { background: var(--warning-bg); }
.badge-resolved, .badge-active { background: var(--success-soft); }
.badge-new, .badge-open { background: var(--danger-soft); }

@media (max-width: 820px) {
  .topbar { padding: .5rem 12px; gap: .5rem; }
  .brand span { display: none; }
  .nav { overflow-x: auto; scrollbar-width: none; }
  .nav a { flex: none; }
  .post-actions a { font-size: .82rem; padding: .5rem .2rem; }
  .request-actions { margin-left: 0; width: 100%; justify-content: flex-end; }
}

/* Device form: camera brand picker */
fieldset.brand-picker { border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem .2rem; margin: 0 0 1rem; min-width: 0; }
fieldset.brand-picker legend { font-weight: 600; padding: 0 .35rem; }
.preset-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 0 .9rem; }
.preset-login { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
@media (max-width: 560px) { .preset-row, .preset-login { grid-template-columns: minmax(0, 1fr); } }
.brand-tip { margin: -.4rem 0 1rem; padding: .6rem .8rem; border-radius: 10px; background: color-mix(in srgb, var(--primary) 8%, transparent); font-size: .87rem; line-height: 1.45; }
.url-preview { display: flex; flex-direction: column; gap: .25rem; margin: 0 0 1rem; padding: .6rem .8rem; border: 1px dashed var(--border); border-radius: 10px; background: var(--surface-2); }
.url-preview code { font-size: .86rem; word-break: break-all; }
