:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --border: #e9ebf2;
  --border-2: #dfe2eb;
  --text: #1e2340;
  --text-2: #3b4160;
  --muted: #747a92;
  --accent: #4352d6;
  --accent-soft: #eef0fd;
  --danger: #d33148;
  --danger-strong: #c42a41;
  --danger-soft: #fdedf0;
  --danger-line: #f3a9b4;
  --success: #12875a;
  --success-soft: #e4f6ec;
  --warn: #c26a06;
  --warn-soft: #fff4dc;
  --warn-strong: #a65b00;
  --live: #e5484d;
  --sev-high: #e0384f;
  --sev-mid: #ec6a2b;
  --sev-low: #d39b0a;
  /* nền nhạt của thẻ số liệu */
  --tint-green: #eaf7f0;
  --tint-red: #fdeef1;
  --tint-blue: #eef1fd;
  --tint-yellow: #fff5e2;
  --tint-purple: #f2effd;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(30, 35, 64, .04), 0 1px 4px rgba(30, 35, 64, .05);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); min-height: 100vh; }
[hidden] { display: none !important; }
h1, h2, h3, h4 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ico { display: inline-flex; width: 15px; height: 15px; flex: none; }
.ico svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.link { color: var(--accent); font-size: 13px; font-weight: 600; text-decoration: none; white-space: nowrap; }
.link:hover { text-decoration: underline; }

/* ---------- Thanh trên ---------- */
.topbar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px; padding: 10px 24px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(145deg, #f0566a, #d93650);
  display: grid; place-items: center; flex: none;
}
.brand-mark span { width: 16px; height: 16px; border-radius: 50%; border: 3px solid #fff; display: grid; place-items: center; }
.brand-mark span::after { content: ""; width: 4px; height: 4px; border-radius: 50%; background: #fff; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 700; font-size: 16px; }
.brand-sub { color: var(--muted); font-size: 11px; }
.tabs { display: flex; gap: 2px; padding: 4px; background: #eff0f5; border-radius: 12px; justify-self: center; }
.tab {
  font: inherit; font-size: 14px; color: var(--text-2); background: none; border: 0; border-radius: 9px;
  padding: 7px 14px; cursor: pointer; display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
}
.tab .ico { width: 15px; height: 15px; }
.tab:hover { color: var(--text); }
.tab.active { background: #fff; color: var(--accent); font-weight: 600; box-shadow: 0 1px 3px rgba(30, 35, 64, .12); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tab-count {
  min-width: 20px; padding: 0 6px; border-radius: 999px; background: #e1e3ec; color: var(--text-2);
  font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}
.tab-count.alert { background: var(--live); color: #fff; }
.topbar-right { display: flex; align-items: center; gap: 12px; font-size: 14px; justify-self: end; }
.live {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--success);
  background: var(--success-soft); padding: 5px 10px; border-radius: 999px; white-space: nowrap;
}
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: #20b26b; }
.live.paused { color: var(--muted); background: #eff0f5; }
.live.paused .live-dot { background: #a0a5b8; }
.live.error { color: var(--danger); background: var(--danger-soft); }
.live.error .live-dot { background: var(--live); }
.who { display: inline-flex; align-items: center; gap: 8px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: #e4e6fb; color: var(--accent); font-size: 12px;
  font-weight: 700; display: grid; place-items: center; flex: none;
}
.who-text { display: flex; flex-direction: column; line-height: 1.2; }
.who-text strong { font-size: 13px; }
.who-text small { font-size: 11px; color: var(--muted); }
.icon-btn {
  width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--border-2); background: #fff; color: var(--text-2);
  display: grid; place-items: center; cursor: pointer; padding: 0;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn .ico { width: 16px; height: 16px; }

/* ---------- Nút, ô nhập ---------- */
.btn {
  font: inherit; font-size: 14px; border-radius: 9px; padding: 8px 14px; cursor: pointer;
  border: 1px solid transparent; background: none; color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, .ev-card:focus-visible,
.seg-btn:focus-visible, .chip-btn:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-danger { background: var(--danger-strong); color: #fff; font-weight: 600; }
.btn-danger:hover:not(:disabled) { background: #b0233a; }
.btn-secondary { background: #fff; border-color: var(--border-2); font-weight: 600; }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-ghost { border-color: var(--border-2); background: #fff; }
.btn-block { width: 100%; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-soft-danger { background: var(--danger-soft); color: var(--danger); border-color: #f6cbd2; font-weight: 600; }
.btn-soft-danger:hover:not(:disabled) { background: #fbdde3; }

.card, .panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel { padding: 16px; }

.login-view { display: grid; place-items: center; padding: 64px 16px; }
.login-card { width: min(380px, 100%); padding: 28px; display: flex; flex-direction: column; gap: 8px; }
.login-card h1 { font-size: 22px; }
.login-card p { margin: 0 0 8px; }
label { font-size: 13px; color: var(--muted); }
input, select, textarea {
  font: inherit; font-size: 14px; color: var(--text); background: #fff;
  border: 1px solid var(--border-2); border-radius: 9px; padding: 8px 10px; width: 100%;
}
.select-sm { width: auto; font-size: 13px; padding: 6px 28px 6px 10px; border-radius: 9px; }
.form-error { color: var(--danger); min-height: 18px; margin: 4px 0; font-size: 13px; }

/* Nút chọn dạng phân đoạn (tab nhỏ) */
.seg { display: inline-flex; gap: 2px; padding: 3px; background: #eff0f5; border-radius: 10px; }
.seg-btn {
  font: inherit; font-size: 13px; color: var(--text-2); background: none; border: 0; border-radius: 8px;
  padding: 5px 11px; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px;
}
.seg-btn span { color: var(--muted); font-size: 12px; }
.seg-btn.active { background: #fff; color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(30, 35, 64, .12); }
.seg-btn:disabled { opacity: .45; cursor: not-allowed; }
.seg-full { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; width: 100%; }
.seg-full .seg-btn { justify-content: center; padding: 7px 10px; }

/* ---------- Nhãn ---------- */
.badges { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.badge {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 6px;
  background: #eff0f5; color: var(--text-2); white-space: nowrap;
}
.badge.live { background: var(--danger-soft); color: var(--danger); }
.badge.confirmed { background: var(--danger-soft); color: var(--danger); }
.badge.false_alarm { background: var(--success-soft); color: var(--success); }
.badge.pending { background: var(--warn-soft); color: var(--warn); }
.badge.backlog { background: #ffe7b0; color: var(--warn-strong); }
.badge.muted-badge { background: #eff0f5; color: var(--muted); font-weight: 500; }
.loop-tag { margin-left: auto; font-size: 11px; color: var(--muted); white-space: nowrap; }
.count-badge {
  display: inline-block; min-width: 22px; padding: 1px 7px; border-radius: 999px; font-size: 12px; font-weight: 700;
  text-align: center; background: #eff0f5; color: var(--text-2); vertical-align: 2px; margin-left: 4px;
}
.count-badge.alert { background: var(--danger-soft); color: var(--danger); }

.sev-chip {
  font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; color: #fff; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.sev-chip.sev-high { background: var(--sev-high); }
.sev-chip.sev-mid { background: var(--sev-mid); }
.sev-chip.sev-low { background: var(--sev-low); }
.sev-chip.sev-pending { background: #eff0f5; color: var(--text-2); font-weight: 600; }
.sev-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: #a0a5b8; }
.sev-dot.sev-high { background: var(--sev-high); }
.sev-dot.sev-mid { background: var(--sev-mid); }
.sev-dot.sev-low { background: var(--sev-low); }

/* ---------- Thẻ số liệu ---------- */
.stat-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; }
.stat-row-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat-card {
  border-radius: var(--radius); padding: 16px 16px 14px; display: flex; flex-direction: column; gap: 4px; min-width: 0;
  background: var(--surface); text-decoration: none; color: inherit;
}
.stat-card.green { background: var(--tint-green); }
.stat-card.red { background: var(--tint-red); }
.stat-card.blue { background: var(--tint-blue); }
.stat-card.yellow { background: var(--tint-yellow); }
.stat-card.purple { background: var(--tint-purple); }
.stat-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); }
.stat-icon { width: 28px; height: 28px; border-radius: 8px; background: #fff; display: grid; place-items: center; flex: none; }
.stat-icon .ico { width: 15px; height: 15px; }
.stat-card.green .stat-icon { color: var(--success); }
.stat-card.red .stat-icon { color: var(--danger); }
.stat-card.blue .stat-icon { color: var(--accent); }
.stat-card.yellow .stat-icon { color: var(--warn); }
.stat-card.purple .stat-icon { color: #6d4fd8; }
.stat-value { font-size: 26px; font-weight: 700; line-height: 1.25; font-variant-numeric: tabular-nums; margin-top: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-value small { font-size: 22px; color: #a3a8bd; font-weight: 600; }
.stat-value.red { color: var(--danger); }
.stat-value.orange { color: var(--warn); }
.stat-value.status { font-size: 19px; display: inline-flex; align-items: center; gap: 8px; }
.stat-value.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #20b26b; }
.stat-value.status.down::before { background: var(--live); }
.stat-value.text { font-size: 18px; }
.stat-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-sub.action { color: var(--warn); font-weight: 700; }
a.stat-card:hover .stat-sub.action { text-decoration: underline; }

/* ---------- Thẻ sự kiện (dùng chung cho dòng sự kiện và danh sách) ---------- */
.event-list, .feed-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.ev-card {
  display: grid; grid-template-columns: 78px 1fr; gap: 10px; padding: 10px; background: #fff;
  border: 1px solid var(--border); border-radius: 12px; cursor: pointer; transition: border-color .15s, box-shadow .15s;
}
.ev-card:hover { border-color: #c8cdf3; box-shadow: var(--shadow); }
.ev-card.selected { border-color: #aab2f0; background: #f5f6ff; box-shadow: 0 0 0 1px #aab2f0 inset; }
.ev-card.ongoing:not(.selected) { border-color: #f5c3cb; }

.ev-thumb { position: relative; aspect-ratio: 4 / 3; background: #1b1f33; border-radius: 8px; overflow: hidden; align-self: start; }
.ev-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ev-thumb-empty { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 2px; color: #8c92a8; font-size: 10px; text-align: center; }
.ev-thumb-empty .ico { width: 18px; height: 18px; }
.ev-thumb-tag {
  position: absolute; right: 4px; bottom: 4px; background: #000b; color: #fff; font-size: 10px; font-weight: 600;
  padding: 1px 5px; border-radius: 4px; font-variant-numeric: tabular-nums;
}
.ev-thumb-tag.live { background: var(--live); left: 4px; right: auto; }
.ev-thumb-clip { position: absolute; left: 4px; bottom: 4px; background: #000b; color: #fff; padding: 2px 3px; border-radius: 4px; display: inline-flex; }
.ev-thumb-clip .ico { width: 11px; height: 11px; }

.ev-body { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.ev-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.ev-title { font-weight: 700; font-size: 13px; line-height: 1.3; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.ev-sub, .ev-meta { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.ev-meta { gap: 10px; color: var(--text-2); }
.ev-meta > span { display: inline-flex; align-items: center; gap: 4px; }
.ev-meta .ico, .ev-sub .ico { width: 13px; height: 13px; }
.ev-foot { grid-column: 1 / -1; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ev-actions { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ev-actions .btn { padding: 6px 10px; font-size: 13px; }
.ev-actions .btn.chosen { box-shadow: 0 0 0 2px currentColor inset; }
.empty-list { padding: 28px 8px; text-align: center; color: var(--muted); font-size: 13px; }

/* ---------- Giám sát (VMS) ---------- */
.monitor-view { padding: 18px 24px 28px; display: flex; flex-direction: column; gap: 18px; }
.monitor-body { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 18px; align-items: start; }
.monitor-main { display: flex; flex-direction: column; gap: 22px; min-width: 0; }
.section-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.section-head h2 { font-size: 17px; }
.section-tools { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.empty-note { margin: 0; padding: 18px; text-align: center; color: var(--muted); font-size: 13px;
  border: 1px dashed var(--border-2); border-radius: 12px; background: var(--surface); }

.alarm-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.cam-grid { display: grid; grid-template-columns: repeat(var(--cols, 4), minmax(0, 1fr)); gap: 14px; }
.cam-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); display: flex; flex-direction: column; min-width: 0;
}
.cam-media { position: relative; aspect-ratio: 16 / 10; background: #0d1020; overflow: hidden; }
.cam-media video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #0d1020; }
.cam-placeholder {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 8px; text-align: center;
  padding: 12px; color: #8c92a8; font-size: 12px; pointer-events: none;
}
.cam-placeholder .ico { width: 28px; height: 28px; }
.cam-card:not(.offline) .cam-placeholder { display: none; }
.cam-card.offline video { visibility: hidden; }
.cam-tag, .cam-live, .cam-seg, .cam-alarm-chip {
  position: absolute; font-size: 11px; font-weight: 600; color: #fff; border-radius: 6px; padding: 2px 7px;
  background: #0f1222b3; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.cam-tag { top: 8px; left: 8px; }
.cam-seg { bottom: 8px; right: 8px; }
.cam-live { top: 8px; right: 8px; display: inline-flex; align-items: center; gap: 5px; }
.cam-live::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #2bd47d; }
.cam-card:not(.alarm) .cam-live { font-size: 0; padding: 0; width: 10px; height: 10px; border-radius: 50%; background: #2bd47d; border: 2px solid #fff; }
.cam-card:not(.alarm) .cam-live::before { display: none; }
.cam-card.down .cam-live, .cam-card.down:not(.alarm) .cam-live { background: #f5a524; }
.cam-alarm-chip {
  display: none; left: 8px; bottom: 8px; background: var(--live); align-items: center; gap: 5px; padding: 3px 8px;
  font-size: 12px; cursor: pointer; border: 0; font-family: inherit;
}
.cam-alarm-chip .ico { width: 13px; height: 13px; }
.cam-info { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 3px; }
.cam-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; min-width: 0; }
.cam-name { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cam-zone { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.cam-stats { display: inline-flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.cam-stats > span { display: inline-flex; align-items: center; gap: 4px; }
.cam-stats .ico { width: 13px; height: 13px; }
.cam-score { display: none; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; white-space: nowrap; color: var(--text-2); }
.score-bar { width: 64px; height: 5px; border-radius: 3px; background: #e7e9f1; overflow: hidden; }
.score-fill { display: block; height: 100%; width: 0; background: #9aa3ff; transition: width .4s; }
.score-fill.high { background: var(--live); }
.cam-score.high { color: var(--danger); }
.cam-r3, .cam-cta { display: none; }

/* Thẻ camera đang có sự kiện: viền đỏ, điểm AI lớn, nút xem sự kiện */
.cam-card.alarm { border: 2px solid var(--danger-line); box-shadow: 0 2px 10px rgba(211, 49, 72, .12); }
.cam-card.alarm .cam-media { aspect-ratio: 16 / 9.5; }
.cam-card.alarm .cam-alarm-chip { display: inline-flex; }
.cam-card.alarm .cam-info { padding: 12px 14px 14px; gap: 4px; }
.cam-card.alarm .cam-name { font-size: 15px; }
.cam-card.alarm .cam-score { display: inline-flex; }
.cam-card.alarm .cam-mini { display: none; }
.cam-card.alarm .cam-r3 { display: inline-flex; margin-top: 4px; }
.cam-card.alarm .cam-cta { display: flex; width: 100%; margin-top: 10px; }
.cam-cta .ico { width: 14px; height: 14px; }
@keyframes alarm-pulse { 50% { border-color: var(--live); } }
.cam-card.alarm { animation: alarm-pulse 1.4s infinite; }

/* ---------- Tình trạng camera (tab Tổng quan) ---------- */
.status-panel { padding: 4px 0; }
.status-list { list-style: none; margin: 0; padding: 0; }
.status-row {
  display: grid; grid-template-columns: 56px minmax(0, 1.6fr) minmax(0, 1.1fr) 52px minmax(120px, 1fr) 96px;
  align-items: center; gap: 12px; padding: 8px 16px; border-bottom: 1px solid var(--border); cursor: pointer; font-size: 13px;
}
.status-row:last-child { border-bottom: 0; }
.status-row:hover { background: var(--surface-2); }
.status-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.status-row.alarm { background: var(--danger-soft); }
.status-people { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-variant-numeric: tabular-nums; }
.status-people .ico { width: 13px; height: 13px; }
.status-row .status-score { display: inline-flex; }
.status-events { text-align: right; color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.chip.alarm { background: var(--live); color: #fff; }

/* ---------- Camera trực tiếp ---------- */
.live-view { padding: 18px 24px 28px; }
.layout-seg .seg-btn { min-width: 30px; justify-content: center; }
/* Trên lưới, thẻ có sự kiện giữ cỡ như thẻ khác: viền đỏ + nhãn "Nghi đánh nhau" (bấm để mở sự kiện) */
.cam-grid .cam-card.alarm .cam-media { aspect-ratio: 16 / 10; }
.cam-grid .cam-card.alarm .cam-info { padding: 10px 12px 12px; gap: 3px; }
.cam-grid .cam-card.alarm .cam-name { font-size: 14px; }
.cam-grid .cam-card.alarm .cam-mini { display: inline-flex; }
.cam-grid .cam-card.alarm .mini-score, .cam-grid .cam-card.alarm .cam-r3, .cam-grid .cam-card.alarm .cam-cta { display: none; }

.feed { position: sticky; top: 72px; max-height: calc(100vh - 92px); display: flex; flex-direction: column; gap: 12px; }
.feed-head { display: flex; justify-content: space-between; align-items: center; }
.feed-head h3 { font-size: 16px; }
.feed-scroll { overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-right: 2px; }
.feed-divider {
  display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; color: var(--warn); margin-top: 4px;
}
.feed-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.feed .ev-card { grid-template-columns: 70px 1fr; }

/* ---------- Màn sự kiện ---------- */
.app-view {
  display: grid; grid-template-columns: 230px minmax(320px, 360px) minmax(0, 1fr); gap: 16px; padding: 18px 24px; align-items: start;
}
.filter-panel { display: flex; flex-direction: column; gap: 16px; position: sticky; top: 72px; }
.filter-total strong { display: block; font-size: 24px; font-variant-numeric: tabular-nums; }
.filter-total span { font-size: 13px; }
.filter-total b { color: var(--warn); }
.backlog-toggle {
  display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-radius: 10px; background: var(--tint-yellow);
  color: var(--warn-strong); font-size: 13px; font-weight: 600; cursor: pointer;
}
.backlog-toggle input { width: 16px; height: 16px; margin: 0; accent-color: var(--warn); }
.radio-group { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.radio-group legend, .legend-label { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; padding: 0; }
.radio-group label {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: 9px; font-size: 13px; color: var(--text-2); cursor: pointer;
}
.radio-group label:hover { background: var(--surface-2); }
.radio-group label:has(input:checked) { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.radio-group input { width: 15px; height: 15px; margin: 0; accent-color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-btn {
  font: inherit; font-size: 12px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border-2);
  background: #fff; color: var(--text-2); cursor: pointer;
}
.chip-btn.active { background: var(--accent-soft); border-color: #aab2f0; color: var(--accent); font-weight: 600; }

/* Danh sách cuộn trong cột, cao bằng màn hình như cột chi tiết */
.list-panel { display: flex; flex-direction: column; gap: 12px; padding: 14px; position: sticky; top: 72px; max-height: calc(100vh - 92px); }
.list-panel .event-list { overflow-y: auto; flex: 1; min-height: 0; padding: 2px; }
.list-head { display: flex; justify-content: space-between; align-items: center; }
.list-head h3 { font-size: 15px; }
.pager { display: flex; justify-content: space-between; align-items: center; font-size: 13px; }

.detail-panel { position: sticky; top: 72px; min-height: 420px; padding: 18px; }
.empty-detail { display: grid; place-items: center; min-height: 380px; color: var(--muted); text-align: center; }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 14px; }
.detail-title { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.kicker { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 600; color: var(--text-2); }
.detail-head h2 { font-size: 21px; }
.detail-sub { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--text-2); }
.detail-sub > span { display: inline-flex; align-items: center; gap: 5px; }
.score-ring {
  flex: none; width: 64px; height: 64px; border-radius: 50%; display: grid; place-content: center; text-align: center;
  border: 4px solid #e7e9f1; color: var(--text);
}
.score-ring strong { font-size: 17px; line-height: 1; font-variant-numeric: tabular-nums; }
.score-ring small { font-size: 9px; color: var(--muted); margin-top: 2px; }
.score-ring.sev-high { border-color: var(--sev-high); color: var(--sev-high); }
.score-ring.sev-mid { border-color: var(--sev-mid); color: var(--sev-mid); }
.score-ring.sev-low { border-color: var(--sev-low); color: var(--sev-low); }

.media-tabs { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.media-note { margin-left: auto; }
.video-wrap {
  position: relative; background: #0d1020; border-radius: 12px; aspect-ratio: 16 / 10; display: grid; place-items: center;
  color: #8c92a8; overflow: hidden; border: 2px solid transparent;
}
.video-wrap.ongoing { border-color: var(--danger-line); }
.video-wrap video, .video-wrap img, .video-wrap a { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
.media-live {
  position: absolute; left: 10px; bottom: 10px; background: var(--live); color: #fff; font-size: 12px; font-weight: 600;
  padding: 4px 10px; border-radius: 999px; pointer-events: none;
}
.media-empty { display: grid; justify-items: center; gap: 8px; font-size: 14px; }
.media-empty .ico { width: 32px; height: 32px; }

.chart-card { margin-top: 16px; }
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.chart-head h3 { font-size: 14px; }
.chart-legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.lg { display: inline-flex; align-items: center; gap: 5px; }
.lg::before { content: ""; width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.lg-line::before { background: var(--accent); }
.lg-span::before { height: 10px; background: #e5484d26; }
.lg-open::before { border-top: 2px dashed var(--sev-high); height: 0; }
.lg-close::before { border-top: 2px dashed var(--sev-low); height: 0; }
.chart { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px 4px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart-empty {
  padding: 30px 0; text-align: center; color: var(--muted); font-size: 13px; display: flex; justify-content: center;
  align-items: center; gap: 8px;
}
.chart:has(.chart-empty) { border-style: dashed; border-color: var(--border-2); }
.chart-empty::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--live); }
.c-grid { stroke: #eceef4; stroke-width: 1; }
.c-axis { font-size: 10px; fill: #9a9fb3; font-family: inherit; }
.c-span { fill: #e5484d18; }
.c-open { stroke: var(--sev-high); stroke-width: 1.4; stroke-dasharray: 5 4; }
.c-close { stroke: var(--sev-low); stroke-width: 1.4; stroke-dasharray: 5 4; }
.c-area { fill: #4352d61f; }
.c-line { fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linejoin: round; }
.c-peak { fill: #fff; stroke: var(--sev-high); stroke-width: 2.5; }
.c-peak-label { font-size: 11px; font-weight: 700; fill: var(--sev-high); font-family: inherit; }

.fact-groups { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 16px 0; }
.fact-group { border-radius: 12px; padding: 12px 14px; background: var(--tint-blue); }
.fact-group:nth-child(2) { background: var(--tint-red); }
.fact-group:nth-child(3) { background: var(--tint-purple); }
.fact-group h4 { font-size: 13px; color: var(--accent); margin-bottom: 8px; }
.fact-group:nth-child(2) h4 { color: var(--danger); }
.fact-group:nth-child(3) h4 { color: #6d4fd8; }
.fact-group dl { margin: 0; display: flex; flex-direction: column; gap: 8px; }
.fact-group dt { font-size: 12px; color: var(--muted); }
.fact-group dd { margin: 1px 0 0; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.fact-group dd.hl { color: var(--danger); }

.verify-box { border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; background: var(--surface-2); }
.verify-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.verify-box h3 { font-size: 15px; }
.current-verdict { margin: 0; font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
textarea { resize: vertical; }
.verify-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.verify-actions .btn { padding: 11px; font-size: 15px; }
.detail-foot { margin: 12px 0 0; }

/* ---------- Quản lý camera ---------- */
.cameras-view { padding: 22px 24px 28px; display: flex; flex-direction: column; gap: 16px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; }
.page-head p { margin: 4px 0 0; font-size: 13px; }
.page-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill { font-size: 12px; font-weight: 600; padding: 6px 12px; border-radius: 999px; background: var(--success-soft); color: var(--success); display: inline-flex; align-items: center; gap: 6px; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.down { background: var(--danger-soft); color: var(--danger); }
.pill-muted { background: #eceef4; color: var(--text-2); }
.pill-muted::before { display: none; }
.table-tools { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.table-tools-right { display: flex; gap: 10px; flex-wrap: wrap; }
.search input { width: 190px; padding: 6px 10px 6px 30px; font-size: 13px;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23747a92' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M20 20l-3.5-3.5'/%3E%3C/svg%3E") no-repeat 9px center / 14px; }
.table-panel { padding: 0; overflow: hidden; }
.table-wrap { overflow-x: auto; }
.cam-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.cam-table th, .cam-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.cam-table th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fff; }
.cam-table tr:last-child td { border-bottom: 0; }
.cam-table tr.inactive td { color: var(--muted); }
.cam-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.cam-table .strong { font-weight: 700; }
.cam-table tr.group td { background: var(--surface-2); padding: 9px 12px; }
.group-head { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--muted); }
.group-head strong { font-size: 13px; color: var(--text); }
.group-head .badge { font-size: 11px; }
.group-head .badge.ok { background: var(--success-soft); color: var(--success); }
.cam-cell { display: flex; align-items: center; gap: 10px; }
.cam-thumb { width: 56px; height: 34px; border-radius: 6px; background: #1b1f33; overflow: hidden; flex: none; display: grid; place-items: center; color: #8c92a8; }
.cam-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-thumb .ico { width: 15px; height: 15px; }
.cam-cell-text { display: flex; flex-direction: column; line-height: 1.3; }
.cam-cell-text strong { font-size: 13px; }
.cam-cell-text small { font-size: 11px; color: var(--muted); }
.chip { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: #eff0f5; color: var(--text-2); display: inline-flex; align-items: center; gap: 5px; }
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip.ok { background: var(--success-soft); color: var(--success); }
.chip.reconnecting, .chip.down, .chip.unknown, .chip.idle, .chip.connecting { background: var(--warn-soft); color: var(--warn); }
.seg-cell strong { font-weight: 600; }
.seg-cell span { color: var(--muted); }
.backlog-cell { display: inline-flex; align-items: center; gap: 8px; justify-content: flex-end; }
.backlog-cell b { min-width: 28px; text-align: right; font-variant-numeric: tabular-nums; }
.backlog-cell b.zero { color: #a3a8bd; font-weight: 500; }
.backlog-cell b.mid { color: var(--warn); }
.backlog-cell b.high { color: var(--danger); }
.backlog-bar { width: 54px; height: 4px; border-radius: 2px; background: #eceef4; overflow: hidden; }
.backlog-bar span { display: block; height: 100%; background: #e9a23b; }
.backlog-bar span.high { background: var(--live); }
.cam-dialog { width: min(420px, 92vw); padding: 22px; border: 1px solid var(--border); }
.cam-dialog::backdrop { background: #1e234080; }
.cam-dialog form { display: flex; flex-direction: column; gap: 8px; }
.cam-dialog h3 { font-size: 17px; margin-bottom: 4px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
.check input { width: auto; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* ---------- Thông báo ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 20; }
.toast {
  max-width: 380px; padding: 10px 14px; border-radius: 10px; color: #fff; background: var(--text);
  box-shadow: 0 6px 20px #0003; font-size: 14px;
}
.toast.ok { background: var(--success); }
.toast.warn { background: var(--warn); }
.toast.error { background: var(--danger); }

/* ---------- Màn hình nhỏ ---------- */
@media (max-width: 1400px) {
  .app-view { grid-template-columns: 210px minmax(300px, 340px) minmax(0, 1fr); }
  .fact-groups { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 1280px) {
  .stat-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stat-row-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .alarm-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .status-row { grid-template-columns: 56px minmax(0, 1.6fr) minmax(0, 1.1fr) 52px minmax(110px, 1fr); }
  .status-events { display: none; }
  .app-view { grid-template-columns: minmax(300px, 360px) minmax(0, 1fr); }
  .filter-panel { grid-column: 1 / -1; position: static; flex-direction: row; flex-wrap: wrap; align-items: flex-start; }
  .filter-panel .radio-group { flex-direction: row; flex-wrap: wrap; }
}
@media (max-width: 1100px) {
  .monitor-body { grid-template-columns: 1fr; }
  .feed { position: static; max-height: none; }
  .topbar { grid-template-columns: auto 1fr; }
  .tabs { grid-column: 1 / -1; grid-row: 2; justify-self: stretch; }
  .tab { flex: 1; justify-content: center; }
}
@media (max-width: 900px) {
  .app-view { grid-template-columns: 1fr; padding: 12px; }
  .detail-panel { position: static; }
  .list-panel { position: static; max-height: 75vh; }
  .cam-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .layout-seg { display: none; }
}
@media (max-width: 620px) {
  .topbar { padding: 8px 12px; gap: 8px; }
  .live, .who-text { display: none; }
  .monitor-view, .cameras-view, .live-view { padding: 12px; }
  .status-row { grid-template-columns: 56px minmax(0, 1fr) auto; gap: 10px; padding: 8px 12px; }
  .status-people, .status-row .status-score { display: none; }
  .stat-row, .stat-row-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat-card { padding: 12px; }
  .stat-value { font-size: 22px; }
  .alarm-grid { grid-template-columns: minmax(0, 1fr); }
  .cam-grid { grid-template-columns: minmax(0, 1fr); }
  .section-tools { margin-left: 0; width: 100%; }
  .filter-panel { flex-direction: column; }
  .fact-groups { grid-template-columns: 1fr; }
  .tab { padding: 6px 4px; font-size: 12px; white-space: normal; text-align: center; line-height: 1.2; }
  .tab .ico { display: none; }
  .search input { width: 100%; }
  .table-tools-right, .table-tools-right > * { width: 100%; }
  .score-ring { width: 56px; height: 56px; }
}
