/* ===================================
   MAP VERSION 2.0 - MODERN STYLES
   =================================== */

/* Contenedor principal del mapa */
#map-container-v2 {
  width: 100%;
  height: 600px;
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  background: #f8f9fa;
}

/* Panel de control del mapa */
.map-control-panel {
  position: absolute;
  top: 15px;
  left: 15px;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(10px);
  border-radius: 12px;
  padding: 15px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  max-width: 300px;
  transition: all 0.3s ease;
}

.map-control-panel.collapsed {
  padding: 10px;
  max-width: 50px;
}

.map-control-panel h6 {
  margin: 0 0 12px 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: #2c3e50;
  display: flex;
  align-items: center;
  gap: 8px;
}

.map-control-toggle {
  position: absolute;
  top: 10px;
  right: 10px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 1.2rem;
  color: #6c757d;
  padding: 5px;
  transition: all 0.2s;
}

.map-control-toggle:hover {
  color: #007bff;
  transform: scale(1.1);
}

/* Métricas en el panel */
.map-metrics {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.metric-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border-radius: 8px;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.metric-item:hover {
  transform: translateX(5px);
  box-shadow: 0 2px 8px rgba(0, 123, 255, 0.15);
}

.metric-item .metric-label {
  color: #6c757d;
  font-weight: 500;
}

.metric-item .metric-value {
  font-weight: 700;
  color: #2c3e50;
  font-size: 1rem;
}

.metric-item.alarm-active .metric-value {
  color: #dc3545;
}

.metric-item.alarm-pending .metric-value {
  color: #ffc107;
}

.metric-item.no-alarm .metric-value {
  color: #28a745;
}

/* Leyenda del mapa */
.map-legend {
  position: absolute;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(10px);
  border-radius: 12px;
  padding: 15px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  min-width: 200px;
}

.map-legend h6 {
  margin: 0 0 12px 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: #2c3e50;
  border-bottom: 2px solid #007bff;
  padding-bottom: 8px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  font-size: 0.85rem;
  color: #495057;
  transition: all 0.2s;
}

.legend-item:hover {
  color: #007bff;
  transform: translateX(5px);
}

.legend-icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.legend-icon.alarm-active {
  background: #dc3545;
  color: white;
  box-shadow: 0 0 8px rgba(220, 53, 69, 0.4);
  animation: pulse-legend 2s infinite;
}

.legend-icon.alarm-pending {
  background: #ffc107;
  color: white;
  box-shadow: 0 0 6px rgba(255, 193, 7, 0.4);
}

.legend-icon.no-alarm {
  background: #007bff;
  color: white;
  box-shadow: 0 0 4px rgba(0, 123, 255, 0.3);
}

.legend-icon.concentrador {
  background: #6f42c1;
  color: white;
  box-shadow: 0 0 6px rgba(111, 66, 193, 0.4);
}

@keyframes pulse-legend {
  0%, 100% { 
    transform: scale(1);
    box-shadow: 0 0 8px rgba(220, 53, 69, 0.4);
  }
  50% { 
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(220, 53, 69, 0.7);
  }
}

/* Marcadores personalizados mejorados */
.custom-marker {
  background: transparent;
  border: none;
}

.custom-marker-inner {
  position: relative;
  width: 40px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.custom-marker-inner:hover {
  transform: scale(1.15) translateY(-5px);
}

.custom-marker-icon {
  position: absolute;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  border: 3px solid white;
  transition: all 0.3s ease;
}

.custom-marker-icon.alarm-active {
  background: linear-gradient(135deg, #2c2c2c 0%, #1a1a1a 100%);
  color: white;
  animation: pulse-marker 2s infinite;
  border: 2px solid #ff0000;
}

.custom-marker-icon.alarm-pending {
  background: linear-gradient(135deg, #4a4a4a 0%, #3a3a3a 100%);
  color: white;
  border: 2px solid #ffc107;
}

.custom-marker-icon.no-alarm {
  background: linear-gradient(135deg, #6a6a6a 0%, #5a5a5a 100%);
  color: white;
  border: 2px solid #888888;
}

.custom-marker-icon.concentrador {
  background: linear-gradient(135deg, #1a1a1a 0%, #000000 100%);
  color: white;
  width: 45px;
  height: 45px;
  font-size: 1.5rem;
  border: 3px solid #333333;
}

/* Variantes por salud del concentrador (anillo coloreado).
   Se usan en el mapa global y en el dashboard demo para indicar a
   simple vista el estado: online (verde) / inactivo (amarillo) / offline (rojo).
*/
.custom-marker-icon.concentrador.status-online {
  border-color: #16a34a;
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.22), 0 4px 12px rgba(0, 0, 0, 0.35);
}

.custom-marker-icon.concentrador.status-inactivo {
  border-color: #f59e0b;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.22), 0 4px 12px rgba(0, 0, 0, 0.35);
}

.custom-marker-icon.concentrador.status-offline {
  border-color: #dc2626;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.28), 0 4px 12px rgba(0, 0, 0, 0.35);
  animation: pulse-marker 2.5s infinite;
}

/* Variante compacta para el mapa global (más marcadores en pantalla). */
.custom-marker-icon.concentrador.concentrador-sm {
  width: 30px;
  height: 30px;
  font-size: 0.95rem;
  border-width: 2px;
}

/* Marcador compacto para transmisores del dashboard (mismo DNA pero más chico
   y con colores según alarma). */
.custom-marker-icon.tx {
  width: 26px;
  height: 26px;
  font-size: 0.78rem;
  color: #fff;
  border: 2px solid #fff;
  background: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2), 0 2px 6px rgba(0, 0, 0, 0.25);
}
.custom-marker-icon.tx.tx-none {
  background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.22), 0 2px 6px rgba(0, 0, 0, 0.25);
}
.custom-marker-icon.tx.tx-ok {
  background: linear-gradient(135deg, #22c55e 0%, #15803d 100%);
  box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.22), 0 2px 6px rgba(0, 0, 0, 0.25);
}
.custom-marker-icon.tx.tx-alarm {
  background: linear-gradient(135deg, #ef4444 0%, #b91c1c 100%);
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.3), 0 2px 6px rgba(0, 0, 0, 0.3);
  animation: pulse-marker 2.5s infinite;
}

@keyframes pulse-marker {
  0%, 100% { 
    transform: scale(1);
    box-shadow: 0 4px 12px rgba(220, 53, 69, 0.4);
  }
  50% { 
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(220, 53, 69, 0.7);
  }
}

/* Tooltip de distancia mejorado */
.distance-tooltip {
  position: absolute;
  background: rgba(0, 0, 0, 0.85);
  color: white;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  pointer-events: none;
  z-index: 10000;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  transform: translate(-50%, -120%);
}

.distance-tooltip::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid rgba(0, 0, 0, 0.85);
}

.distance-tooltip .distance-icon {
  margin-right: 6px;
}

/* Popup personalizado mejorado */
.leaflet-marker-icon,
.leaflet-marker-pane {
  z-index: 600 !important;
}

/* CONTENEDOR REAL DEL POPUP */
.leaflet-popup-content-wrapper {
  overflow: visible;
  min-width: 350px;
  max-width: 450px;
  padding: 0;
}

.popup-header {
  background: linear-gradient(135deg, #4a4a4a 0%, #3a3a3a 100%);
  color: white;
  padding: 15px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.popup-header.alarm-active {
  background: linear-gradient(135deg, #2c2c2c 0%, #1a1a1a 100%);
  border-left: 4px solid #ff0000;
  animation: pulse-header 2s infinite;
}

.popup-header.alarm-pending {
  background: linear-gradient(135deg, #4a4a4a 0%, #3a3a3a 100%);
  border-left: 4px solid #ffc107;
}

.popup-header.no-alarm {
  background: linear-gradient(135deg, #6a6a6a 0%, #5a5a5a 100%);
  border-left: 4px solid #888888;
}

.popup-header.concentrador {
  background: linear-gradient(135deg, #1a1a1a 0%, #000000 100%);
  border-left: 4px solid #333333;
}

.popup-header-icon {
  font-size: 1.5rem;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 8px;
}

.popup-header-content {
  flex: 1;
}

.popup-header-title {
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
}

.popup-header-mac {
  font-size: 0.75rem;
  opacity: 0.8;
  font-family: 'Courier New', monospace;
}

@keyframes pulse-header {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.85; }
}

.popup-body {
  padding: 15px;
  background: white;
  max-height: 500px;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: auto;
}

/* Scroll personalizado para popup */
.popup-body::-webkit-scrollbar {
  width: 6px;
}

.popup-body::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

.popup-body::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 3px;
}

.popup-body::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* Contenedor scrolleable para sensores */
.tx-sensors-container {
  max-height: 300px;
  overflow-y: auto;
  overflow-x: hidden;
  margin-top: 10px;
}

.tx-sensors-container::-webkit-scrollbar {
  width: 6px;
}

.tx-sensors-container::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

.tx-sensors-container::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 3px;
}

.tx-sensors-container::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* Información extra del transmisor (batería, señal, distancia) */
.tx-extra-info {
  display: flex;
  gap: 8px;
  margin-bottom: 15px;
  flex-wrap: wrap;
}

.info-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  flex: 1;
  min-width: 90px;
  justify-content: center;
}

.info-badge i {
  font-size: 0.9rem;
}

.info-badge-success {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.info-badge-warning {
  background: #fff3cd;
  color: #856404;
  border: 1px solid #ffeaa7;
}

.info-badge-danger {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.info-badge-neutral {
  background: #e9ecef;
  color: #495057;
  border: 1px solid #dee2e6;
}

/* Grid de información */
.popup-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 15px;
  width: 100%;
  box-sizing: border-box;
}

.popup-info-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 10px;
  background: #f8f9fa;
  border-radius: 8px;
  border-left: 3px solid #dee2e6;
  min-width: 0;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.popup-info-item i {
  font-size: 1.2rem;
  color: #6c757d;
  margin-top: 2px;
}

.popup-info-item .info-label {
  font-size: 0.7rem;
  color: #6c757d;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.popup-info-item .info-value {
  font-size: 0.85rem;
  color: #2c3e50;
  font-weight: 600;
}

/* Secciones de sensores */
.tx-sensors-section {
  margin-top: 12px;
}

.tx-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: #e9ecef;
  border-radius: 6px 6px 0 0;
  font-size: 0.85rem;
  font-weight: 700;
  color: #495057;
  border-left: 3px solid #6c757d;
}

.tx-section-header.active {
  background: #d4edda;
  color: #155724;
  border-left-color: #28a745;
}

.tx-section-header.inactive {
  background: #f8d7da;
  color: #721c24;
  border-left-color: #dc3545;
}

.tx-section-header i {
  font-size: 1rem;
}

/* Items de sensores individuales */
.tx-sensor-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-bottom: 1px solid #e9ecef;
  background: white;
  transition: all 0.2s;
}

.tx-sensor-item:last-child {
  border-bottom: none;
  border-radius: 0 0 6px 6px;
}

.tx-sensor-item:hover {
  background: #f8f9fa;
}

.tx-sensor-item.active {
  border-left: 3px solid #28a745;
}

.tx-sensor-item.inactive {
  border-left: 3px solid #dc3545;
  opacity: 0.7;
}

.tx-sensor-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8f9fa;
  border-radius: 6px;
  font-size: 1rem;
  color: #495057;
  flex-shrink: 0;
}

.tx-sensor-item.active .tx-sensor-icon {
  background: #d4edda;
  color: #28a745;
}

.tx-sensor-item.inactive .tx-sensor-icon {
  background: #f8d7da;
  color: #dc3545;
}

.tx-sensor-info {
  flex: 1;
}

.tx-sensor-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: #2c3e50;
  margin-bottom: 2px;
}

.tx-sensor-time {
  font-size: 0.7rem;
  color: #6c757d;
  font-family: 'Courier New', monospace;
}

.tx-sensor-value {
  font-size: 0.95rem;
  font-weight: 700;
  color: #2c3e50;
  text-align: right;
}

.tx-sensor-unit {
  font-size: 0.75rem;
  font-weight: 500;
  color: #6c757d;
  margin-left: 3px;
}

.popup-info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #e9ecef;
  font-size: 0.85rem;
}

.popup-info-row:last-child {
  border-bottom: none;
}

.popup-info-label {
  color: #6c757d;
  font-weight: 500;
}

.popup-info-value {
  color: #2c3e50;
  font-weight: 600;
}

.popup-info-item .popup-info-label {
  font-size: 0.75rem;
  color: #6c757d;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
}

.popup-info-item .popup-info-value {
  font-size: 0.9rem;
  color: #2c3e50;
  font-weight: 600;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}

/* Sección de título para canales internos */
.popup-section-title {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 0;
  font-size: 0.85rem;
  font-weight: 700;
  color: #495057;
  margin-bottom: 8px;
}

.popup-section-title i {
  color: #6c757d;
}

/* Lista de canales internos */
.popup-channels-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 250px;
  overflow-y: auto;
  overflow-x: hidden;
  width: 100%;
}

.popup-channel-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: #f8f9fa;
  border-radius: 6px;
  border-left: 3px solid #dee2e6;
  transition: all 0.2s;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}

.popup-channel-item:hover {
  background: #e9ecef;
  border-left-color: #6c757d;
}

.popup-channel-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: #2c3e50;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-right: 8px;
}

.popup-channel-value {
  font-size: 0.9rem;
  font-weight: 700;
  color: #2c3e50;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  white-space: nowrap;
}

.popup-sensors {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 2px solid #e9ecef;
}

.popup-sensors h6 {
  margin: 0 0 10px 0;
  font-size: 0.9rem;
  color: #495057;
  font-weight: 600;
}

.sensor-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: #f8f9fa;
  border-radius: 6px;
  margin-bottom: 6px;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.sensor-item:hover {
  background: #e9ecef;
  transform: translateX(3px);
}

.sensor-item .sensor-name {
  color: #495057;
  font-weight: 500;
}

.sensor-item .sensor-value {
  color: #007bff;
  font-weight: 700;
}

.popup-footer {
  padding: 12px 15px;
  background: #f8f9fa;
  border-top: 1px solid #e9ecef;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.popup-btn {
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  flex-shrink: 0;
}

.popup-btn-primary {
  background: #007bff;
  color: white;
}

.popup-btn-primary:hover {
  background: #0056b3;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 123, 255, 0.3);
}

.popup-btn-secondary {
  background: #6c757d;
  color: white;
}

.popup-btn-secondary:hover {
  background: #5a6268;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(108, 117, 125, 0.3);
}

/* Líneas de conexión mejoradas */
.connection-line {
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 8, 4;
  opacity: 0.7;
  transition: all 0.3s ease;
}

.connection-line:hover {
  stroke-width: 5;
  opacity: 1;
}

.connection-line.alarm-active {
  stroke: #dc3545;
  animation: line-pulse 2s infinite;
}

.connection-line.alarm-pending {
  stroke: #ffc107;
}

.connection-line.no-alarm {
  stroke: #007bff;
}

@keyframes line-pulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

/* Modal de configuración inicial */
.map-config-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(5px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.map-config-content {
  background: white;
  border-radius: 16px;
  padding: 30px;
  max-width: 500px;
  width: 90%;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { 
    opacity: 0;
    transform: translateY(50px);
  }
  to { 
    opacity: 1;
    transform: translateY(0);
  }
}

.map-config-header {
  text-align: center;
  margin-bottom: 25px;
}

.map-config-icon {
  font-size: 4rem;
  margin-bottom: 15px;
}

.map-config-header h3 {
  margin: 0 0 10px 0;
  color: #2c3e50;
  font-size: 1.5rem;
}

.map-config-header p {
  margin: 0;
  color: #6c757d;
  font-size: 0.95rem;
}

.map-config-body {
  margin: 20px 0;
}

.map-config-alert {
  background: #fff3cd;
  border: 2px solid #ffc107;
  border-radius: 10px;
  padding: 15px;
  margin-bottom: 20px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.map-config-alert-icon {
  font-size: 1.5rem;
  color: #ffc107;
  flex-shrink: 0;
}

.map-config-alert-text {
  color: #856404;
  font-size: 0.9rem;
  line-height: 1.4;
}

.map-config-footer {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 25px;
}

.map-config-btn {
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
}

.map-config-btn-primary {
  background: #007bff;
  color: white;
}

.map-config-btn-primary:hover {
  background: #0056b3;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
}

.map-config-btn-secondary {
  background: #6c757d;
  color: white;
}

.map-config-btn-secondary:hover {
  background: #5a6268;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(108, 117, 125, 0.3);
}

/* Modo pantalla completa mejorado */
.map-fullscreen-mode {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  z-index: 9999;
  background: white;
}

.map-fullscreen-toolbar {
  position: absolute;
  top: 15px;
  right: 15px;
  z-index: 10000;
  display: flex;
  gap: 10px;
}

.map-fullscreen-btn {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border: none;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  gap: 8px;
}

.map-fullscreen-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.map-fullscreen-btn-primary {
  background: #007bff;
  color: white;
}

.map-fullscreen-btn-primary:hover {
  background: #0056b3;
}

/* Filtros de mapa */
.map-filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.map-filter-btn {
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  border: 2px solid #dee2e6;
  background: white;
  color: #6c757d;
  cursor: pointer;
  transition: all 0.2s;
}

.map-filter-btn.active {
  background: #007bff;
  color: white;
  border-color: #007bff;
}

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

/* Responsive */
@media (max-width: 768px) {
  #map-container-v2 {
    height: 400px;
  }
  
  .map-control-panel {
    max-width: 250px;
    font-size: 0.85rem;
  }
  
  .map-legend {
    bottom: 10px;
    right: 10px;
    min-width: 150px;
    font-size: 0.8rem;
  }
  
  .popup-header {
    font-size: 0.9rem;
    padding: 12px;
  }
  
  .popup-body {
    padding: 12px;
  }
}

/* Loading state */
.map-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10000;
  text-align: center;
}

.map-loading-spinner {
  width: 60px;
  height: 60px;
  border: 6px solid #f3f3f3;
  border-top: 6px solid #007bff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.map-loading-text {
  margin-top: 15px;
  color: #6c757d;
  font-weight: 500;
}

/* Map guard - previene interacciones hasta que el usuario haga click */
.map-inactive {
  pointer-events: none !important;
  user-select: none !important;
}

.map-inactive * {
  pointer-events: none !important;
}

/* Asegurar que el mapa esté activo por defecto */
#map-container:not(.map-inactive) {
  pointer-events: auto !important;
}

#map-container:not(.map-inactive) .leaflet-container {
  pointer-events: auto !important;
}

#map-container:not(.map-inactive) .leaflet-pane {
  pointer-events: auto !important;
}

#map-container:not(.map-inactive) .leaflet-control-container {
  pointer-events: auto !important;
}

.map-guard {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(248, 249, 250, 0.95);
  backdrop-filter: blur(2px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
}

.map-guard.hidden {
  display: none;
}

.map-activation-message {
  text-align: center;
  padding: 2rem;
}

.map-activation-icon {
  color: var(--blynk-text-light, #6c757d);
  margin-bottom: 1rem;
}

/* Asegurar que el contenedor del mapa no capture eventos cuando está inactivo */
#map-container.map-inactive {
  pointer-events: none !important;
}

#map-container.map-inactive .leaflet-container {
  pointer-events: none !important;
}

#map-container.map-inactive .leaflet-pane {
  pointer-events: none !important;
}

#map-container.map-inactive .leaflet-control-container {
  pointer-events: none !important;
}
/* ================================================= */
/* PANEL DE CONTROL IOT - ESTILO MODERNO             */
/* ================================================= */

.map-iot-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: auto; /* Asegura que los clics funcionen */
}

/* Grupos de botones con efecto de cristal */
.iot-control-group {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 12px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.4);
  transition: all 0.3s ease;
}

/* Botón individual */
.iot-btn {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  border: none;
  background: transparent;
  color: #444;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  outline: none !important;
}

/* Efecto al pasar el mouse */
.iot-btn:hover {
  background-color: #f0f4f8;
  color: #007bff;
  transform: translateY(-2px);
}

/* Estado Activo (Cuando el filtro está encendido) */
.iot-btn.active {
  background-color: #007bff;
  color: white !important;
  box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
}

/* Botón de Alarmas (Rojo cuando está activo) */
.btn-status-red:hover {
  color: #dc3545;
}

.btn-status-red.active {
  background-color: #dc3545 !important;
  color: white !important;
  box-shadow: 0 4px 12px rgba(220, 53, 69, 0.3);
}

/* Botón de Salud de Red (Verde/Azul al activar) */
#btn-network-health.active {
  background-color: #28a745 !important;
}

/* Ajuste para dispositivos móviles */
@media (max-width: 768px) {
  .iot-control-group {
      padding: 4px;
  }
  .iot-btn {
      width: 44px; /* Un poco más grande para dedos */
      height: 44px;
  }
}

/* Leaflet: controles más limpios (mapa v2, modal, incrustado) */
.leaflet-bar {
  border: none;
  border-radius: 10px;
  box-shadow: 0 2px 14px rgba(15, 23, 42, 0.12);
  overflow: hidden;
}

.leaflet-bar a {
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.leaflet-bar a:last-child {
  border-bottom: none;
}

.leaflet-control-layers {
  border: none;
  border-radius: 10px;
  box-shadow: 0 2px 14px rgba(15, 23, 42, 0.12);
}

.leaflet-control-layers-expanded {
  padding: 10px 12px;
  border-radius: 12px;
}