:root {
  --bg: #0b0e16;
  --bg-2: #11151f;
  --panel: rgba(20, 25, 38, 0.92);
  --panel-border: rgba(120, 140, 180, 0.16);
  --text: #e6e9f2;
  --muted: #8a93a8;
  --accent: #36e0e0;
  --accent-2: #5b9dff;
  --product: #5b9dff;
  --person: #f0a44b;
  --company: #46d6a0;
  --vc_firm: #c77dff;
  --danger: #ff6b6b;
  --ok: #46d6a0;
  --warn: #f0a44b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ===== Topbar ===== */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  background: linear-gradient(180deg, #0f1320, #0b0e16);
  border-bottom: 1px solid var(--panel-border);
  flex-wrap: wrap;
  min-height: 56px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  white-space: nowrap;
}
.brand-mark { color: var(--accent); font-size: 18px; }
.brand-title { font-size: 15px; letter-spacing: 0.5px; }

.search-wrap {
  position: relative;
  flex: 1 1 280px;
  min-width: 220px;
  max-width: 460px;
  display: flex;
  align-items: center;
}
#search {
  width: 100%;
  padding: 8px 30px 8px 12px;
  background: var(--bg-2);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  outline: none;
}
#search:focus { border-color: var(--accent); }
#search-clear {
  position: absolute;
  right: 6px;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 6px;
  border-radius: 4px;
}
#search-clear:hover { color: var(--text); background: rgba(255,255,255,0.06); }

.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  max-height: 320px;
  overflow-y: auto;
  z-index: 50;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
}
.search-results .sr-item {
  padding: 7px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.search-results .sr-item:last-child { border-bottom: none; }
.search-results .sr-item:hover { background: rgba(54,224,224,0.10); }
.sr-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.sr-name { font-weight: 600; }
.sr-meta { color: var(--muted); font-size: 11px; margin-left: auto; }

.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 16px;
  border: 1px solid var(--panel-border);
  background: var(--bg-2);
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  user-select: none;
  transition: all 0.15s;
}
.filter-chip .chip-dot { width: 9px; height: 9px; border-radius: 50%; }
.filter-chip.active { color: var(--text); border-color: rgba(255,255,255,0.3); background: rgba(255,255,255,0.05); }
.filter-chip:not(.active) { opacity: 0.45; }
.filter-chip .chip-count { color: var(--muted); font-variant-numeric: tabular-nums; }

.primary-btn {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: rgba(54,224,224,0.12);
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transition: all 0.15s;
}
.primary-btn:hover { background: rgba(54,224,224,0.22); }
.primary-btn:active { transform: translateY(1px); }

.icon-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  border-radius: 4px;
}

/* ===== Layout ===== */
.layout {
  flex: 1;
  display: flex;
  min-height: 0;
}
.graph-area {
  position: relative;
  flex: 1;
  min-width: 0;
  background:
    radial-gradient(circle at 30% 20%, rgba(54,224,224,0.05), transparent 50%),
    radial-gradient(circle at 70% 80%, rgba(91,157,255,0.05), transparent 50%),
    var(--bg);
}
#graph { display: block; width: 100%; height: 100%; cursor: grab; }
#graph.grabbing { cursor: grabbing; }
#graph.node-cursor { cursor: pointer; }

.legend {
  position: absolute;
  left: 14px;
  bottom: 14px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 10px 12px;
  backdrop-filter: blur(8px);
  font-size: 12px;
}
.legend-title { color: var(--muted); margin-bottom: 6px; font-size: 11px; letter-spacing: 0.5px; }
.legend-row { display: flex; align-items: center; gap: 8px; margin: 3px 0; }
.legend-row .ldot { width: 11px; height: 11px; border-radius: 50%; }

.hint {
  position: absolute;
  right: 14px;
  bottom: 14px;
  color: var(--muted);
  font-size: 11px;
  background: rgba(0,0,0,0.35);
  padding: 5px 10px;
  border-radius: 6px;
  pointer-events: none;
}

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  max-width: 260px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
  z-index: 40;
  backdrop-filter: blur(6px);
}
.tooltip .tt-name { font-weight: 700; font-size: 13px; }
.tooltip .tt-type { color: var(--muted); margin-top: 2px; }
.tooltip .tt-desc { color: var(--text); margin-top: 4px; line-height: 1.45; }

/* ===== Sidebar ===== */
.sidebar {
  width: 340px;
  flex: none;
  border-left: 1px solid var(--panel-border);
  background: var(--bg-2);
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 4px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 12px;
}
.panel-title {
  margin: 0 0 10px 0;
  font-size: 12px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.muted { color: var(--muted); margin: 0; line-height: 1.5; }

/* node info */
.info-content .field { margin: 6px 0; }
.info-content .field-label { color: var(--muted); font-size: 11px; }
.info-content .field-value { font-size: 13px; }
.info-content .info-name { font-size: 16px; font-weight: 700; margin: 0 0 4px; }
.info-content .info-type { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; margin-bottom: 8px; }
.info-content .info-desc { color: var(--text); line-height: 1.55; margin: 8px 0; font-size: 12.5px; }
.info-content .info-stats { display: flex; gap: 14px; margin: 8px 0; }
.info-content .info-stat { font-size: 12px; }
.info-content .info-stat b { font-size: 15px; display: block; }
.info-content .info-aliases { font-size: 11px; color: var(--muted); margin-top: 6px; }
.info-content .neighbors { margin-top: 10px; }
.info-content .neighbors-title { font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.info-content .neighbor-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
}
.info-content .neighbor-item:hover { background: rgba(255,255,255,0.06); }
.info-content .neighbor-rel { color: var(--muted); font-size: 10px; margin-left: auto; }
.info-content .ndot { width: 9px; height: 9px; border-radius: 50%; flex: none; }

/* path */
.path-controls { display: flex; flex-direction: column; gap: 8px; }
.path-controls input {
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--panel-border);
  border-radius: 7px;
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.path-controls input:focus { border-color: var(--accent); }
.path-result { margin-top: 10px; font-size: 12.5px; line-height: 1.5; }
.path-result .path-msg { padding: 8px 10px; border-radius: 7px; }
.path-result .path-msg.ok { background: rgba(70,214,160,0.10); color: var(--ok); border: 1px solid rgba(70,214,160,0.3); }
.path-result .path-msg.unreachable { background: rgba(255,107,107,0.10); color: var(--danger); border: 1px solid rgba(255,107,107,0.3); }
.path-result .path-msg.same { background: rgba(240,164,75,0.10); color: var(--warn); border: 1px solid rgba(240,164,75,0.3); }
.path-result .path-msg.invalid { background: rgba(255,107,107,0.10); color: var(--danger); border: 1px solid rgba(255,107,107,0.3); }
.path-result .path-chain { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: 8px; }
.path-result .path-node {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: 14px;
  background: rgba(54,224,224,0.12);
  border: 1px solid rgba(54,224,224,0.4);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}
.path-result .path-node:hover { background: rgba(54,224,224,0.22); }
.path-result .path-node .ndot { width: 8px; height: 8px; border-radius: 50%; }
.path-result .path-arrow { color: var(--muted); }
.path-result .path-meta { color: var(--muted); margin-top: 6px; font-size: 11px; }

/* stats */
.stats-list { display: flex; flex-direction: column; gap: 4px; }
.stat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12.5px;
}
.stat-row:hover { background: rgba(255,255,255,0.06); }
.stat-row .rank { color: var(--muted); width: 18px; font-variant-numeric: tabular-nums; font-size: 11px; }
.stat-row .sname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-row .sval { color: var(--accent); font-variant-numeric: tabular-nums; font-weight: 600; }
.stat-row .bar {
  position: absolute;
}
.stat-row { position: relative; }
.stat-row .bar-bg {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: rgba(91,157,255,0.10);
  border-radius: 6px;
  z-index: 0;
}
.stat-row > * { position: relative; z-index: 1; }
.stat-row .sdot { width: 9px; height: 9px; border-radius: 50%; flex: none; }

/* loading & error */
.loading {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.loading-card { text-align: center; color: var(--muted); }
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 14px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-box {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255,107,107,0.15);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 12px 18px;
  border-radius: 8px;
  z-index: 200;
  max-width: 90vw;
}

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; border-left: none; border-top: 1px solid var(--panel-border); max-height: 45vh; }
  .topbar { gap: 8px; }
  .brand-title { display: none; }
}
