* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  padding: 20px;
}

.contenedor {
  max-width: 1400px;
  margin: 0 auto;
}

header {
  background: white;
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

header h1 {
  color: #333;
  margin-bottom: 15px;
  font-size: 28px;
}

.controles-principales {
  display: flex;
  gap: 15px;
  align-items: center;
  flex-wrap: wrap;
}

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 5px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.btn-ejecutar {
  background: #4CAF50;
  color: white;
}

.btn-ejecutar:hover {
  background: #45a049;
}

.btn-detener {
  background: #f44336;
  color: white;
}

.btn-detener:hover {
  background: #da190b;
}

.btn-reset {
  background: #ff9800;
  color: white;
}

.btn-reset:hover {
  background: #e68900;
}

.estado-plc {
  margin-left: auto;
}

.estado-plc span {
  padding: 10px 20px;
  border-radius: 5px;
  font-weight: bold;
  font-size: 16px;
}

.estado-ejecutar {
  background: #4CAF50;
  color: white;
}

.estado-detener {
  background: #f44336;
  color: white;
}

.panel-principal {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.panel {
  background: white;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.panel h2 {
  color: #333;
  margin-bottom: 15px;
  font-size: 20px;
  border-bottom: 2px solid #667eea;
  padding-bottom: 10px;
}

.grid-entradas,
.grid-salidas {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 15px;
}

.entrada-digital,
.salida-digital {
  background: #f5f5f5;
  border: 2px solid #ddd;
  border-radius: 8px;
  padding: 15px;
  text-align: center;
  transition: all 0.3s ease;
  cursor: pointer;
}

.entrada-digital:hover {
  background: #e8e8e8;
}

.entrada-digital label {
  display: block;
  font-weight: bold;
  color: #555;
  margin-bottom: 10px;
  font-size: 14px;
}

.entrada-digital .switch {
  position: relative;
  width: 60px;
  height: 30px;
  margin: 0 auto;
}

.entrada-digital .switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.entrada-digital .slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: 0.4s;
  border-radius: 30px;
}

.entrada-digital .slider:before {
  position: absolute;
  content: "";
  height: 22px;
  width: 22px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: 0.4s;
  border-radius: 50%;
}

.entrada-digital input:checked + .slider {
  background-color: #4CAF50;
}

.entrada-digital input:checked + .slider:before {
  transform: translateX(30px);
}

.salida-digital {
  cursor: default;
}

.salida-digital label {
  display: block;
  font-weight: bold;
  color: #555;
  margin-bottom: 10px;
  font-size: 14px;
}

.led {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  margin: 0 auto;
  background-color: #ccc;
  border: 3px solid #999;
  transition: all 0.3s ease;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.2);
}

.led.activo {
  background-color: #4CAF50;
  border-color: #45a049;
  box-shadow: 0 0 20px rgba(76, 175, 80, 0.6), inset 0 0 10px rgba(255, 255, 255, 0.3);
}

.led.inactivo {
  background-color: #f44336;
  border-color: #da190b;
}

.controles-editor {
  margin-bottom: 15px;
}

.controles-editor h2 {
  margin-bottom: 10px;
}

.paleta-herramientas {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 15px;
}

.btn-herramienta {
  padding: 8px 15px;
  border: 2px solid #667eea;
  border-radius: 5px;
  background: white;
  color: #667eea;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-family: 'Courier New', monospace;
}

.btn-herramienta:hover {
  background: #667eea;
  color: white;
}

.btn-herramienta.activo {
  background: #667eea;
  color: white;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
}

.editor-ladder-container {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 600px;
  border: 2px solid #ddd;
  border-radius: 5px;
  background: #f9f9f9;
}

.editor-ladder {
  position: relative;
  padding: 20px 30px;
  min-width: 900px;
  background: linear-gradient(to right, #f0f0f0 0%, #fff 2%, #fff 98%, #f0f0f0 100%);
}

.rung {
  position: relative;
  margin-bottom: 50px;
  padding: 20px 0;
  min-height: 80px;
  border-bottom: 2px solid #e0e0e0;
}

.rail-left,
.rail-right {
  position: absolute;
  width: 6px;
  background: #000;
  top: 0;
  bottom: 0;
  z-index: 1;
}

.rail-left {
  left: 0;
}

.rail-right {
  right: 0;
}

.celda-ladder {
  position: relative;
  display: inline-block;
  width: 100px;
  height: 60px;
  border: 2px dashed #999;
  margin: 0 2px;
  vertical-align: middle;
  cursor: pointer;
  transition: all 0.2s ease;
  background: #f9f9f9;
  box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.05);
}

.celda-ladder:hover {
  border-color: #667eea;
  border-style: solid;
  background: #e8f0ff;
  box-shadow: 0 0 10px rgba(102, 126, 234, 0.3);
  transform: scale(1.05);
}

.celda-ladder.ocupada {
  border: 2px solid #333;
  background: #fff;
  box-shadow: none;
}

.celda-ladder.ocupada:hover {
  transform: scale(1);
}

.indicador-celda {
  pointer-events: none;
}

.elemento-ladder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Courier New', monospace;
  font-size: 16px;
  font-weight: bold;
  position: relative;
}

.contacto-no {
  color: #2196F3;
}

.contacto-nc {
  color: #f44336;
}

.bobina {
  color: #4CAF50;
}

.elemento-ladder.energizado {
  color: #FF9800;
  font-weight: bold;
}

.elemento-ladder.energizado .contacto-no,
.elemento-ladder.energizado .contacto-nc {
  text-shadow: 0 0 5px rgba(255, 152, 0, 0.5);
}

.elemento-ladder.energizado .bobina {
  text-shadow: 0 0 5px rgba(255, 152, 0, 0.5);
}

.selector-entrada,
.selector-salida {
  position: absolute;
  bottom: 2px;
  left: 50%;
  transform: translateX(-50%);
  width: 80px;
  padding: 2px;
  font-size: 10px;
  border: 1px solid #ccc;
  border-radius: 3px;
  background: white;
  text-align: center;
}

.conexion-horizontal {
  display: inline-block;
  width: 20px;
  height: 4px;
  background: #333;
  vertical-align: middle;
  margin: 0 -2px;
}

.conexion-vertical {
  position: absolute;
  width: 4px;
  height: 20px;
  background: #333;
  left: 50%;
  transform: translateX(-50%);
}

.conexion-horizontal.energizado,
.conexion-vertical.energizado {
  background: #FF9800;
  box-shadow: 0 0 5px rgba(255, 152, 0, 0.5);
}

.info-programa {
  background: #f0f0f0;
  padding: 15px;
  border-radius: 5px;
  font-size: 13px;
}

.info-programa ul {
  margin-left: 20px;
  margin-top: 10px;
}

.info-programa li {
  margin-bottom: 8px;
}

.info-programa code {
  background: #e0e0e0;
  padding: 2px 6px;
  border-radius: 3px;
  font-family: 'Courier New', monospace;
}

.panel-log {
  width: 100%;
}

.log-contenido {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 15px;
  border-radius: 5px;
  height: 200px;
  overflow-y: auto;
  font-family: 'Courier New', monospace;
  font-size: 12px;
}

.log-entrada {
  color: #4ec9b0;
  margin-bottom: 5px;
}

.log-salida {
  color: #ce9178;
  margin-bottom: 5px;
}

.log-error {
  color: #f48771;
  margin-bottom: 5px;
}

.log-info {
  color: #9cdcfe;
  margin-bottom: 5px;
}

@media (max-width: 1200px) {
  .panel-principal {
    grid-template-columns: 1fr;
  }
}

/* Estilos para el editor SVG */
.editor-ladder-container {
  overflow: auto;
  max-height: 600px;
  border: 2px solid #ddd;
  border-radius: 5px;
  background: #f9f9f9;
  min-height: 400px;
}

#svgLadder {
  display: block;
  background: #ffffff;
  /* Cuadrícula oculta */
  min-width: 100%;
  min-height: 400px;
}

.celda-svg {
  fill: #ffffff;
  stroke: #999;
  stroke-width: 2;
  stroke-dasharray: 5,5;
  cursor: pointer;
  transition: all 0.2s ease;
  rx: 3;
  ry: 3;
}

.celda-svg:hover {
  fill: #e8f0ff;
  stroke: #667eea;
  stroke-width: 2.5;
  stroke-dasharray: none;
  filter: drop-shadow(0 2px 4px rgba(102, 126, 234, 0.3));
}

.celda-svg.ocupada {
  fill: #ffffff;
  stroke: #333;
  stroke-width: 2;
  stroke-dasharray: none;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));
}

.indicador-svg {
  fill: #999;
  font-size: 24px;
  font-weight: bold;
  opacity: 0.3;
  pointer-events: none;
}

.rail-svg {
  fill: #dc3545 !important;
  stroke: #dc3545 !important;
  stroke-width: 3 !important;
}

.conexion-svg {
  stroke: #000;
  stroke-width: 3;
  stroke-linecap: round;
  fill: none;
}

.conexion-svg.energizado {
  stroke: #FF9800;
  stroke-width: 4;
  filter: drop-shadow(0 0 5px rgba(255, 152, 0, 0.8));
  animation: pulso 1s ease-in-out infinite;
}

@keyframes pulso {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.elemento-energizado line {
  stroke: #4CAF50 !important;
  filter: drop-shadow(0 0 3px rgba(76, 175, 80, 0.8));
  animation: pulso-linea 1s ease-in-out infinite;
}

.elemento-energizado circle {
  fill: #4CAF50 !important;
  filter: drop-shadow(0 0 3px rgba(76, 175, 80, 0.8));
}

@keyframes pulso-linea {
  0%, 100% { stroke-width: 3; }
  50% { stroke-width: 4; }
}

.bobina-energizada {
  filter: drop-shadow(0 0 8px rgba(76, 175, 80, 1));
  animation: pulso-bobina 1s ease-in-out infinite;
}

@keyframes pulso-bobina {
  0%, 100% { 
    opacity: 1; 
    filter: drop-shadow(0 0 8px rgba(76, 175, 80, 1));
  }
  50% { 
    opacity: 0.9; 
    filter: drop-shadow(0 0 12px rgba(76, 175, 80, 1));
  }
}

.btn-herramienta {
  cursor: grab;
  transition: all 0.2s ease;
  user-select: none;
}

.btn-herramienta:active {
  cursor: grabbing;
  transform: scale(0.95);
}

.btn-herramienta[draggable="true"]:hover {
  background: #e0e0e0 !important;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.elemento-ladder-libre {
  transition: transform 0.1s ease;
}

.elemento-ladder-libre:hover {
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

.conexion-auto {
  stroke: #666;
  stroke-width: 2;
  stroke-dasharray: 5,5;
  opacity: 0.7;
}

.zona-colocacion {
  fill: rgba(200, 220, 255, 0.1);
  stroke: #b3d9ff;
  stroke-width: 1;
  stroke-dasharray: 2,2;
  pointer-events: none;
}

.zona-colocacion:hover {
  fill: rgba(200, 220, 255, 0.2);
  stroke: #6699ff;
}

.texto-elemento {
  font-family: 'Courier New', monospace;
  font-size: 16px;
  font-weight: bold;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
}

.contacto-no {
  fill: #2196F3;
}

.contacto-nc {
  fill: #f44336;
}

.bobina {
  fill: #4CAF50;
}

.elemento-energizado {
  filter: drop-shadow(0 0 5px rgba(255, 152, 0, 0.8));
}

.selector-svg {
  font-size: 10px;
  border: 1px solid #ccc;
  border-radius: 3px;
}
