:root {
  --bg: #0d1017;
  --bg-soft: #151a24;
  --bg-panel: #171d29;
  --bg-elev: #1e2532;
  --border: #2a3342;
  --text: #e6ebf2;
  --text-dim: #97a3b6;
  --muted: #6b7688;
  --accent: #5b9dff;
  --accent-soft: rgba(91, 157, 255, 0.14);
  --path: #ff5d6c;
  --product: #4f8ef7;
  --company: #2fbf8f;
  --person: #f5a623;
  --vc_firm: #b06ef7;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 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;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 16px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: baseline; gap: 8px; white-space: nowrap; }
.brand-mark {
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 1px;
  background: linear-gradient(90deg, #ff5d6c, #b06ef7, #5b9dff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand-sub { color: var(--text-dim); font-size: 13px; }

.search-wrap { position: relative; flex: 1 1 240px; min-width: 200px; max-width: 420px; }
#search-input {
  width: 100%;
  padding: 8px 30px 8px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  outline: none;
}
#search-input:focus { border-color: var(--accent); }
.search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
}
.search-clear:hover { color: var(--text); background: var(--bg-panel); }

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 320px;
  overflow-y: auto;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
  z-index: 30;
}
.search-result-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--accent-soft); }
.search-result-item .name { flex: 1; }
.search-result-item .id { color: var(--muted); font-size: 12px; }
.search-result-count { padding: 6px 12px; color: var(--muted); font-size: 12px; }

.type-filters { display: flex; gap: 8px; flex-wrap: wrap; }
.type-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
}
.type-chip input { display: none; }
.type-chip .swatch { width: 10px; height: 10px; border-radius: 50%; }
.type-chip.off { opacity: 0.4; }
.type-chip .cnt { color: var(--muted); font-size: 12px; }

.reset-btn, .primary-btn {
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}
.reset-btn:hover { border-color: var(--accent); color: var(--accent); }
.primary-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #061225;
  font-weight: 700;
}
.primary-btn:hover { filter: brightness(1.08); }

.layout {
  display: flex;
  height: calc(100% - 57px);
}

.graph-area {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  background:
    radial-gradient(1200px 700px at 30% 20%, rgba(91, 157, 255, 0.06), transparent 60%),
    radial-gradient(900px 600px at 80% 90%, rgba(176, 110, 247, 0.06), transparent 60%),
    var(--bg);
}
#graph-canvas { display: block; width: 100%; height: 100%; cursor: grab; }
#graph-canvas.dragging { cursor: grabbing; }

.legend {
  position: absolute;
  left: 14px;
  bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  background: rgba(21, 26, 36, 0.82);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(6px);
  font-size: 12px;
}
.legend .row { display: flex; align-items: center; gap: 8px; color: var(--text-dim); }
.legend .swatch { width: 11px; height: 11px; border-radius: 50%; }

.zoom-controls {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.zoom-controls button {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(30, 37, 50, 0.9);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}
.zoom-controls button:hover { border-color: var(--accent); color: var(--accent); }

.graph-hint {
  position: absolute;
  left: 14px;
  top: 12px;
  color: var(--muted);
  font-size: 12px;
  background: rgba(21, 26, 36, 0.7);
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  pointer-events: none;
}

.tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(13, 16, 23, 0.95);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 9px;
  font-size: 12px;
  z-index: 20;
  max-width: 240px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
}
.tooltip .t-name { font-weight: 700; }
.tooltip .t-type { color: var(--text-dim); font-size: 11px; }

.loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 15px;
}

.sidebar {
  flex: 0 0 348px;
  width: 348px;
  overflow-y: auto;
  background: var(--bg-soft);
  border-left: 1px solid var(--border);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.panel-title {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  text-transform: uppercase;
}

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

.detail .d-head { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; }
.detail .d-dot { width: 13px; height: 13px; border-radius: 50%; flex: 0 0 auto; }
.detail .d-name { font-size: 17px; font-weight: 800; }
.detail .d-type {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-elev);
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.detail .d-id { color: var(--muted); font-size: 12px; margin-bottom: 8px; word-break: break-all; }
.detail .d-desc { color: var(--text); line-height: 1.55; margin: 0 0 10px; }
.detail .d-metrics { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.detail .metric {
  flex: 1 1 auto;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 9px;
  text-align: center;
  min-width: 70px;
}
.detail .metric .v { font-size: 16px; font-weight: 800; }
.detail .metric .k { font-size: 11px; color: var(--muted); }
.detail .d-aliases { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.detail .alias {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}
.detail .d-sub { font-size: 12px; color: var(--text-dim); margin: 6px 0; font-weight: 700; }
.detail .rel-list { display: flex; flex-direction: column; gap: 4px; max-height: 240px; overflow-y: auto; }
.detail .rel-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 8px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 12.5px;
  background: var(--bg-elev);
  border: 1px solid transparent;
}
.detail .rel-item:hover { border-color: var(--accent); }
.detail .rel-tag {
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--bg-soft);
  color: var(--text-dim);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.detail .rel-dir { color: var(--muted); }
.detail .rel-name { flex: 1; }

.path-form { display: flex; flex-direction: column; gap: 9px; margin-bottom: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12px; color: var(--text-dim); }
.field input {
  padding: 7px 10px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  outline: none;
}
.field input:focus { border-color: var(--accent); }

.path-result { font-size: 13px; }
.path-result .pr-msg { margin: 0; line-height: 1.5; }
.path-result .pr-ok { color: var(--text); }
.path-result .pr-bad { color: #ffb02e; }
.path-result .pr-len { color: var(--muted); font-size: 12px; margin: 0 0 8px; }
.path-nodes { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
.path-chip {
  padding: 4px 9px;
  border-radius: 7px;
  background: rgba(255, 93, 108, 0.14);
  border: 1px solid rgba(255, 93, 108, 0.5);
  color: #ffd0d5;
  font-weight: 600;
  cursor: pointer;
}
.path-chip:hover { background: rgba(255, 93, 108, 0.28); }
.path-arrow { color: var(--path); font-weight: 700; }

.stats-list { display: flex; flex-direction: column; gap: 4px; }
.stat-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 8px;
  border-radius: 7px;
  cursor: pointer;
  background: var(--bg-elev);
  border: 1px solid transparent;
}
.stat-row:hover { border-color: var(--accent); }
.stat-row .rank {
  width: 20px;
  text-align: center;
  color: var(--muted);
  font-weight: 700;
  font-size: 12px;
}
.stat-row .rank.top { color: #ffce54; }
.stat-row .dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.stat-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-row .deg {
  font-weight: 800;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
}

.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.stat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 7px 9px;
  border-radius: 7px;
  background: var(--bg-elev);
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 12.5px;
}
.stat-item:hover { border-color: var(--accent); }
.stat-item.active { border-color: var(--accent); background: var(--accent-soft); }
.stat-item .lbl { display: flex; align-items: center; gap: 6px; overflow: hidden; }
.stat-item .lbl .txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-item .swatch { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.stat-item .cnt { font-weight: 800; color: var(--text); }

.sidebar::-webkit-scrollbar, .search-results::-webkit-scrollbar, .rel-list::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb, .search-results::-webkit-scrollbar-thumb, .rel-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 8px;
}

@media (max-width: 860px) {
  html, body { overflow: auto; }
  .layout { flex-direction: column; height: auto; }
  .graph-area { height: 60vh; }
  .sidebar { flex: 1 1 auto; width: 100%; border-left: none; border-top: 1px solid var(--border); }
}
