/* Region visualizer page: the sidebar (search, filters, legend) and the
   canvas/SVG graph stage. The graph itself is drawn to <canvas> by
   agency-graph/canvas-renderer.js for performance, not with SVG elements -
   so this file only styles the sidebar chrome, the legend swatches, and the
   canvas surface/overlays, not per-node/per-link SVG rules. */

.graph-page {
  min-height: calc(100vh - 5.4rem);
  padding: 1.5rem clamp(1rem, 3vw, 2rem) 2rem;
}

.graph-header {
  width: min(1440px, 100%);
  margin: 0 auto 1rem;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
}

.graph-header h1 {
  margin: 0.25rem 0 0;
  font-size: clamp(1.9rem, 4vw, 3.4rem);
  line-height: 1.02;
}

.relationship-graph {
  width: min(1440px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(250px, 320px) minmax(0, 1fr);
  gap: 1rem;
  align-items: stretch;
}

.graph-sidebar,
.graph-stage {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.07);
}

.graph-sidebar {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.graph-field {
  display: grid;
  gap: 0.45rem;
}

.graph-field > label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.graph-field input,
.graph-field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem 0.8rem;
  background: var(--surface-strong);
  color: var(--text);
  font: inherit;
}

.graph-combobox {
  position: relative;
  display: block;
}

.graph-search-options {
  position: absolute;
  z-index: 10;
  top: calc(100% + 0.25rem);
  left: 0;
  right: 0;
  max-height: 14rem;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
}

.graph-search-option {
  display: block;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 0.65rem 0.8rem;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.graph-search-option:last-child {
  border-bottom: 0;
}

.graph-search-option:hover,
.graph-search-option[aria-selected="true"] {
  background: var(--surface-strong);
  color: var(--text);
}

.graph-search {
  display: grid;
  gap: 0.6rem;
}

.graph-search > button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111111;
  color: #ffffff;
  min-height: 2.5rem;
  padding: 0.65rem 0.7rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.graph-search-message {
  min-height: 1.2rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

.graph-legend {
  display: grid;
  gap: 1rem;
}

.graph-control-group {
  display: grid;
  gap: 0.65rem;
  padding-top: 0.1rem;
}

.graph-control-group h2,
.graph-legend h2 {
  margin: 0 0 0.55rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.graph-control-group h2 {
  margin-bottom: 0;
}

.graph-check-list {
  display: grid;
  gap: 0.45rem;
}

.graph-check,
.graph-switch {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 0.55rem;
  color: var(--text);
  font-size: 0.88rem;
  line-height: 1.25;
  cursor: pointer;
}

.graph-check input {
  width: 1rem;
  height: 1rem;
  margin: 0;
  accent-color: #111111;
}

.graph-check span {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.graph-switch input {
  appearance: none;
  position: relative;
  width: 2.2rem;
  height: 1.2rem;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #d9d9d9;
  cursor: pointer;
  transition: background 160ms ease;
}

.graph-switch input::after {
  content: "";
  position: absolute;
  top: 0.12rem;
  left: 0.12rem;
  width: 0.84rem;
  height: 0.84rem;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.28);
  transition: transform 160ms ease;
}

.graph-switch input:checked {
  background: #111111;
}

.graph-switch input:checked::after {
  transform: translateX(1rem);
}

.graph-switch input:focus-visible,
.graph-check input:focus-visible,
.graph-view-controls button:focus-visible,
.graph-search button:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.35);
  outline-offset: 2px;
}

.graph-search-option:focus-visible {
  position: relative;
  z-index: 1;
  outline: 3px solid rgba(37, 99, 235, 0.35);
  outline-offset: -3px;
}

.graph-legend ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}

.graph-legend li {
  display: grid;
  grid-template-columns: 1rem minmax(0, 1fr);
  align-items: center;
  gap: 0.55rem;
  color: var(--text);
  font-size: 0.88rem;
  line-height: 1.25;
}

.legend-swatch {
  display: inline-block;
  width: 0.9rem;
  height: 0.9rem;
  border: 1px solid #111111;
  flex: 0 0 auto;
}

.legend-node {
  border-radius: 999px;
}

.legend-edge {
  height: 0.18rem;
  border: 0;
}

.graph-stage {
  min-width: 0;
  display: grid;
  grid-template-rows: minmax(560px, 72vh) auto;
  overflow: hidden;
}

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

#agency-graph-canvas,
#agency-graph {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#agency-graph-canvas {
  background:
    linear-gradient(rgba(17, 17, 17, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(17, 17, 17, 0.04) 1px, transparent 1px), #ffffff;
  background-size: 32px 32px;
  pointer-events: none;
}

.graph-count-badge {
  position: absolute;
  top: 1rem;
  left: 1rem;
  z-index: 3;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  box-shadow: 0 8px 24px rgba(17, 17, 17, 0.08);
  pointer-events: none;
}

.graph-view-controls {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.graph-view-controls button {
  min-width: 2.3rem;
  min-height: 2.3rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #111111;
  color: #ffffff;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

#reset-graph {
  min-width: 4.2rem;
  padding: 0 0.65rem;
}

.edge-tooltip {
  position: absolute;
  z-index: 4;
  max-width: min(20rem, calc(100% - 2rem));
  padding: 0.45rem 0.6rem;
  border: 1px solid #111111;
  border-radius: 7px;
  background: #ffffff;
  color: #111111;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.25;
  pointer-events: none;
  transform: translate(0.65rem, -50%);
  opacity: 0;
  transition: opacity 120ms ease;
}

.edge-tooltip.is-visible {
  opacity: 1;
}

/* Relationship-type colors, shared between the sidebar legend/filter
   swatches (the only place these are drawn - node/link colors on the
   canvas itself are set directly in canvas-renderer.js). */
.legend-edge.bounding-address {
  background: #16a34a;
}

.legend-edge.same-address {
  background: #2563eb;
}

.legend-edge.fax {
  background: #92400e;
}

.legend-edge.telephone,
.legend-edge.phone {
  background: #7c3aed;
}

.legend-edge.email {
  background: #111111;
}

.legend-node.normal {
  background: #00b7ff;
}

.legend-node.accredited-ph {
  background: #16a34a;
}

.legend-node.accredited-ind {
  background: #7c3aed;
}

.legend-node.accredited-thai {
  background: #f97316;
}

.legend-node.accredited-ph-ind {
  background: #facc15;
}

.legend-node.accredited-ph-thai {
  background: #14b8a6;
}

.legend-node.accredited-ind-thai {
  background: #ec4899;
}

.legend-node.accredited-ph-ind-thai {
  background: #78350f;
}

.legend-node.money-lender {
  background: #dc2626;
}

.graph-detail {
  min-height: 6.5rem;
  padding: 1rem;
  border-top: 1px solid var(--line);
  background: #ffffff;
}

.graph-detail h2 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
}

.graph-detail p {
  margin: 0.35rem 0;
  color: var(--muted);
  line-height: 1.4;
}

.graph-detail strong {
  color: var(--text);
}
