:root {
  --bg: #0b0f1a;
  --bg-2: #111727;
  --card: rgba(22, 30, 50, 0.85);
  --border: rgba(120, 150, 220, 0.16);
  --text: #dbe4f5;
  --text-dim: #7d8db0;
  --accent: #4f8cff;
  --accent-2: #38e1c6;
  --good: #3ddc84;
  --warn: #ffc145;
  --bad: #ff5d6c;
  --radius: 14px;
}

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

body {
  font-family: "Segoe UI", "Microsoft YaHei", -apple-system, sans-serif;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(79, 140, 255, 0.12), transparent),
    radial-gradient(900px 500px at -10% 110%, rgba(56, 225, 198, 0.08), transparent),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 15, 26, 0.7);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 1100;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon { font-size: 30px; }
.brand h1 {
  font-size: 20px;
  letter-spacing: 0.5px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand p { font-size: 12px; color: var(--text-dim); }

.search { display: flex; gap: 10px; flex: 1; min-width: 320px; max-width: 760px; margin-left: auto; }
.search input {
  flex: 1;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 16px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.18); }

.btn {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.12s, filter 0.2s, background 0.2s;
}
.btn:hover { transform: translateY(-1px); filter: brightness(1.15); }
.btn:active { transform: translateY(0); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #6a5cff);
  border: none;
  color: #fff;
  font-weight: 600;
}
.btn-ghost { background: var(--bg-2); color: var(--text); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ---------- 布局 ---------- */
.panel { flex: 1; padding: 20px 28px; display: flex; flex-direction: column; gap: 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  backdrop-filter: blur(6px);
}
.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 1px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- 指标条 ---------- */
.chips { display: flex; gap: 12px; flex-wrap: wrap; }
.chip {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 16px;
  min-width: 120px;
}
.chip label { display: block; font-size: 11px; color: var(--text-dim); margin-bottom: 2px; }
.chip b { font-size: 15px; font-weight: 600; }
.status-idle { color: var(--text-dim); }
.status-running { color: var(--warn); }
.status-ok { color: var(--good); }
.status-fail { color: var(--bad); }

/* ---------- 路由跟踪区 ---------- */
.trace-grid {
  display: grid;
  grid-template-columns: minmax(420px, 5fr) 7fr;
  gap: 16px;
  min-height: 520px;
}
.map-card { padding: 6px; overflow: hidden; }
#map { width: 100%; height: 100%; min-height: 508px; border-radius: 10px; background: #0a0e17; }

.hop-list { display: flex; flex-direction: column; max-height: 640px; }
.hop-table-wrap { overflow-y: auto; flex: 1; }
.hop-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.hop-table th {
  text-align: left;
  font-size: 11px;
  color: var(--text-dim);
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: #161e32;
  z-index: 1;
}
.hop-table td { padding: 8px; border-bottom: 1px solid rgba(120, 150, 220, 0.07); vertical-align: top; }
.hop-table tbody tr { animation: rowIn 0.35s ease; }
.hop-table tbody tr:hover { background: rgba(79, 140, 255, 0.07); }
@keyframes rowIn { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; } }
.placeholder-row td { color: var(--text-dim); text-align: center; padding: 40px 0 !important; }

.hop-no {
  display: inline-flex;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: rgba(79, 140, 255, 0.18);
  color: var(--accent);
  font-weight: 700;
  font-size: 11px;
  align-items: center;
  justify-content: center;
}
.hop-no.is-target { background: rgba(61, 220, 132, 0.2); color: var(--good); }
.mono { font-family: Consolas, "JetBrains Mono", monospace; }
.dim { color: var(--text-dim); font-size: 12px; }
.lat-good { color: var(--good); } .lat-mid { color: var(--warn); }
.lat-high { color: #ff9f43; } .lat-bad { color: var(--bad); }
.timeout-cell { color: var(--text-dim); letter-spacing: 3px; }

/* ---------- 地图标记 ---------- */
.hop-marker {
  background: linear-gradient(135deg, var(--accent), #6a5cff);
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 50%;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex !important;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 12px rgba(79, 140, 255, 0.8);
}
.hop-marker.target {
  background: linear-gradient(135deg, var(--good), #1fa365);
  box-shadow: 0 0 14px rgba(61, 220, 132, 0.9);
}
.trace-path { stroke-dasharray: 8 8; animation: dashFlow 1.2s linear infinite; }
@keyframes dashFlow { to { stroke-dashoffset: -16; } }
.leaflet-popup-content-wrapper { background: #1a2238; color: var(--text); border-radius: 10px; }
.leaflet-popup-tip { background: #1a2238; }

/* ---------- 智能分析 ---------- */
.analysis #analysisText { font-size: 14px; line-height: 1.9; }
.analysis .as-chain { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.as-tag {
  background: rgba(56, 225, 198, 0.1);
  border: 1px solid rgba(56, 225, 198, 0.3);
  color: var(--accent-2);
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 12px;
}
.as-arrow { color: var(--text-dim); }

/* ---------- IP 检测面板 ---------- */
.check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
  gap: 16px;
  align-items: start;
}
.empty-hint { text-align: center; color: var(--text-dim); padding: 60px 0; font-size: 14px; }

#miniMap { height: 180px; border-radius: 10px; margin-top: 14px; border: 1px solid var(--border); }

.native-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
}
.native-badge.yes { background: rgba(61, 220, 132, 0.12); border: 1px solid rgba(61, 220, 132, 0.35); color: var(--good); }
.native-badge.no { background: rgba(255, 159, 67, 0.12); border: 1px solid rgba(255, 159, 67, 0.35); color: #ff9f43; }

.risk-sources { margin-top: 12px; font-size: 11px; }

.webrtc-result { margin-top: 12px; font-size: 13px; line-height: 1.8; }
.webrtc-result .leak { color: var(--warn); }
.webrtc-result .safe { color: var(--good); }

.ip-headline { font-size: 22px; font-weight: 700; margin-bottom: 12px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ip-headline .flag { font-size: 26px; }
.kv { display: grid; grid-template-columns: 96px 1fr; gap: 8px 14px; font-size: 13px; }
.kv dt { color: var(--text-dim); }
.kv dd { word-break: break-all; }

/* 风险仪表 */
.risk-top { display: flex; gap: 20px; align-items: center; margin-bottom: 14px; }
.gauge-wrap { position: relative; width: 120px; height: 120px; flex-shrink: 0; }
.gauge { transform: rotate(-90deg); }
.gauge circle { fill: none; stroke-width: 10; stroke-linecap: round; }
.gauge-bg { stroke: rgba(120, 150, 220, 0.12); }
.gauge-val { stroke: var(--good); stroke-dasharray: 314; stroke-dashoffset: 314; transition: stroke-dashoffset 0.9s ease, stroke 0.5s; }
.gauge-num {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.gauge-num b { font-size: 26px; }
.gauge-num span { font-size: 11px; color: var(--text-dim); }
.risk-level { font-size: 18px; font-weight: 700; }
.ip-type {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 12px;
  border-radius: 8px;
  background: rgba(79, 140, 255, 0.12);
  border: 1px solid rgba(79, 140, 255, 0.3);
  font-size: 13px;
}
.ip-usage { margin-top: 6px; font-size: 12px; color: var(--text-dim); }

.factors { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.factors li {
  display: flex; gap: 10px; align-items: baseline;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(120, 150, 220, 0.05);
}
.factors .f-icon { flex-shrink: 0; }
.factors .f-desc { color: var(--text-dim); font-size: 12px; }
.factors li.hit { background: rgba(255, 93, 108, 0.08); border: 1px solid rgba(255, 93, 108, 0.2); }

/* 质量检测 */
.quality-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 10px; margin-bottom: 14px; }
.q-stat { background: rgba(120, 150, 220, 0.06); border-radius: 10px; padding: 10px; text-align: center; }
.q-stat b { display: block; font-size: 18px; }
.q-stat span { font-size: 11px; color: var(--text-dim); }
.ping-chart { display: flex; align-items: flex-end; gap: 6px; height: 96px; padding-top: 20px; }
.ping-bar {
  flex: 1;
  background: linear-gradient(to top, var(--accent), var(--accent-2));
  border-radius: 4px 4px 0 0;
  min-height: 4px;
  position: relative;
  animation: barUp 0.4s ease;
  transform-origin: bottom;
}
@keyframes barUp { from { transform: scaleY(0); } }
.ping-bar.lost { background: rgba(255, 93, 108, 0.35); }
.ping-bar .tip {
  position: absolute; top: -18px; left: 50%; transform: translateX(-50%);
  font-size: 10px; color: var(--text-dim); white-space: nowrap;
}

/* ---------- 其他 ---------- */
.spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  padding: 14px;
  border-top: 1px solid var(--border);
}

@media (max-width: 980px) {
  .trace-grid { grid-template-columns: 1fr; }
  #map { min-height: 380px; }
  .hop-list { max-height: 400px; }
  .topbar { gap: 12px; }
  .search { min-width: 100%; }
}
