:root {
  --bg: #f7f8fb;
  --panel: #ffffff;
  --ink: #1c2434;
  --muted: #6b7280;
  --line: #e4e8f0;
  --accent: #3455db;
  --accent-soft: #e8ecff;
  --warn: #d97706;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(28, 36, 52, 0.08);
  font-family: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-columns: 288px minmax(0, 1fr);
  height: 100vh;
}
#app.with-detail { grid-template-columns: 288px minmax(0, 1fr) 400px; }

#sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 20px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  background: linear-gradient(135deg, #3455db, #6a8bff);
  color: #fff; font-weight: 700; font-size: 14px;
  display: grid; place-items: center; flex: none;
}
.brand h1 { font-size: 16px; margin: 0 0 3px; letter-spacing: 0.2px; }
.brand p { margin: 0; font-size: 11.5px; color: var(--muted); }

.search-box { position: relative; }
.search-box input {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: #f9fafc;
  font-size: 13px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.search-box input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-results {
  position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; right: 0;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); max-height: 320px; overflow-y: auto; padding: 6px;
}
.search-results button {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  padding: 8px 9px; border-radius: 7px; cursor: pointer; font-size: 12.5px; color: var(--ink);
}
.search-results button:hover { background: #f2f4fa; }
.search-results .muted { color: var(--muted); font-size: 11px; margin-left: 6px; }

.panel h2 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); margin: 0 0 10px; font-weight: 600;
}
.field { display: block; margin-bottom: 12px; font-size: 12px; color: var(--muted); }
.field > span { display: block; margin-bottom: 6px; }
.field select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 12.5px; color: var(--ink); background: #fff;
}
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  border-radius: 999px; padding: 4px 10px; font-size: 11.5px; cursor: pointer;
  transition: all .15s;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.toggle { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); margin: 4px 0 12px; cursor: pointer; }
.toggle input { accent-color: var(--accent); }
.reset {
  width: 100%; border: 1px solid var(--line); background: #f9fafc; color: var(--ink);
  padding: 8px; border-radius: 8px; cursor: pointer; font-size: 12px;
}
.reset:hover { background: #f0f2f8; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat-grid div { background: #f8f9fc; border-radius: 9px; padding: 8px 10px; }
.stat-grid strong { display: block; font-size: 17px; letter-spacing: -0.02em; }
.stat-grid span { font-size: 10.5px; color: var(--muted); }

.legend { display: flex; flex-direction: column; gap: 5px; max-height: 300px; overflow-y: auto; }
.legend button {
  display: flex; align-items: center; gap: 8px; border: 0; background: none;
  font-size: 11.5px; color: var(--muted); cursor: pointer; padding: 2px 0; text-align: left;
}
.legend button:hover { color: var(--ink); }
.legend .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.legend .count { margin-left: auto; font-variant-numeric: tabular-nums; opacity: .7; }

.sidebar-foot { display: flex; flex-direction: column; gap: 3px; font-size: 10.5px; color: #9aa1ae; margin-top: auto; }
.sidebar-foot a { color: #6b7280; }

#main { display: flex; flex-direction: column; min-width: 0; }
#toolbar {
  height: 52px; flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.86);
  backdrop-filter: blur(8px);
}
.breadcrumb { font-size: 12.5px; color: var(--muted); }
.breadcrumb strong { color: var(--ink); }
.toolbar-actions { display: flex; gap: 6px; }
.toolbar-actions button {
  width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; cursor: pointer; font-size: 15px; color: var(--ink); display: grid; place-items: center;
}
.toolbar-actions button:hover { background: #f4f6fb; }

#graph-wrap { position: relative; flex: 1; overflow: hidden; background:
  radial-gradient(circle at 1px 1px, #e7eaf2 1px, transparent 0) 0 0 / 22px 22px, var(--bg); }
#graph { width: 100%; height: 100%; display: block; cursor: grab; }
#graph.dragging { cursor: grabbing; }

.node { cursor: pointer; }
.node rect { stroke: rgba(255,255,255,.9); stroke-width: 1.5; rx: 7; }
.node text { font-size: 10.5px; fill: #fff; pointer-events: none; font-weight: 500; }
.node .grade-label { font-size: 8.5px; fill: rgba(255,255,255,.8); }
.node.dimmed { opacity: .13; }
.node.highlighted rect { stroke: #111827; stroke-width: 2.5; }
.node.ancestor rect { stroke: #2563eb; stroke-width: 2.5; }
.node.descendant rect { stroke: #ea580c; stroke-width: 2.5; }
.node.selected rect { stroke: #f59e0b; stroke-width: 3.5; }

.edge { fill: none; stroke: #aeb6c8; stroke-width: 1; opacity: .17; }
.edge.hard { stroke: #7d8aa5; }
.edge.soft { stroke-dasharray: 3 3; }
.edge.ancestor-edge { stroke: #2563eb; opacity: .75; stroke-width: 1.9; }
.edge.descendant-edge { stroke: #ea580c; opacity: .75; stroke-width: 1.9; }
.edge.dimmed { opacity: .025; }

#tooltip {
  position: absolute; z-index: 20; pointer-events: none; max-width: 280px;
  background: rgba(28, 36, 52, .94); color: #fff; padding: 9px 11px;
  border-radius: 9px; font-size: 11.5px; line-height: 1.5; box-shadow: var(--shadow);
}
#tooltip strong { display: block; font-size: 12px; margin-bottom: 2px; }
#tooltip span { color: #c9d2e8; }

#empty-state {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--muted); font-size: 13px; background: var(--bg); text-align: center; padding: 20px;
}

#empty-state[hidden] { display: none; }

#detail {
  background: var(--panel); border-left: 1px solid var(--line);
  overflow-y: auto; padding: 24px 22px 40px; position: relative;
}
.detail-close {
  position: absolute; top: 14px; right: 14px; width: 30px; height: 30px;
  border: 1px solid var(--line); background: #fff; border-radius: 8px; cursor: pointer; font-size: 18px; color: var(--muted);
}
#detail-body h2 { font-size: 19px; margin: 0 34px 10px 0; line-height: 1.35; }
.meta-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 15px; }
.meta-chips span {
  font-size: 10.5px; padding: 3px 8px; border-radius: 999px; background: #f1f3f9; color: #4b5563;
}
.meta-chips .accent { background: var(--accent-soft); color: var(--accent); }
#detail-body h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted);
  margin: 20px 0 8px; font-weight: 600;
}
#detail-body p { font-size: 13px; line-height: 1.7; margin: 0 0 8px; }
#detail-body ul { margin: 0; padding-left: 18px; }
#detail-body li { font-size: 12.5px; line-height: 1.65; margin-bottom: 5px; }
.assess-box { background: #f7f9ff; border: 1px solid #e2e8ff; border-radius: 10px; padding: 11px 12px; font-size: 12.5px; line-height: 1.65; }
.std-card, .tb-card {
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; margin-bottom: 7px;
  font-size: 12px; line-height: 1.55; background: #fcfcfe;
}
.std-card strong, .tb-card strong { display: block; margin-bottom: 2px; font-size: 12px; }
.std-card code { font-size: 10.5px; color: var(--accent); background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; }
.dep-list button {
  width: 100%; text-align: left; border: 1px solid var(--line); background: #fff;
  border-radius: 9px; padding: 8px 10px; margin-bottom: 6px; cursor: pointer; font-size: 12px; color: var(--ink);
}
.dep-list button:hover { border-color: var(--accent); background: #fafbff; }
.dep-list .reason { display: block; color: var(--muted); font-size: 11px; margin-top: 3px; line-height: 1.5; }
.badge { display: inline-block; font-size: 9.5px; padding: 1px 6px; border-radius: 999px; margin-left: 5px; vertical-align: 1px; }
.badge.hard { background: #fde8e8; color: #b91c1c; }
.badge.soft { background: #fff4e5; color: #b45309; }
.card-section { border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; margin-bottom: 8px; background: #fcfcfe; }
.card-section h4 { font-size: 12px; margin: 0 0 6px; }
.card-section p, .card-section li { font-size: 12px; line-height: 1.6; }
.copy-id { font-size: 10.5px; color: var(--muted); background: #f4f6fa; border: 0; border-radius: 6px; padding: 4px 8px; cursor: pointer; }

@media (max-width: 1100px) {
  #app { grid-template-columns: 240px minmax(0, 1fr); }
  #app.with-detail { grid-template-columns: 240px minmax(0, 1fr); }
  #detail {
    position: fixed; z-index: 40; right: 0; top: 0; bottom: 0; width: min(400px, 92vw);
    box-shadow: var(--shadow);
  }
}
@media (max-width: 760px) {
  body { overflow: auto; }
  #app { display: block; height: auto; min-height: 100vh; }
  #sidebar { display: flex; border-right: 0; border-bottom: 1px solid var(--line); }
  #main { height: 72vh; min-height: 440px; }
}
