:root {
  --bg: #0e1117;
  --bg-2: #161b22;
  --bg-3: #1c2230;
  --panel: #151a23;
  --border: #262d3a;
  --text: #e6edf3;
  --text-dim: #8b97a7;
  --text-mute: #5b6573;
  --accent: #4f9eff;
  --accent-2: #2ec4b6;
  --danger: #ff5d73;
  --warn: #f5a623;
  --ok: #3fb950;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);

  --c-product: #5b8cff;
  --c-person: #f5a623;
  --c-company: #2ec4b6;
  --c-vc: #ff5d73;
}

* { 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;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-3);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 12px;
  transition: background 0.15s, border-color 0.15s;
}
button:hover { background: #232b3a; border-color: #3a4456; }
button:active { transform: translateY(1px); }

input[type="text"], input[type="search"] {
  font-family: inherit;
  background: #0c1016;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 7px 10px;
  outline: none;
  width: 100%;
}
input:focus { border-color: var(--accent); }

/* ---------- top bar ---------- */
.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: linear-gradient(180deg, #11161f, #0d1219);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}
.brand { display: flex; align-items: baseline; gap: 8px; white-space: nowrap; }
.brand-mark {
  font-weight: 800;
  letter-spacing: 1px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand-sub { color: var(--text-dim); font-size: 13px; }

.search-wrap { position: relative; flex: 1; max-width: 460px; display: flex; gap: 8px; }
.search-wrap input { flex: 1; }
.search-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-height: 320px;
  overflow-y: auto;
  z-index: 30;
}
.search-list li {
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}
.search-list li:hover, .search-list li.active { background: #1f2733; }
.search-list li .sl-type { color: var(--text-mute); font-size: 11px; }

.top-actions { margin-left: auto; }

/* ---------- layout ---------- */
.layout {
  display: flex;
  height: calc(100% - 56px);
}
.sidebar {
  width: 320px;
  flex-shrink: 0;
  background: var(--bg);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: #2a3340; border-radius: 4px; }

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

/* type filters */
.type-filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.type-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0c1118;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
}
.type-chip .dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.type-chip .tc-count { margin-left: auto; color: var(--text-mute); font-size: 12px; }
.type-chip.off { opacity: 0.45; }
.type-chip.off .dot { filter: grayscale(0.7); }

/* path form */
.path-form { display: flex; flex-direction: column; gap: 8px; }
.path-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-dim); }
.path-form button { margin-top: 2px; background: var(--accent); color: #fff; border-color: var(--accent); }
.path-form button:hover { background: #3a87e6; }
.path-result {
  margin-top: 10px;
  min-height: 24px;
  font-size: 13px;
  line-height: 1.5;
}
.path-msg { padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: #0c1118; }
.path-msg.ok { border-color: var(--ok); color: #b6f0c0; background: rgba(63,185,80,0.08); }
.path-msg.bad { border-color: var(--danger); color: #ffc4cc; background: rgba(255,93,115,0.08); }
.path-msg.warn { border-color: var(--warn); color: #ffe2a8; background: rgba(245,166,35,0.08); }
.path-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: 8px; }
.path-chip {
  background: #0c1118;
  border: 1px solid var(--accent);
  color: #cfe4ff;
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 12px;
  cursor: pointer;
}
.path-chip:hover { background: #16223a; }
.path-chip.endpoint { background: var(--accent); color: #fff; }
.path-arrow { color: var(--text-mute); font-size: 12px; }
.path-tip { margin-top: 8px; font-size: 11px; color: var(--text-mute); }

/* stats lists */
.stats-list { display: flex; flex-direction: column; gap: 4px; }
.stat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 7px;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 13px;
}
.stat-row:hover { background: #1a212c; border-color: var(--border); }
.stat-row .dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.stat-row .stat-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-row .stat-val { color: var(--text-dim); font-variant-numeric: tabular-nums; font-size: 12px; }
.stat-row .rank { color: var(--text-mute); width: 18px; font-size: 11px; text-align: right; }

/* ---------- stage ---------- */
.stage {
  position: relative;
  flex: 1;
  min-width: 0;
  background:
    radial-gradient(circle at 30% 20%, #131a26 0%, #0c1016 60%);
  overflow: hidden;
}
#graph { display: block; width: 100%; height: 100%; cursor: grab; }
#graph.grabbing { cursor: grabbing; }
#graph.node-hover { cursor: pointer; }

.legend {
  position: absolute;
  left: 14px;
  top: 14px;
  background: rgba(15, 20, 28, 0.85);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12px;
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-width: 200px;
}
.legend .lg-title { color: var(--text-mute); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 2px; }
.legend .lg-row { display: flex; align-items: center; gap: 7px; }
.legend .dot { width: 10px; height: 10px; border-radius: 50%; }

.hint {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  color: var(--text-mute);
  font-size: 12px;
  background: rgba(15, 20, 28, 0.7);
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  white-space: nowrap;
  pointer-events: none;
}

.zoom-ctrl {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.zoom-ctrl button {
  width: 34px;
  height: 34px;
  padding: 0;
  font-size: 16px;
  line-height: 1;
  background: rgba(20, 26, 36, 0.9);
  border: 1px solid var(--border);
}

/* node detail */
.node-detail {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 320px;
  max-height: calc(100% - 100px);
  overflow-y: auto;
  background: rgba(18, 23, 32, 0.95);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 14px;
  backdrop-filter: blur(8px);
}
.node-detail::-webkit-scrollbar { width: 8px; }
.node-detail::-webkit-scrollbar-thumb { background: #2a3340; border-radius: 4px; }
.detail-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 20px;
  line-height: 1;
}
.detail-close:hover { color: var(--text); background: #232b3a; }
.detail-body .d-type {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-dim);
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 20px;
  margin-bottom: 8px;
}
.detail-body .d-name { font-size: 18px; font-weight: 700; margin-bottom: 4px; word-break: break-word; }
.detail-body .d-id { font-size: 12px; color: var(--text-mute); margin-bottom: 10px; }
.detail-body .d-desc { font-size: 13px; line-height: 1.6; color: #c4cdd9; margin-bottom: 12px; }
.detail-body .d-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.detail-body .d-cell { background: #0c1118; border: 1px solid var(--border); border-radius: 8px; padding: 8px; }
.detail-body .d-cell .k { font-size: 11px; color: var(--text-mute); }
.detail-body .d-cell .v { font-size: 16px; font-weight: 700; }
.detail-body .d-aliases { font-size: 12px; color: var(--text-dim); margin-bottom: 12px; line-height: 1.6; }
.detail-body .d-section-title { font-size: 12px; color: var(--text-mute); margin: 6px 0 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.detail-body .d-rel { display: flex; flex-direction: column; gap: 4px; }
.detail-body .d-rel-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #0c1118;
  cursor: pointer;
  font-size: 12px;
}
.detail-body .d-rel-item:hover { background: #16202e; }
.detail-body .d-rel-tag { font-size: 10px; color: var(--text-mute); padding: 1px 6px; border: 1px solid var(--border); border-radius: 10px; white-space: nowrap; }
.detail-body .d-rel-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail-body .d-empty { color: var(--text-mute); font-size: 12px; }

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

@media (max-width: 900px) {
  .sidebar { width: 260px; }
  .node-detail { width: 260px; }
  .brand-sub { display: none; }
}
