:root {
  --bg: #eef3f9;
  --panel: #fff;
  --line: #dce6f1;
  --text: #172033;
  --muted: #6b7c91;
  --blue: #2563eb;
  --blue-soft: #eaf2ff;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-family: "Microsoft YaHei", "PingFang SC", sans-serif; }
.app { min-height: 100vh; display: flex; }
.sidebar { width: 232px; flex: 0 0 232px; background: linear-gradient(180deg,#0b111a,#0e1723); color: #bfccda; padding: 22px 15px; display: flex; flex-direction: column; }
.brand { display: flex; gap: 10px; align-items: center; margin-bottom: 28px; }
.brand-mark { width: 36px; height: 36px; border-radius: 9px; background: linear-gradient(135deg,#3b82f6,#1d4ed8); display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; font-size: 21px; }
.brand-title { color: #f4f8ff; font-size: 16px; font-weight: 700; }
.brand-sub { color: #6d8399; font-size: 10px; margin-top: 3px; }
.nav-label { color: #5c7187; font-size: 9px; letter-spacing: 1.8px; margin: 0 8px 8px; }
.nav-item { display: block; color: #a3b6c8; text-decoration: none; font-size: 13px; padding: 11px 12px; border-radius: 8px; margin-bottom: 4px; }
.nav-item:hover { background: #172434; color: #fff; }
.nav-item.active { background: linear-gradient(90deg,#2563eb,#1d4ed8); color: #fff; }
.sidebar-foot { margin-top: auto; border-top: 1px solid #1d2b3a; padding-top: 14px; font-size: 10px; color: #7690a6; }
.mqtt-state { display: flex; align-items: center; gap: 7px; margin-bottom: 9px; color: #b7c7d6; }
.env { font-size: 8px; letter-spacing: 1.1px; color: #526a80; }
.main { flex: 1; min-width: 0; }
.topbar { height: 82px; background: #fff; border-bottom: 1px solid #e0e9f3; display: flex; align-items: center; justify-content: space-between; padding: 0 28px; }
.kicker { color: #7e92a7; font-size: 9px; letter-spacing: 1.4px; }
.topbar h1 { font-size: 21px; margin: 4px 0 0; color: #172b46; }
.top-right { display: flex; align-items: center; gap: 8px; }
.token-input { width: 170px; padding: 8px 10px; border: 1px solid #cfddec; border-radius: 6px; color: #243b53; font-size: 12px; }
.content { padding: 20px 28px 30px; max-width: 1280px; }
.device-row { display: flex; align-items: center; gap: 10px; margin-bottom: 15px; }
.muted { color: var(--muted); font-size: 11px; }
.select { padding: 8px 12px; border: 1px solid #cfddec; border-radius: 6px; background: #fff; color: #20364e; font-size: 13px; }
.cards { display: grid; grid-template-columns: 1fr 1.15fr 1fr; gap: 14px; margin-bottom: 14px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; box-shadow: 0 3px 14px rgba(30,64,110,.045); }
.card-title { color: #50677d; font-size: 12px; font-weight: 700; margin-bottom: 12px; }
.state-line { display: flex; align-items: center; gap: 8px; font-size: 21px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #9aaec1; display: inline-block; }
.dot.online { background: var(--green); box-shadow: 0 0 7px rgba(22,163,74,.45); }
.dot.counting { background: var(--blue); box-shadow: 0 0 7px rgba(37,99,235,.55); }
.dot.offline { background: var(--red); }
.minor { color: #7a8da2; font-size: 11px; margin-top: 7px; line-height: 1.5; }
.count { font-size: 52px; line-height: 1; font-weight: 800; color: #12315a; margin: 8px 0; }
.controls { display: flex; gap: 8px; margin: 20px 0 10px; }
.btn { border: 0; border-radius: 7px; padding: 10px 18px; font-size: 13px; font-weight: 700; cursor: pointer; }
.btn.primary { background: linear-gradient(180deg,#3b82f6,#2563eb); color: #fff; box-shadow: 0 3px 0 #1d4ed8; }
.btn.danger { background: linear-gradient(180deg,#ef5350,#dc2626); color: #fff; box-shadow: 0 3px 0 #b91c1c; }
.btn.ghost { background: #f4f8fe; border: 1px solid #c9d8ea; color: #28415f; }
.btn.small { padding: 7px 10px; font-size: 11px; }
.btn:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; }
.table-card { margin-bottom: 14px; padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid #e8eff7; }
.card-head .card-title { margin: 0; }
.table-wrap { max-height: 250px; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { text-align: left; color: #687e94; background: #f4f8fd; padding: 9px 18px; font-weight: 600; }
td { padding: 9px 18px; border-top: 1px solid #edf2f8; color: #2a4159; }
.empty { text-align: center; color: #91a3b6; padding: 20px; }
.error-box { background: #fff0f0; border: 1px solid #f2c4c4; color: #b91c1c; padding: 10px 12px; border-radius: 7px; font-size: 12px; margin-bottom: 12px; }

/* 实时画面 */
.live-card { margin-bottom: 14px; padding: 0; overflow: hidden; }
.live-card .card-head { border-bottom: 1px solid #e8eff7; }
.live-frame-wrap { position: relative; padding: 10px 18px 16px; line-height: 0; }
.live-image { display: block; width: 100%; height: auto; max-height: none; object-fit: contain; background: #0b1722; border-radius: 8px; }
.live-overlay { position: absolute; inset: 10px 18px 16px 18px; width: calc(100% - 36px); height: calc(100% - 26px); pointer-events: none; border-radius: 8px; }
.live-count-hud {
  position: absolute; top: 24px; right: 32px; z-index: 2;
  padding: 10px 14px; border-radius: 9px;
  background: rgba(8, 18, 30, .68); color: #fff;
  border: 1px solid rgba(255,255,255,.16);
  backdrop-filter: blur(5px);
}
.live-count-hud[hidden] { display: none; }
.live-count-main { font-size: 34px; line-height: 1; font-weight: 800; color: #fff; }
.live-count-sub { margin-top: 7px; font-size: 12px; color: #dfeaf5; }
.live-placeholder { min-height: 150px; display: flex; align-items: center; justify-content: center; color: #8aa0b5; background: #f4f8fd; border-radius: 8px; font-size: 13px; }
.live-placeholder[hidden] { display: none; }


/* 历史录像 / Session 详情 */
.session-dialog { width: min(900px, 94vw); border: 1px solid #2b3d50; border-radius: 12px; background: #0f1c28; color: #e3effb; padding: 18px; }
.session-dialog::backdrop { background: rgba(0,0,0,.72); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.session-video { width: 100%; max-height: 52vh; background: #000; border-radius: 8px; }
.dialog-meta { margin: 10px 0 14px; color: #a9bfd2; font-size: 12px; }
.correction-form { display: flex; align-items: end; gap: 10px; flex-wrap: wrap; }
.correction-form label { display: flex; flex-direction: column; gap: 4px; color: #a9bfd2; font-size: 12px; }
.correction-form input { min-width: 150px; padding: 8px 10px; border: 1px solid #36516a; border-radius: 6px; background: #0b1620; color: #e3effb; }

/* 原始视频 + 逐帧检测结果叠加 */
.session-video-wrap { position: relative; width: 100%; line-height: 0; }
.session-overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }


.download-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 10px 0 14px;
}
.download-actions .minor {
  margin-right: 2px;
}

/* 登录 */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 18, 30, .72);
  backdrop-filter: blur(4px);
}
.login-overlay[hidden] { display: none; }
.login-card {
  width: min(360px, 92vw);
  background: #fff;
  border: 1px solid #dbe6f2;
  border-radius: 12px;
  padding: 26px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,.28);
}
.login-card h2 { margin: 0 0 8px; font-size: 18px; color: #172b46; }
.login-card .brand-mark { margin-bottom: 4px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: #50677d; }
.login-card input { padding: 10px 12px; border: 1px solid #cfddec; border-radius: 7px; font-size: 14px; }
.login-error { min-height: 18px; color: #b91c1c; font-size: 12px; }
