:root {
  --bg: #0b0d0f;
  --panel: #111417;
  --panel-2: #15191d;
  --line: #2a3036;
  --line-soft: #1c2227;
  --text: #eef1f3;
  --muted: #8e979f;
  --dim: #626b73;
  --accent: #d6ff3f;
  --accent-soft: rgba(214, 255, 63, 0.12);
  --danger: #ff6b5f;
  --warning: #ffbc42;
  --blue: #69a7ff;
  --mono: "SFMono-Regular", "Cascadia Code", "Roboto Mono", monospace;
  --sans: "Avenir Next", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; min-width: 320px; min-height: 100%; background: var(--bg); color: var(--text); }
body { font-family: var(--sans); overflow: hidden; }
button, input { font: inherit; }
button { color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.app-shell { height: 100dvh; min-height: 0; display: grid; grid-template-rows: 68px 54px minmax(0, 1fr); }

.topbar {
  display: grid;
  grid-template-columns: 260px minmax(290px, 1fr) minmax(260px, 420px) auto;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.brand-block { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  display: grid; place-items: center; width: 32px; height: 32px;
  background: var(--accent); color: #0b0d0f; font: 700 18px/1 var(--mono);
}
.brand-block div { display: grid; gap: 2px; }
.brand-block strong { font-size: 15px; letter-spacing: .01em; }
.brand-block span:not(.brand-mark) { color: var(--muted); font: 11px/1.2 var(--mono); }

.view-switch { display: flex; justify-self: center; height: 34px; border: 1px solid var(--line); background: var(--panel); }
.view-button, .toolbar-actions button {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  padding: 0 16px; font-size: 12px; transition: color 140ms ease, background 140ms ease;
}
.view-button + .view-button { border-left: 1px solid var(--line); }
.view-button:hover, .toolbar-actions button:hover { color: var(--text); background: var(--panel-2); }
.view-button.is-active { color: #0b0d0f; background: var(--accent); }
.view-button:active, .toolbar-actions button:active, .file-control:active { transform: translateY(1px); }

.search-control { height: 36px; display: flex; align-items: center; border-bottom: 1px solid var(--line); }
.search-control:focus-within { border-color: var(--accent); }
.search-control input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 13px; }
.search-control input::placeholder { color: var(--dim); }
.search-control kbd { color: var(--dim); font: 10px/1 var(--mono); border: 1px solid var(--line); padding: 4px 6px; }

.file-control {
  position: relative; display: grid; place-items: center; height: 34px; padding: 0 13px;
  border: 1px solid var(--line); color: var(--muted); font-size: 12px; cursor: pointer;
}
.file-control:hover { border-color: var(--muted); color: var(--text); }
.file-control input { position: absolute; opacity: 0; pointer-events: none; }

.contextbar {
  display: grid; grid-template-columns: minmax(360px, 1fr) auto auto; align-items: center;
  gap: 28px; padding: 0 20px; border-bottom: 1px solid var(--line-soft); background: var(--panel);
}
.context-title { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.context-title strong { font-size: 13px; white-space: nowrap; }
.context-title span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 11px; }
.status-dot { width: 7px; height: 7px; background: var(--accent); box-shadow: 0 0 12px rgba(214,255,63,.45); flex: none; }

.metrics { display: flex; align-items: center; margin: 0; height: 100%; }
.metrics div { display: flex; align-items: baseline; gap: 7px; padding: 0 16px; border-left: 1px solid var(--line); }
.metrics dt { color: var(--dim); font: 10px/1 var(--mono); }
.metrics dd { margin: 0; font: 14px/1 var(--mono); }
.toolbar-actions { height: 100%; display: flex; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }

.workspace { min-height: 0; display: grid; grid-template-columns: 180px minmax(0, 1fr) 340px; }
.rail { min-height: 0; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--bg); }
.rail-heading { padding: 18px 16px 12px; color: var(--dim); font: 10px/1 var(--mono); text-transform: uppercase; letter-spacing: .16em; }
.type-filters { overflow: auto; padding: 0 8px; }
.type-filter {
  width: 100%; display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: 9px;
  padding: 9px 8px; border: 0; background: transparent; color: var(--muted); text-align: left; cursor: pointer;
}
.type-filter:hover { color: var(--text); background: var(--panel); }
.type-filter[aria-pressed="false"] { opacity: .35; }
.type-swatch { width: 8px; height: 8px; background: var(--type-color); }
.type-label { font-size: 12px; }
.type-count { font: 10px/1 var(--mono); color: var(--dim); }
.rail-footer { margin-top: auto; display: grid; gap: 8px; padding: 14px 16px; border-top: 1px solid var(--line-soft); color: var(--dim); font: 10px/1 var(--mono); }
.rail-footer span { display: flex; align-items: center; gap: 8px; }
.legend-line { display: inline-block; width: 18px; border-top: 1px solid var(--muted); }
.inferred-line { border-top-style: dashed; }

.canvas-wrap { position: relative; min-width: 0; min-height: 0; overflow: hidden; background-color: #0d1012; background-image: linear-gradient(var(--line-soft) 1px, transparent 1px), linear-gradient(90deg, var(--line-soft) 1px, transparent 1px); background-size: 32px 32px; }
.viz-canvas { display: none; width: 100%; height: 100%; overflow: hidden; cursor: grab; user-select: none; }
.viz-canvas:active { cursor: grabbing; }
.viz-canvas.is-visible { display: block; }

.state-message { position: absolute; inset: 0; z-index: 8; display: grid; place-content: center; justify-items: center; gap: 8px; background: var(--bg); }
.state-message strong { font-size: 15px; }
.state-message span { color: var(--muted); font-size: 12px; }
.state-message.is-error strong { color: var(--danger); }

.tree-link, .graph-link { stroke: #3a4249; stroke-width: 1; vector-effect: non-scaling-stroke; }
.tree-link.is-dimmed, .graph-link.is-dimmed { opacity: .08; }
.tree-link.is-highlighted, .graph-link.is-highlighted { stroke: var(--accent); stroke-width: 1.6; }
.link-hit { stroke: transparent; stroke-width: 12; cursor: pointer; }
.link-label { fill: var(--dim); font: 8px/1 var(--mono); pointer-events: none; }
.node { cursor: pointer; }
.node .node-body { fill: var(--panel); stroke: var(--node-color); stroke-width: 1; vector-effect: non-scaling-stroke; }
.node .node-index { fill: var(--node-color); font: 8px/1 var(--mono); }
.node .node-name { fill: var(--text); font: 11px/1 var(--sans); }
.node .node-type { fill: var(--dim); font: 8px/1 var(--mono); text-transform: uppercase; }
.node:hover .node-body, .node.is-selected .node-body { stroke-width: 2; }
.node.is-selected .node-body { fill: var(--accent-soft); }
.node.is-dimmed { opacity: .12; }
.node.is-search-hit .node-body { stroke: var(--accent); stroke-width: 3; }
.graph-node circle { fill: var(--panel); stroke: var(--node-color); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.graph-node text { fill: var(--text); font: 9px/1 var(--sans); paint-order: stroke; stroke: var(--bg); stroke-width: 3px; stroke-linejoin: round; }
.graph-node.is-selected circle { fill: var(--accent); stroke: var(--accent); }
.graph-node.is-selected text { fill: var(--accent); }

.inspector { min-width: 0; min-height: 0; overflow-y: auto; border-left: 1px solid var(--line); background: var(--panel); }
.inspector-empty { min-height: 100%; display: grid; align-content: center; padding: 32px; }
.empty-index { color: var(--accent); font: 10px/1 var(--mono); margin-bottom: 18px; }
.inspector-empty strong { font-size: 18px; font-weight: 500; }
.inspector-empty p { max-width: 28ch; margin: 10px 0 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.inspector-header { padding: 24px 22px 20px; border-bottom: 1px solid var(--line); }
.entity-type { display: inline-block; margin-bottom: 12px; color: var(--type-color); font: 10px/1 var(--mono); text-transform: uppercase; letter-spacing: .12em; }
.inspector-header h2 { margin: 0; font-size: 23px; line-height: 1.2; font-weight: 500; overflow-wrap: anywhere; }
.inspector-header p { margin: 10px 0 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.inspector-section { padding: 18px 22px; border-bottom: 1px solid var(--line-soft); }
.inspector-section h3 { margin: 0 0 12px; color: var(--dim); font: 10px/1 var(--mono); text-transform: uppercase; letter-spacing: .12em; }
.relation-item { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 9px 0; border-top: 1px solid var(--line-soft); cursor: pointer; }
.relation-item { width: 100%; border-right: 0; border-bottom: 0; border-left: 0; background: transparent; color: inherit; text-align: left; }
.relation-item:first-of-type { border-top: 0; }
.relation-main { min-width: 0; }
.relation-main strong { display: block; font-size: 12px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.relation-main span { color: var(--muted); font: 9px/1 var(--mono); }
.confidence { color: var(--accent); font: 9px/1 var(--mono); }
.evidence-quote { margin: 12px 0; padding-left: 12px; border-left: 2px solid var(--accent); color: #c6ccd1; font-size: 12px; line-height: 1.55; }
.source-link { color: var(--accent); font: 10px/1.4 var(--mono); text-decoration: none; overflow-wrap: anywhere; }
.source-link:hover { text-decoration: underline; }
.gap-item { margin-top: 10px; padding: 11px 12px; background: rgba(255,188,66,.07); border-left: 2px solid var(--warning); }
.gap-meta { display: flex; gap: 7px; margin-bottom: 6px; color: var(--warning); font: 9px/1 var(--mono); }
.gap-item p { margin: 0; color: #c6ccd1; font-size: 11px; line-height: 1.5; }

.gaps-view { height: 100%; overflow: auto; padding: 28px; background: var(--bg); }
.gaps-heading { display: flex; align-items: end; justify-content: space-between; margin-bottom: 22px; }
.gaps-heading h2 { margin: 0; font-size: 24px; font-weight: 500; }
.gaps-heading p { margin: 0; color: var(--muted); font-size: 12px; }
.gap-group { display: grid; grid-template-columns: 180px minmax(0, 1fr); border-top: 1px solid var(--line); }
.gap-group-title { padding: 16px 0; color: var(--text); font-size: 12px; }
.gap-list { border-left: 1px solid var(--line); }
.gap-row { width: 100%; display: grid; grid-template-columns: 100px 150px 1fr; gap: 14px; padding: 14px 16px; border: 0; border-bottom: 1px solid var(--line-soft); background: transparent; color: inherit; text-align: left; cursor: pointer; }
.gap-row:hover { background: var(--panel); }
.gap-row .status { color: var(--warning); font: 9px/1.4 var(--mono); }
.gap-row .subject { font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gap-row .detail { color: var(--muted); font-size: 11px; line-height: 1.45; }

.search-results { position: absolute; z-index: 10; top: 12px; right: 12px; width: min(420px, calc(100% - 24px)); max-height: calc(100% - 24px); overflow: auto; background: var(--panel); border: 1px solid var(--line); box-shadow: 0 18px 60px rgba(0,0,0,.35); }
.search-result { width: 100%; display: grid; grid-template-columns: 8px 1fr auto; gap: 10px; align-items: center; padding: 12px 14px; border: 0; border-bottom: 1px solid var(--line-soft); background: transparent; color: inherit; text-align: left; cursor: pointer; }
.search-result:hover { background: var(--panel-2); }
.search-result i { width: 8px; height: 8px; background: var(--type-color); }
.search-result strong { font-size: 12px; font-weight: 500; }
.search-result span { color: var(--dim); font: 9px/1 var(--mono); }

@media (max-width: 1100px) {
  .topbar { grid-template-columns: 210px 1fr 260px; }
  .file-control { display: none; }
  .workspace { grid-template-columns: 150px minmax(0, 1fr) 300px; }
  .contextbar { grid-template-columns: 1fr auto; }
  .toolbar-actions { display: none; }
}

@media (max-width: 780px) {
  body { overflow: auto; }
  .app-shell { height: auto; min-height: 100dvh; grid-template-rows: auto auto minmax(680px, 1fr); }
  .topbar { grid-template-columns: 1fr auto; gap: 12px; padding: 12px; }
  .topbar, .brand-block, .view-switch, .search-control, .search-control input { min-width: 0; width: 100%; }
  .view-switch { grid-column: 1 / -1; grid-row: 2; justify-self: stretch; }
  .view-button { flex: 1 1 0; min-width: 0; padding-inline: 8px; }
  .search-control { grid-column: 1 / -1; grid-row: 3; }
  .contextbar { padding: 10px 12px; grid-template-columns: 1fr; gap: 8px; }
  .metrics { display: none; }
  .workspace { grid-template-columns: 1fr; grid-template-rows: 48px 520px auto; }
  .rail { border-right: 0; border-bottom: 1px solid var(--line); }
  .rail-heading, .rail-footer { display: none; }
  .type-filters { display: flex; width: 100%; max-width: 100vw; min-width: 0; overflow-x: auto; padding: 6px 8px; }
  .type-filter { width: auto; grid-template-columns: 8px auto auto; flex: none; }
  .inspector { min-height: 320px; border-left: 0; border-top: 1px solid var(--line); }
  .gap-group { grid-template-columns: 1fr; }
  .gap-group-title { padding-bottom: 8px; }
  .gap-list { border-left: 0; }
  .gap-row { grid-template-columns: 90px 1fr; }
  .gap-row .detail { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
