/* Reset and Base Styles */
body {
    margin: 0;
    padding: 0;
}

#map {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 100%;
}

/* Popup Styles */
.mapboxgl-popup-content {
    padding: 15px;
    max-width: 300px;
}

.monitor-readings {
    margin-top: 15px;
    border-top: 1px solid #eee;
    padding-top: 15px;
}

.reading {
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.reading.ias-reading {
    margin: 15px 0;
}

.reading-label {
    color: #666;
    font-size: 14px;
}

.reading-label.ias-label {
    font-size: 1.5em;
    color: #000000;
    font-weight: bold;
}

.reading-value {
    font-weight: bold;
    color: #000000;
    display: flex;
    align-items: center;
}

.ias-reading .reading-value {
    font-size: 1.5em;
}

.loading { 
    color: #6b7280; 
    font-style: italic; 
}

.status-container {
    margin: 8px 0;
}

.status-text {
    font-size: 14px;
    color: #000000;
    margin: 4px 0;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    text-align: left;
    font-weight: bold;
}

.indicator {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    margin-right: 12px;
    display: inline-block;
    border: 1.5px solid #999;
}

.marker-pin {
    cursor: pointer;
    width: 37.5px;
    height: 37.5px;
}

.contact-links {
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.whatsapp-icon {
    width: 24px;
    height: 24px;
}

/* Legend Styles */
.legend {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(255, 255, 255, 0.75);
    padding: 10px;
    border-radius: 12px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
    font-size: 11px;
    z-index: 1;
    transition: all 0.3s ease;
    min-width: 150px;
}

.legend-content {
    max-height: 500px;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.legend.collapsed {
    min-width: auto;
    background: none;
    box-shadow: none;
    padding: 0;
}

.legend.collapsed .legend-content {
    max-height: 0;
}

.legend-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.legend-toggle {
    border: none;
    background: rgba(255, 255, 255, 0.75);
    cursor: pointer;
    padding: 0;
    font-size: 16px;
    font-weight: bold;
    color: #000000;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.legend.collapsed .legend-toggle {
    border: 1px solid #ccc;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.75);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.legend-title {
    font-weight: bold;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.legend.collapsed .legend-title {
    opacity: 0;
    visibility: hidden;
    position: absolute;
}

.legend-item {
    display: flex;
    align-items: center;
    margin: 4px 0;
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-right: 8px;
    border: 1px solid rgba(0, 0, 0, 0.2);
}

/* NUEVO: Estilos para iconos de leyenda */
.legend-icon {
    width: 12px;
    height: 12px;
    margin-right: 8px;
    border: 1px solid rgba(0, 0, 0, 0.2);
}

.legend-square {
    border-radius: 2px; /* Ligeramente redondeado para consistencia */
}

.legend-circle {
    border-radius: 50%;
}

/* NUEVO: Divisor entre secciones de leyenda */
.legend-divider {
    height: 8px; /* Espacio vertical */
    margin: 4px 0; /* Margen adicional arriba y abajo */
}

.legend-branding {
    margin-top: 5px;
    padding-top: 4px;
    border-top: 0px solid rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 4px;
}

.brand-text {
    font-family: 'DIN Pro', Arial, sans-serif;
    font-weight: '';
    color: #888888;
    font-size: 11px;
    text-decoration: none;
}

.copyright {
    color: #888888;
    font-size: 11px;
}

/* Chart Panel Styles - UPDATED AND IMPROVED */
.chart-panel {
    position: fixed;
    background-color: rgba(255, 255, 255, 0.98);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    padding: 16px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    border: 2px solid #4264fb; /* Borde azul dinámico (se actualiza con JS) */
}

/* Chart Panel Header - NO BORDER */
.chart-panel-header {
    display: flex;
    flex-direction: column;
    position: relative;
    padding-bottom: 0;
    margin-bottom: 16px;
}

/* Device Info Container - EXTENDED TO FULL WIDTH */
#deviceInfoContainer {
    background: rgba(255, 255, 255, 0.95);
    padding: 12px 16px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    font-size: 12px;
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 12px;
    position: relative;
}

/* Close Button - TOP RIGHT CORNER */
.chart-panel-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.1);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: #666;
    transition: all 0.2s ease;
    z-index: 2;
}

.chart-panel-close:hover {
    background: rgba(0, 0, 0, 0.2);
    transform: scale(1.1);
}

/* Device and Sensor Titles */
#currentDeviceTitle {
    font-family: 'DIN Pro', Arial, sans-serif;
    font-weight: bold;
    color: #333;
    margin-bottom: 6px;
    font-size: 16px;
    padding-right: 35px; /* Space for close button */
}

#currentSensorTitle {
    font-family: 'DIN Pro', Arial, sans-serif;
    color: #666;
    margin-bottom: 12px;
    font-size: 13px;
    padding-right: 35px; /* Space for close button */
}

/* Controls Container - ALL DROPDOWNS IN ONE ROW */
.controls-container {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.controls-container label {
    font-family: 'DIN Pro', Arial, sans-serif;
    color: #666;
    font-size: 11px;
    white-space: nowrap;
    margin-right: 4px;
}

.controls-container select {
    font-family: 'DIN Pro', Arial, sans-serif;
    font-size: 11px;
    padding: 4px 6px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: white;
    min-width: 100px;
    flex: 1;
}

/* Título principal OCULTO (ahora está en la caja de dispositivo) */
.chart-panel-title {
    display: none;
}

/* Desktop styles */
@media (min-width: 768px) {
    .chart-panel {
        bottom: 20px;
        right: 20px;
        width: 600px;
        height: 400px;
        border-radius: 12px;
    }
    
    .chart-panel-header {
        flex-direction: column;
        height: auto;
    }
    
    .select-container {
        display: none; /* Hide old select container */
    }
    
    .controls-container {
        flex-wrap: nowrap;
    }
    
    .controls-container select {
        min-width: 120px;
    }
}

/* Mobile styles */
@media (max-width: 767px) {
    .chart-panel {
        bottom: 0;
        left: 0;
        right: 0;
        width: 95%;
        height: 40vh;
        border-radius: 12px 12px 0 0;
    }
    
    .chart-panel-header {
        flex-direction: column;
        height: auto;
        gap: 0;
        padding-bottom: 0;
    }
    
    .select-container {
        display: none; /* Hide old select container */
    }
    
    .controls-container {
        flex-wrap: wrap;
    }
    
    .controls-container select {
        min-width: 80px;
        font-size: 10px;
    }
    
    #currentDeviceTitle {
        font-size: 14px;
    }
    
    #currentSensorTitle {
        font-size: 12px;
    }
    
    .panel-select {
        flex: 1;
        min-width: 0;
        font-size: 12px;
    }
}

.chart-container {
    flex: 1;
    width: 100%;
    position: relative;
    min-height: 0;
}

#iasChart {
    width: 100%;
    height: 100%;
}

/* Plotly Controls - MOVED TO BOTTOM */
.chart-container .js-plotly-plot .plotly .modebar {
    position: absolute !important;
    bottom: 10px !important;
    right: 10px !important;
    top: auto !important;
}

.chart-link {
    text-decoration: none;
    color: #666;
    width: 100%;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 2px solid #e8e8e8;
    padding: 8px;
    border-radius: 8px;
    background-color: rgba(232, 232, 232, 0.1);
    cursor: pointer;
    transition: all 0.2s ease;
}

.chart-link:hover {
    background-color: rgba(232, 232, 232, 0.2);
    border-color: #4264fb;
    color: #4264fb;
}

.chart-link span {
    font-size: 20px;
}

.chart-panel-branding {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 8px 16px 0;
    margin-top: 8px;
}

/* WhatsApp Float Button */
.whatsapp-float-button {
    position: fixed;
    bottom: 80px; /* Above AIre button */
    left: 20px;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background-color: #25D366;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    text-decoration: none;
    cursor: pointer;
    z-index: 1000;
    transition: all 0.3s ease;
    border: 2px solid white;
}

.whatsapp-float-button:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    background-color: #128C7E;
}

/* AI Float Button */
.ai-float-button {
    position: fixed;
    bottom: 25px;
    left: 20px;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background-color: #4264fb;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    text-decoration: none;
    font-family: 'DIN Pro', Arial, sans-serif;
    font-weight: bold;
    font-size: 14px;
    cursor: pointer;
    z-index: 1000;
    transition: all 0.3s ease;
    border: 2px solid white;
}

.ai-float-button:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    background-color: #3251d8;
}

.ai-float-button span {
    animation: pulse 2s infinite;
}

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

/* Mobile adjustments for legend - Buffer between panels */
@media (max-width: 768px) {
    .legend {
        margin-bottom: 8px; /* ← Buffer específico entre leyenda y SmabilityPanels */
    }
}
