/* Graph View Styles - vis-network specific */

#graph-container {
  width: 100%;
  height: 100%;
  background-color: var(--bg-graph);
  border: 1px solid var(--border-color);
  position: relative;
  overflow: visible;
}

/* Graph is in full view mode */
.content-area.graph-only #graph-container {
  height: 100%;
}

/* Hybrid mode: flex layout keeps both children as block-level boxes.
   Google Maps requires a block formatting context to render tiles correctly;
   inline-block containers cause tiles to fail to load. */
.content-area.hybrid {
  display: flex;
  flex-direction: row;
  align-items: stretch;
}

/* Graph is in hybrid mode (split view) — width overridden by JS via applyHybridRatio */
.content-area.hybrid #graph-container {
  width: calc(50% - 2px);
  height: 100%;
  flex-shrink: 0;
  border-right: none;
}

/* Custom marker for vis-network */
.custom-marker {
  background: none !important;
  border: none !important;
}

/* Vis.js tooltip customization */
.vis-tooltip {
  position: absolute;
  visibility: hidden;
  padding: 10px;
  background-color: var(--tooltip-bg);
  color: white;
  font-size: 13px;
  border-radius: 5px;
  pointer-events: none;
  z-index: 5;
  max-width: 300px;
  word-wrap: break-word;
  box-shadow: 0 4px 15px var(--shadow-strong);
}

.vis-tooltip strong {
  color: var(--text-accent);
}

/* Vis.js network canvas styling */
.vis-network {
  position: relative;
  z-index: 1;
}

.vis-network canvas {
  outline: none;
  position: relative;
  z-index: 1;
}

/* Node selection highlight */
.vis-network .vis-manipulation {
  background-color: var(--bg-tertiary);
  border-top: 1px solid var(--border-color);
  padding: 10px;
}

/* Physics controls overlay */
.graph-controls-overlay {
  position: absolute;
  top: 10px;
  right: 10px;
  background-color: var(--legend-bg);
  padding: 15px;
  border-radius: 8px;
  box-shadow: 0 2px 10px var(--shadow-color);
  z-index: 100;
  min-width: 200px;
}

.graph-controls-overlay h4 {
  margin: 0 0 10px 0;
  font-size: 14px;
  color: var(--accent-primary);
}

.graph-controls-overlay label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  margin-bottom: 8px;
  cursor: pointer;
}

/* Node legend - Always on top overlay */
.node-legend {
  position: fixed;
  bottom: 20px;
  left: 320px; /* Sidebar width (300px) + margin */
  background-color: var(--legend-bg);
  padding: 15px;
  border-radius: 8px;
  box-shadow: 0 4px 20px var(--shadow-strong);
  border: 1px solid var(--border-color);
  z-index: 10000;
  pointer-events: auto;
  display: none; /* Hidden by default, shown by JavaScript */
  color: var(--text-primary);
}

.node-legend h4 {
  margin: 0 0 10px 0;
  font-size: 14px;
  color: var(--accent-primary);
}

.node-legend-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.node-legend-header h4 { margin: 0; }

.node-legend-toggle {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 2px;
  display: inline-flex;
  align-items: center;
  border-radius: 4px;
}
.node-legend-toggle:hover { color: var(--text-primary); }
.node-legend-toggle .icon-expand { display: none; }
.node-legend-toggle svg { width: 16px; height: 16px; pointer-events: none; }

.node-legend-collapsed-label { display: none; }

.node-legend.collapsed {
  left: 320px;
  bottom: 20px;
  padding: 6px 10px;
  min-width: 0;
  white-space: nowrap;
}
.node-legend.collapsed .legend-item { display: none; }
.node-legend.collapsed .node-legend-header {
  display: inline-flex;
  margin-bottom: 0;
  vertical-align: middle;
}
.node-legend.collapsed .node-legend-header h4 { display: none; }
.node-legend.collapsed .node-legend-collapsed-label {
  display: inline;
  font-size: 12px;
  color: var(--text-primary);
  margin-right: 6px;
  vertical-align: middle;
}
.node-legend.collapsed .icon-collapse { display: none; }
.node-legend.collapsed .icon-expand { display: inline-flex; }

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 13px;
}

/* Legend shape base */
.legend-shape {
  width: 24px;
  height: 24px;
  display: inline-block;
  position: relative;
  flex-shrink: 0;
}

/* Facility - Yellow Triangle (pointing up) */
.facility-shape {
  width: 0;
  height: 0;
  border-left: 11px solid transparent;
  border-right: 11px solid transparent;
  border-bottom: 19px solid #f1c40f;
  margin-top: 2px;
}

/* Component - Pink Square */
.component-shape {
  width: 18px;
  height: 18px;
  background-color: #f8bbd0;
  border: 2px solid #f06292;
  margin: 3px;
}

/* Company - Forest Green Diamond */
.company-shape {
  width: 15px;
  height: 15px;
  background-color: #228B22;
  border: 2px solid #1a6b1a;
  transform: rotate(45deg);
  margin: 2px 4px;
}

/* Tier 2 Supplier - Orange Diamond */
.tier2-supplier-shape {
  width: 15px;
  height: 15px;
  background-color: rgba(255, 165, 0, 0.7);
  border: 2px solid #cc8400;
  transform: rotate(45deg);
  margin: 2px 4px;
}

/* State Location - Large Blue Circle */
.state-location-shape {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background-color: #3498db;
  border: 2px solid #2980b9;
  margin: 1px;
}

/* City Location - Small Gray Circle */
.city-location-shape {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background-color: #95a5a6;
  border: 2px solid #7f8c8d;
  margin: 5px;
}

/* Bottleneck - Red Star */
.bottleneck-shape {
  width: 20px;
  height: 20px;
  background-color: #e74c3c;
  border: 2px solid #c0392b;
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  margin: 2px;
}

/* Material - Maroon Hexagon */
.material-shape {
  width: 16px;
  height: 16px;
  background-color: #800000;
  border: 2px solid #5c0000;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  margin: 2px;
}

/* Contract - Light Green Hexagon (fallback) */
.contract-shape {
  width: 16px;
  height: 16px;
  background-color: #90EE90;
  border: 2px solid #7CCD7C;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  margin: 2px;
}

/* Active Contract - Green Hexagon */
.contract-active-shape {
  width: 16px;
  height: 16px;
  background-color: #2ecc71;
  border: 2px solid #27ae60;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  margin: 2px;
}

/* Expired Contract - Orange Hexagon */
.contract-expired-shape {
  width: 16px;
  height: 16px;
  background-color: #e67e22;
  border: 2px solid #d35400;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  margin: 2px;
}

/* Agency - Navy Blue Inverted Triangle */
.agency-shape {
  width: 0;
  height: 0;
  border-left: 11px solid transparent;
  border-right: 11px solid transparent;
  border-top: 19px solid #34495e;
  margin-top: 3px;
}

/* Cluster node styling (via vis.js) */
.vis-network .vis-cluster-node {
  border-width: 3px !important;
  font-size: 16px !important;
}

/* Loading overlay for stabilization */
.graph-loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--loading-overlay-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.graph-loading-overlay.hidden {
  display: none;
}

.loading-spinner {
  border: 4px solid var(--border-color);
  border-top: 4px solid var(--accent-primary);
  border-radius: 50%;
  width: 50px;
  height: 50px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Graph info panel */
.graph-info-panel {
  position: absolute;
  top: 10px;
  left: 10px;
  background-color: var(--legend-bg);
  padding: 10px 15px;
  border-radius: 8px;
  box-shadow: 0 2px 10px var(--shadow-color);
  z-index: 100;
  font-size: 12px;
  max-width: 250px;
  color: var(--text-primary);
}

.graph-info-panel.hidden {
  display: none;
}

.graph-info-panel p {
  margin: 3px 0;
}

/* Selected node info box */
.selected-node-info {
  position: absolute;
  bottom: 10px;
  right: 10px;
  background-color: var(--accent-primary);
  color: white;
  padding: 15px;
  border-radius: 8px;
  box-shadow: 0 2px 10px var(--shadow-strong);
  z-index: 100;
  max-width: 300px;
  display: none;
}

.selected-node-info.visible {
  display: block;
}

.selected-node-info h4 {
  margin: 0 0 8px 0;
  font-size: 14px;
  font-weight: 600;
}

.selected-node-info p {
  margin: 4px 0;
  font-size: 12px;
}

/* Navigation buttons (vis.js built-in) */
.vis-navigation {
  position: absolute;
  bottom: 60px;
  right: 10px;
}

.vis-button {
  background-color: var(--legend-bg) !important;
  border: 1px solid var(--border-color) !important;
  box-shadow: 0 2px 5px var(--shadow-color) !important;
}

.vis-button:hover {
  background-color: var(--bg-tertiary) !important;
}

/* Cluster expand animation */
@keyframes clusterExpand {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.2);
    opacity: 0.7;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.vis-network .expanding-cluster {
  animation: clusterExpand 0.5s ease-out;
}

/* Edge label styling */
.vis-network .vis-label {
  background-color: var(--legend-bg);
  padding: 2px 4px;
  border-radius: 3px;
  font-size: 11px;
}

/* Highlighted node pulse effect */
@keyframes nodePulse {
  0%, 100% {
    box-shadow: 0 0 0 0 var(--accent-primary);
  }
  50% {
    box-shadow: 0 0 0 10px transparent;
  }
}

.vis-network .highlighted-node {
  animation: nodePulse 2s infinite;
}

/* ============================================
   HYBRID DIVIDER — draggable split between
   graph and map in hybrid view
   ============================================ */
.hybrid-divider {
  display: none;
  width: 0;
  height: 100%;
  vertical-align: top;
  cursor: col-resize;
  align-items: center;
  justify-content: center;
  background: #d0d0d0;
  pointer-events: none;
  touch-action: none;
  position: relative;
  z-index: 10;
}

[data-theme="dark"] .hybrid-divider {
  background: #2a2a2a;
}

.content-area.hybrid .hybrid-divider {
  display: block;
  width: 3px;
  flex-shrink: 0;
  pointer-events: auto;
  box-shadow: -1px 0 0 var(--border-color), 1px 0 0 var(--border-color);
}

.hybrid-divider:hover,
.hybrid-divider.dragging {
  background: #b0b0b0;
}

[data-theme="dark"] .hybrid-divider:hover,
[data-theme="dark"] .hybrid-divider.dragging {
  background: #444;
}

.hybrid-divider-grip {
  display: none;
}
