/* graph.css — fund-flow graph layout and SVG styling. The canvas follows
   the page theme (a light canvas by default, dark in dark mode); node
   colors are fixed across both themes (see --kind-* in base.css) so a
   trace reads the same regardless of theme. */

.graph-page {
  display: flex;
  flex-direction: column;
  height: 70vh;
  min-height: 420px;
  max-height: 900px;
}

.graph-toolbar {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 0.6rem;
}

.graph-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  overflow: hidden;
}

.graph-stage.is-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 200;
  border-radius: 0;
  height: 100vh;
}

.graph-svg {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
  background:
    radial-gradient(var(--bg-sunken) 1px, transparent 1px) 0 0 / 22px 22px,
    var(--bg-elevated);
}
.graph-svg.is-panning { cursor: grabbing; }

.graph-controls {
  position: absolute;
  right: 0.6rem;
  bottom: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  z-index: 5;
}

.graph-legend {
  position: absolute;
  left: 0.6rem;
  bottom: 0.6rem;
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.45rem 0.6rem;
  font-size: 0.72rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.8rem;
  max-width: 60%;
  z-index: 5;
}
.graph-legend__item { display: flex; align-items: center; gap: 0.3rem; color: var(--fg-muted); }
.graph-legend__swatch { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }

.graph-hint {
  position: absolute;
  top: 0.6rem;
  left: 0.6rem;
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.35rem 0.6rem;
  font-size: 0.72rem;
  color: var(--fg-muted);
  z-index: 5;
}

.node-shape { stroke-width: 1.5; }

/* Labels are hidden by default (real-data graphs can have 400+ nodes) and
   only shown once zoomed in past a threshold, or on hover/highlight/select
   regardless of zoom. The `labels-zoomed` class is toggled in graph.js. */
.node-label {
  font-size: 9.5px;
  fill: var(--fg-muted);
  font-family: var(--font-mono);
  pointer-events: none;
  display: none;
}
.graph-svg.labels-zoomed .node-label { display: inline; }
.gnode:hover .node-label,
.gnode.is-highlight .node-label,
.gnode.is-selected .node-label {
  display: inline;
}

.lane-label {
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.04em;
  fill: var(--fg-muted);
  font-family: var(--font-mono);
  pointer-events: none;
}

/* The "subtle, turn accent-colored when highlighted" edge spec maps
   exactly onto --border-strong (#CBD5E1 in light) and --accent (#4063FF). */
.edge-path {
  fill: none;
  stroke: var(--border-strong);
  opacity: 0.9;
}
.edge-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 12px;
  cursor: pointer;
}
/* When every edge carries the same (missing) weight, keep them uniformly
   thin and neutral instead of letting the width-scale code add noise. */
.graph-svg.edges-uniform .edge-path { opacity: 0.6; }

.gnode { cursor: pointer; }
.gnode .node-shape { fill: var(--bg-raised); stroke: var(--border-strong); }

.gnode[data-kind="attacker"] .node-shape { fill: var(--kind-attacker); stroke: var(--kind-attacker); }
.gnode[data-kind="victim"] .node-shape { fill: var(--kind-victim); stroke: var(--kind-victim); }
.gnode[data-kind="exchange"] .node-shape { fill: var(--kind-exchange); stroke: var(--kind-exchange); }
.gnode[data-kind="bridge"] .node-shape { fill: var(--kind-bridge); stroke: var(--kind-bridge); }
.gnode[data-kind="dex"] .node-shape { fill: var(--kind-dex); stroke: var(--kind-dex); }
.gnode[data-kind="mixer"] .node-shape { fill: var(--kind-mixer); stroke: var(--kind-mixer); }
.gnode[data-kind="service"] .node-shape { fill: var(--kind-service); stroke: var(--kind-service); }
.gnode[data-kind="unknown"] .node-shape { fill: var(--bg-raised); stroke: var(--kind-unknown); stroke-dasharray: 2 2; }

.gnode-fold .fold-shape { fill: var(--bg-raised); stroke: var(--border-strong); stroke-dasharray: 2 2; }
.gnode-fold:hover .fold-shape { stroke: var(--accent); fill: var(--accent-muted); }
.fold-label {
  font-size: 9px;
  font-weight: 600;
  fill: var(--fg-muted);
  font-family: var(--font-mono);
  text-anchor: middle;
  pointer-events: none;
}

.gedge.is-highlight .edge-path { stroke: var(--accent); opacity: 0.95; }
.gnode.is-highlight .node-shape,
.gnode.is-highlight .fold-shape {
  stroke: var(--accent);
  stroke-width: 2.5;
}
.gnode.is-selected .node-shape { stroke: var(--fg); stroke-width: 3; }

.graph-stage.has-selection .gedge:not(.is-highlight),
.graph-stage.has-selection .gnode:not(.is-highlight):not(.is-selected) {
  opacity: 0.18;
}

.gnode.is-hidden, .gedge.is-hidden { display: none; }

.graph-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 320px;
  max-width: 85%;
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-hover);
  overflow-y: auto;
  padding: 0.9rem;
  z-index: 10;
  color: var(--fg);
}
.graph-panel__close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
}
.graph-panel dl { margin: 0.6rem 0; font-size: 0.84rem; }
.graph-panel dt { color: var(--fg-muted); font-size: 0.72rem; text-transform: uppercase; margin-top: 0.5rem; }
.graph-panel dd { margin: 0.1rem 0 0; word-break: break-all; }
.graph-panel ul.edge-list { list-style: none; padding: 0; margin: 0.3rem 0; max-height: 160px; overflow-y: auto; }
.graph-panel ul.edge-list li { padding: 0.3rem 0; border-bottom: 1px solid var(--border); font-size: 0.8rem; }
.graph-panel a { color: var(--accent); }

.graph-fallback-table { font-size: 0.82rem; }
