/* css/analisis.css - UPDATED - Black & White Analysis Section Styling */

/* ===== ANALYSIS SECTION ===== */
.reporte-completo,
.analisis-producciones {
    background: var(--bg);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    box-shadow: var(--shadow);
    border: 2px solid var(--border);
    margin-bottom: var(--space-lg);
}

/* ===== REPORT HEADER ===== */
.reporte-header {
    text-align: center;
    margin-bottom: var(--space-xl);
    padding-bottom: var(--space);
    border-bottom: 2px solid var(--border);
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
}

.reporte-header h3 {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--text);
    margin-bottom: var(--space-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    letter-spacing: -0.01em;
}

.reporte-header p {
    color: var(--text-muted);
    font-size: 1rem;
    font-weight: 500;
}

/* ===== MAIN METRICS - ENHANCED BLACK & WHITE ===== */
.metricas-principales,
.metricas-generales {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--space-xl);
    margin-bottom: var(--space-xl);
}

/* Enhanced metric card styling */
.metrica-card {
    background: var(--bg);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    text-align: center;
    border: 2px solid var(--border);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    min-height: 160px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    box-shadow: var(--shadow);
}

.metrica-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--primary);
}

.metrica-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
}

.metrica-card h4 {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: var(--space);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 700;
    line-height: 1.3;
    text-align: center;
}

/* ENHANCED: Much better amount display - FIXED */
.metrica-card .amount {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: var(--space-sm);
    font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    line-height: 1;
    text-align: center;
    width: 100%;
    display: block;
    letter-spacing: -0.02em;
    word-break: break-word;
    hyphens: auto;
    min-width: 0;
    color: var(--text);
}

.metrica-card .amount.positive {
    color: var(--success);
}

.metrica-card .amount.negative {
    color: var(--danger);
}

.metrica-card small {
    color: var(--text-light);
    font-size: 0.875rem;
    text-align: center;
    line-height: 1.4;
    font-weight: 500;
}

/* ===== DETAILED ANALYSIS ===== */
.analisis-detallado {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
    gap: var(--space-xl);
    margin-bottom: var(--space-xl);
}

.analisis-section {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    border: 2px solid var(--border-light);
    border-left: 4px solid var(--primary);
    box-shadow: var(--shadow-sm);
    transition: all 0.2s ease;
}

.analisis-section:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
    border-color: var(--primary);
}

.analisis-section h4 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: var(--space-lg);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding-bottom: var(--space);
    border-bottom: 2px solid var(--border-light);
}

/* ===== CATEGORY AND PRODUCT LISTS - ENHANCED ALIGNMENT ===== */
.categoria-lista,
.producto-lista,
.top-productos {
    display: flex;
    flex-direction: column;
    gap: var(--space);
}

.categoria-item,
.producto-item,
.top-producto-item {
    background: white;
    padding: var(--space-lg);
    border-radius: var(--radius-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 2px solid var(--border-light);
    transition: all 0.2s ease;
    min-height: 60px;
    box-shadow: var(--shadow-sm);
}

.categoria-item:hover,
.producto-item:hover,
.top-producto-item:hover {
    box-shadow: var(--shadow);
    transform: translateY(-1px);
    border-color: var(--primary);
}

.categoria-item span:first-child,
.producto-item span:first-child,
.top-producto-item span:first-child {
    font-weight: 600;
    color: var(--text);
    flex: 1;
    text-align: left;
    font-size: 0.95rem;
}

/* ENHANCED: Perfect number alignment in lists */
.categoria-item span:last-child,
.producto-item span:last-child,
.top-producto-item span:last-child {
    font-weight: 800;
    color: var(--text);
    font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    text-align: right;
    min-width: 120px;
    letter-spacing: -0.01em;
    font-size: 1rem;
    padding: var(--space-xs) var(--space-sm);
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    word-break: break-word;
    hyphens: auto;
}

/* Color coding for financial amounts */
.categoria-item span:last-child:contains("S/") {
    color: var(--primary);
}

.producto-item span:last-child:contains("S/") {
    color: var(--success);
}

/* ===== GENERAL STATISTICS - ENHANCED LAYOUT ===== */
.estadisticas-generales {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    border: 2px solid var(--border-light);
    border-left: 4px solid var(--info);
    box-shadow: var(--shadow-sm);
}

.estadisticas-generales .stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space) 0;
    border-bottom: 1px solid var(--border-light);
    font-size: 0.95rem;
    min-height: 50px;
    transition: all 0.2s ease;
}

.estadisticas-generales .stat-item:hover {
    background: var(--bg-light);
    border-radius: var(--radius-sm);
    padding-left: var(--space);
    padding-right: var(--space);
}

.estadisticas-generales .stat-item:last-child {
    border-bottom: none;
}

.estadisticas-generales .stat-item span:first-child {
    color: var(--text-light);
    font-weight: 500;
    flex: 1;
    text-align: left;
}

.estadisticas-generales .stat-item span:last-child {
    font-weight: 700;
    color: var(--text);
    font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    text-align: right;
    min-width: 100px;
    background: white;
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    word-break: break-word;
    hyphens: auto;
}

/* ===== PRODUCTION ANALYSIS - ENHANCED CARDS ===== */
.produccion-analisis-card {
    background: var(--bg);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    margin-bottom: var(--space-lg);
    border: 2px solid var(--border);
    border-left: 4px solid var(--success);
    transition: all 0.3s ease;
    box-shadow: var(--shadow);
}

.produccion-analisis-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
}

.produccion-analisis-card.cerrada {
    border-left-color: var(--text-muted);
    opacity: 0.9;
    background: var(--bg-secondary);
}

.produccion-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-lg);
    gap: var(--space);
    padding-bottom: var(--space);
    border-bottom: 2px solid var(--border-light);
}

.produccion-header h4 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    margin: 0;
    flex: 1;
}

.fecha {
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    background: var(--bg-secondary);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.produccion-stats,
.produccion-financiero {
    margin-bottom: var(--space-lg);
    background: var(--bg-secondary);
    padding: var(--space);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-light);
}

/* ENHANCED: Better stat row layout */
.stat-row,
.financiero-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm) var(--space);
    font-size: 0.9rem;
    min-height: 44px;
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
}

.stat-row:hover,
.financiero-item:hover {
    background: white;
    box-shadow: var(--shadow-sm);
}

.stat-row span:first-child,
.financiero-item span:first-child {
    color: var(--text-light);
    font-weight: 500;
    flex: 1;
    text-align: left;
}

.stat-row span:last-child,
.financiero-item span:last-child {
    font-weight: 700;
    color: var(--text);
    font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    text-align: right;
    min-width: 100px;
    letter-spacing: -0.01em;
    background: white;
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    word-break: break-word;
    hyphens: auto;
}

.financiero-item.total {
    border-top: 2px solid var(--border);
    padding-top: var(--space);
    margin-top: var(--space);
    background: white;
    font-weight: 600;
}

.financiero-item .positive {
    color: var(--success);
}

.financiero-item .negative {
    color: var(--danger);
}

/* ===== PERIOD ANALYSIS ===== */
.analisis-periodo {
    background: var(--bg);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    box-shadow: var(--shadow);
    border: 2px solid var(--border);
    margin-bottom: var(--space-lg);
}

.analisis-periodo h3 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: var(--space-lg);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding-bottom: var(--space);
    border-bottom: 2px solid var(--border-light);
}

.form-actions {
    display: flex;
    gap: var(--space);
    justify-content: center;
    margin-top: var(--space-lg);
    flex-wrap: wrap;
}

/* ===== REPORT ACTIONS ===== */
.acciones-reporte {
    display: flex;
    gap: var(--space);
    justify-content: center;
    margin-top: var(--space-xl);
    padding-top: var(--space-lg);
    border-top: 2px solid var(--border);
    flex-wrap: wrap;
}

/* ===== ENHANCED STATS CARDS ===== */
.stat-card {
    background: var(--bg);
    padding: var(--space-xl);
    border-radius: var(--radius-lg);
    text-align: center;
    border: 2px solid var(--border);
    transition: all 0.3s ease;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    box-shadow: var(--shadow-sm);
}

.stat-card:hover {
    background: var(--bg-light);
    box-shadow: var(--shadow);
    transform: translateY(-2px);
    border-color: var(--primary);
}

.stat-card h4,
.stat-card h5 {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-bottom: var(--space);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 700;
    text-align: center;
    line-height: 1.3;
}

/* FIXED: .stat-card .amount */
.stat-card .amount {
    font-size: 2rem;
    font-weight: 800;
    color: var(--text);
    font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    margin-bottom: var(--space-xs);
    line-height: 1;
    text-align: center;
    width: 100%;
    display: block;
    letter-spacing: -0.02em;
    word-break: break-word;
    hyphens: auto;
}

.stat-card .amount.positive {
    color: var(--success);
}

.stat-card .amount.negative {
    color: var(--danger);
}

.stat-card small {
    color: var(--text-light);
    font-size: 0.875rem;
    text-align: center;
    line-height: 1.4;
    font-weight: 500;
}

/* ===== ENHANCED ANALYSIS ITEMS ===== */
.categoria-item,
.mes-item,
.proveedor-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-lg);
    background: white;
    border-radius: var(--radius-md);
    border: 2px solid var(--border-light);
    transition: all 0.2s ease;
    min-height: 60px;
    box-shadow: var(--shadow-sm);
    margin-bottom: var(--space-sm);
}

.categoria-item:hover,
.mes-item:hover,
.proveedor-item:hover {
    background: var(--bg-light);
    box-shadow: var(--shadow);
    transform: translateY(-1px);
    border-color: var(--primary);
}

.categoria-nombre,
.mes-nombre,
.proveedor-nombre {
    font-weight: 600;
    color: var(--text);
    flex: 1;
    text-align: left;
    font-size: 0.95rem;
}

.categoria-monto,
.mes-monto,
.proveedor-monto {
    font-weight: 800;
    color: var(--text);
    font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    text-align: right;
    min-width: 120px;
    letter-spacing: -0.01em;
    background: var(--bg-secondary);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    word-break: break-word;
    hyphens: auto;
}

.categoria-bar {
    width: 100%;
    height: 6px;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    margin-top: var(--space);
    overflow: hidden;
    border: 1px solid var(--border-light);
}

.categoria-fill {
    height: 100%;
    background: var(--primary);
    border-radius: var(--radius);
    transition: width 0.8s ease;
}

/* ENHANCED: Better expense statistics grid */
.estadisticas-gastos {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--space);
    margin-top: var(--space-lg);
}

.estadisticas-gastos .stat-item {
    background: var(--bg);
    padding: var(--space-lg);
    border-radius: var(--radius-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 2px solid var(--border);
    min-height: 70px;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.estadisticas-gastos .stat-item:hover {
    background: var(--bg-light);
    box-shadow: var(--shadow);
    transform: translateY(-1px);
    border-color: var(--primary);
}

.estadisticas-gastos .stat-item span:first-child {
    font-weight: 500;
    color: var(--text-light);
    flex: 1;
    text-align: left;
    font-size: 0.9rem;
}

.estadisticas-gastos .stat-value {
    font-weight: 800;
    color: var(--text);
    font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    text-align: right;
    min-width: 100px;
    letter-spacing: -0.01em;
    background: var(--bg-secondary);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    word-break: break-word;
    hyphens: auto;
}

/* ===== ANALYSIS NAVIGATION ===== */
.analisis-nav {
    display: flex;
    gap: var(--space);
    margin-bottom: var(--space-xl);
    justify-content: center;
    flex-wrap: wrap;
}

.analisis-nav button {
    padding: var(--space) var(--space-lg);
    border: 2px solid var(--border);
    background: var(--bg);
    color: var(--text);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.875rem;
}

.analisis-nav button:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.analisis-nav button.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 768px) {
    .metricas-principales,
    .metricas-generales {
        grid-template-columns: 1fr;
        gap: var(--space-lg);
    }
    
    .analisis-detallado {
        grid-template-columns: 1fr;
        gap: var(--space-lg);
    }
    
    .produccion-header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space);
        text-align: left;
    }
    
    .acciones-reporte,
    .form-actions {
        flex-direction: column;
        align-items: center;
    }
    
    .metrica-card .amount {
        font-size: 2.25rem;
    }
    
    .stat-card .amount {
        font-size: 1.75rem;
    }
    
    .categoria-item span:last-child,
    .producto-item span:last-child,
    .top-producto-item span:last-child {
        min-width: 100px;
        font-size: 0.9rem;
    }
    
    .estadisticas-gastos {
        grid-template-columns: 1fr;
    }
    
    .analisis-nav {
        flex-direction: column;
        align-items: center;
    }
    
    .analisis-nav button {
        width: 100%;
        max-width: 300px;
    }
}

@media (max-width: 480px) {
    .metrica-card {
        padding: var(--space-lg);
        min-height: 140px;
    }
    
    .metrica-card .amount {
        font-size: 2rem;
    }
    
    .stat-card {
        padding: var(--space-lg);
        min-height: 100px;
    }
    
    .stat-card .amount {
        font-size: 1.5rem;
    }
    
    .categoria-item,
    .producto-item,
    .top-producto-item,
    .mes-item,
    .proveedor-item {
        padding: var(--space);
        min-height: 50px;
        flex-direction: column;
        gap: var(--space-sm);
        text-align: center;
    }
    
    .categoria-item span:last-child,
    .producto-item span:last-child,
    .top-producto-item span:last-child,
    .mes-monto,
    .proveedor-monto {
        min-width: auto;
        text-align: center;
    }
    
    .stat-row,
    .financiero-item {
        min-height: 40px;
        padding: var(--space-sm);
        flex-direction: column;
        gap: var(--space-xs);
        text-align: center;
    }
    
    .stat-row span:last-child,
    .financiero-item span:last-child {
        min-width: auto;
        text-align: center;
    }
    
    .reporte-header {
        padding: var(--space-lg);
    }
    
    .reporte-header h3 {
        font-size: 1.5rem;
    }
}

/* ===== LOADING AND EMPTY STATES ===== */
.analisis-loading {
    text-align: center;
    padding: var(--space-2xl);
    color: var(--text-muted);
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 2px dashed var(--border);
}

.analisis-error {
    text-align: center;
    padding: var(--space-2xl);
    background: var(--danger-light);
    border-radius: var(--radius-lg);
    color: var(--danger);
    border: 2px solid var(--danger);
    font-weight: 500;
}

.analisis-error h3 {
    margin-bottom: var(--space);
    font-size: 1.25rem;
}

/* ===== PRINT STYLES ===== */
@media print {
    .acciones-reporte,
    .form-actions,
    .analisis-nav {
        display: none;
    }
    
    .reporte-completo,
    .analisis-producciones {
        box-shadow: none;
        border: 1px solid var(--border);
    }
    
    .metrica-card,
    .stat-card {
        break-inside: avoid;
    }
}