:root {
  --bg: #0b0e14;
  --panel: #141925;
  --panel-2: #1a2130;
  --line: #252d3d;
  --txt: #e6ebf5;
  --muted: #8a94a8;
  --accent: #3b82f6;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: radial-gradient(1200px 600px at 70% -10%, #16203a 0%, var(--bg) 55%);
  color: var(--txt);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  min-height: 100vh;
}

button {
  cursor: pointer; border: 1px solid var(--line); background: var(--panel-2);
  color: var(--txt); padding: 9px 16px; border-radius: 10px; font-size: 14px;
  transition: .15s; font-weight: 550;
}
button:hover { border-color: #3a455c; }
button.primary { background: var(--accent); border-color: var(--accent); }
button.primary:hover { background: #2f6fe0; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.active { background: var(--accent); border-color: var(--accent); }
button.ghost { padding: 6px 14px; font-size: 13px; }
.card-head { display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin-bottom: 0; }
input, select {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--txt);
  padding: 9px 12px; border-radius: 10px; font-size: 14px; outline: none;
  width: 100%;
}
input:focus { border-color: var(--accent); }

/* ---------- 登录页 ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 360px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 18px; padding: 32px 28px;
}
.login-card h1 { font-size: 20px; margin-bottom: 6px; }
.login-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.login-card label { display: block; font-size: 12px; color: var(--muted);
  margin: 14px 0 6px; }
.login-card button { width: 100%; margin-top: 22px; padding: 11px; }
.login-err { color: #ffb4b4; font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ---------- 主框架 ---------- */
.app { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px; border-bottom: 1px solid var(--line);
  background: rgba(11,14,20,.8); backdrop-filter: blur(8px);
}
.topbar h1 { font-size: 17px; font-weight: 650; display: flex; align-items: center; gap: 9px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.live { background: var(--green); box-shadow: 0 0 0 4px rgba(34,197,94,.18); }
.topbar .meta { font-size: 12px; color: var(--muted); }

/* ---------- 摄像头切换条（多摄像头时显示） ---------- */
.cambar {
  display: none; gap: 8px; padding: 10px 16px 0;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.cambar button {
  flex: 0 0 auto; padding: 7px 16px; border-radius: 999px;
  background: var(--panel); font-size: 13px;
}
.cambar button.on {
  background: var(--accent); border-color: var(--accent); color: #fff;
}

main { flex: 1; overflow-y: auto; padding: 16px; }
.view { display: none; max-width: 1200px; margin: 0 auto; width: 100%; }
.view.on { display: block; }

/* ---------- 设置：左右二级 tab ---------- */
.settings-shell {
  display: flex; gap: 16px; align-items: flex-start;
}
.settings-nav {
  flex: 0 0 200px; display: flex; flex-direction: column; gap: 6px;
  position: sticky; top: 0;
}
.settings-nav button {
  text-align: left; background: var(--panel); border-radius: 10px; padding: 11px 14px;
}
.settings-nav button.on {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.settings-nav .nav-group {
  font-size: 12px; color: var(--muted); padding: 2px 14px 8px;
  white-space: nowrap;
}
.settings-nav .nav-group b { color: var(--txt); font-weight: 600; }
.settings-nav .nav-sep { height: 1px; background: var(--line); margin: 6px 4px; }
.settings-body { flex: 1; min-width: 0; }
.settings-panel { display: none; }
.settings-panel.on { display: block; }
.settings-panel .card { margin: 0; }

/* 窄屏：设置导航横向滚动，面板在下方 */
@media (max-width: 720px) {
  .settings-shell { flex-direction: column; gap: 12px; }
  .settings-nav {
    flex: none; width: 100%; position: static;
    flex-direction: row; overflow-x: auto; gap: 8px;
    -webkit-overflow-scrolling: touch;
  }
  .settings-nav button {
    white-space: nowrap; text-align: center; flex: 0 0 auto;
  }
  .settings-nav .nav-group { flex: 0 0 auto; padding: 8px 10px; }
  .settings-nav .nav-sep { width: 1px; height: auto; margin: 4px 0; }
}

/* 底部标签栏（移动端优先） */
.tabs {
  display: flex; border-top: 1px solid var(--line); background: var(--panel);
}
.tabs button {
  flex: 1; border: none; border-radius: 0; background: none; padding: 13px 0;
  color: var(--muted); font-size: 13px; display: flex; flex-direction: column;
  align-items: center; gap: 4px;
}
.tabs button.on { color: var(--accent); }
.tabs .ico { font-size: 18px; line-height: 1; }

/* ---------- 卡片 ---------- */
.card {
  background: linear-gradient(180deg, var(--panel) 0%, #11151f 100%);
  border: 1px solid var(--line); border-radius: 16px; padding: 16px;
  margin-bottom: 16px;
}
.card h2 {
  font-size: 13px; color: var(--muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: .8px; margin-bottom: 12px;
}

/* 算法实时值 */
.det-metrics { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.metric-group { border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; background: var(--panel-2); }
.metric-title { font-size: 12px; color: var(--muted); font-weight: 600;
  margin-bottom: 8px; letter-spacing: .5px; }
.metric-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px 16px; }
.metric { display: flex; flex-direction: column; gap: 2px; }
.metric .m-label { font-size: 11px; color: var(--muted); }
.metric .m-value { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- 直播 ---------- */
.stage { position: relative; background: #000; border-radius: 12px;
  overflow: hidden; aspect-ratio: 16/9; }
.stage video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.box-overlay {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none;
}
.live-hint {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  color: var(--muted); font-size: 14px;
}
.spin {
  width: 34px; height: 34px; border: 3px solid var(--line);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.live-bar { display: flex; gap: 10px; margin-top: 12px; align-items: center;
  flex-wrap: wrap; font-size: 13px; color: var(--muted); }

/* ---------- 回放 ---------- */
.day-group { margin-bottom: 8px; }
.day-title { font-size: 13px; color: var(--muted); margin: 10px 0 8px; }
.seg-list { display: flex; flex-direction: column; gap: 6px; }
.seg-item {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 14px; font-size: 14px; cursor: pointer;
}
.seg-item:hover { border-color: var(--accent); }
.seg-item.playing { border-color: var(--accent); background: rgba(59,130,246,.12); }
.seg-item .sz { color: var(--muted); font-size: 12px; }
.seg-kind {
  font-size: 11px; padding: 1px 7px; border-radius: 999px; margin-left: 8px;
  vertical-align: middle;
}
.seg-kind.original {
  color: #93c5fd; background: rgba(59,130,246,.14);
  border: 1px solid rgba(59,130,246,.3);
}
.seg-kind.compressed {
  color: #a7f3d0; background: rgba(34,197,94,.12);
  border: 1px solid rgba(34,197,94,.3);
}
.live-grid {
  display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 14px; align-items: start;
}
@media (max-width: 900px) { .live-grid { grid-template-columns: 1fr; } }
.live-side { display: flex; flex-direction: column; gap: 14px; }
.cap-card .cap-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px;
}
.cap-now {
  display: flex; align-items: baseline; gap: 8px;
  padding: 8px 12px; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 10px; font-size: 13px;
}
.cap-label {
  color: #93c5fd; background: rgba(59,130,246,.14);
  border: 1px solid rgba(59,130,246,.3);
  padding: 1px 8px; border-radius: 999px; font-size: 11px; flex-shrink: 0;
}
.cap-history {
  margin-top: 10px; max-height: 320px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px; font-size: 13px;
}
.cap-line { display: flex; gap: 8px; line-height: 1.5; }
.cap-line .cap-time {
  color: var(--muted); font-size: 11px; flex-shrink: 0;
  font-variant-numeric: tabular-nums; padding-top: 2px;
}
.cap-empty { color: var(--muted); font-size: 12px; text-align: center; padding: 16px 0; }
.player-box video { width: 100%; border-radius: 12px; background: #000; }
.player-grid {
  display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 14px; align-items: start;
}
@media (max-width: 900px) { .player-grid { grid-template-columns: 1fr; } }
.analysis-panel {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; min-height: 120px;
}
.analysis-panel .ana-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px;
}
.analysis-panel h3 { font-size: 14px; margin: 0; }
.ana-empty { color: var(--muted); font-size: 13px; padding: 18px 0; }
.ana-summary { font-size: 14px; line-height: 1.7; }
.ana-interest { color: #fbbf24; font-size: 13px; margin-top: 8px; }
.ana-tags { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.ana-tags i {
  font-style: normal; font-size: 11px; padding: 1px 8px; border-radius: 999px;
  color: #93c5fd; background: rgba(59,130,246,.14);
  border: 1px solid rgba(59,130,246,.3);
}
.ana-meta { color: var(--muted); font-size: 11px; margin-top: 10px; }
.ana-err { color: #fca5a5; font-size: 13px; }
.seg-thumb {
  width: 96px; border-radius: 8px; margin-right: 12px; flex-shrink: 0;
  background: #000; aspect-ratio: 16/9; object-fit: cover;
}
.seg-item .seg-meta { flex: 1; min-width: 0; }
.seg-item .seg-time { display: block; }
.seg-item .seg-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.quota-bar { height: 6px; background: #0e1320; border-radius: 4px;
  overflow: hidden; margin-top: 8px; }
.quota-bar > i { display: block; height: 100%;
  background: linear-gradient(90deg, var(--accent), #60a5fa); }

/* ---------- 事件 ---------- */
.event-item {
  display: flex; gap: 12px; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px;
  margin-bottom: 10px; cursor: pointer;
}
.event-item img { width: 128px; height: 72px; object-fit: cover;
  border-radius: 8px; background: #000; flex-shrink: 0; }
.event-noimg {
  width: 128px; height: 72px; flex-shrink: 0; border-radius: 8px;
  background: var(--panel); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 12px;
}
.event-item .info { flex: 1; min-width: 0; }
.event-item .t { font-size: 14px; font-weight: 600; }
.event-item .d { font-size: 12px; color: var(--muted); margin-top: 4px; }
.event-side {
  display: flex; flex-direction: column; align-items: flex-end;
  justify-content: space-between; gap: 8px; flex-shrink: 0;
}
.badge-video {
  font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 500;
  color: #86efac; background: rgba(34,197,94,.15);
  border: 1px solid rgba(34,197,94,.35);
  cursor: pointer;
}
.badge-video:hover { background: rgba(34,197,94,.28); }
.evt-thumb { cursor: zoom-in; }
.event-label {
  background: none; border: 1px solid var(--line); color: #93c5fd;
  border-radius: 8px; padding: 4px 10px; cursor: pointer; font-size: 12px;
}
.event-label:hover { border-color: var(--accent); color: var(--accent); }
.event-del {
  background: none; border: 1px solid var(--line); color: var(--muted);
  border-radius: 8px; padding: 4px 10px; cursor: pointer; font-size: 12px;
}
.event-del:hover { color: #fecaca; border-color: rgba(239,68,68,.5); }
.badge-cam, .badge-danger {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  margin-left: 6px; font-weight: 500;
}
.badge-cam {
  color: #93c5fd; background: rgba(59,130,246,.14);
  border: 1px solid rgba(59,130,246,.3);
}
.badge-danger {
  color: #fecaca; background: rgba(239,68,68,.15);
  border: 1px solid rgba(239,68,68,.35);
}
.badge-label {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  margin-left: 6px; font-weight: 500;
  color: #86efac; background: rgba(34,197,94,.14);
  border: 1px solid rgba(34,197,94,.3);
}
.badge-label.bad {
  color: #fdba74; background: rgba(249,115,22,.14);
  border: 1px solid rgba(249,115,22,.35);
}
.event-item.evt-hit {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(59,130,246,.35);
}
.empty { color: var(--muted); text-align: center; padding: 40px 0; font-size: 14px; }

/* 图片查看器 */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 50;
  display: none; align-items: center; justify-content: center; padding: 16px;
}
.lightbox.on { display: flex; }
.lightbox img, .lightbox video { max-width: 100%; max-height: 100%;
  border-radius: 8px; }

/* ---------- 设置 ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field .row { display: flex; gap: 10px; align-items: center; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 6px; line-height: 1.5; }
.switch { display: flex; justify-content: space-between; align-items: center;
  padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.switch:last-child { border-bottom: none; }
.toggle { position: relative; width: 44px; height: 24px; background: var(--line);
  border-radius: 999px; cursor: pointer; transition: .2s; flex-shrink: 0; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: .2s; }
.toggle.on { background: var(--accent); }
.toggle.on::after { left: 23px; }

/* PWA service worker 相关占位（样式见下） */

/* ---------- 摄像头管理 ---------- */
.manage-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}
.cam-block { margin-bottom: 10px; }
.cam-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 13px 16px; cursor: pointer; flex-wrap: wrap;
}
.cam-row:hover { border-color: var(--accent); }
.cam-row-main { display: flex; align-items: center; gap: 10px; min-width: 0; }
.cam-row-main .chev { color: var(--muted); width: 14px; flex-shrink: 0; }
.cam-row-main b { font-size: 15px; }
.cam-id-tag {
  font-size: 11px; color: var(--muted); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 6px; padding: 1px 7px;
}
.cam-state { font-size: 12px; padding: 2px 9px; border-radius: 999px; }
.cam-state.on { color: #86efac; background: rgba(34,197,94,.12); }
.cam-state.off { color: var(--muted); background: var(--panel-2); }
.cam-row-actions { min-width: 0; }
.cam-caps { display: flex; gap: 6px; flex-wrap: wrap; }
.cam-caps i {
  font-style: normal; font-size: 11px; color: #93c5fd;
  background: rgba(59,130,246,.14); border: 1px solid rgba(59,130,246,.3);
  padding: 2px 9px; border-radius: 999px;
}
.cam-caps i.none { color: var(--muted); background: var(--panel-2);
  border-color: var(--line); }

.cam-detail { padding: 14px 4px 4px; }
.cam-detail-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
}
.cam-detail-grid .cam-cap-card { grid-column: 1 / -1; }
.roi-box {
  position: relative; width: 100%; border-radius: 12px; overflow: hidden;
  background: #000; touch-action: none;
}
.roi-box canvas { width: 100%; display: block; cursor: crosshair; }

/* 能力勾选列表 */
.cap-list, .cap-edit-list {
  display: flex; flex-direction: column; gap: 8px;
}
.cap-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  font-size: 13px; cursor: pointer;
}
.cap-item.on { border-color: rgba(59,130,246,.5); }
.cap-item input { width: auto; flex-shrink: 0; }
.det-params-list { margin-top: 14px; }
.det-params-list .det-card { margin-bottom: 12px; }
.det-card .det-params .switch { padding: 8px 0; }
.det-card .btn-save-det { margin-top: 12px; }
.danger-card { margin-top: 4px; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.65); z-index: 60;
  display: none; align-items: center; justify-content: center; padding: 18px;
}
.modal-mask.on { display: flex; }
.modal {
  width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 20px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; }
.modal-x {
  width: 34px; height: 34px; padding: 0; font-size: 20px; line-height: 1;
  border-radius: 8px;
}

@media (max-width: 900px) {
  .cam-detail-grid { grid-template-columns: 1fr; }
}

.msg { font-size: 13px; margin-top: 10px; min-height: 18px; }
.msg.ok { color: var(--green); }
.msg.err { color: #ffb4b4; }

/* ---------- 哭声事件标记面板 ---------- */
.toggle-btn {
  flex: 1; padding: 10px; font-size: 14px; text-align: center;
  border: 2px solid var(--line); background: var(--panel-2);
  border-radius: 10px; transition: .15s;
}
.toggle-btn.on { border-color: var(--accent); background: rgba(59,130,246,.15); }
.toggle-btn.on[data-v="true"] { border-color: var(--green); background: rgba(34,197,94,.15); }
.toggle-btn.on[data-v="false"] { border-color: var(--red); background: rgba(239,68,68,.15); }
.reason-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--panel-2);
  font-size: 13px; cursor: pointer; transition: .15s;
}
.reason-chip.on { border-color: var(--accent); background: rgba(59,130,246,.15); }
.reason-chip input { display: none; }

/* 桌面端：tab 栏移到顶部右侧 */
@media (min-width: 900px) {
  .app { flex-direction: column; }
  .tabs {
    position: fixed; top: 0; right: 18px; border: none; background: none;
    height: 49px; align-items: center; z-index: 10; width: auto; gap: 4px;
  }
  .tabs button {
    flex: none; flex-direction: row; gap: 6px; padding: 8px 16px;
    border-radius: 999px;
  }
  .tabs button.on { background: rgba(59,130,246,.14); }
  main { padding: 24px; }
}
