/* ==========================================================================
   Editor CSS - SubstationTopologySim
   Estilos específicos del lienzo SVG, renderizado de componentes y controles.
   Completamente adaptado a los temas Noche y Día de Electricidad Aplicada.
   ========================================================================== */

.canvas-viewport {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

.canvas-viewport.mode-pan {
  cursor: grab;
}

.canvas-viewport.mode-pan:active {
  cursor: grabbing;
}

.canvas-viewport.mode-wiring {
  cursor: crosshair;
}

/* Rejilla de fondo SVG */
.grid-pattern-minor line {
  stroke: var(--grid-line-minor);
  stroke-width: 1;
}

.grid-pattern-major line {
  stroke: var(--grid-line-major);
  stroke-width: 1.25;
}

/* Agrupaciones de componentes */
.substation-component {
  cursor: pointer;
  transition: filter 0.15s ease;
}

.substation-component:hover {
  filter: drop-shadow(0 0 6px var(--color-accent-focus));
}

.substation-component.energized {
  filter: drop-shadow(0 0 2px var(--color-state-closed));
}

.substation-component.dragging {
  cursor: grabbing;
  opacity: 0.9;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.5));
}

.substation-component.selected .component-selection-bbox {
  display: block;
}

.component-selection-bbox {
  display: none;
  fill: var(--canvas-selection-box);
  stroke: var(--canvas-selection-border);
  stroke-width: 1.5;
  stroke-dasharray: 4 2;
  pointer-events: none;
}

/* Terminales / Pines de conexión */
.component-terminal {
  fill: var(--color-info);
  stroke: var(--color-text-inverse);
  stroke-width: 1.5;
  cursor: crosshair;
  transition: r 0.15s ease, fill 0.15s ease;
}

.component-terminal:hover {
  r: 6;
  fill: var(--color-accent);
  filter: drop-shadow(0 0 6px var(--color-accent));
}

.component-terminal.connected {
  fill: var(--color-state-open);
}

.component-terminal.energized {
  fill: var(--color-state-closed);
}

/* Ramas Eléctricas / Conexiones */
.electrical-connection {
  cursor: pointer;
}

.electrical-connection .connection-line {
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke 0.25s ease, stroke-width 0.15s ease;
}

.electrical-connection.energized .connection-line {
  stroke: var(--color-state-closed);
  filter: drop-shadow(0 0 4px var(--color-state-closed));
}

.electrical-connection.deenergized .connection-line {
  stroke: var(--color-state-deenergized);
  stroke-dasharray: 4 3;
}

.electrical-connection:hover .connection-line {
  stroke-width: 3.5;
  filter: drop-shadow(0 0 6px var(--color-accent));
}

.electrical-connection.selected .connection-line {
  stroke: var(--color-border-active) !important;
  stroke-width: 3.5;
  stroke-dasharray: 5 2;
}

.connection-junction-dot {
  fill: var(--color-info);
  stroke: var(--color-text-inverse);
  stroke-width: 1;
  transition: fill 0.25s ease;
}

.electrical-connection.energized .connection-junction-dot {
  fill: var(--color-state-closed);
}

.wiring-preview {
  stroke: var(--color-accent);
  stroke-width: 2;
  stroke-dasharray: 5 4;
  pointer-events: none;
}

/* Símbolos eléctricos */
.symbol-busbar-body {
  stroke-linecap: round;
  transition: stroke 0.2s ease;
}

.symbol-body {
  stroke-linejoin: round;
  stroke-linecap: round;
}

.symbol-breaker-box {
  stroke: var(--color-border-medium);
  stroke-width: 2;
  fill: var(--color-bg-surface-elevated);
}

.symbol-breaker-cross {
  stroke: var(--color-state-closed);
  stroke-width: 2.5;
  stroke-linecap: round;
}

.symbol-breaker-cross.state-open {
  display: none;
}

.symbol-breaker-open-indicator {
  stroke: var(--color-state-open);
  stroke-width: 2;
  stroke-linecap: round;
}

.symbol-disconnector-blade {
  stroke-width: 2.5;
  stroke-linecap: round;
  transition: transform 0.25s ease-out;
  transform-origin: center;
}

.symbol-transformer-winding {
  stroke-width: 2.2;
  fill: none;
}

/* Etiquetas técnicas SVG */
.component-label {
  font-family: var(--font-family-mono);
  font-size: 11px;
  font-weight: 600;
  fill: var(--color-text-primary);
  text-anchor: middle;
  pointer-events: none;
  user-select: none;
  paint-order: stroke fill;
  stroke: var(--color-bg-canvas);
  stroke-width: 3.5px;
  stroke-linejoin: round;
}

.component-sublabel {
  font-family: var(--font-family-mono);
  font-size: 9px;
  fill: var(--color-text-secondary);
  text-anchor: middle;
  pointer-events: none;
  user-select: none;
  paint-order: stroke fill;
  stroke: var(--color-bg-canvas);
  stroke-width: 3px;
  stroke-linejoin: round;
}

.state-badge-text {
  font-family: var(--font-family-mono);
  font-size: 9px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: central;
}

/* Barra superior de navegación rápida del lienzo */
.canvas-top-navbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: var(--top-nav-height);
  background-color: var(--color-bg-surface);
  border-bottom: 1px solid var(--color-border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-md);
  z-index: 14;
  backdrop-filter: blur(8px);
}

.canvas-nav-group {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.canvas-nav-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.nav-select {
  background-color: var(--color-bg-surface-elevated);
  border: 1px solid var(--color-border-medium);
  border-radius: var(--radius-sm);
  color: var(--color-text-primary);
  font-size: 11.5px;
  font-family: var(--font-family-sans);
  font-weight: 500;
  padding: 4px 8px;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.nav-select:focus {
  border-color: var(--color-accent);
}

.canvas-nav-actions {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

/* Barras de navegación / Scrollbars del lienzo interactivo */
.canvas-nav-bar {
  position: absolute;
  z-index: 13;
  display: flex;
  background: transparent;
  user-select: none;
}

.canvas-nav-bar-h {
  bottom: 0;
  left: 0;
  right: 14px;
  height: 12px;
}

.canvas-nav-bar-v {
  top: var(--top-nav-height);
  right: 0;
  bottom: 12px;
  width: 12px;
}

.canvas-nav-track {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--scrollbar-track);
  border-radius: 6px;
  cursor: pointer;
}

.canvas-nav-thumb {
  position: absolute;
  background: var(--scrollbar-thumb);
  border-radius: 6px;
  cursor: grab;
  transition: background 0.15s ease, transform 0.1s ease;
  min-width: 24px;
  min-height: 24px;
}

.canvas-nav-thumb:hover,
.canvas-nav-thumb.dragging {
  background: var(--scrollbar-thumb-hover);
}

.canvas-nav-thumb:active,
.canvas-nav-thumb.dragging {
  cursor: grabbing;
}

/* Barra flotante de controles del lienzo */
.canvas-floating-controls {
  position: absolute;
  bottom: 22px;
  right: 22px;
  display: flex;
  align-items: center;
  background-color: var(--color-bg-surface);
  backdrop-filter: blur(8px);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  padding: 4px;
  gap: 4px;
  box-shadow: var(--shadow-md);
  z-index: 15;
}

.canvas-floating-info {
  position: absolute;
  top: calc(var(--top-nav-height) + var(--space-sm));
  left: var(--space-md);
  background-color: var(--color-bg-surface);
  backdrop-filter: blur(6px);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  padding: 4px 10px;
  font-family: var(--font-family-mono);
  font-size: 11px;
  color: var(--color-text-secondary);
  pointer-events: none;
  z-index: 15;
}

/* Overlay de arrastre desde paleta */
.drag-ghost {
  position: fixed;
  pointer-events: none;
  opacity: 0.8;
  z-index: 1000;
  transform: translate(-50%, -50%);
}
