:root {
  --bg: #060b12;
  --panel: rgba(11, 20, 31, 0.88);
  --line: #1b2c3d;
  --text: #d7e3f0;
  --dim: #7d94ab;
  --accent: #38bdf8;
  --ok: #22c55e;
  --warn: #f59e0b;
  --alarm: #ef4444;
  --gold: #e8b13a;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); }
body {
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 13px;
}
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------- top bar ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 58px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px; z-index: 10;
  background: linear-gradient(180deg, rgba(4, 9, 15, 0.95), rgba(4, 9, 15, 0.45));
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 12px var(--accent);
}
.brand-text strong { display: block; font-size: 15px; letter-spacing: 0.5px; }
.brand-text small { color: var(--dim); font-size: 11px; }
.top-right { display: flex; align-items: center; gap: 18px; }
.metric-line { display: flex; gap: 14px; color: var(--dim); font-size: 12px; font-variant-numeric: tabular-nums; }
.metric-line b { color: var(--text); font-weight: 600; }

.badge {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 11px; border-radius: 20px; font-size: 12px;
  border: 1px solid var(--line); background: rgba(255,255,255,0.03);
}
.badge i { width: 7px; height: 7px; border-radius: 50%; background: var(--dim); }
.badge.online { border-color: rgba(34,197,94,.45); color: #86efac; }
.badge.online i { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.badge.connecting { border-color: rgba(245,158,11,.45); color: #fcd34d; }
.badge.connecting i { background: var(--warn); animation: blink 1s infinite; }
.badge.offline { border-color: rgba(239,68,68,.45); color: #fca5a5; }
.badge.offline i { background: var(--alarm); }
@keyframes blink { 50% { opacity: 0.25; } }

/* ---------- panels ---------- */
.panel {
  position: fixed; z-index: 9; top: 70px; bottom: 62px;
  width: 262px; padding: 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  backdrop-filter: blur(6px); overflow-y: auto;
}
.panel.left { left: 14px; }
.panel.right { right: 14px; width: 288px; }
.panel::-webkit-scrollbar { width: 6px; }
.panel::-webkit-scrollbar-thumb { background: #1e3348; border-radius: 3px; }

.panel h3 {
  margin: 14px 0 8px; font-size: 12px; font-weight: 600; color: var(--dim);
  letter-spacing: 1.2px; text-transform: uppercase;
}
.panel h3:first-child { margin-top: 0; }

.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.kpi {
  background: rgba(255,255,255,0.03); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px;
}
.kpi label { display: block; color: var(--dim); font-size: 11px; }
.kpi b { font-size: 19px; font-weight: 650; font-variant-numeric: tabular-nums; }
.kpi small { display: block; color: var(--dim); font-size: 11px; }
.alert-kpi b { color: var(--warn); }

.legend { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; color: var(--dim); }
.legend li { display: flex; align-items: center; gap: 7px; }
.sw { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.sw.occ-0 { background: #22303d; border: 1px solid #34506a; }
.sw.occ-1 { background: #27a06b; }
.sw.occ-2 { background: #d9a441; }
.sw.occ-3 { background: #d64545; }
.sw.agv { background: var(--gold); border-radius: 50%; }
.sw.warn { background: var(--alarm); border-radius: 50%; box-shadow: 0 0 8px var(--alarm); }

.btn-row { display: flex; gap: 6px; margin-bottom: 6px; flex-wrap: wrap; }
button {
  flex: 1; min-width: 72px; padding: 7px 8px; cursor: pointer;
  background: rgba(255,255,255,0.04); color: var(--text);
  border: 1px solid var(--line); border-radius: 7px; font-size: 12px;
  font-family: inherit; transition: all 0.15s;
}
button:hover { border-color: #2f5573; background: rgba(56,189,248,0.09); }
button.active { border-color: var(--accent); color: #bae6fd; background: rgba(56,189,248,0.14); }
button.ghost { flex: 0 0 auto; min-width: 0; }

.zone-list { list-style: none; margin: 0; padding: 0; }
.zone-list li {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 7px; border-radius: 6px; color: var(--dim); font-size: 12px;
}
.zone-list li b { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }
.zone-list li .zu { color: #66d9a0; }

/* ---------- alerts / events ---------- */
.pill { background: rgba(56,189,248,.16); color: #bae6fd; border-radius: 10px; padding: 1px 7px; font-size: 11px; }
.alerts, .events { list-style: none; margin: 0; padding: 0; }
.alerts li {
  border-left: 3px solid var(--warn); background: rgba(245,158,11,0.07);
  padding: 7px 9px; border-radius: 0 6px 6px 0; margin-bottom: 6px; font-size: 12px; line-height: 1.45;
}
.alerts li.alarm { border-color: var(--alarm); background: rgba(239,68,68,0.09); }
.alerts li.empty { border: 0; background: none; color: var(--dim); }
.alerts li .t { color: var(--dim); font-size: 11px; margin-right: 6px; font-variant-numeric: tabular-nums; }
.events li { padding: 5px 0; border-bottom: 1px dashed rgba(125,148,171,0.14); color: var(--dim); font-size: 12px; line-height: 1.4; }
.events li b { color: var(--text); font-weight: 500; }
.events li .t { font-variant-numeric: tabular-nums; color: #5f7a92; margin-right: 6px; }

/* ---------- timeline ---------- */
.timeline {
  position: fixed; left: 0; right: 0; bottom: 0; height: 54px; z-index: 10;
  display: flex; align-items: center; gap: 14px; padding: 0 18px;
  background: linear-gradient(0deg, rgba(4, 9, 15, 0.96), rgba(4, 9, 15, 0.55));
  border-top: 1px solid var(--line);
}
.tl-left, .tl-right { display: flex; align-items: center; gap: 10px; color: var(--dim); font-size: 12px; min-width: 170px; }
.tl-right { justify-content: flex-end; }
.tl-label { color: var(--text); font-variant-numeric: tabular-nums; }
input[type="range"] {
  flex: 1; height: 4px; appearance: none; border-radius: 2px;
  background: linear-gradient(90deg, #2b4a67, #1b2c3d);
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none; width: 13px; height: 13px; border-radius: 50%;
  background: var(--accent); cursor: pointer; box-shadow: 0 0 8px rgba(56,189,248,0.7);
}

/* ---------- tooltip / boot ---------- */
.tooltip {
  position: fixed; z-index: 20; pointer-events: none;
  background: rgba(8, 16, 25, 0.96); border: 1px solid #29455f;
  border-radius: 8px; padding: 9px 11px; font-size: 12px; line-height: 1.6;
  min-width: 180px; box-shadow: 0 8px 26px rgba(0,0,0,0.5);
}
.tooltip .tt-id { color: var(--accent); font-weight: 600; }
.tooltip .tt-row { color: var(--dim); }
.tooltip .tt-row b { color: var(--text); font-weight: 500; }
.hidden { display: none !important; }

.boot {
  position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px;
  background: rgba(4, 9, 15, 0.92); color: var(--dim); transition: opacity 0.4s;
}
.boot.done { opacity: 0; pointer-events: none; }
.spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid #1e3348; border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
