.graph-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: 100vh;
  background: var(--bg);
}

.graph-sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  border-right: 1px solid var(--line);
  background: #fbfcfe;
  padding: 22px;
}

.graph-back,
.graph-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--primary-strong);
  font-weight: 800;
  text-decoration: none;
}

.graph-back {
  display: flex;
  align-items: center;
  justify-content: center;
}

.graph-back:hover,
.graph-button:hover {
  border-color: #9bc9c3;
  background: var(--primary-soft);
}

.graph-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.graph-search {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 11px 12px;
  outline: none;
}

.graph-search:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.graph-legend,
.graph-stats,
.node-details {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.graph-legend {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
}

.graph-legend h2 {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.graph-legend div {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
}

.legend-dot.entity {
  background: #2563eb;
}

.legend-dot.concept {
  background: #0f766e;
}

.legend-dot.source {
  background: #7c3aed;
}

.legend-dot.overview {
  background: #f59e0b;
}

.legend-dot.source-file {
  background: #64748b;
}

.graph-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
}

.graph-stats div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: #fff;
  padding: 14px;
}

.graph-stats strong {
  color: var(--primary-strong);
  font-size: 24px;
}

.graph-stats span {
  color: var(--muted);
  font-size: 13px;
}

.graph-main {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 100vh;
}

.graph-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
  padding: 18px 24px;
}

.graph-header h2,
.graph-header p {
  margin: 0;
}

.graph-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.graph-button {
  padding: 0 14px;
}

.zoom-controls {
  display: inline-grid;
  grid-template-columns: 40px 64px 40px;
  min-height: 40px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.zoom-button {
  border: 0;
  background: #fff;
  color: var(--primary-strong);
  font-size: 20px;
  font-weight: 900;
}

.zoom-button:hover {
  background: var(--primary-soft);
}

.zoom-level {
  display: grid;
  place-items: center;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.graph-button.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.graph-button.primary:hover {
  background: var(--primary-strong);
}

.graph-canvas-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.graph-canvas {
  width: 100%;
  height: 100%;
  min-height: 600px;
  background:
    linear-gradient(#eef3f8 1px, transparent 1px),
    linear-gradient(90deg, #eef3f8 1px, transparent 1px),
    #f8fafc;
  background-size: 36px 36px;
}

.graph-edge {
  stroke: #aab7c6;
  stroke-opacity: 0.62;
  stroke-width: 1.2;
}

.graph-edge.source {
  stroke-dasharray: 5 4;
}

.graph-node {
  cursor: grab;
}

.graph-node:active {
  cursor: grabbing;
}

.graph-node circle {
  stroke: #fff;
  stroke-width: 2.5;
  filter: drop-shadow(0 8px 14px rgba(15, 23, 42, 0.18));
}

.graph-node text {
  fill: #17202a;
  font-size: 12px;
  font-weight: 700;
  paint-order: stroke;
  pointer-events: none;
  stroke: rgba(255, 255, 255, 0.88);
  stroke-width: 4px;
}

.graph-node.dimmed,
.graph-edge.dimmed {
  opacity: 0.16;
}

.graph-node.selected circle {
  stroke: #111827;
  stroke-width: 3.5;
}

.node-details {
  position: absolute;
  right: 20px;
  bottom: 20px;
  width: min(360px, calc(100% - 40px));
  padding: 16px;
}

.node-details h3 {
  margin: 0 0 8px;
  font-size: 18px;
}

.node-details p {
  margin: 0 0 8px;
  color: var(--muted);
  line-height: 1.45;
}

.node-details code {
  display: inline-block;
  max-width: 100%;
  overflow-wrap: anywhere;
  border-radius: 6px;
  background: var(--panel-soft);
  padding: 3px 6px;
  color: var(--text);
}

@media (max-width: 900px) {
  .graph-shell {
    grid-template-columns: 1fr;
  }

  .graph-sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .graph-canvas {
    min-height: 520px;
  }
}

@media (max-width: 560px) {
  .graph-sidebar,
  .graph-header {
    padding-left: 14px;
    padding-right: 14px;
  }

  .graph-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .graph-actions {
    width: 100%;
  }

  .graph-button,
  .zoom-controls {
    flex: 1;
  }
}
