:root {
  --bg: #0a0e17;
  --panel: #111a2b;
  --panel-2: #162134;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --txt: #e8eef7;
  --muted: #94a2bc;
  --accent: #3b9dff;
  --accent-dim: rgba(59, 157, 255, 0.14);
  --up: #ff5b6a;
  --down: #1fd49a;
  --warn: #f5a623;
  --mono: Consolas, Menlo, monospace;
  --sans: "Microsoft YaHei", "PingFang SC", -apple-system, sans-serif;
  --r: 10px;
}

[data-theme="light"] {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --panel-2: #f7f9fc;
  --line: #e5e8ee;
  --line-strong: #d3d8e2;
  --txt: #1f2329;
  --muted: #6b7280;
  --accent: #2b6cb0;
  --accent-dim: rgba(43, 108, 176, 0.1);
  --up: #e54545;
  --down: #1a9e4b;
  --warn: #c07806;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--txt);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: var(--mono); }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 20px;
  height: 58px;
  padding: 0 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: baseline; gap: 10px; }
.brand h1 { font-size: 17px; font-weight: 600; letter-spacing: 0.3px; }
.brand .tag {
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 2px 8px;
  border-radius: 4px;
  letter-spacing: 0.5px;
}

.topbar .spacer { flex: 1; }

.mode-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--muted);
  padding: 4px 11px;
  border: 1px solid var(--line);
  border-radius: 20px;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--down); }
.dot.live { animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

.clock { font-family: var(--mono); font-size: 13px; color: var(--muted); }

.icon-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  font-family: var(--sans);
  cursor: pointer;
  transition: all 0.15s;
}
.icon-btn:hover { border-color: var(--line-strong); color: var(--txt); }

/* ---------- 布局 ---------- */
.wrap { max-width: 1560px; margin: 0 auto; padding: 20px 22px 48px; }

.sec-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 26px 0 12px;
}
.sec-head h2 {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 1.4px;
  color: var(--muted);
  text-transform: uppercase;
}
.sec-head .line { flex: 1; height: 1px; background: var(--line); }
.sec-head .hint { font-size: 12px; color: var(--muted); }

/* ---------- 指标卡 ---------- */
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
  gap: 12px;
}

.mcard {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 14px 16px;
  position: relative;
  overflow: hidden;
}
.mcard .label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.mcard .val {
  font-family: var(--mono);
  font-size: 26px;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.5px;
}
.mcard .unit { font-size: 12px; color: var(--muted); font-family: var(--sans); margin-left: 3px; }
.mcard .sub { font-size: 11px; color: var(--muted); margin-top: 5px; }
.mcard.crit .val { color: var(--up); }
.mcard.ok .val { color: var(--down); }
.mcard.acc .val { color: var(--accent); }

/* ---------- 门店卡 ---------- */
.sites {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
  gap: 14px;
}

.site {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 16px 18px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.site:hover { border-color: var(--line-strong); }
.site.active { border-color: var(--accent); background: var(--accent-dim); }

.site-top { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.site-top h3 { font-size: 15px; font-weight: 600; flex: 1; }
.badge {
  font-size: 11px;
  padding: 2px 9px;
  border-radius: 4px;
  white-space: nowrap;
  font-weight: 500;
}
.badge.on { color: var(--down); background: rgba(31, 212, 154, 0.13); }
.badge.off { color: var(--up); background: rgba(255, 91, 106, 0.13); }
.badge.warn { color: var(--warn); background: rgba(245, 166, 35, 0.13); }

.site-addr { font-size: 12px; color: var(--muted); margin-bottom: 12px; }

.site-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.site-stats div { min-width: 0; }
.site-stats .k { font-size: 11px; color: var(--muted); }
.site-stats .v {
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 600;
  margin-top: 1px;
}

.occ-bar {
  height: 4px;
  background: var(--panel-2);
  border-radius: 2px;
  margin-top: 7px;
  overflow: hidden;
}
.occ-fill { height: 100%; background: var(--accent); border-radius: 2px; transition: width 0.5s; }

/* ---------- 主布局 ---------- */
.split { display: grid; grid-template-columns: 1.35fr 1fr; gap: 14px; align-items: start; }

@media (max-width: 1080px) {
  .split { grid-template-columns: 1fr; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
}
.panel-head h3 { font-size: 13px; font-weight: 600; flex: 1; }
.panel-head .count { font-family: var(--mono); font-size: 12px; color: var(--muted); }

/* ---------- 事件流 ---------- */
.filters { display: flex; gap: 6px; padding: 11px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.chip {
  font-size: 12px;
  padding: 4px 11px;
  border-radius: 5px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-family: var(--sans);
  transition: all 0.15s;
}
.chip:hover { color: var(--txt); border-color: var(--line-strong); }
.chip.on { background: var(--accent-dim); color: var(--accent); border-color: transparent; }

.events { max-height: 660px; overflow-y: auto; }

.ev {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.12s;
}
.ev:hover { background: var(--panel-2); }
.ev.critical { border-left: 2px solid var(--up); }
.ev.high { border-left: 2px solid var(--warn); }
.ev.medium { border-left: 2px solid var(--accent); }
.ev.info { border-left: 2px solid var(--line-strong); }

.ev-ico {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--panel-2);
}
.ev-ico svg { width: 15px; height: 15px; }

.ev-main { flex: 1; min-width: 0; }
.ev-title { font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 8px; }
.ev-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  font-family: var(--mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ev-right { text-align: right; flex-shrink: 0; }
.ev-time { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.ev-conf { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-top: 2px; }

.sev-tag {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 3px;
  font-weight: 500;
  letter-spacing: 0.3px;
}
.sev-critical { color: var(--up); background: rgba(255, 91, 106, 0.13); }
.sev-high { color: var(--warn); background: rgba(245, 166, 35, 0.13); }
.sev-medium { color: var(--accent); background: var(--accent-dim); }
.sev-info { color: var(--muted); background: var(--panel-2); }

/* ---------- 图表 ---------- */
.chart-box { padding: 14px 16px; }
.chart-box canvas { width: 100%; }

/* ---------- 状态机回放 ---------- */
.replay-wrap { display: flex; flex-direction: column; }
.replay-stage {
  position: relative;
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 232px;
}
#skeletonCanvas { display: block; }

.replay-ctrl {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
}
.play-btn {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--txt);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.play-btn:hover { border-color: var(--accent); color: var(--accent); }

.timeline {
  flex: 1;
  height: 30px;
  position: relative;
  background: var(--panel-2);
  border-radius: 4px;
  overflow: hidden;
  cursor: pointer;
}
.tl-seg { position: absolute; top: 0; height: 100%; }
.tl-seg.normal { background: rgba(148, 162, 188, 0.3); }
.tl-seg.possible { background: rgba(245, 166, 35, 0.55); }
.tl-seg.confirmed { background: rgba(255, 91, 106, 0.7); }
.tl-cursor {
  position: absolute;
  top: 0;
  width: 2px;
  height: 100%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
}

.replay-meta {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 0 16px 14px;
}
.replay-meta .k { font-size: 11px; color: var(--muted); }
.replay-meta .v { font-family: var(--mono); font-size: 14px; font-weight: 600; margin-top: 1px; }

.state-chip {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  margin-top: 5px;
}
.state-NORMAL { color: var(--muted); background: var(--panel-2); }
.state-POSSIBLE_FALL { color: var(--warn); background: rgba(245, 166, 35, 0.13); }
.state-FALL_CONFIRMED { color: var(--up); background: rgba(255, 91, 106, 0.13); }

/* ---------- 摄像头占位 ---------- */
.cams {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 10px;
  max-height: 420px;
  overflow-y: auto;
  padding-right: 4px;
  padding-bottom: 2px;
}
.cam {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.cam-view {
  aspect-ratio: 16 / 9;
  background:
    repeating-linear-gradient(
      45deg,
      transparent,
      transparent 9px,
      rgba(255, 255, 255, 0.014) 9px,
      rgba(255, 255, 255, 0.014) 18px
    ),
    var(--panel-2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 5px;
  border-bottom: 1px solid var(--line);
}
.cam-view .ph-icon { width: 22px; height: 22px; opacity: 0.28; }
.cam-view .ph-txt { font-size: 10px; color: var(--muted); }
.cam-info { padding: 8px 10px; }
.cam-name { font-size: 12px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.cam-sub { font-size: 10px; color: var(--muted); font-family: var(--mono); margin-top: 1px; }
.cam-name .badge { font-size: 10px; padding: 1px 6px; }

/* ---------- 设备概览条 ---------- */
.dev-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 1px;
  background: var(--line);
  border-bottom: 1px solid var(--line);
}
.dev-cell { background: var(--panel); padding: 9px 12px; }
.dev-cell .k { font-size: 10px; color: var(--muted); }
.dev-cell .v { font-family: var(--mono); font-size: 14px; font-weight: 600; margin-top: 1px; }

/* ---------- 抽屉 ---------- */
.drawer-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 100;
}
.drawer-mask.on { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 420px;
  max-width: 92vw;
  background: var(--panel);
  border-left: 1px solid var(--line);
  transform: translateX(100%);
  transition: transform 0.22s ease;
  z-index: 101;
  overflow-y: auto;
}
.drawer.on { transform: translateX(0); }

.drawer-head {
  position: sticky;
  top: 0;
  background: var(--panel);
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 10px;
}
.drawer-head h3 { font-size: 15px; flex: 1; }
.drawer-body { padding: 18px 20px 40px; }

.kv { display: grid; grid-template-columns: 96px 1fr; gap: 9px 14px; margin-bottom: 20px; }
.kv .k { font-size: 12px; color: var(--muted); }
.kv .v { font-size: 13px; word-break: break-all; }

.note {
  font-size: 12px;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 13px;
  line-height: 1.7;
}

.note strong { color: var(--txt); font-weight: 500; }

/* 滚动条 */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

.footer {
  margin-top: 30px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
}
