/* ── Graph Layout ────────────────────────────── */
.graph-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  flex: 1;
  min-height: 0;
}

.graph-canvas-wrapper {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 50%, var(--bg-inset) 0%, var(--bg) 70%);
  border-right: 1px solid var(--border);
}

.graph-svg {
  width: 100%;
  height: calc(100vh - 61px);
  cursor: grab;
}
.graph-svg:active { cursor: grabbing; }

/* ── Graph Controls ─────────────────────────── */
.graph-controls {
  position: absolute;
  top: 16px; left: 16px;
  display: flex; gap: 4px;
  z-index: 10;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px;
  box-shadow: var(--shadow-sm);
}
.control-separator {
  width: 1px;
  background: var(--border);
  margin: 2px 4px;
}
.layout-btn.active {
  background: var(--accent-soft);
  color: var(--accent-text);
  border-color: var(--accent);
}

/* ── SVG Nodes ──────────────────────────────── */
.graph-node { cursor: pointer; }
.graph-node:hover .node-circle { filter: brightness(1.1); }

.node-circle {
  stroke-width: 2;
  transition: filter 120ms, stroke-width 120ms;
}
.node-circle.selected {
  stroke-width: 3.5;
  filter: drop-shadow(0 0 8px rgba(59, 108, 245, 0.4));
}

.node-label {
  font-family: "IBM Plex Sans", sans-serif;
  font-size: 11px;
  font-weight: 600;
  fill: var(--ink);
  text-anchor: middle;
  pointer-events: none;
  user-select: none;
}

.node-abbrev {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  font-weight: 700;
  fill: white;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
  user-select: none;
}

.node-tool-count {
  font-family: "IBM Plex Mono", monospace;
  font-size: 9px;
  font-weight: 600;
  fill: var(--ink-tertiary);
  text-anchor: middle;
  pointer-events: none;
}

/* ── SVG Edges ──────────────────────────────── */
.edge-delegation {
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-opacity: 0.35;
  fill: none;
  transition: stroke-opacity 200ms;
}
.edge-delegation.highlighted {
  stroke-opacity: 0.85;
  stroke-width: 2;
}

.edge-dependency {
  stroke: var(--warning);
  stroke-width: 1.5;
  stroke-dasharray: 6 4;
  stroke-opacity: 0.35;
  fill: none;
  transition: stroke-opacity 200ms;
}
.edge-dependency.highlighted {
  stroke-opacity: 0.85;
  stroke-width: 2;
}

.edge-arrowhead-delegation { fill: var(--accent); opacity: 0.5; }
.edge-arrowhead-dependency { fill: var(--warning); opacity: 0.5; }

/* ── Node Categories ────────────────────────── */
.cat-master  .node-circle { fill: var(--accent); stroke: var(--accent-hover); }
.cat-infra   .node-circle { fill: #6366f1; stroke: #4f46e5; }
.cat-core    .node-circle { fill: #0891b2; stroke: #0e7490; }
.cat-support .node-circle { fill: #64748b; stroke: #475569; }

[data-theme="dark"] .cat-master  .node-circle { fill: #5b8af5; stroke: #7aa2ff; }
[data-theme="dark"] .cat-infra   .node-circle { fill: #818cf8; stroke: #a5b4fc; }
[data-theme="dark"] .cat-core    .node-circle { fill: #22d3ee; stroke: #67e8f9; }
[data-theme="dark"] .cat-support .node-circle { fill: #94a3b8; stroke: #cbd5e1; }

/* ── Detail Panel ───────────────────────────── */
.graph-detail-panel {
  background: var(--bg-raised);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  height: calc(100vh - 61px);
  position: sticky;
  top: 61px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.detail-empty { padding: 40px 0; text-align: center; }

.detail-agent-header {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 12px;
}
.detail-agent-icon {
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  display: grid; place-items: center;
  font-weight: 700; font-size: 14px;
  color: white;
}
.detail-agent-name { font-size: 16px; font-weight: 700; }
.detail-agent-service { font-size: 12px; color: var(--ink-tertiary); }

.detail-section { margin-bottom: 0; }
.detail-section h3 {
  font-size: 11px; font-weight: 700;
  color: var(--ink-tertiary);
  text-transform: uppercase; letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.detail-deps-list { display: flex; flex-direction: column; gap: 4px; }
.detail-dep {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  font-size: 12px; font-weight: 500;
}
.detail-dep-arrow { color: var(--ink-tertiary); font-size: 10px; }

.detail-keywords {
  display: flex; flex-wrap: wrap; gap: 4px;
}
.detail-keyword {
  padding: 2px 8px;
  font-size: 11px; font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent-text);
  border-radius: 99px;
}

.detail-stat-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.detail-stat {
  padding: 10px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-align: center;
}
.detail-stat-value { font-size: 20px; font-weight: 700; display: block; }
.detail-stat-label { font-size: 11px; color: var(--ink-tertiary); }

/* ── Legend ──────────────────────────────────── */
.legend-grid { display: flex; flex-direction: column; gap: 6px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-secondary); }

.legend-swatch {
  width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0;
}
.legend-master { background: var(--accent); }
.legend-infra  { background: #6366f1; }
.legend-core   { background: #0891b2; }
.legend-support { background: #64748b; }

[data-theme="dark"] .legend-infra  { background: #818cf8; }
[data-theme="dark"] .legend-core   { background: #22d3ee; }
[data-theme="dark"] .legend-support { background: #94a3b8; }

.legend-line {
  width: 24px; height: 2px; flex-shrink: 0;
}
.legend-delegates { background: var(--accent); }
.legend-depends { background: var(--warning); background-image: repeating-linear-gradient(90deg, var(--warning) 0 6px, transparent 6px 10px); }

/* ── Responsive ─────────────────────────────── */
@media (max-width: 900px) {
  .graph-layout { grid-template-columns: 1fr; }
  .graph-detail-panel {
    position: static; height: auto;
    border-left: none; border-top: 1px solid var(--border);
  }
  .graph-svg { height: 60vh; }
}
