:root {
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --secondary: #10b981;
    --danger: #ef4444;
    --dark-bg: #0f172a;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.08);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --gutter: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Inter', system-ui, -apple-system, sans-serif; }

body { background-color: var(--dark-bg); color: var(--text-main); min-height: 100vh; padding: 20px; display: flex; flex-direction: column; align-items: center; }

canvas#backgroundCanvas { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: -1; pointer-events: none; }

/* --- CLASES UTILITARIAS Y DE PANELES --- */
.glass-panel { background: var(--glass-bg); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border: 1px solid var(--glass-border); border-radius: 16px; box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3); }

.btn-primary, .btn-secondary, .btn-text, .btn-icon, .btn-sm { cursor: pointer; border: none; border-radius: 8px; font-weight: 600; transition: all 0.2s; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }

.btn-primary { background: var(--primary); color: white; padding: 8px 10px; }
.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary { background: transparent; border: 1px solid var(--glass-border); color: var(--text-main); padding: 12px 20px; }
.btn-secondary:hover { background: rgba(255,255,255,0.05); }

.btn-text { background: none; color: var(--primary); padding: 8px; }
.btn-text:hover { text-decoration: underline; }

.btn-sm { padding: 6px 12px; font-size: 0.85rem; }

.full-width { width: 100%; }

input, select { width: 100%; padding: 12px; margin-bottom: 15px; background: rgba(0, 0, 0, 0.2); border: 1px solid var(--glass-border); border-radius: 8px; color: white; outline: none; }
input:focus, select:focus { border-color: var(--primary); }

/* --- AUTENTICACIÓN --- */
.auth-container { max-width: 400px; width: 100%; padding: 40px; text-align: center; }

.logo-area { margin-bottom: 0rem; }
.logo-area img { margin-bottom: 1rem; border-radius: 12px; }

/* --- APP LAYOUT --- */
.app-header { width: 100%; max-width: 900px; padding: 15px 25px; margin-bottom: 20px; display: flex; justify-content: space-between; align-items: center; }

.header-left { display: flex; align-items: center; gap: 12px; font-weight: 600; }

.controls-bar { width: 100%; max-width: 900px; padding: 15px; margin-bottom: 20px; display: flex; gap: 15px; align-items: center; }

.date-selector { display: flex; gap: 10px; flex: 1; }
.date-selector select { margin-bottom: 0; }

.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; width: 100%; max-width: 900px; margin-bottom: 20px; }

.card { padding: 25px; display: flex; flex-direction: column; justify-content: space-between; min-height: 160px; }

.card-header { display: flex; justify-content: space-between; color: var(--text-muted); font-size: 0.9rem; margin-bottom: 10px; }

.card-value { font-size: 2.5rem; font-weight: 700; margin-bottom: 5px; }

.card-subtext { font-size: 0.8rem; color: var(--text-muted); }

.highlight-card { border-color: rgba(59, 130, 246, 0.3); }
.highlight-card .card-value { color: #60a5fa; }

.text-success { color: var(--secondary); }
.text-danger { color: var(--danger); }

.summary-row { display: flex; justify-content: space-between; padding: 8px 0; font-size: 0.95rem; }
.border-top { border-top: 1px solid var(--glass-border); margin-top: 8px; padding-top: 12px; font-weight: 700; }

/* --- TABLA --- */
.transactions-container { width: 100%; max-width: 900px; padding: 25px; }

.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }

.table-responsive { overflow-x: auto; }

.modern-table { width: 100%; border-collapse: collapse; }

.modern-table th, .modern-table td { padding: 15px; text-align: left; border-bottom: 1px solid var(--glass-border); }
.modern-table th { color: var(--text-muted); font-weight: 500; }
.modern-table tr:last-child td { border-bottom: none; }

.empty-state { text-align: center; padding: 40px; color: var(--text-muted); }
.empty-state i { width: 48px; height: 48px; margin-bottom: 15px; opacity: 0.5; }

/* --- MODALES --- */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); backdrop-filter: blur(5px); display: none; align-items: center; justify-content: center; z-index: 100; }

.modal-card { background: #1e293b; border: 1px solid var(--glass-border); border-radius: 16px; padding: 30px; width: 90%; max-width: 400px; position: relative; box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5); overflow-y: auto; max-height: 90vh; }

.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }

.close-btn { background: none; border: none; color: var(--text-muted); cursor: pointer; }
.close-btn:hover { color: white; }

.form-group { margin-bottom: 0px; }
.form-group label { display: block; margin-bottom: 8px; font-size: 0.9rem; color: var(--text-muted); }

/* --- LANDING PAGE NUEVA (DOBLE COLUMNA) --- */
#landingLayout { display: flex; gap: 40px; max-width: 1100px; width: 90%; margin: 40px auto; align-items: center; justify-content: center; }

#infoPanel { flex: 1; max-width: 600px; padding: 20px; }

#infoPanel h2 { font-size: 2.8rem; line-height: 1.1; margin-bottom: 20px; color: var(--primary); }

#infoPanel h3 { margin-top: 0px; margin-bottom: 15px; color: var(--text-muted); font-size: 1.3rem; letter-spacing: 1px; }

/* --- RESPONSIVE GENERAL (TABLETS/MÓVILES GRANDES) --- */
@media (max-width: 850px) {
    #landingLayout { flex-direction: column; text-align: center; }
    #infoPanel { padding: 0; }
    #infoPanel h2 { font-size: 2.2rem; }
    .feature-list li { justify-content: flex-start; text-align: left; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .controls-bar { flex-direction: column; gap: 10px; align-items: stretch; }
    .date-selector { display: flex; }
    .date-selector select { flex: 1; margin: 0; }
    .date-selector select:first-child { margin-right: 10px; }
    .modern-table th:nth-child(1), .modern-table th:nth-child(3) { display: none; }
    .modern-table td:nth-child(1), .modern-table td:nth-child(3) { display: none; }
    /* TABLA: Reducción de fuente en móviles grandes/tablets */
    .modern-table th, .modern-table td { font-size: 0.9rem; padding: 10px; }
    .btn-icon-only { padding: 4px; font-size: 14px; }
    .btn-icon-only svg { width: 18px; height: 18px; }
    .action-btn-group { gap: 4px; }
}

/* ===========================================================
   SISTEMA RESPONSIVO BASADO EN IPHONE SE (MÍNIMO: 375px)
   =========================================================== */

/* Safety global para evitar scroll horizontal en cualquier circunstancia */
html, body { width: 100%; overflow-x: hidden; }

/* FLUIDO ENTRE 450px Y 375px */
@media (max-width: 450px) {
    body { padding: 0 !important; background-color: var(--dark-bg); color: var(--text-main); min-height: 100vh; display: flex; flex-direction: column; align-items: center; }
    .app-header, .controls-bar, .dashboard-grid, .transactions-container, #landingLayout, #infoPanel, .auth-container, .modal-card, main, section, .page-section, .content-wrapper {
        width: 100% !important; max-width: calc(100% - (var(--gutter) * 2)) !important; margin-top: 20px; margin-left: auto; margin-right: auto; box-sizing: border-box !important;
    }
    h1, h2 { font-size: clamp(2rem, 4vw, 1.3rem) !important; }
    /* TABLA: Tamaño de fuente y padding fluido */
    .modern-table th, .modern-table td { font-size: clamp(0.75rem, 2.8vw, 0.9rem) !important; padding: clamp(8px, 2vw, 12px) !important; }
    .card { padding: clamp(8px, 3vw, 14px) !important; min-height: clamp(100px, 26vw, 140px) !important; box-sizing: border-box; }
    .card-value { font-size: clamp(1.2rem, 6vw, 1.7rem) !important; }
    .dashboard-grid { grid-template-columns: 1fr !important; gap: clamp(8px, 3vw, 14px) !important; }
    input, select { padding: clamp(8px, 2vw, 12px) !important; font-size: clamp(0.8rem, 3vw, 1rem) !important; box-sizing: border-box; }
    
    .modal-card { width: 100% !important; max-width: calc(100% - (var(--gutter) * 2)) !important; padding: clamp(10px, 3vw, 18px) !important; box-sizing: border-box !important; }
}

/* TOPE MÍNIMO 375px (iPhone SE 3ª Gen): Se detiene el escalado hacia abajo */
@media (max-width: 375px) {
    :root { --gutter: 10px; }
    .app-header, .controls-bar, .dashboard-grid, .transactions-container, #landingLayout, #infoPanel, .auth-container, .modal-card { max-width: calc(100% - (var(--gutter) * 2)) !important; }
    h1, h2 { font-size: 1.6rem !important; }
    h3 { font-size: 1.2rem !important; }
    /* TABLA: Límite de tamaño de fuente */
    .modern-table th, .modern-table td { font-size: 0.75rem !important; padding: 8px !important; }
    .card { padding: 8px !important; min-height: 100px !important; }
    .card-value { font-size: 1.2rem !important; }
    input, select { padding: 8px !important; font-size: 0.85rem !important; }
    
}


/* --- NOTIFICACIONES --- */
.notification-container { position: fixed; top: 20px; right: 20px; z-index: 1000; display: flex; flex-direction: column; align-items: flex-end; pointer-events: none; }

.notification { pointer-events: auto; min-width: 300px; display: flex; justify-content: space-between; align-items: center; transition: opacity 0.3s ease; }

.notification-text { margin-right: 15px; }

/* Estilo para el botón Deshacer */
.btn-undo { background: white; color: var(--primary); border: none; padding: 5px 10px; border-radius: 4px; cursor: pointer; font-weight: 600; margin-left: 10px; transition: background 0.2s; }
.btn-undo:hover { background: #e5e7eb; }

/* --- ESTÉTICA DE LA TABLA Y BOTONES DE ACCIÓN --- */

/* Estilo para la fila de gasto pagado */
.paid-row { opacity: 0.7; background-color: rgba(16, 185, 129, 0.05); }
.paid-row td:first-child { border-left: 4px solid var(--secondary); }

/* Mejorar los botones de acción en la tabla */
.btn-icon-only { border: none; border-radius: 6px; padding: 8px; width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: background-color 0.2s, color 0.2s; }

/* Editar (Azul/Primary) */
.btn-edit { color: var(--primary); background-color: rgba(59, 130, 246, 0.15); }
.btn-edit:hover { background-color: rgba(59, 130, 246, 0.3); }

/* Eliminar (Rojo/Danger) */
.btn-delete { color: var(--danger); background-color: rgba(239, 68, 68, 0.15); }
.btn-delete:hover { background-color: rgba(239, 68, 68, 0.3); }

/* Pagar (Verde/Secondary) */
.btn-pay { color: var(--secondary); background-color: rgba(16, 185, 129, 0.15); }
.btn-pay:hover { background-color: rgba(16, 185, 129, 0.3); }

/* Pagado (Gris/Disabled) */
.btn-paid { color: var(--text-muted); background-color: rgba(148, 163, 184, 0.1); cursor: default; }

/* --- CONTROL DE NAVEGACIÓN DE MES --- */
.date-selector-control { display: flex; align-items: center; gap: 10px; background: var(--glass-bg); border: 1px solid var(--glass-border); border-radius: 12px; padding: 5px; margin-bottom: 10px; box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2); margin-top: 10px; }

.month-display { font-size: 1.1rem; font-weight: 600; color: var(--text-main); min-width: 120px; text-align: center; }

.date-selector-control .btn-icon-only { width: 30px; height: 30px; color: var(--primary); background: transparent; border-radius: 8px; transition: background-color 0.2s; }

.date-selector-control .btn-icon-only:hover { background-color: rgba(59, 130, 246, 0.1); }

/* === ESTILOS PARA CAJAS DE BALANCE Y AHORRO (MODIFICADO) === */
.highlight-card { border-color: rgba(59, 130, 246, 0.3); background: rgba(59, 130, 246, 0.1); }
.highlight-card .card-value { color: #60a5fa; }

.savings-card { border-color: rgba(16, 185, 129, 0.3); background: rgba(16, 185, 129, 0.1); }
.savings-card .card-value { color: var(--secondary); }