/* ==============================================
   ARCHIVO: smability-panels.css - VERSIÓN COMPLETA
   DESCRIPCIÓN: Panel único expandible con gráfico inline
   ============================================== */

/* === CONTENEDOR PRINCIPAL === */
#smabilityPanelContainer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2000;
}

/* === PANEL PRINCIPAL SMABILITY - EXPANDIBLE === */
.smability-main-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 650px;
    background: var(--smability-ias-bg);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15); /* Sombra más sutil */
    border: 2px solid var(--smability-ias-color);
    backdrop-filter: blur(20px); /* Más blur para efecto glass */
    -webkit-backdrop-filter: blur(20px); /* Safari compatibility */
    z-index: 2001;
    max-height: 55vh;
    overflow-y: auto;
    transition: all 0.3s ease;
    pointer-events: all;
    font-family: 'DIN Pro', Arial, sans-serif;
}

/* === HEADER DEL PANEL - CON AIR QUALITY === */
.smability-panel-header {
    background: var(--smability-header-bg);
    padding: 16px;
    border-radius: 12px 12px 0 0;
    border-bottom: 1px solid rgba(0,0,0,0.08); /* Borde más sutil */
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background-color 0.3s ease;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.smability-header-left {
    flex: 1;
}

.smability-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.smability-whatsapp-popup {
    background: rgba(37, 211, 102, 0.9);
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: white;
    text-decoration: none;
    font-weight: bold;
    font-family: 'DIN Pro', Arial, sans-serif;
}

.smability-whatsapp-popup:hover {
    background: rgba(37, 211, 102, 1);
    transform: scale(1.05);
}

.smability-whatsapp-popup svg {
    width: 16px;
    height: 16px;
    fill: white;
}

.smability-panel-close {
    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;
    font-family: 'DIN Pro', Arial, sans-serif;
}

.smability-panel-title {
    font-size: 18px;
    font-weight: bold;
    color: #000;
    margin: 0 0 4px 0; /* Margen menor para Air Quality */
    font-family: 'DIN Pro', Arial, sans-serif;
}

/* NUEVO: Etiqueta Air Quality */
.smability-air-quality-label {
    font-size: 12px;
    color: #666;
    margin: 0;
    font-family: 'DIN Pro', Arial, sans-serif;
    font-weight: normal;
}


/* === CONTENIDO DEL PANEL === */
.smability-panel-content {
    padding: 16px;
}

.smability-ias-section {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    padding: 14px; /* Más padding */
    background: var(--smability-ias-bg);
    border-radius: 10px; /* Más redondeado */
    transition: all 0.3s ease;
    position: relative;
    border: 1px solid var(--smability-ias-color);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
}

.smability-ias-section.smability-clickable {
    cursor: pointer;
    user-select: none;
}

.smability-ias-section.smability-clickable:hover {
    background: var(--smability-ias-bg-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--smability-ias-color);
}


.smability-ias-emoji {
    font-size: 24px;
}

.smability-ias-indicator {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #ffff00;
}

.smability-ias-value {
    font-size: 24px;
    font-weight: bold;
    color: #000;
    font-family: 'DIN Pro', Arial, sans-serif;
}

.smability-ias-status {
    margin-left: auto;
    text-align: right;
}

/* NUEVO: Estructura de etiquetas Status/Risk */
.smability-status-row {
    display: flex;
    align-items: center;
    gap: 4px;
    margin: 2px 0;
}

.smability-status-label {
    font-size: 12px;     /* ← Aumentado de 10px a 12px */
    color: #000;         /* ← Cambiado de #666 a #000 */
    font-family: 'DIN Pro', Arial, sans-serif;
    font-weight: bold;   /* ← Cambiado de normal a bold */
}

.smability-status-value {
    font-size: 12px;
    font-weight: bold;
    color: #000;
    font-family: 'DIN Pro', Arial, sans-serif;
}

/* === GRID DE DATOS === */
.smability-data-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 16px;
}

.smability-data-item {
    background: var(--smability-data-bg);
    padding: 10px; /* Más padding */
    border-radius: 8px; /* Más redondeado */
    font-size: 12px;
    border: 1px solid var(--smability-ias-color);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: all 0.2s ease;
}

.smability-data-item:hover {
    background: var(--smability-data-bg-hover);
    transform: translateY(-1px);
    box-shadow: 0 2px 6px var(--smability-ias-color);
}

.smability-data-label {
    color: #666;
    font-size: 10px;
    margin-bottom: 2px;
    font-family: 'DIN Pro', Arial, sans-serif;
}

.smability-data-value {
    font-weight: bold;
    color: #000;
    font-family: 'DIN Pro', Arial, sans-serif;
}

/* === BARRA IAS === */
.smability-ias-bar-container {
    margin: 12px 16px;
    padding: 0;
    background: transparent;
}

.smability-ias-bar {
    width: 100%;
    height: 12px; /* 1/4 de la altura del contenedor IAS */
    background: linear-gradient(
        to right,
        #00e400 0%,     /* Good 0-50 */
        #00e400 25%,    
        #ffff00 25%,    /* Moderate 51-100 */
        #ffff00 50%,    
        #ff7e00 50%,    /* Unhealthy for Sensitive 101-150 */
        #ff7e00 75%,    
        #ff0000 75%,    /* Unhealthy 151-200 */
        #ff0000 87.5%,  
        #8f3f97 87.5%,  /* Very Unhealthy 201-300 */
        #8f3f97 100%    
    );
    border-radius: 6px;
    border: 1px solid rgba(0,0,0,0.1);
    position: relative;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.smability-ias-bar::after {
    content: '';
    position: absolute;
    top: -2px;
    bottom: -2px;
    width: 3px;
    background: #000;
    border-radius: 2px;
    left: var(--ias-position, 43.5%); /* Posición dinámica */
    box-shadow: 0 0 4px rgba(0,0,0,0.3);
    transition: left 0.3s ease;
}

.smability-ias-bar-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 4px;
    font-size: 8px;
    color: #666;
    font-family: 'DIN Pro', Arial, sans-serif;
    padding: 0 2px;
}

.smability-ias-bar-label {
    font-weight: bold;
    text-align: center;
    flex: 1;
}

.smability-ias-bar-label:first-child {
    text-align: left;
}

.smability-ias-bar-label:last-child {
    text-align: right;
}

/* === BOTONES === */
.smability-action-buttons {
    display: flex;
    justify-content: center;
    margin-top: 16px;
    margin-bottom: 16px; /* Espacio para gráfico inline */
}

.smability-btn {
    padding: 12px 24px;
    border: 2px solid #4264fb;
    border-radius: 8px; /* Bordes más redondeados */
    background: rgba(66, 100, 251, 0.05); /* Fondo azul muy claro por defecto */
    cursor: pointer;
    font-size: 14px;
    text-align: center;
    transition: all 0.3s ease;
    text-decoration: none;
    color: #4264fb;
    font-weight: bold;
    font-family: 'DIN Pro', Arial, sans-serif;
    box-shadow: 0 2px 8px rgba(66, 100, 251, 0.1); /* Sombra azul sutil */
}

.smability-btn:hover {
    background: rgba(66, 100, 251, 0.15); /* Azul claro al hover */
    border-color: #3251d8; /* Borde más oscuro al hover */
    color: #3251d8;
    transform: translateY(-1px); /* Efecto de elevación */
    box-shadow: 0 4px 12px rgba(66, 100, 251, 0.2); /* Sombra más intensa */
}

/* === CONTENIDO EXPANDIDO === */
.smability-expanded-content {
    transition: all 0.3s ease;
    overflow: hidden;
}

.smability-expanded-content.show {
    display: block !important;
}

/* === NUEVO: GRÁFICO INLINE === */
.smability-inline-chart-container {
    border-top: 1px solid rgba(0,0,0,0.1);
    padding-top: 16px;
    margin-top: 16px;
}

.smability-inline-chart-header {
    margin-bottom: 12px;
}

.smability-inline-chart-controls {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: nowrap;
    justify-content: flex-start;
    padding: 10px 12px; /* ← Mejor padding */
    background: rgba(66, 100, 251, 0.04); /* ← Color más sutil */
    border-radius: 8px; /* ← Más redondeado */
    border: 1px solid rgba(66, 100, 251, 0.1); /* ← Borde sutil */
}

.smability-inline-chart-controls label {
    font-size: 11px;
    color: #666;
    font-weight: bold;
    white-space: nowrap;
    font-family: 'DIN Pro', Arial, sans-serif;
}

.smability-inline-chart-controls select {
    font-size: 10px;
    padding: 3px 6px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: white;
    min-width: 80px;
    max-width: 120px;
    font-family: 'DIN Pro', Arial, sans-serif;
}

.smability-inline-chart-area {
    background: rgba(255, 255, 255, 0.9); /* Más transparente */
    border-radius: 8px;
    padding: 12px;
    min-height: 250px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(0,0,0,0.06); /* Borde más sutil */
    position: relative;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.smability-chart-placeholder {
    width: 100%;
    height: 200px;
    background: linear-gradient(135deg, rgba(66, 100, 251, 0.08) 0%, rgba(118, 75, 162, 0.08) 100%);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-family: 'DIN Pro', Arial, sans-serif;
    color: #666;
    border: 2px dashed rgba(66, 100, 251, 0.2); /* Borde punteado sutil */
}

/* NUEVO: Contenedor para gráfico real de Plotly */
#smabilityInlineChart {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: none; /* Inicialmente oculto */
}

#smabilityInlineChart.active {
    display: block;
}

#smabilityChartPlaceholder.hidden {
    display: none;
}

/* === FOOTER DEL PANEL === */
.smability-panel-footer {
    padding: 12px 16px;
    border-top: 1px solid rgba(0,0,0,0.06); /* Borde más sutil */
    background: var(--smability-footer-bg);
    border-radius: 0 0 12px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    color: #666;
    font-family: 'DIN Pro', Arial, sans-serif;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.smability-last-update {
    font-weight: bold;
}

.smability-branding {
    color: #4264fb;
    font-weight: bold;
}

/* === RESPONSIVE === */
@media (max-width: 768px) {
    .smability-main-panel {
        left: 10px;  /* ← CAMBIO: Alinear al lado izquierdo como la leyenda */
        right: auto; /* ← CAMBIO: Quitar alineación derecha */
        width: calc(100vw - 20px); /* ← CAMBIO: Usar casi todo el ancho */
        max-width: none; /* ← CAMBIO: Sin límite de ancho máximo */
        max-height: 70vh;
    }
    
    .smability-data-grid {
        grid-template-columns: 1fr;
    }
       
    .smability-inline-chart-controls label {
        font-size: 9px;
    }
    
   .smability-inline-chart-controls select {
       font-size: 10px;
       padding: 4px 8px; /* Más padding */
       border: 1px solid rgba(66, 100, 251, 0.2);
       border-radius: 6px; /* Más redondeado */
       background: rgba(255, 255, 255, 0.9);
       min-width: 80px;
       max-width: 120px;
       font-family: 'DIN Pro', Arial, sans-serif;
       transition: all 0.2s ease;
   }
   
   .smability-inline-chart-controls select:focus {
    outline: none;
    border-color: #4264fb;
    background: white;
    box-shadow: 0 0 0 2px rgba(66, 100, 251, 0.1);
   }

    .smability-inline-chart-area {
        min-height: 200px; /* Menos altura en móvil */
    }

    .smability-chart-placeholder {
        height: 150px; /* Gráfico más pequeño en móvil */
    }
}

/* === MARKERS SMABILITY === */
.smability-marker {
    cursor: pointer;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    border: 3px solid white;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 14px;
    color: #000;
    transition: transform 0.2s ease;
    background-color: #ffff00;
    font-family: 'DIN Pro', Arial, sans-serif;
}

.smability-marker:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 12px rgba(0,0,0,0.4);
}

/* === AJUSTES PARA PLOTLY EN GRÁFICO INLINE === */
.smability-inline-chart-area #smabilityInlineChart,
.smability-inline-chart-area .js-plotly-plot {
    width: 100% !important;
    max-width: 100% !important;
    height: 200px !important;
    overflow: hidden !important;
}

.smability-inline-chart-area .plotly .modebar {
    position: absolute !important;
    bottom: 10px !important;
    right: 10px !important;
    top: auto !important;
    z-index: 10 !important;
}

/* === TIPOGRAFÍA GLOBAL === */
.smability-main-panel *,
.smability-inline-chart-container * {
    font-family: 'DIN Pro', Arial, sans-serif !important;
}

/* === ESTADOS ESPECIALES === */

/* Cuando el panel está expandido con gráfico */
.smability-main-panel.expanded {
    max-height: 80vh;
    height: auto;
}

/* Ocultar scrollbar en webkit browsers pero mantener funcionalidad */
.smability-main-panel::-webkit-scrollbar {
    width: 6px;
}

.smability-main-panel::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.1);
    border-radius: 3px;
}

.smability-main-panel::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.3);
    border-radius: 3px;
}

.smability-main-panel::-webkit-scrollbar-thumb:hover {
    background: rgba(0,0,0,0.5);
}

/* === ANIMACIONES === */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.smability-inline-chart-container {
    animation: fadeIn 0.3s ease-out;
}

/* === FIXES PARA COMPATIBILIDAD === */

/* Asegurar que los elementos no interfieren con la app principal */
.smability-main-panel,
.smability-main-panel * {
    box-sizing: border-box;
}

/* Evitar conflictos con estilos globales */
.smability-main-panel button {
    font-family: 'DIN Pro', Arial, sans-serif;
    border: none;
    outline: none;
}

.smability-main-panel select {
    font-family: 'DIN Pro', Arial, sans-serif;
    outline: none;
}

/* Asegurar que los z-index no conflictúen */
.smability-main-panel {
    z-index: 2001;
}

#smabilityPanelContainer {
    z-index: 2000;
}

/* === AJUSTES FINALES === */

/* Mejorar la legibilidad en pantallas de alta densidad */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .smability-panel-title,
    .smability-ias-value,
    .smability-data-value {
        text-rendering: optimizeLegibility;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* Asegurar que las transiciones sean suaves */
* {
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}
