/* ============================================= */
/* ========= ESTILOS VISTA FLUJO DE CAJA ========= */
/* ============================================= */

.cashflow-main-container {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* --- Encabezado --- */
.cashflow-header-modern {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--card-border);
}

.cashflow-header-modern .title-section {
    display: flex;
    align-items: center;
    gap: 15px;
}

.cashflow-header-modern .icon-wrapper {
    background: rgba(0, 150, 136, 0.1);
    padding: 10px;
    border-radius: 12px;
    color: rgb(0, 150, 136);
    display: flex;
}

.cashflow-header-modern h2 {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--text-primary);
    margin: 0;
}

.cashflow-header-modern p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 500;
}

.cashflow-controls {
    display: flex;
    gap: 10px;
    background: var(--input-bg);
    padding: 0.5rem;
    border-radius: 12px;
}

.cashflow-controls select {
    background: transparent;
    border: 1px solid var(--input-border);
    color: var(--text-primary);
    padding: 0.6rem 1rem;
    border-radius: 8px;
    font-weight: 600;
    outline: none;
    cursor: pointer;
}

/* --- KPIs Superiores --- */
.cashflow-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 15px;
}

.cf-kpi-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 15px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
}

.cf-kpi-card.highlight-card {
    background: rgba(0, 150, 136, 0.05);
    border: 1px solid rgba(0, 150, 136, 0.3);
    border-left: 4px solid rgb(0, 150, 136);
}

.cf-kpi-card .kpi-icon {
    background: rgba(108, 117, 125, 0.1);
    padding: 12px;
    border-radius: 10px;
    color: var(--text-secondary);
}

.cf-kpi-card .inflow-icon { background: rgba(25, 135, 84, 0.1); color: var(--success-color); }
.cf-kpi-card .outflow-icon { background: rgba(220, 53, 69, 0.1); color: var(--danger-color); }
.cf-kpi-card.highlight-card .kpi-icon { background: rgb(0, 150, 136); color: white; }

.cf-kpi-card .kpi-info {
    display: flex;
    flex-direction: column;
}

.cf-kpi-card .kpi-info span {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 600;
    margin-bottom: 4px;
}

.cf-kpi-card .kpi-info strong {
    font-size: 1.5rem;
    font-weight: 800;
    line-height: 1;
}

.cf-kpi-card.highlight-card .kpi-info strong {
    color: rgb(0, 150, 136);
    font-size: 1.6rem;
}

/* --- Layout Principal --- */
.cashflow-content-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    align-items: start;
}

@media (max-width: 992px) {
    .cashflow-content-grid {
        grid-template-columns: 1fr;
    }
}

/* --- Estado de Flujo Detallado --- */
.cashflow-statement-card {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.statement-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--input-bg);
    border: 1px solid var(--card-border);
    padding: 1rem 1.5rem;
    border-radius: 12px;
}

.statement-header h3 {
    font-size: 1.1rem;
    margin: 0;
    color: var(--text-secondary);
    font-weight: 700;
}

.net-flow-badge {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.2rem;
}

.statement-group {
    border: 1px solid var(--card-border);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 1.5rem;
    background: var(--card-bg);
}

.group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    background: var(--input-bg);
    border-bottom: 1px solid var(--card-border);
    font-weight: 700;
}

.group-header .group-title {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-primary);
}

.group-header .group-title .lucide {
    width: 18px;
}

.op-group .group-header { border-left: 4px solid var(--primary-color); }
.inv-group .group-header { border-left: 4px solid var(--warning-color); }
.fin-group .group-header { border-left: 4px solid var(--success-color); }

.group-list {
    max-height: 250px;
    overflow-y: auto;
}

.activity-row {
    display: flex;
    justify-content: space-between;
    padding: 12px 15px;
    border-bottom: 1px solid var(--card-border);
    font-size: 0.95rem;
    cursor: pointer;
}

.activity-row:last-child {
    border-bottom: none;
}

.activity-label {
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: capitalize;
}

/* --- Analíticas y Gráficas --- */
.cashflow-analytics-col {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.cashflow-chart-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.cashflow-chart-card h3 {
    margin: 0 0 1.5rem 0;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    text-align: center;
}

.canvas-wrapper {
    position: relative;
    height: 280px;
    width: 100%;
}

/* Panel de Lectura Financiera */
.cashflow-insights-card {
    background: rgba(0, 150, 136, 0.05);
    border: 1px solid rgba(0, 150, 136, 0.2);
    border-radius: 12px;
    padding: 1.5rem;
}

.cashflow-insights-card h3 {
    margin: 0 0 1rem 0;
    font-size: 1.1rem;
    font-weight: 700;
    color: rgb(0, 150, 136);
    display: flex;
    align-items: center;
    gap: 8px;
}

.insights-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.insight-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--text-secondary);
    margin: 0;
}

.insight-item .lucide {
    flex-shrink: 0;
    margin-top: 2px;
    width: 18px;
    height: 18px;
}

.insight-item.positive .lucide { color: var(--success-color); }
.insight-item.attention .lucide { color: var(--warning-color); }
.insight-item.critical .lucide { color: var(--danger-color); }
.insight-item.info .lucide { color: var(--primary-color); }
.insight-item strong { color: var(--text-primary); }

/* --- Modales de detalle del flujo --- */
#modal-cashflow-table {
    width: 100%;
    border-collapse: collapse;
}

#modal-cashflow-table th,
#modal-cashflow-table td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid var(--card-border);
    vertical-align: middle;
}

#modal-cashflow-table th {
    background-color: var(--input-bg);
    position: sticky;
    top: 0;
    z-index: 10;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

#modal-cashflow-table .type-cell,
#modal-cashflow-table .amount-cell {
    font-weight: 600;
    text-align: right;
}

#modal-cashflow-table .empty-cell {
    text-align: center;
    padding: 3rem;
    color: var(--text-secondary);
}

/* =================================================================== */
/* === SOLUCIÓN: DISEÑO FLUIDO Y SIN DESBORDAMIENTO EN MÓVILES === */
/* =================================================================== */

/* 1. Obligamos a todos los contenedores del flujo de caja a no exceder la pantalla */
.cashflow-main-container,
.cashflow-content-grid,
.cashflow-analytics-col,
.cashflow-chart-card,
.cashflow-statement-card,
.cashflow-insights-card {
    min-width: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
}

/* 2. Ajuste estricto para la gráfica (Evita que rompa el ancho del celular) */
.cashflow-chart-card .canvas-wrapper {
    min-width: 0 !important;
    max-width: 100% !important;
    overflow: hidden !important;
}

/* 3. Ajustes específicos para pantallas pequeñas */
@media (max-width: 768px) {
    /* Hacemos que las tarjetas de métricas (KPIs) se apilen una debajo de otra */
    .cashflow-kpi-grid {
        grid-template-columns: 1fr !important; 
    }
    
    /* El encabezado del desglose ocupa mucho espacio horizontal, lo apilamos */
    .statement-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    
    /* Achicamos ligeramente la letra de las filas para que quepa el monto */
    .activity-row {
        font-size: 0.85rem; 
        padding: 12px 10px;
    }
}