/**
 * Nombre: dashboard-metricas.css
 * Proposito: Estilos para dashboard de metricas avanzadas
 * Fecha: 2025-10-23
 */

/* ========================================
   DASHBOARD SECTION - Contenedor Principal
   ======================================== */
.dashboard-section {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    position: relative;
    overflow: hidden;
}

.dashboard-section::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('data:image/svg+xml,<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="2" fill="white" opacity="0.1"/></svg>');
    opacity: 0.3;
    pointer-events: none;
    z-index: 0; /* Fondo detras de todo */
}

.dashboard-section .section-container {
    position: relative;
    z-index: 10; /* Contenido adelante del fondo */
}

.dashboard-section .section-title {
    color: #ffffff !important;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.dashboard-section .section-subtitle {
    color: rgba(255, 255, 255, 0.95) !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* ========================================
   LOADING & ERROR
   ======================================== */
.dashboard-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    margin: 20px 0;
}

.dashboard-loading .spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(102, 126, 234, 0.2);
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.dashboard-loading p {
    margin-top: 15px;
    color: #667eea;
    font-weight: 500;
}

.dashboard-error {
    background: rgba(231, 76, 60, 0.1);
    border: 2px solid #e74c3c;
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    color: #e74c3c;
    margin: 20px 0;
}

.dashboard-error i {
    font-size: 24px;
    margin-bottom: 10px;
}

/* ========================================
   FUENTE DE DATOS
   ======================================== */
.fuente-datos {
    display: inline-block;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    margin: 10px 0 20px;
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    backdrop-filter: blur(10px);
}

.fuente-datos i {
    margin-right: 6px;
}

.fuente-bd {
    background: rgba(46, 204, 113, 0.3);
    border: 1px solid rgba(46, 204, 113, 0.5);
}

.fuente-cache {
    background: rgba(241, 196, 15, 0.3);
    border: 1px solid rgba(241, 196, 15, 0.5);
}

.fuente-fallback {
    background: rgba(231, 76, 60, 0.3);
    border: 1px solid rgba(231, 76, 60, 0.5);
}

/* ========================================
   CONTROLES Y FILTROS
   ======================================== */
.dashboard-controls {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 20px;
    margin: 20px 0;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.control-group {
    display: flex;
    align-items: center;
    gap: 15px;
}

.control-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: #2c3e50;
    font-size: 14px;
}

.filtro-select {
    padding: 10px 16px;
    border: 2px solid #e0e6ed;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    color: #2c3e50;
    background: #fff;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 220px;
}

.filtro-select:hover {
    border-color: #667eea;
}

.filtro-select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* ========================================
   TABS DE METRICAS
   ======================================== */
.tabs-metricas {
    display: flex;
    gap: 10px;
    margin: 20px 0;
    background: rgba(255, 255, 255, 0.95);
    padding: 15px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    flex-wrap: wrap;
}

.tab-metrica {
    flex: 1;
    min-width: 150px;
    padding: 12px 20px;
    border: none;
    background: transparent;
    color: #7f8c8d;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.tab-metrica:hover {
    background: rgba(102, 126, 234, 0.1);
    color: #667eea;
}

.tab-metrica.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.tab-metrica i {
    font-size: 16px;
}

/* ========================================
   CONTROL DE ORDENAMIENTO
   ======================================== */
.ordenamiento-controls {
    margin: 20px 0;
}

.ordenamiento-wrapper {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95) 0%, rgba(255, 255, 255, 0.98) 100%);
    border-radius: 16px;
    padding: 20px 24px;
    display: flex;
    align-items: center;
    gap: 20px;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.15);
    border: 2px solid rgba(102, 126, 234, 0.1);
    transition: all 0.3s ease;
}

.ordenamiento-wrapper:hover {
    box-shadow: 0 6px 25px rgba(102, 126, 234, 0.25);
    border-color: rgba(102, 126, 234, 0.3);
    transform: translateY(-2px);
}

.ordenamiento-icon {
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.ordenamiento-icon i {
    font-size: 24px;
    color: #fff;
}

.ordenamiento-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ordenamiento-label {
    font-size: 13px;
    font-weight: 700;
    color: #667eea;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0;
}

.ordenamiento-select {
    background: #fff;
    border: 2px solid #e8ecf1;
    border-radius: 10px;
    padding: 10px 16px;
    font-size: 15px;
    font-weight: 600;
    color: #2c3e50;
    cursor: pointer;
    transition: all 0.3s ease;
    outline: none;
    appearance: none;
    background-image: url('data:image/svg+xml;charset=UTF-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23667eea"><path d="M7 10l5 5 5-5z"/></svg>');
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 20px;
    padding-right: 40px;
}

.ordenamiento-select:hover {
    border-color: #667eea;
    background-color: #f8f9ff;
}

.ordenamiento-select:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
    background-color: #fff;
}

.ordenamiento-select option {
    padding: 10px;
    font-size: 14px;
    font-weight: 500;
}

/* Responsive para ordenamiento */
@media (max-width: 768px) {
    .ordenamiento-wrapper {
        flex-direction: column;
        text-align: center;
        padding: 16px;
    }
    
    .ordenamiento-content {
        width: 100%;
    }
    
    .ordenamiento-select {
        width: 100%;
    }
}

/* ========================================
   PANELES DE METRICAS
   ======================================== */
.panel-metrica {
    display: none;
    animation: fadeIn 0.5s ease;
}

.panel-metrica.active {
    display: block;
}

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

.panel-info {
    background: rgba(255, 255, 255, 0.95);
    padding: 20px;
    border-radius: 12px;
    text-align: center;
    color: #7f8c8d;
    font-size: 14px;
}

.panel-info i {
    margin-right: 8px;
    color: #667eea;
}

/* ========================================
   GRID DE KPIs
   ======================================== */
.kpis-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin: 20px 0;
}

/* ========================================
   KPI CARDS
   ======================================== */
.kpi-card {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    min-height: 120px; /* Altura minima para mantener proporcion */
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, transparent 0%, rgba(255, 255, 255, 0.1) 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.kpi-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.kpi-card:hover::before {
    opacity: 1;
}

.kpi-icon {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.kpi-icon i {
    font-size: 28px;
    color: #fff;
}

.kpi-info {
    flex: 1;
}

.kpi-titulo {
    font-size: 13px;
    font-weight: 600;
    color: #7f8c8d;
    margin: 0 0 8px 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.kpi-valor {
    font-size: 32px;
    font-weight: 700;
    color: #2c3e50;
    margin: 0 0 5px 0;
    line-height: 1;
}

.kpi-label {
    font-size: 12px;
    color: #95a5a6;
    font-weight: 500;
}

/* ========================================
   GRID DE GRAFICAS
   ======================================== */
.graficas-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 25px;
    margin: 20px 0;
}

/* ========================================
   CONTENEDORES DE GRAFICAS
   ======================================== */
.grafica-contenedor {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    padding: 25px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.grafica-contenedor:hover {
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    transform: translateY(-3px);
}

.grafica-titulo {
    font-size: 16px;
    font-weight: 700;
    color: #2c3e50;
    margin: 0 0 8px 0;
}

.grafica-subtitulo {
    font-size: 13px;
    color: #95a5a6;
    margin: 0 0 20px 0;
    font-weight: 500;
}

.grafica-canvas {
    position: relative;
    height: 300px; /* Reducido para mejor proporcion en grid */
    width: 100%;
}

.grafica-canvas canvas {
    max-height: 100%;
    width: 100% !important;
    height: 100% !important;
}

/* ========================================
   RESPONSIVE
   ======================================== */
@media (max-width: 1200px) {
    .graficas-grid {
        grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    }
}

@media (max-width: 768px) {
    .tabs-metricas {
        flex-direction: column;
    }
    
    .tab-metrica {
        width: 100%;
    }
    
    .kpis-grid {
        grid-template-columns: 1fr;
    }
    
    .graficas-grid {
        grid-template-columns: 1fr;
    }
    
    .control-group {
        flex-direction: column;
        align-items: stretch;
    }
    
    .filtro-select {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .kpi-card {
        flex-direction: column;
        text-align: center;
    }
    
    .kpi-valor {
        font-size: 28px;
    }
    
    .grafica-canvas {
        height: 300px;
    }
}

/* ========================================
   ANIMACIONES ADICIONALES
   ======================================== */
@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

.kpi-card:active {
    animation: pulse 0.3s ease;
}

/* ========================================
   UTILIDADES
   ======================================== */
.oculto {
    display: none !important;
}

/* ========================================
   TITULO SECCION DENTRO DE PANEL
   ======================================== */
.seccion-panel-titulo {
    color: #ffffff !important;
    font-size: 24px;
    font-weight: 600;
    margin: 30px 0 20px 0;
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.1);
    border-left: 4px solid #3498db;
    border-radius: 8px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.seccion-panel-titulo:first-child {
    margin-top: 0;
}

/* ========================================
   FIX: FORZAR VISIBILIDAD DE METRICAS
   Mismo problema que Timeline: el fondo tapa el contenido
   ======================================== */
#dashboard-metricas-container {
    position: relative !important;
    z-index: 10 !important;
    opacity: 1 !important;
    visibility: visible !important;
    
    /* GRID RESPONSIVE: KPIs 4 por fila, Graficas 3 por fila en pantallas grandes */
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)) !important;
    gap: 20px !important;
    margin: 20px 0 !important;
}

.metrica-item {
    position: relative !important;
    z-index: 10 !important;
    opacity: 1 !important;
    visibility: visible !important;
}

/* KPIs: mas pequenios, 4 por fila en pantallas grandes */
.metrica-item[data-tipo="kpi"] {
    min-width: 250px;
}

/* Graficas: mas grandes, ocupan mas espacio, 3 por fila en pantallas grandes */
.metrica-item[data-tipo="grafica"] {
    grid-column: span 1;
    min-width: 350px;
}

/* En pantallas muy grandes (1600px+), graficas ocupan mas espacio */
@media (min-width: 1600px) {
    #dashboard-metricas-container {
        grid-template-columns: repeat(auto-fit, minmax(350px, 1fr)) !important;
    }
}

/* En pantallas medianas (tablets), 2 por fila */
@media (max-width: 992px) {
    #dashboard-metricas-container {
        grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)) !important;
    }
}

/* En pantallas pequenias (moviles), 1 por fila */
@media (max-width: 576px) {
    #dashboard-metricas-container {
        grid-template-columns: 1fr !important;
    }
    
    .metrica-item[data-tipo="grafica"],
    .metrica-item[data-tipo="kpi"] {
        min-width: 100%;
    }
}

.kpi-card,
.grafica-contenedor {
    position: relative !important;
    z-index: 10 !important;
    opacity: 1 !important;
    visibility: visible !important;
    width: 100%; /* Ocupar todo el espacio del grid */
    height: 100%; /* Ocupar todo el alto disponible */
}

.dashboard-header-controls,
.dashboard-header-tabs,
.ordenamiento-controls {
    position: relative !important;
    z-index: 10 !important;
    opacity: 1 !important;
    visibility: visible !important;
}

/* ========================================
   BOTON EXPANDIR/COLAPSAR
   ======================================== */
.expandir-container {
    position: relative !important;
    z-index: 10 !important;
}

.btn-expandir {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border: none;
    padding: 12px 24px;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-expandir:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
}

.btn-expandir:active {
    transform: translateY(0);
}

.btn-expandir i {
    font-size: 14px;
}

