/* ================================== */
/* ESTILOS METAS DE AHORRO (MEJORADOS) */
/* ================================== */

.savings-view {
    display: none;
    padding: 2rem 2rem 2rem;
    animation: fadeIn 0.5s ease-in-out;
}

.savings-container {
    max-width: 1400px;
    margin: 1rem;
}

.savings-header-dashboard {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 2rem;
    margin-bottom: 2.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--card-border);
}

.savings-main-title {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--text-primary);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.savings-main-title .icon-wrapper {
    background: rgba(0, 150, 136, 0.1);
    padding: 8px;
    border-radius: 10px;
    display: flex;
    color: rgb(0, 150, 136);
}

.global-reserve-card {
    background: linear-gradient(135deg, rgb(0, 150, 136), #20c997);
    color: white;
    padding: 1.5rem 2rem;
    border-radius: 16px;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    box-shadow: 0 8px 20px rgba(0, 150, 136, 0.25);
    min-width: 280px;
}

.global-reserve-card .reserve-icon {
    background: rgba(255, 255, 255, 0.2);
    padding: 1rem;
    border-radius: 50%;
    display: flex;
}

.modern-form-container {
    background: var(--input-bg);
    padding: 1.5rem;
    border-radius: 16px;
    border: 1px solid var(--card-border);
    margin-bottom: 2.5rem;
    transition: all 0.3s ease;
}

.modern-form-container:focus-within {
    border-color: rgb(0, 150, 136);
    box-shadow: 0 0 0 3px rgba(0, 150, 136, 0.1);
}

.responsive-grid-form {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr auto;
    gap: 15px;
    align-items: end;
}

.btn-submit {
    background: rgb(0, 150, 136);
    color: white;
    border: none;
    padding: 0 1.5rem;
    height: 42px;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-submit:hover {
    background: rgb(0, 125, 113);
    transform: translateY(-2px);
}


/* =================================================================== */
/* NUEVO DISEÑO: FILAS COMPACTAS PARA RESERVAS MULTIPLES               */
/* =================================================================== */

.savings-goals-grid {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-height: 65vh;
    overflow-y: auto;
    
    /* --- NUEVO: Contenedor gris claro igual al de la agenda --- */
    background: rgba(0, 0, 0, 0.02);
    border: 1px dashed rgba(0, 0, 0, 0.08);
    border-radius: 16px;
    padding: 15px; 
    padding-bottom: 150px; /* Mantiene el espacio inferior para que el menú de 3 puntos no se corte */
    width: 100%;
    box-sizing: border-box;
}

body.dark-mode .savings-goals-grid {
    background: rgba(255, 255, 255, 0.02);
    border-color: rgba(255, 255, 255, 0.08);
}

.savings-goal-card {
    background: #00968808;
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 1.2rem 1.5rem;
    display: grid;
    /* Divide la fila en 4 columnas: Icono/Titulo, Progreso, Analítica, Botón */
    grid-template-columns: 2fr 3fr 2fr auto;
    gap: 1.5rem;
    align-items: center;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    transition: transform 0.2s, box-shadow 0.2s;
    letter-spacing: 0.3px; 
    line-height: 1.6;
}

.savings-goal-card:hover {
    transform: translateY(-2px); /* Un levante sutil en lugar de un salto lateral */
    box-shadow: 0 6px 12px -2px rgba(0, 0, 0, 0.08); /* Sombra un poco más suave */
    border-color: rgb(0, 150, 136); /* Usa el verde corporativo en lugar del primary genérico */
}

.card-header-modern {
    display: flex;
    align-items: center;
    border-bottom: none !important;
    padding-bottom: 0 !important;
    margin-bottom: 0 !important;
}

.goal-card-body {
    display: flex;
    flex-direction: column;
    justify-content: center;
    width: 100%;
}

.card-footer-modern {
    margin-top: 0 !important;
}

/* --- BADGES DE ANALÍTICA INTELIGENTE --- */
.analytics-badge {
    display: flex;
    flex-direction: column;
    background: rgba(0,0,0,0.02);
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--card-border);
}

.analytics-badge .label { font-size: 0.75rem; color: var(--text-secondary); text-transform: uppercase; font-weight: 700;}
.analytics-badge .value { font-size: 0.95rem; font-weight: 800; color: var(--text-primary); margin-top: 2px;}
.analytics-badge.warning { border-left: 3px solid var(--warning-color); }
.analytics-badge.success { border-left: 3px solid var(--success-color); }

@media (max-width: 900px) {
    .savings-goal-card {
        grid-template-columns: 1fr;
        gap: 1rem;
        padding: 1rem;
    }
    .savings-goal-card:hover { transform: translateY(-3px); }
}


/* =================================================================== */
/* VIEJAS CLASES DE BARRAS DE PROGRESO Y BOTONES QUE SE MANTIENEN      */
/* =================================================================== */

.goal-action-btn {
    background: var(--input-bg);
    border: 1px solid var(--card-border);
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.goal-action-btn:hover {
    background-color: var(--primary-color);
    color: white;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    font-weight: 500;
}

.progress-info span:first-child { color: var(--text-primary); font-weight: 700; }

.progress-bar-container {
    width: 100%;
    height: 12px;
    background-color: var(--border-color);
    border-radius: 6px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, rgb(0, 150, 136), #4db6ac);
    border-radius: 6px;
    transition: width 0.8s cubic-bezier(0.25, 1, 0.5, 1);
}

.progress-percentage {
    text-align: right;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

.btn-add-contribution {
    width: 100%;
    padding: 0.85rem;
    background: rgb(0, 150, 136);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.05rem;
    font-weight: 600;
    transition: background 0.3s, transform 0.2s;
}

.btn-add-contribution:hover {
    background: rgb(0, 125, 113);
    transform: translateY(-2px);
}

.savings-goal-card.completed { border-color: #10b981; }
.savings-goal-card.completed .progress-bar { background: #10b981; }
.completed-badge { text-align: center; padding: 0.85rem; border-radius: 8px; background: rgba(16, 185, 129, 0.1); font-weight: bold; color: #10b981; }

@media (max-width: 768px) {
    .savings-header-dashboard { flex-direction: column; align-items: stretch; gap: 1.5rem; }
    .global-reserve-card { min-width: 100%; justify-content: space-between; }
    .responsive-grid-form { grid-template-columns: 1fr; }
}


/* =================================================================== */
/* ESTILOS PARA ELEMENTOS DE FORMULARIOS Y MODALES                     */
/* =================================================================== */

.segmented-control {
    display: flex;
    gap: 0.5rem;
    background-color: var(--input-bg);
    padding: 0.5rem;
    border-radius: 12px;
    border: 1px solid var(--input-border);
}

.segmented-control input[type="radio"] {
    display: none;
}

.segmented-control label {
    flex-grow: 1;
    padding: 0.8rem 1rem;
    border-radius: 8px;
    border: none;
    background-color: transparent;
    color: var(--text-secondary);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
}

.segmented-control label:hover {
    color: var(--text-primary);
}

body.light-mode .segmented-control label:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.segmented-control input[type="radio"]:checked + label {
    background-color: rgb(0 150 136 / 85%);
    color: #ffffff;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

/* === SELECTOR DE CATEGORÍA PERSONALIZADO === */
#add-contribution-modal .category-manager {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.custom-select-container {
    flex-grow: 1;
    position: relative;
}

.custom-select-trigger {
    width: 100%;
    padding: 0 14px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    transition: all 0.3s ease;
    box-sizing: border-box;
    height: 42px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    text-align: left;
}

.custom-select-trigger:focus,
.custom-select-trigger.active {
    outline: none;
    border-color: var(--input-focus-border);
    box-shadow: var(--input-focus-shadow);
}

#selected-category-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.custom-select-trigger .lucide-chevron-down {
    transition: transform 0.3s ease;
    flex-shrink: 0;
    margin-left: 8px;
}

.custom-select-trigger.active .lucide-chevron-down {
    transform: rotate(180deg);
}

#category-search-dropdown {
    width: 100%; 
    left: 0;
    right: 0;
    top: calc(100% + 5px);
}

/* Estilos para el historial de ahorros */
#savings-history-table .movement-add .amount {
    color: var(--income-color);
    font-weight: 600;
}
#savings-history-table .movement-add .amount::before {
    content: "+ ";
}
#savings-history-table .movement-withdraw .amount {
    color: var(--expense-color);
    font-weight: 600;
}
#savings-history-table .movement-withdraw .amount::before {
    content: "- ";
}

/* Modales */
#savings-goal-modal .modal-content,
#add-contribution-modal .modal-content,
#reminder-modal .modal-content {
    overflow-y: auto;
    max-height: 90vh;
}

#savings-goal-modal .modal-content form,
#add-contribution-modal .modal-content form,
#reminder-modal .modal-content form {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.modal-content .form-actions-full {
    display: flex;
    gap: 1rem;
    margin-top: auto;
    padding-top: 1.5rem;
    border-top: 1px solid var(--card-border);
}

.modal-content .form-actions-full .btn-main-action {
    flex-grow: 2;
}

.modal-content .form-actions-full .btn-secondary {
    flex-grow: 1;
    background-color: rgb(13, 108, 248);
    border: 1px solid var(--card-border);
    color: #ffffff;
}

.modal-content .form-actions-full .btn-secondary:hover {
    background-color: rgb(13, 108, 248);
    color: #FFFFFF;
}

body.light-mode .btn-add-contribution {
    background: rgb(0 150 136 / 85%);
    color: #ffffff;
}

#savings-form-container {
    transition: all 0.3s ease;
}

#savings-form-container:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.1);
}

@media (max-width: 600px) {
    #savings-goal-form {
        grid-template-columns: 1fr !important;
    }
}

/* =================================================================== */
/* FORZAR MODALES DE AHORRO A PANTALLA COMPLETA ESTILO REPORTE/HOJA    */
/* =================================================================== */

#savings-goal-modal,
#add-contribution-modal,
#savings-history-modal {
    padding: 0 !important;
    align-items: flex-end !important;
}

#savings-goal-modal .details-modal-container,
#add-contribution-modal .details-modal-container,
#savings-history-modal .details-modal-container {
    height: 95dvh !important;       
    max-height: 95dvh !important;
    width: 100% !important;        
    max-width: 100% !important;  
    border-radius: 20px 20px 0 0 !important; 
    margin: 0 !important;
    background-color: #eef2f5 !important; /* Fondo Gris */
    position: relative;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
}

.options-dropdown {
    transition: none !important;
}

/* ======================================================= */
/* === BADGES DE FECHAS Y COLORES (ESTILO AGENDA) ======== */
/* ======================================================= */
.savings-due-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    font-weight: 800;
    padding: 4px 12px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    margin-top: 6px;
    width: fit-content;
}

/* Colores de las etiquetas (Badges) */
.savings-due-badge.badge-overdue { background: #fee2e2; color: #dc2626; border: 1px solid #fca5a5; } 
.savings-due-badge.badge-today   { background: #ffedd5; color: #ea580c; border: 1px solid #fdba74; } 
.savings-due-badge.badge-week    { background: #fef9c3; color: #ca8a04; border: 1px solid #fde047; } 
.savings-due-badge.badge-ok      { background: #dcfce7; color: #16a34a; border: 1px solid #86efac; } 
.savings-due-badge.badge-neutral { background: #f1f5f9; color: #64748b; border: 1px solid #e2e8f0; }

/* Soporte para modo oscuro en las etiquetas */
body.dark-mode .savings-due-badge.badge-overdue { background: rgba(220, 53, 69, 0.15); color: #ff6b6b; border-color: rgba(220, 53, 69, 0.3); }
body.dark-mode .savings-due-badge.badge-today   { background: rgba(253, 126, 20, 0.15); color: #ffa94d; border-color: rgba(253, 126, 20, 0.3); }
body.dark-mode .savings-due-badge.badge-week    { background: rgba(255, 193, 7, 0.15); color: #ffd43b; border-color: rgba(255, 193, 7, 0.3); }
body.dark-mode .savings-due-badge.badge-ok      { background: rgba(25, 135, 84, 0.15); color: #51cf66; border-color: rgba(25, 135, 84, 0.3); }
body.dark-mode .savings-due-badge.badge-neutral { background: rgba(255, 255, 255, 0.1); color: #cbd5e1; border-color: rgba(255, 255, 255, 0.2); }

/* Tintes de fondo para las tarjetas de ahorro */
.savings-goal-card.status-overdue { background: linear-gradient(rgba(220, 53, 69, 0.04), rgba(220, 53, 69, 0.04)), var(--card-bg) !important; border-left: 5px solid var(--danger-color); }
.savings-goal-card.status-today   { background: linear-gradient(rgba(234, 88, 12, 0.04), rgba(234, 88, 12, 0.04)), var(--card-bg) !important; border-left: 5px solid #ea580c; }
.savings-goal-card.status-week    { background: linear-gradient(rgba(202, 138, 4, 0.04), rgba(202, 138, 4, 0.04)), var(--card-bg) !important; border-left: 5px solid #ca8a04; }
.savings-goal-card.status-ok      { background: linear-gradient(rgba(25, 135, 84, 0.03), rgba(25, 135, 84, 0.03)), var(--card-bg) !important; border-left: 5px solid var(--success-color); }
.savings-goal-card.status-neutral { border-left: 5px solid rgb(0, 150, 136); }

@media (max-width: 768px) {
    .savings-goals-grid {
        max-height: none !important;
        overflow-y: visible !important;
        padding-bottom: 20px;
    }
}

/* =================================================================== */
/* CORRECCIÓN DEFINITIVA: EVITAR DESBORDAMIENTO DE TEXTO EN MÓVIL      */
/* =================================================================== */
@media (max-width: 768px) {
    /* 1. Forzar la tarjeta y sus columnas a no crecer más de la pantalla */
    .savings-goal-card {
        grid-template-columns: 1fr !important;
        width: 100% !important;
        box-sizing: border-box !important;
        min-width: 0 !important; 
    }

    /* 2. Obligar a TODOS los contenedores padre a poder encogerse */
    .card-header-modern,
    .title-group,
    .title-group > div:nth-child(2) {
        min-width: 0 !important;
        max-width: 100% !important;
    }

    /* 3. Imponer la regla de truncado al texto directamente */
    .title-group h4 {
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        display: block !important; /* Quita el contexto flex si lo hubiera heredado */
        width: 100% !important;
    }

    /* 4. Asegurar que los montos bajen si no caben */
    .savings-goal-card .progress-info {
        flex-wrap: wrap !important;
        gap: 8px;
    }

    /* 5. Alinear los botones inferiores */
    .savings-goal-card .card-footer-modern {
        justify-content: space-between !important;
        width: 100%;
    }
    
    .savings-goal-card .btn-add-contribution {
        flex-grow: 1; 
        margin-right: 15px; 
    }
}