/* ============================================
   CARDS, KPIs Y MÉTRICAS - MEJORADO
   ============================================ */

/* KPI Cards Modernas */
.kpi-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.kpi-card {
    padding: 20px;
    border-radius: var(--border-radius);
    color: var(--white);
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
    min-height: 120px;
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    animation: fadeIn 0.5s ease-out;
}

.kpi-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 80px;
    height: 80px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    transform: translate(30%, -30%);
}

/* Colores de KPI Cards */
.kpi-card.pink { 
    background: linear-gradient(135deg, #ec4899 0%, #8b5cf6 100%); 
}
.kpi-card.purple { 
    background: linear-gradient(135deg, #8b5cf6 0%, #06d6a0 100%); 
}
.kpi-card.orange { 
    background: linear-gradient(135deg, #f59e0b 0%, #ec4899 100%); 
}
.kpi-card.blue { 
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%); 
}

.kpi-label {
    font-size: clamp(12px, 2vw, 14px);
    opacity: 0.9;
    margin-bottom: 8px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.kpi-value {
    font-size: clamp(18px, 4vw, 26px);
    font-weight: 800;
    margin-bottom: 8px;
    word-break: break-word;
    letter-spacing: -0.02em;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* KPI Subtitle mejorado para comparaciones */
.kpi-subtitle {
    font-size: clamp(11px, 2.5vw, 13px);
    font-weight: 600;
    padding: 6px 10px;
    border-radius: 8px;
    margin-top: 8px;
    display: inline-block;
    max-width: 100%;
    min-height: 20px;
    line-height: 1.3;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    word-break: break-word;
    overflow: hidden;
}

/* Contenedor de comparación en KPIs */
.comparacion-kpi-container {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}

.banco-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
}

.banco-info.principal {
    background: rgba(59, 130, 246, 0.2);
    color: #ffffff;
    border-left: 3px solid #3b82f6;
}

.banco-info.comparacion {
    background: rgba(16, 185, 129, 0.2);
    color: #ffffff;
    border-left: 3px solid #10b981;
}

.banco-nombre {
    display: flex;
    align-items: center;
    gap: 6px;
}

.banco-nombre::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.banco-info.principal .banco-nombre::before {
    background: #3b82f6;
}

.banco-info.comparacion .banco-nombre::before {
    background: #10b981;
}

.banco-valor {
    font-weight: 700;
}

.diferencia-kpi {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    margin-left: 8px;
    vertical-align: middle;
}

.diferencia-positiva {
    background: rgba(16, 185, 129, 0.3);
    color: #10b981;
}

.diferencia-negativa {
    background: rgba(239, 68, 68, 0.3);
    color: #ef4444;
}

.kpi-icon {
    position: absolute;
    bottom: 16px;
    right: 16px;
    font-size: clamp(24px, 5vw, 32px);
    opacity: 0.2;
}

/* Métricas Adicionales - MEJORADO */
.metricas-adicionales {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    border: 2px solid #e2e8f0;
    max-height: 900px;
    animation: fadeIn 0.5s ease-out;
}

.metricas-adicionales h3 {
    font-size: clamp(15px, 3vw, 18px);
    color: var(--neutral-dark);
    margin-bottom: 20px;
    text-align: center;
    font-weight: 700;
    letter-spacing: -0.01em;
    padding-bottom: 12px;
    border-bottom: 2px solid #f1f5f9;
    position: relative;
}

.metricas-adicionales h3::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 2px;
    background: linear-gradient(90deg, var(--primary) 0%, var(--primary-light) 100%);
}

.metricas-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.metrica-item {
    background: var(--white);
    padding: 16px;
    border-radius: var(--border-radius-sm);
    text-align: center;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
    border: 2px solid #f1f5f9;
    position: relative;
    overflow: hidden;
    min-height: 110px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.metrica-item:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
    border-color: #cbd5e1;
}

/* Efecto de borde para métricas con comparación */
.metrica-item.con-comparacion {
    border-top: 3px solid #3b82f6;
    border-bottom: 3px solid #10b981;
}

.metrica-label {
    font-size: clamp(11px, 2vw, 13px);
    color: var(--neutral-dark);
    margin-bottom: 8px;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: -0.01em;
}

.metrica-value {
    font-size: clamp(16px, 3.5vw, 20px);
    font-weight: 800;
    color: #1f2937;
    margin: 8px 0;
    letter-spacing: -0.01em;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Métricas de comparación - MEJORADO */
.metrica-comp {
    font-size: clamp(11px, 2vw, 13px);
    font-weight: 600;
    padding: 8px 10px;
    border-radius: 8px;
    margin-top: 10px;
    background: #f8fafc;
    border-left: 4px solid transparent;
    min-height: 28px;
    line-height: 1.4;
    text-align: left;
    word-break: break-word;
    overflow: hidden;
}

/* Estilos específicos para valores de comparación */
.metrica-comp.comparacion-positiva {
    color: #059669;
    border-left-color: #10b981;
    background: linear-gradient(90deg, rgba(16, 185, 129, 0.1) 0%, rgba(16, 185, 129, 0.05) 100%);
}

.metrica-comp.comparacion-negativa {
    color: #dc2626;
    border-left-color: #ef4444;
    background: linear-gradient(90deg, rgba(239, 68, 68, 0.1) 0%, rgba(239, 68, 68, 0.05) 100%);
}

.metrica-comp.comparacion-neutra {
    color: #6b7280;
    border-left-color: #9ca3af;
    background: linear-gradient(90deg, rgba(156, 163, 175, 0.1) 0%, rgba(156, 163, 175, 0.05) 100%);
}

/* Contenedor de comparación detallada */
.comparacion-detalle {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}

.comparacion-fila {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
}

.comparacion-fila.banco-principal {
    background: rgba(59, 130, 246, 0.08);
    color: #1d4ed8;
    border-left: 3px solid #3b82f6;
}

.comparacion-fila.banco-comparacion {
    background: rgba(16, 185, 129, 0.08);
    color: #047857;
    border-left: 3px solid #10b981;
}

.comparacion-fila .nombre {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
}

.comparacion-fila .nombre::before {
    content: '';
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.comparacion-fila.banco-principal .nombre::before {
    background: #3b82f6;
}

.comparacion-fila.banco-comparacion .nombre::before {
    background: #10b981;
}

.comparacion-fila .valor {
    font-weight: 700;
    font-size: 13px;
}

/* Badges de identificación */
.badge-banco {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
    margin-bottom: 8px;
}

.badge-principal {
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    color: white;
    border: 2px solid #3b82f6;
}

.badge-comparacion {
    background: linear-gradient(135deg, #10b981, #047857);
    color: white;
    border: 2px solid #10b981;
}

/* Separador visual */
.separador-comparacion {
    height: 2px;
    background: linear-gradient(90deg, #3b82f6, #10b981);
    margin: 12px 0;
    border-radius: 1px;
    opacity: 0.5;
}

/* Charts Container */
.chart-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.chart-card {
    background: var(--white);
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    min-height: 280px;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: var(--transition);
    animation: fadeIn 0.5s ease-out;
}

.chart-card:hover {
    box-shadow: var(--shadow-md);
}

.chart-card h3 {
    color: var(--neutral-dark);
    margin-bottom: 16px;
    font-size: clamp(13px, 2.5vw, 16px);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.chart-icon {
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--white);
    font-size: 13px;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

/* Contenedores de gráficos */
.chart-card canvas {
    width: 100% !important;
    height: 220px !important;
    max-height: 220px;
}

/* Responsive para cards y métricas */
@media (max-width: 768px) {
    .chart-container {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .chart-card canvas {
        height: 200px !important;
        max-height: 200px;
    }
    
    .metricas-grid {
        gap: 12px;
    }
}

@media (max-width: 480px) {
    .kpi-container {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .metricas-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .metricas-adicionales {
        min-height: 1200px;
    }
    
    .chart-card {
        padding: 16px;
        min-height: 240px;
    }
    
    .chart-card canvas {
        height: 180px !important;
        max-height: 180px;
    }
    
    .metrica-item {
        min-height: 95px;
        padding: 14px;
    }
    
    .metrica-comp {
        padding: 6px 8px;
        font-size: 11px;
    }
}

/* Animación para nuevas comparaciones */
@keyframes highlightComparison {
    0% {
        background-color: rgba(59, 130, 246, 0.1);
        transform: scale(1);
    }
    50% {
        background-color: rgba(59, 130, 246, 0.3);
        transform: scale(1.02);
    }
    100% {
        background-color: transparent;
        transform: scale(1);
    }
}

.highlight-new-comparison {
    animation: highlightComparison 1.5s ease-in-out;
}

/* Tooltip para diferencias */
.tooltip-diferencia {
    display: inline-block;
    margin-left: 4px;
    font-size: 10px;
    padding: 1px 4px;
    border-radius: 3px;
    font-weight: 700;
}

.tooltip-positivo {
    background: #dcfce7;
    color: #059669;
}

.tooltip-negativo {
    background: #fee2e2;
    color: #dc2626;
}