:root {
  --bg: #08111d;
  --bg-2: #0c1726;
  --panel: #101d2f;
  --panel-2: #14243a;
  --line: rgba(153, 182, 214, 0.14);
  --text: #eaf2fb;
  --muted: #8fa6bf;
  --cyan: #47d7d0;
  --blue: #5aa9ff;
  --green: #5ee2a0;
  --amber: #ffbe5c;
  --red: #ff6b6b;
  --violet: #a78bfa;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.32);
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Inter", "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(900px 500px at 12% -8%, rgba(71, 215, 208, 0.09), transparent 60%),
    radial-gradient(800px 500px at 100% 0%, rgba(90, 169, 255, 0.08), transparent 55%),
    var(--bg);
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}

.sidebar {
  width: 232px;
  flex: 0 0 232px;
  padding: 26px 18px;
  border-right: 1px solid var(--line);
  background: rgba(7, 16, 27, 0.72);
  backdrop-filter: blur(18px);
  display: flex;
  flex-direction: column;
  gap: 26px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px; }
.brand-mark {
  width: 42px; height: 42px;
  border-radius: 13px;
  display: grid; place-items: center;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #052022;
  background: linear-gradient(135deg, var(--cyan), #8ff3df);
  box-shadow: 0 8px 26px rgba(71, 215, 208, 0.26);
}
.brand-name { font-size: 17px; font-weight: 750; letter-spacing: 0.2px; }
.brand-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

.nav { display: flex; flex-direction: column; gap: 7px; }
.nav-item {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  text-align: left;
  padding: 12px 13px;
  border-radius: 12px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: 0.18s ease;
}
.nav-item span {
  font-size: 10px;
  color: rgba(143, 166, 191, 0.68);
  font-variant-numeric: tabular-nums;
}
.nav-item:hover { color: var(--text); background: rgba(255, 255, 255, 0.035); }
.nav-item.active {
  color: #061b1c;
  background: linear-gradient(135deg, var(--cyan), #8ff3df);
  box-shadow: 0 8px 24px rgba(71, 215, 208, 0.16);
}
.nav-item.active span { color: rgba(4, 32, 34, 0.55); }

.sidebar-foot {
  margin-top: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.025);
  display: flex; gap: 10px; align-items: flex-start;
}
.live-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--green);
  margin-top: 4px;
  box-shadow: 0 0 0 5px rgba(94, 226, 160, 0.09);
}
.foot-title { font-size: 12px; font-weight: 700; }
.foot-sub { font-size: 11px; color: var(--muted); margin-top: 5px; line-height: 1.45; }

.main { flex: 1; min-width: 0; padding: 28px 34px 46px; }
.topbar {
  display: flex; justify-content: space-between; gap: 22px; align-items: flex-end;
  margin-bottom: 24px;
}
.eyebrow {
  color: var(--cyan);
  font-size: 10px;
  letter-spacing: 2.2px;
  font-weight: 700;
  text-transform: uppercase;
  margin-bottom: 7px;
}
h1 { margin: 0; font-size: clamp(22px, 2.2vw, 31px); letter-spacing: -0.4px; }
h2 { margin: 0; font-size: 16px; letter-spacing: -0.2px; font-weight: 700; }
.top-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.clock {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 12px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
}
.btn {
  appearance: none; border: 1px solid transparent; cursor: pointer;
  border-radius: 10px; padding: 10px 14px; font-size: 12.5px; font-weight: 650;
  transition: 0.18s ease;
}
.btn.primary {
  color: #051d1f;
  background: linear-gradient(135deg, var(--cyan), #8ff3df);
  box-shadow: 0 8px 24px rgba(71, 215, 208, 0.16);
}
.btn.primary:hover { transform: translateY(-1px); }
.btn.ghost {
  color: var(--text);
  background: rgba(255, 255, 255, 0.035);
  border-color: var(--line);
}
.btn.ghost:hover { background: rgba(255, 255, 255, 0.07); }

.view { display: none; animation: fade 0.25s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.cards {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 13px;
  margin-bottom: 15px;
}
.metric {
  border: 1px solid var(--line);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.012));
  border-radius: 16px;
  padding: 16px 17px 15px;
  min-height: 102px;
  position: relative;
  overflow: hidden;
}
.metric::after {
  content: "";
  position: absolute; right: -25px; top: -30px;
  width: 90px; height: 90px; border-radius: 50%;
  background: radial-gradient(circle, rgba(71, 215, 208, 0.13), transparent 65%);
}
.metric-label { color: var(--muted); font-size: 11.5px; font-weight: 600; }
.metric-value { font-size: 27px; font-weight: 750; margin-top: 8px; letter-spacing: -0.6px; font-variant-numeric: tabular-nums; }
.metric-note { color: var(--muted); font-size: 10.5px; margin-top: 5px; }

.grid { display: grid; gap: 15px; margin-bottom: 15px; }
.grid.two { grid-template-columns: minmax(0, 1.12fr) minmax(0, 0.88fr); }
.grid.two > .panel:first-child { min-width: 0; }

.panel {
  background: linear-gradient(165deg, rgba(16, 29, 47, 0.96), rgba(11, 22, 37, 0.96));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 19px 20px 18px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 14px; }
.panel-kicker { color: var(--muted); font-size: 9.5px; letter-spacing: 1.7px; font-weight: 700; margin-bottom: 5px; }
.pill {
  font-size: 10.5px; color: var(--muted); border: 1px solid var(--line);
  padding: 6px 9px; border-radius: 999px; white-space: nowrap;
  background: rgba(255, 255, 255, 0.025);
}
.pill.soft { color: var(--cyan); border-color: rgba(71, 215, 208, 0.22); background: rgba(71, 215, 208, 0.06); }
.link-btn { border: 0; background: transparent; color: var(--cyan); font-size: 11.5px; cursor: pointer; font-weight: 650; }

.score-body { display: flex; align-items: center; gap: 30px; min-height: 165px; }
.gauge { width: 150px; height: 150px; position: relative; flex: 0 0 auto; }
.gauge svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.gauge .track { fill: none; stroke: rgba(255,255,255,0.06); stroke-width: 10; }
.gauge .value { fill: none; stroke-width: 10; stroke-linecap: round; transition: stroke-dashoffset 0.5s ease; }
.score-num { font-size: 38px; font-weight: 760; letter-spacing: -1px; line-height: 1; }
.score-label { color: var(--muted); font-size: 12px; margin-top: 7px; }
.score-lines { margin-top: 14px; display: grid; gap: 7px; }
.score-line { display: flex; justify-content: space-between; gap: 18px; color: var(--muted); font-size: 11.5px; }
.score-line b { color: var(--text); font-weight: 650; }

.chart-wrap { height: 170px; position: relative; }
.chart-wrap canvas { width: 100%; height: 100%; display: block; }

.event-mix { display: grid; gap: 13px; padding-top: 2px; }
.mix-row { display: grid; grid-template-columns: 72px 1fr 48px; gap: 10px; align-items: center; font-size: 12px; }
.mix-name { color: var(--muted); }
.mix-bar { height: 8px; border-radius: 999px; background: rgba(255,255,255,0.055); overflow: hidden; }
.mix-fill { height: 100%; border-radius: 999px; width: 0; transition: width 0.45s ease; }
.mix-val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }

.table-wrap { overflow: auto; }
.table-wrap.compact { max-height: 215px; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th {
  text-align: left; color: var(--muted); font-weight: 600;
  padding: 8px 8px 10px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { padding: 11px 8px; border-bottom: 1px solid rgba(153, 182, 214, 0.07); white-space: nowrap; }
tbody tr { cursor: pointer; transition: 0.15s ease; }
tbody tr:hover { background: rgba(71, 215, 208, 0.035); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap.compact td { padding: 9px 8px; }
.muted { color: var(--muted); }
.score-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 38px; padding: 4px 8px; border-radius: 8px;
  font-weight: 750; font-size: 11.5px;
}
.score-good { color: #7df0b8; background: rgba(94,226,160,0.11); }
.score-mid { color: #ffd28f; background: rgba(255,190,92,0.11); }
.score-bad { color: #ff9b9b; background: rgba(255,107,107,0.11); }
.ev-chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip { font-size: 9.5px; padding: 3px 6px; border-radius: 6px; border: 1px solid var(--line); color: var(--muted); }
.chip.acc { color: #ffcf83; border-color: rgba(255,190,92,0.25); }
.chip.brk { color: #ff9999; border-color: rgba(255,107,107,0.25); }
.chip.turn { color: #aebcff; border-color: rgba(167,139,250,0.25); }
.chip.spd { color: #8de5ff; border-color: rgba(90,169,255,0.25); }

.event-list { display: grid; gap: 8px; }
.event-row {
  display: grid; grid-template-columns: 38px 1fr auto auto; gap: 12px; align-items: center;
  padding: 12px 13px; border: 1px solid var(--line); border-radius: 12px;
  background: rgba(255,255,255,0.018);
}
.event-icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-size: 10px; font-weight: 800; letter-spacing: 0.4px; }
.event-title { font-size: 12.5px; font-weight: 650; }
.event-sub { color: var(--muted); font-size: 10.5px; margin-top: 3px; }
.event-time { color: var(--muted); font-size: 10.5px; }

.device-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.device-card { border: 1px solid var(--line); border-radius: 14px; padding: 15px; background: rgba(255,255,255,0.02); }
.device-top { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.device-name { font-weight: 700; font-size: 13px; }
.device-id { color: var(--muted); font-size: 10.5px; margin-top: 4px; }
.status { font-size: 10px; font-weight: 700; padding: 4px 8px; border-radius: 999px; }
.status.online { color: #7df0b8; background: rgba(94,226,160,0.1); }
.status.offline { color: var(--muted); background: rgba(255,255,255,0.05); }
.device-meta { margin-top: 13px; color: var(--muted); font-size: 10.5px; line-height: 1.7; }

.modal { position: fixed; inset: 0; display: none; z-index: 50; }
.modal.open { display: block; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(3, 8, 14, 0.7); backdrop-filter: blur(6px); }
.modal-card {
  position: relative; width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 60px);
  margin: 30px auto; overflow: auto;
  background: #0f1d2e; border: 1px solid var(--line); border-radius: 20px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.5); padding: 22px;
}
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 16px; }
.icon-btn { border: 1px solid var(--line); background: transparent; color: var(--text); width: 32px; height: 32px; border-radius: 9px; font-size: 21px; line-height: 1; cursor: pointer; }
.modal-body { color: var(--text); }
.detail-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin-bottom: 16px; }
.detail-cell { border: 1px solid var(--line); border-radius: 11px; padding: 10px; }
.detail-cell span { display: block; color: var(--muted); font-size: 10px; margin-bottom: 4px; }
.detail-cell b { font-size: 16px; font-variant-numeric: tabular-nums; }
.detail-events { display: grid; gap: 6px; }
.detail-events .event-row { grid-template-columns: 38px 1fr auto; }

.toast {
  position: fixed; right: 24px; bottom: 24px; z-index: 80;
  padding: 11px 15px; border-radius: 11px; border: 1px solid rgba(71,215,208,0.3);
  background: #0d2428; color: #dffcf7; font-size: 12px;
  opacity: 0; transform: translateY(8px); pointer-events: none; transition: 0.2s ease;
}
.toast.show { opacity: 1; transform: none; }

@media (max-width: 1100px) {
  .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid.two { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  body { display: block; }
  .sidebar { position: relative; width: auto; height: auto; flex-direction: row; align-items: center; gap: 14px; padding: 15px 16px; }
  .nav { flex-direction: row; overflow: auto; }
  .sidebar-foot, .brand-sub { display: none; }
  .main { padding: 18px 16px 30px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .top-actions { justify-content: flex-start; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .device-grid { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .cards { grid-template-columns: 1fr; }
  .score-body { flex-direction: column; align-items: flex-start; }
  .detail-grid { grid-template-columns: repeat(2, 1fr); }
  .mix-row { grid-template-columns: 62px 1fr 40px; }
}

/* login */
.login-page {
  display: block;
  min-height: 100vh;
  background:
    radial-gradient(700px 500px at 15% 20%, rgba(71,215,208,0.12), transparent 60%),
    radial-gradient(700px 500px at 90% 80%, rgba(90,169,255,0.10), transparent 60%),
    #08111d;
}
.login-shell {
  min-height: 100vh;
  display: grid;
  place-content: center;
  gap: 26px;
  padding: 28px;
}
.login-brand { display: flex; align-items: center; gap: 12px; justify-content: center; }
.login-card {
  width: min(390px, calc(100vw - 40px));
  background: linear-gradient(165deg, rgba(16,29,47,0.98), rgba(10,20,34,0.98));
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 26px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.4);
}
.login-card h1 { font-size: 25px; margin-bottom: 8px; }
.login-hint { color: var(--muted); font-size: 12px; line-height: 1.6; margin: 0 0 20px; }
.login-card label { display: grid; gap: 7px; color: var(--muted); font-size: 11.5px; margin-bottom: 14px; }
.login-card input {
  width: 100%;
  padding: 12px 13px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.035);
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.login-card input:focus { border-color: rgba(71,215,208,0.55); box-shadow: 0 0 0 3px rgba(71,215,208,0.08); }
.login-btn { width: 100%; margin-top: 3px; padding: 12px; font-size: 13px; }
.login-error { min-height: 17px; color: #ff9b9b; font-size: 11.5px; margin: 2px 0 9px; }
.login-foot { color: rgba(143,166,191,0.65); font-size: 10.5px; text-align: center; margin-top: 17px; }

/* GPS map */
.gps-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: -2px 0 12px; color: var(--muted); font-size: 11.5px; }
.gps-map-wrap { position: relative; }
.gps-map { height: 430px; border-radius: 14px; overflow: hidden; border: 1px solid var(--line); background: #0a1421; }
.gps-empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px; color: var(--muted); font-size: 13px; background: rgba(8,17,29,0.72); border-radius: 14px; pointer-events: none; }
.gps-empty span { font-size: 10.5px; color: rgba(143,166,191,0.7); }
.leaflet-container { background: #0a1421; font-family: inherit; }
.leaflet-control-attribution { background: rgba(8,17,29,0.75) !important; color: #8fa6bf !important; font-size: 9px !important; }
.leaflet-control-attribution a { color: #47d7d0 !important; }
.leaflet-bar a { background: #101d2f !important; color: #eaf2fb !important; border-color: rgba(153,182,214,0.16) !important; }
@media (max-width: 520px) { .gps-map { height: 320px; } }

/* map base */
.gps-map {
  background-color: #08111d;
  background-image:
    linear-gradient(rgba(71,215,208,0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(71,215,208,0.06) 1px, transparent 1px);
  background-size: 42px 42px;
}
.gps-map .leaflet-tile {
  filter: brightness(0.62) saturate(0.72) contrast(1.12);
}
.gps-map .leaflet-control-attribution {
  background: rgba(8,17,29,0.8) !important;
}

/* GPS replay */
.gps-actions { display: flex; gap: 14px; align-items: center; }
.gps-replay-hud {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 500;
  width: 190px;
  padding: 14px 15px;
  border-radius: 13px;
  border: 1px solid rgba(94,226,160,0.32);
  background: rgba(8,17,29,0.9);
  box-shadow: 0 18px 45px rgba(0,0,0,0.38);
  backdrop-filter: blur(8px);
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.gps-replay-hud.active { opacity: 1; transform: translateY(0); pointer-events: auto; }
.replay-kicker { color: #5ee2a0; font-size: 9px; letter-spacing: .18em; margin-bottom: 5px; }
.replay-distance { color: #eaf2fb; font-size: 31px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.replay-distance small { font-size: 12px; color: #8fa6bf; margin-left: 5px; font-weight: 500; }
.replay-status { color: #8fa6bf; font-size: 10.5px; margin: 7px 0 10px; }
.replay-track { height: 4px; border-radius: 99px; background: rgba(153,182,214,0.17); overflow: hidden; margin-bottom: 11px; }
.replay-progress { height: 100%; width: 0; background: linear-gradient(90deg,#47d7d0,#5ee2a0); transition: width .12s linear; }
.replay-close { padding: 0 !important; color: #8fa6bf !important; font-size: 10.5px !important; }
.gps-map .leaflet-marker-icon { filter: none; }
@media (max-width: 520px) {
  .gps-actions { gap: 10px; }
  .gps-replay-hud { top: 12px; right: 12px; width: 160px; }
  .replay-distance { font-size: 25px; }
}
