:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --panel-2: #f2f5f9;
  --panel-3: #eaeff6;
  --border: #e4e9f0;
  --border-2: #d5dce6;
  --text: #1f2733;
  --text-dim: #6b7683;
  --text-soft: #98a3b1;
  --accent: #2563eb;
  --accent-soft: #eef3fd;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
#app {
  display: grid; grid-template-columns: 268px minmax(0, 1fr) 396px;
  grid-template-rows: minmax(0, 1fr); height: 100vh;
}
#sidebar, #main, #detail { min-height: 0; }

/* ---------- sidebar ---------- */
#sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  min-width: 0;
}
.brand { padding: 18px 16px 14px; border-bottom: 1px solid var(--border); }
.brand-title { font-size: 17px; font-weight: 800; letter-spacing: .2px; }
.brand-sub { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.search-wrap { padding: 12px 12px 8px; }
#search {
  width: 100%; padding: 9px 12px; border-radius: 9px;
  border: 1px solid var(--border-2); background: var(--panel-2); color: var(--text);
  outline: none; font-size: 13px; transition: .15s;
}
#search::placeholder { color: var(--text-soft); }
#search:focus { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px var(--accent-soft); }
.stats { padding: 6px 16px 10px; font-size: 12px; color: var(--text-dim); line-height: 1.7; }
.stats b { color: var(--text); }
.filters { flex: 1; min-height: 0; overflow-y: auto; padding: 0 12px 12px; }
.filter-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chip {
  font-size: 12px; padding: 5px 11px; border-radius: 20px; cursor: pointer;
  border: 1px solid var(--border-2); color: var(--text-dim); user-select: none;
  background: #fff; transition: .15s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 2px 8px rgba(37,99,235,.25); }
.cat-list { display: flex; flex-direction: column; gap: 2px; }
.cat-item {
  display: flex; align-items: center; gap: 8px; padding: 7px 9px;
  border-radius: 7px; cursor: pointer; user-select: none; font-size: 13px;
  transition: .12s;
}
.cat-item:hover { background: var(--panel-2); }
.cat-item.off { opacity: .38; }
.cat-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.cat-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-count { color: var(--text-dim); font-size: 12px; }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--border); }
.doc-link { color: var(--accent); text-decoration: none; font-size: 12.5px; }
.doc-link:hover { text-decoration: underline; }

/* ---------- main graph ---------- */
#main { display: flex; flex-direction: column; min-width: 0; }
#topbar {
  height: 52px; display: flex; align-items: center; justify-content: space-between;
  gap: 14px; padding: 0 18px; border-bottom: 1px solid var(--border); background: var(--panel);
}
#graphTitle { font-weight: 700; }
.hint { color: var(--text-dim); font-size: 12px; }
#graphHost {
  position: relative; flex: 1;
  background: radial-gradient(circle at 50% 42%, #ffffff 0%, var(--bg) 72%);
}
#graph { position: absolute; inset: 0; cursor: grab; }
#graph:active { cursor: grabbing; }
#legend {
  position: absolute; left: 14px; bottom: 14px; background: rgba(255,255,255,.94);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px;
  display: flex; flex-direction: column; gap: 5px; font-size: 11.5px; max-height: 46%;
  overflow-y: auto; box-shadow: var(--shadow-sm); backdrop-filter: blur(6px);
}
#legend .lg-item { display: flex; align-items: center; gap: 6px; }
#legend .lg-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
#empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--text-soft); font-size: 15px;
}

/* ---------- detail ---------- */
#detail {
  background: var(--panel); border-left: 1px solid var(--border);
  overflow-y: auto; padding: 18px;
}
#detailEmpty { color: var(--text-soft); text-align: center; margin-top: 44px; font-size: 13px; }
.d-head { margin-bottom: 12px; }
.d-badge {
  display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 5px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text-dim);
  margin-right: 6px; margin-bottom: 6px;
}
.d-title { font-size: 20px; font-weight: 700; line-height: 1.3; }
.d-id { color: var(--text-dim); font-size: 12px; margin-top: 4px; }
.d-section { margin: 14px 0; }
.d-section h4 {
  margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--accent);
}
.d-section p { margin: 0; line-height: 1.75; color: #333d49; }
.d-visual { margin: 4px 0 0; }
.d-visual svg { width: 100%; height: auto; max-width: 520px; display: block; border-radius: 10px; overflow: hidden; box-shadow: 0 1px 4px rgba(15,23,42,.10); }
.d-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.d-tag { font-size: 12px; padding: 3px 9px; border-radius: 5px; background: var(--panel-2); border: 1px solid var(--border); }
.d-why { display: block; font-size: 11px; line-height: 1.35; opacity: .75; margin-top: 3px; }
.d-evidence { border-left: 3px solid #2563eb; padding: 8px 11px; background: #f4f8ff; border-radius: 0 6px 6px 0; font-size: 12.5px; line-height: 1.65; color: #334155; }
.yin-bar { height: 6px; border-radius: 3px; background: var(--panel-3); overflow: hidden; margin-top: 6px; }
.yin-fill { height: 100%; background: linear-gradient(90deg,#2563eb,#9aa7b8); }
.d-link { color: var(--accent); cursor: pointer; text-decoration: none; }
.d-link:hover { text-decoration: underline; }
.quiz-item { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; background: var(--panel-2); }
.quiz-q { font-weight: 600; margin-bottom: 6px; }
.quiz-a { color: #1f7a3d; font-size: 13px; }
.quiz-toggle { font-size: 12px; color: var(--accent); cursor: pointer; margin-top: 6px; user-select: none; }
.quiz-a { display: none; }
.quiz-a.show { display: block; }
.source { font-size: 12px; color: var(--text-dim); word-break: break-all; }

/* scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cfd8e3; border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #b4c0d0; background-clip: content-box; }
