/*
 * Relationship graphs, drawn by graph_view.js: the Estate Explorer and the Command Centre
 * (estate_graph.js), and the map on Asset and Application 360 (object_graph.js), with their
 * toolbars, lenses and legends. The SVGs have no viewBox, so sizes here are real pixels at 100% zoom.
 *
 * Readability comes from showing less: the server groups interchangeable nodes, subtitles and edge
 * labels appear only when zoomed in (.zoomed) or around the selected node, and selecting a node
 * (.has-focus) dims everything it is not connected to.
 */

/* Explorer lenses */

.explorerbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-5);
  margin: 0 var(--space-10) var(--space-3);
}

.lens {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0 var(--space-8);
}

.explorerbar .lens {
  margin: 0;
}

.lens button {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--text-tertiary);
  font-size: var(--text-sm);
}

.lens button.active {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--text-inverse);
}

.graph-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-muted);
  font-size: var(--text-xs);
}

.graph-actions button,
.graph-controls button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-tertiary);
  cursor: pointer;
}

.graph-actions button {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
}

.graph-controls {
  display: flex;
  gap: var(--space-1);
}

.graph-controls button {
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
}

.graph-controls button.active {
  border-color: var(--border-accent);
  background: var(--accent-soft);
  color: var(--text-accent);
}

/* Estate Explorer canvas */

.graph-shell {
  position: relative;
  overflow: hidden;
  height: 680px;
  margin: 0 var(--space-10) var(--space-10);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.estate-graph {
  position: absolute;
  inset: 0;
  min-height: 680px;
  background: radial-gradient(circle at 50% 44%, var(--surface-subtle) 0, var(--surface) 52%, var(--surface-subtle) 100%);
}

.graph-help {
  position: absolute;
  top: var(--space-4);
  left: var(--space-5);
  z-index: var(--z-raised);
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-translucent);
  box-shadow: var(--shadow-md);
}

.graph-help b {
  display: block;
}

.graph-help span {
  display: block;
  margin-top: var(--space-1);
  color: var(--text-muted);
  font-size: var(--text-xs);
}

.graph-loading {
  display: grid;
  place-items: center;
  height: 100%;
  color: var(--text-muted);
}

.command-canvas .graph-loading {
  position: absolute;
  inset: 0;
  font-size: var(--text-sm);
}

/* The graph */

.graph-svg {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

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

.graph-edge {
  stroke: var(--border-strong);
  stroke-width: 1.2;
  transition: opacity var(--duration-fast) var(--ease);
}

.edge-label,
.node-sub {
  opacity: 0;
  transition: opacity var(--duration-fast) var(--ease);
}

.edge-label {
  fill: var(--text-muted);
  font-size: var(--text-xs);
  paint-order: stroke;
  pointer-events: none;
  stroke: var(--surface);
  stroke-width: 3px;
  text-anchor: middle;
}

.graph-svg.zoomed .edge-label,
.graph-svg.zoomed .node-sub,
.edge-label.is-focus,
.graph-node.is-focus .node-sub,
.graph-node:focus-visible .node-sub,
.graph-node:hover .node-sub {
  opacity: 1;
}

.graph-node {
  cursor: pointer;
  outline: 0;
  transition: opacity var(--duration-fast) var(--ease);
}

.graph-node circle {
  fill: var(--surface);
  stroke: var(--chart-asset);
  stroke-width: 2;
  filter: drop-shadow(var(--shadow-xs));
}

.graph-node:hover circle {
  stroke-width: 3;
}

.graph-node.tone-hub circle {
  fill: var(--accent-soft-strong);
  stroke: var(--accent);
}

.graph-node.tone-application circle {
  fill: var(--chart-application-soft);
  stroke: var(--chart-application);
}

.graph-node.tone-group circle {
  fill: var(--accent-soft);
  stroke: var(--accent);
  stroke-dasharray: 5 3;
}

.graph-node.tone-finance circle {
  fill: var(--success-soft);
  stroke: var(--success);
}

.graph-node.tone-risk circle {
  fill: var(--danger-soft);
  stroke: var(--danger);
}

.graph-node.root circle {
  fill: var(--surface-inverse);
  stroke: var(--surface-inverse);
}

.graph-node:focus-visible circle,
.graph-node[aria-pressed="true"] circle {
  stroke: var(--accent);
  stroke-width: 4;
}

.graph-node text {
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  pointer-events: none;
  text-anchor: middle;
}

.node-badge {
  fill: var(--text-secondary);
  font-weight: var(--weight-bold);
}

.graph-node.tone-group .node-badge {
  fill: var(--text-accent);
}

.graph-node.root .node-badge {
  fill: var(--text-inverse);
}

.node-label,
.node-sub {
  paint-order: stroke;
  stroke: var(--surface);
  stroke-width: 3px;
}

.node-label {
  fill: var(--text);
  font-weight: var(--weight-bold);
}

.node-sub {
  fill: var(--text-muted);
}

/* Focus mode: the selected node and its neighbours stay; everything else steps back. */
.graph-svg.has-focus .graph-node:not(.is-focus),
.graph-svg.has-focus .graph-edge:not(.is-focus) {
  opacity: 0.2;
}

.graph-svg.has-focus .edge-label:not(.is-focus) {
  opacity: 0;
}

.graph-svg.has-focus .graph-edge.is-focus {
  stroke: var(--accent);
  stroke-width: 2;
}

/* Legends */

.graph-legend {
  position: absolute;
  bottom: var(--space-4);
  left: var(--space-5);
  display: flex;
  align-items: center;
  gap: var(--space-5);
  height: 42px;
  padding: 0 var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-translucent);
  color: var(--text-muted);
  font-size: var(--text-xs);
}

.graph-legend span,
.graph-key span {
  display: flex;
  align-items: center;
}

.graph-legend small {
  padding-left: var(--space-2);
  border-left: 1px solid var(--border);
  color: var(--text-muted);
}

.legend-dot {
  display: inline-block;
  flex: none;
  width: 9px;
  height: 9px;
  margin-right: var(--space-1-5);
  border: 2px solid;
  border-radius: 50%;
}

.legend-dot.tone-asset {
  border-color: var(--chart-asset);
  background: var(--surface);
}

.legend-dot.is-root {
  border-color: var(--surface-inverse);
  background: var(--surface-inverse);
}

.legend-dot.tone-hub {
  border-color: var(--accent);
  background: var(--accent-soft-strong);
}

.legend-dot.tone-application {
  border-color: var(--chart-application);
  background: var(--chart-application-soft);
}

.legend-dot.tone-group {
  border-style: dashed;
  border-color: var(--accent);
  background: var(--accent-soft);
}

.legend-dot.tone-finance {
  border-color: var(--success);
  background: var(--success-soft);
}

.legend-dot.tone-risk {
  border-color: var(--danger);
  background: var(--danger-soft);
}

/* Legend strip under a graph card */

.graph-key {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
  min-height: 45px;
  padding: var(--space-2) var(--space-6);
  border-top: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: var(--text-xs);
}

.graph-hint {
  margin-left: auto;
}

/* Object map (Asset and Application 360) */

.graph-frame {
  position: relative;
}

.object-graph {
  position: relative;
  overflow: hidden;
  height: 440px;
  background: radial-gradient(circle at center, var(--surface-subtle), var(--surface) 65%);
}

.object-graph::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(var(--border) 0.7px, transparent 0.7px);
  background-size: 22px 22px;
}

.graph-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  font-size: var(--text-xs);
}

.graph-selection {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 42px;
  margin: 0;
  padding: var(--space-2) var(--space-6);
  border-top: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

.graph-selection a {
  margin-left: auto;
  white-space: nowrap;
}

.graph-frame .graph-legend {
  position: static;
  flex-wrap: wrap;
  height: auto;
  min-height: 42px;
  border: 0;
  border-top: 1px solid var(--border-subtle);
  border-radius: 0;
}

/* Legacy static node boxes (search results' relationship preview). */

.node {
  display: inline-block;
  min-width: 135px;
  padding: var(--space-4) var(--space-6);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text-muted);
}

.node b {
  color: var(--text);
}

.node.root {
  border: 2px solid var(--accent);
  box-shadow: var(--shadow-accent);
}

@media (max-width: 820px) {
  .explorerbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .explorerbar .lens {
    flex-wrap: wrap;
  }

  .graph-shell {
    height: 620px;
  }

  .graph-shell .graph-legend {
    right: var(--space-5);
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-3);
    height: auto;
    padding: var(--space-2) var(--space-3);
  }

  .graph-legend small,
  .graph-hint {
    display: none;
  }
}
