:root {
    --primary: #1e3a8a;
    --primary-dark: #0f172a;
    --accent: #2563eb;
    --accent-light: #eff6ff;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --card-bg: #ffffff;
    --bg-main: #f8fafc;
    --text-dark: #0f172a;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif; }
html { scroll-behavior: smooth; }
html, body { touch-action: manipulation; -webkit-text-size-adjust: 100%; }
body { background-color: var(--bg-main); color: var(--text-dark); padding: 16px; padding-bottom: 90px; -webkit-font-smoothing: antialiased; }
.app-container { max-width: 1750px; margin: 0 auto; display: none; /* Controlado por Firebase Auth */ }

/* ENCABEZADO Y CABECERA FLOTANTE FIJA (STICKY TOP WRAPPER) */
.sticky-top-wrapper {
    position: sticky;
    top: 0;
    z-index: 1000;
    background-color: var(--bg-main);
    padding-top: 4px;
    padding-bottom: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.03);
    margin-bottom: 16px;
}

header { 
    background: white;
    color: var(--text-dark); 
    padding: 14px 22px; 
    border-radius: 16px; 
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
    border: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 10px;
}

.brand-logo-container { display: flex; align-items: center; gap: 16px; cursor: pointer; transition: opacity 0.2s; }
.brand-logo-container:hover { opacity: 0.85; }
.brand-logo-img { height: 100px; width: auto; object-fit: contain; display: block; }
.brand-slogan { font-size: 14.5px; color: var(--text-muted); font-weight: 700; letter-spacing: -0.2px; }

.user-profile-badge {
    background: #f1f5f9;
    color: var(--primary-dark);
    padding: 8px 16px;
    border-radius: 30px;
    font-size: 12.5px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--border-color);
}
.user-profile-badge button {
    background: var(--danger);
    color: white;
    border: none;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    transition: background-color 0.2s;
}
.user-profile-badge button:hover {
    background: #dc2626;
}

/* BARRA DE SUBSECCIONES MÓVIL (CHIPS) */
.quick-subnav {
    display: none;
    gap: 8px;
    margin-top: 8px;
    flex-wrap: wrap;
}
.chip-btn {
    background: white;
    border: 1px solid var(--border-color);
    padding: 7px 12px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-dark);
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.02);
    flex: 1 1 auto;
    text-align: center;
}

/* NAVEGACIÓN ESCRITORIO */
.nav-tabs { 
    display: flex; 
    gap: 10px; 
    border-bottom: 2px solid var(--border-color); 
    padding-bottom: 6px; 
    background: var(--bg-main);
}
.tab-btn { 
    background: none; 
    border: none; 
    padding: 10px 18px; 
    font-size: 13.5px; 
    font-weight: 600; 
    color: var(--text-muted); 
    cursor: pointer; 
    transition: all 0.2s; 
    border-radius: 10px; 
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.tab-btn.active { color: var(--accent); background-color: var(--accent-light); font-weight: 700; }

/* BARRA INFERIOR MÓVIL ESTILO APP NATIVA */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100vw;
    background: white;
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -4px 15px rgba(0,0,0,0.05);
    z-index: 9000;
    padding: 6px 0;
    justify-content: space-around;
}
.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
}
.mobile-nav-item.active { color: var(--accent); font-weight: 800; }
.mobile-nav-item span { font-size: 18px; margin-bottom: 2px; }

.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn 0.25s ease-in-out; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* GRID Y TARJETAS */
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; margin-bottom: 22px; }
.card-kpi { 
    background: var(--card-bg); 
    padding: 20px; 
    border-radius: 16px; 
    box-shadow: 0 4px 20px -2px rgba(0,0,0,0.03); 
    border: 1px solid var(--border-color);
    border-left: 6px solid #cbd5e1; 
}
.card-kpi.ingresos { border-left-color: var(--success); }
.card-kpi.gastos { border-left-color: var(--danger); }
.card-kpi.ahorro { border-left-color: var(--accent); }
.card-kpi h3 { font-size: 11.5px; color: var(--text-muted); text-transform: uppercase; font-weight: 700; }
.card-kpi .monto { font-size: 26px; font-weight: 800; margin-top: 4px; color: var(--text-dark); }

.panel { 
    background: var(--card-bg); 
    padding: 20px; 
    border-radius: 16px; 
    box-shadow: 0 4px 20px -2px rgba(0,0,0,0.03); 
    border: 1px solid var(--border-color); 
    margin-bottom: 22px; 
}
.panel h2 { font-size: 15.5px; color: var(--primary-dark); margin-bottom: 16px; border-bottom: 1px solid var(--border-color); padding-bottom: 10px; font-weight: 700; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; }

.split-container { display: flex; gap: 20px; flex-wrap: wrap; }
.split-left { flex: 2.5; min-width: 60%; }
.split-right { flex: 1; min-width: 35%; }

.form-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 14px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; }
.form-group { display: flex; flex-direction: column; margin-bottom: 10px; width: 100%; }
.form-group label { font-size: 12px; font-weight: 600; color: #475569; margin-bottom: 5px; }

.form-control { 
    padding: 10px 12px; 
    border: 1px solid var(--border-color); 
    border-radius: 10px; 
    font-size: 13.5px; 
    outline: none; 
    background-color: #f8fafc; 
    width: 100%; 
    max-width: 100%;
    box-sizing: border-box;
    -webkit-appearance: none;
}
.form-control:focus { border-color: var(--accent); background-color: white; box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1); }
.form-control.required-tc { border-color: var(--accent); background-color: #eff6ff; font-weight: 700; }

/* Ocultar flechas en inputs numéricos */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input[type="number"] {
    -moz-appearance: textfield; /* Para Firefox */
}

/* CSS ESTANDARIZADO DE BOTONES FINTECH */
.btn { padding: 10px 16px; border: none; border-radius: 10px; font-weight: 600; cursor: pointer; font-size: 13px; transition: all 0.2s ease; display: inline-flex; align-items: center; justify-content: center; gap: 5px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; } 

.btn-primary { background-color: var(--primary-dark); color: white; }
.btn-primary:hover:not(:disabled) { background-color: var(--primary); }

.btn-secondary { background-color: #64748b; color: white; }
.btn-secondary:hover:not(:disabled) { background-color: #475569; }

.btn-danger { background-color: var(--danger); color: white; }
.btn-danger:hover:not(:disabled) { background-color: #dc2626; }

.alert-banner { display: none; background-color: #fef2f2; border-left: 4px solid var(--danger); color: #991b1b; padding: 12px; border-radius: 10px; margin-bottom: 15px; font-size: 13px; font-weight: 600; }

.table-wrapper { overflow-x: auto; margin-top: 8px; border-radius: 10px; width: 100%; }
table { width: 100%; border-collapse: collapse; text-align: left; font-size: 12.5px; }
th { background-color: #f8fafc; color: #475569; font-weight: 700; padding: 10px 6px; border-bottom: 2px solid var(--border-color); text-align: center; white-space: nowrap; }
td { padding: 8px 6px; border-bottom: 1px solid #f1f5f9; color: var(--text-dark); vertical-align: middle; text-align: center; }
tr:hover { background-color: #f8fafc; }
.tfoot-totals { background-color: #f8fafc; font-weight: 700; border-top: 2px solid var(--border-color); }

/* ESTILOS DE MATRIZ CON COLUMNAS STICKY CONGELADAS */
.sticky-col-1 { position: sticky; left: 0; background: white; z-index: 10; }
.sticky-col-2 { position: sticky; left: 88px; background: white; z-index: 10; }
.sticky-col-3 { position: sticky; left: 218px; background: white; z-index: 10; box-shadow: 3px 0 6px rgba(0,0,0,0.08); }
th.sticky-col-1, th.sticky-col-2, th.sticky-col-3 { background-color: #f8fafc; z-index: 15; }

.badge { padding: 4px 8px; border-radius: 20px; font-size: 10px; font-weight: 700; text-transform: uppercase; display: inline-block; }
.badge.gasto { background-color: #fee2e2; color: var(--danger); }
.badge.ingreso { background-color: #d1fae5; color: var(--success); }

.semaforo { width: 10px; height: 10px; border-radius: 50%; display: inline-block; vertical-align: middle; }
.semaforo.verde { background-color: var(--success); box-shadow: 0 0 6px var(--success); }
.semaforo.ambar { background-color: var(--warning); box-shadow: 0 0 6px var(--warning); }
.semaforo.rojo { background-color: var(--danger); box-shadow: 0 0 6px var(--danger); }

.dashboard-row { display: flex; gap: 20px; flex-wrap: wrap; margin-bottom: 22px; }
.dashboard-col { flex: 1; min-width: 45%; background: white; padding: 20px; border-radius: 16px; box-shadow: 0 4px 20px -2px rgba(0,0,0,0.03); border: 1px solid var(--border-color); }

.input-matrix { width: 72px; padding: 6px 4px; font-size: 12px; text-align: right; border: 1px solid var(--border-color); border-radius: 6px; font-weight: 600; }

/* ESTILOS FILTROS AVANZADOS HISTORIAL */
.filtros-historial-container { display:flex; gap:10px; align-items:center; flex-wrap:wrap; margin-top: 15px; margin-bottom: 15px; }
.date-filter-wrapper { display: flex; flex: 1 1 130px; align-items: center; background: white; border: 1px solid var(--border-color); border-radius: 10px; padding: 0 10px; box-sizing: border-box; }
.date-filter-wrapper label { font-size:11.5px; font-weight:700; color:var(--text-muted); margin-right:6px; margin-bottom:0; white-space: nowrap; }
.date-filter-wrapper input { border:none; outline:none; background:transparent; font-size:13px; width:100%; padding: 10px 0; color: var(--text-dark); font-family: inherit; }

/* ESTILOS DE METAS DE AHORRO Y NUEVO PANEL DASHBOARD */
.card-meta {
    background: var(--card-bg);
    padding: 24px;
    border-radius: 16px;
    box-shadow: 0 4px 20px -2px rgba(0,0,0,0.03);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 16px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.card-meta:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 25px -5px rgba(0,0,0,0.06);
}
.meta-header { display: flex; align-items: center; gap: 14px; }
.meta-icon { font-size: 30px; background: var(--accent-light); width: 56px; height: 56px; display: flex; align-items: center; justify-content: center; border-radius: 14px; box-shadow: 0 2px 8px rgba(37,99,235,0.1); }
.meta-title { font-size: 16px; font-weight: 800; color: var(--primary-dark); margin: 0; line-height: 1.2; }
.meta-objetivo { font-size: 13px; color: var(--text-muted); font-weight: 600; margin: 4px 0 0 0; }
.meta-saldo { font-size: 26px; font-weight: 800; color: var(--success); margin: 0; letter-spacing: -0.5px; }
.progress-bar-bg { background: #e2e8f0; height: 12px; border-radius: 10px; width: 100%; overflow: hidden; margin: 4px 0; }
.progress-bar-fill { height: 100%; border-radius: 10px; transition: width 0.5s ease; }
.meta-actions { display: flex; gap: 10px; margin-top: auto; padding-top: 8px; border-top: 1px dashed var(--border-color); }
.meta-actions button { flex: 1; padding: 10px; font-size: 12px; }

.metas-summary-panel {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 24px 28px;
    border-radius: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 24px;
    box-shadow: 0 10px 25px rgba(30, 58, 138, 0.25);
}
.metas-summary-grid {
    display: flex;
    gap: 32px;
    flex-wrap: wrap;
    flex: 1;
}
.meta-stat-box {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 140px;
}
.meta-stat-title {
    font-size: 11px;
    color: #94a3b8;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding-bottom: 8px;
    margin-bottom: 4px;
}
.meta-stat-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 17px;
    font-weight: 800;
    margin: 0;
    line-height: 1.2;
}
.meta-stat-row span.currency { font-size: 13px; font-weight: 600; opacity: 0.7; }

/* NUEVOS ESTILOS: LANDING PAGE REDISEÑADA */
#login-screen {
    position: absolute; top: 0; left: 0; width: 100%; min-height: 100vh;
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    z-index: 9999; display: flex; flex-direction: column;
    overflow-y: auto; 
}

.landing-header {
    position: fixed; top: 0; left: 0; width: 100%; z-index: 10000;
    background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(8px);
    padding: 12px 30px; box-shadow: 0 4px 20px rgba(0,0,0,0.06);
    display: flex; justify-content: space-between; align-items: center;
    border-bottom: 1px solid rgba(226, 232, 240, 0.8);
    box-sizing: border-box;
}

.landing-hero {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    text-align: center; padding: 140px 20px 40px; max-width: 900px; margin: 0 auto; width: 100%; box-sizing: border-box;
}

.landing-title {
    font-size: 3rem; font-weight: 800; color: var(--primary-dark); margin-bottom: 24px; line-height: 1.15; letter-spacing: -1px;
}
.landing-title span { color: var(--accent); }
.landing-subtitle {
    font-size: 1.25rem; color: var(--text-muted); margin-bottom: 40px; font-weight: 500; line-height: 1.6; max-width: 750px;
}
.cta-button-main {
    font-size: 1.15rem; padding: 18px 40px; border-radius: 14px; 
    background: var(--accent); color: white; border: none; font-weight: 700;
    box-shadow: 0 10px 25px rgba(37,99,235,0.35); cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}
.cta-button-main:hover {
    transform: translateY(-3px); box-shadow: 0 15px 35px rgba(37,99,235,0.45); background: #1d4ed8;
}

.benefits-section {
    padding: 20px 20px 80px; max-width: 1200px; margin: 0 auto; width: 100%; box-sizing: border-box;
}

.benefits-grid {
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); 
    gap: 24px;
    align-items: stretch; /* Obliga a las tarjetas a tener la misma altura */
}

.benefit-card {
    background: white; padding: 0; border-radius: 20px; text-align: left; overflow: hidden;
    box-shadow: 0 10px 30px rgba(0,0,0,0.04); border: 1px solid var(--border-color);
    transition: transform 0.3s ease, border-color 0.3s ease;
    display: flex; flex-direction: column;
    height: 100%;
}

.benefit-card:hover { transform: translateY(-5px); border-color: #cbd5e1; }

.benefit-img-wrapper {
    width: 100%; 
    height: 250px; /* Caja de altura fija para uniformidad */
    background-color: #f8fafc; 
    padding: 20px; 
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid var(--border-color);
}

.benefit-img {
    max-width: 100%; 
    max-height: 100%; 
    width: auto;
    height: auto;
    display: block; 
    object-fit: contain; /* Encaja la foto sin recortarla ni estirar la caja */
    border-radius: 8px; 
    box-shadow: 0 10px 20px rgba(0,0,0,0.1); 
    border: 1px solid #e2e8f0; 
    transition: transform 0.5s ease;
}

.benefit-card:hover .benefit-img { transform: scale(1.03); }

.benefit-content {
    padding: 25px 25px 30px; flex: 1; display: flex; flex-direction: column; justify-content: flex-start;
}
.benefit-title { font-size: 1.25rem; font-weight: 800; color: var(--primary-dark); margin-bottom: 12px; }
.benefit-desc { font-size: 0.95rem; color: var(--text-muted); line-height: 1.6; font-weight: 500; margin: 0; }

/* Modales */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(15, 23, 42, 0.85); backdrop-filter: blur(4px);
    z-index: 10000; display: none; align-items: center; justify-content: center; padding: 16px;
}
.modal-card {
    background: white; padding: 36px 28px; border-radius: 24px; width: 100%; max-width: 420px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.25); text-align: center; position: relative;
}
.btn-close-modal {
    position: absolute; top: 16px; right: 20px; font-size: 28px; font-weight: 600;
    color: #94a3b8; cursor: pointer; border: none; background: none; line-height: 1;
}
.btn-close-modal:hover { color: var(--primary-dark); }
.login-logo-img { height: 100px; width: auto; object-fit: contain; margin-bottom: 2px; display: block; margin-left: auto; margin-right: auto; }
.login-slogan-text { font-size: 14px; color: var(--primary-dark); font-weight: 700; margin-top: 10px; margin-bottom: 20px; }

.error-msg-box {
    display: none; color: #991b1b; font-size: 0.85rem; font-weight: 600; text-align: center; 
    margin-bottom: 16px; background: #fef2f2; padding: 12px; border-radius: 8px; border: 1px solid #fca5a5;
}

/* MEDIA QUERIES CELULAR Y CELDAS DE MATRIZ OPTIMIZADAS */
@media (max-width: 900px) {
    body { padding: 8px; padding-bottom: 85px; }
    .nav-tabs { display: none; } 
    .mobile-bottom-nav { display: flex; } 
    .quick-subnav { display: flex; }

    .landing-header { padding: 12px 16px; }
    .landing-header .brand-slogan { display: none; }
    .landing-hero { padding: 110px 15px 30px; }
    .landing-title { font-size: 2.2rem; }
    .landing-subtitle { font-size: 1.05rem; }
    
    header { padding: 10px 14px; margin-bottom: 6px; }
    .brand-logo-img { height: 75px; }
    .brand-slogan { font-size: 11px; }

    .form-grid { grid-template-columns: 1fr; } 
    .form-grid-2 { grid-template-columns: 1fr; }
    .split-container { flex-direction: column; }
    .split-left, .split-right, .dashboard-col { min-width: 100%; }

    .filtros-historial-container { flex-direction: column; align-items: stretch; }
    .filtros-historial-container > select, 
    .filtros-historial-container > button, 
    .filtros-historial-container > .date-filter-wrapper { width: 100%; flex: 1 1 100% !important; min-height: 44px; margin-bottom: 4px; display: block; }
    .filtros-historial-container > .date-filter-wrapper { display: flex !important; }

    .sticky-col-1 { width: 55px; min-width: 55px; left: 0; }
    .sticky-col-2 { width: 75px; min-width: 75px; left: 55px; }
    .sticky-col-3 { width: 85px; min-width: 85px; left: 130px; box-shadow: 3px 0 6px rgba(0,0,0,0.08); }
    
    .sel-mat-tipo { width: 52px; font-size: 9.5px; padding: 2px; }
    .sel-mat-cat { width: 72px; font-size: 9.5px; padding: 2px; }
    .sel-mat-con { width: 80px; font-size: 9.5px; padding: 2px; }

    .input-matrix { width: 68px; padding: 6px; font-size: 12px; font-weight: 700; }

    .mobile-card-row {
        background: white;
        border: 1px solid var(--border-color);
        border-radius: 12px;
        padding: 14px;
        margin-bottom: 10px;
        display: flex;
        flex-direction: column;
        gap: 6px;
        text-align: left;
        box-shadow: 0 2px 5px rgba(0,0,0,0.02);
    }
    .mobile-card-row .m-row-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #f1f5f9; padding-bottom: 6px; }
    .mobile-card-row .m-row-body { display: flex; justify-content: space-between; align-items: center; font-size: 13px; margin-top: 4px; }
    .mobile-card-row .m-row-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; border-top: 1px solid #f1f5f9; padding-top: 8px; }
    
    .desktop-only-table { display: none; }
    .mobile-only-cards { display: block; }
    
    /* Metas Responsive */
    .metas-summary-grid { flex-direction: column; gap: 16px; }
    .meta-stat-box { width: 100%; border-bottom: 1px dashed rgba(255,255,255,0.1); padding-bottom: 12px; }
    .meta-stat-box:last-child { border-bottom: none; padding-bottom: 0; }
    .metas-summary-panel { flex-direction: column; align-items: stretch; padding: 20px; }
    .metas-summary-panel > button { width: 100%; margin-top: 10px; justify-content: center; }
}

@media (min-width: 901px) {
    .mobile-only-cards { display: none; }
    .desktop-only-table { display: table; }
    .sticky-col-1 { left: 0; width: 88px; }
    .sticky-col-2 { left: 88px; width: 130px; }
    .sticky-col-3 { left: 218px; width: 140px; }
    .sel-mat-tipo { width: 85px; }
    .sel-mat-cat { width: 130px; }
    .sel-mat-con { width: 140px; }
}