:root {
    --bg-main: #f0f2f5;
    --panel-bg: #ffffff;
    --border-color: #e5e7eb;
    --accent: #10b981; 
    --accent-hover: #059669;
    --text-main: #111827;
    --text-muted: #6b7280;
    --error: #ef4444;
    --warning: #f59e0b;
    --bank-color: #3b82f6; 
    
    --font-ui: 'Inter', sans-serif;
    --font-mono: 'Fira Code', monospace;
    
    --radius: 12px;
    --transition: all 0.2s ease;
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body { font-family: var(--font-ui); background-color: var(--bg-main); color: var(--text-main); line-height: 1.6; display: flex; flex-direction: column; min-height: 100vh; }
.amount, .amount-input { font-family: var(--font-mono); }
.view-container { display: none; min-height: 100vh; flex-direction: column; }
.view-container.active { display: flex; }
.hidden { display: none !important; }

/* Login Box Update */
#login-view.active { display: flex; align-items: center; justify-content: center; }
.login-box { background: var(--panel-bg); padding: 3.5rem; border-radius: var(--radius); border: 1px solid var(--border-color); box-shadow: 0 10px 25px -5px rgba(0,0,0,0.1); text-align: center; width: 100%; max-width: 420px; }
.login-box .logo { font-size: 2.2rem; font-weight: 700; margin-bottom: 0.5rem; color: var(--text-main); }
.login-box .logo span { color: var(--accent); }
.login-box p { color: var(--text-muted); margin-bottom: 2.5rem; font-size: 0.95rem; }

/* NUEVO BOTÓN GOOGLE */
.btn-google { 
    background: #ffffff; 
    color: #3c4043; 
    border: 1px solid #dadce0; 
    padding: 0.8rem 1.5rem; 
    border-radius: 8px; 
    font-size: 1rem; 
    font-weight: 500; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    gap: 12px; 
    cursor: pointer; 
    transition: var(--transition); 
    box-shadow: 0 1px 2px 0 rgba(60,64,67,0.3);
    width: 100%;
}
.btn-google:hover { 
    background: #f8f9fa; 
    box-shadow: 0 1px 3px 1px rgba(60,64,67,0.15), 0 1px 2px 0 rgba(60,64,67,0.3); 
    transform: translateY(-1px);
}

/* Topbar */
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 1rem 2rem; background: #1f2937; color: white; }
.app-logo { display: flex; align-items: center; gap: 10px; }
.logo-icon { width: 32px; height: 32px; background: var(--accent); border-radius: 6px; position: relative; display: flex; align-items: flex-end; padding: 5px; gap: 2px; }
.logo-icon::before, .logo-icon::after { content: ''; background: #1f2937; width: 6px; border-radius: 2px; }
.logo-icon::before { height: 60%; }
.logo-icon::after { height: 90%; width: 6px; background: #1f2937; box-shadow: 8px 0 #1f2937; }
.logo-icon.small-icon { width: 24px; height: 24px; padding: 3px; gap: 2px; border-radius: 4px; }
.logo-icon.small-icon::before, .logo-icon.small-icon::after { width: 4px; border-radius: 1px; }
.logo-icon.small-icon::after { box-shadow: 6px 0 #1f2937; }
.app-logo h1 { font-size: 1.4rem; color: white; letter-spacing: -0.5px; }
.app-logo h1 span { color: var(--accent); }
.period-selector { display: flex; align-items: center; gap: 1.5rem; background: rgba(255,255,255,0.1); padding: 0.5rem 1rem; border-radius: 50px; }
.btn-nav { background: transparent; color: white; border: none; cursor: pointer; font-weight: bold; font-size: 1.2rem; }
.header-actions { display: flex; align-items: center; gap: 1.2rem; }

/* Icono Configuración */
.btn-icon { background: rgba(255,255,255,0.08); color: white; border: 1px solid rgba(255,255,255,0.1); padding: 0.45rem; border-radius: 50%; cursor: pointer; transition: var(--transition); display: flex; align-items: center; justify-content: center; }
.btn-icon:hover { background: rgba(255,255,255,0.2); transform: rotate(45deg); }

/* Perfil de Usuario */
.user-profile { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,0.08); padding: 0.35rem 1rem 0.35rem 0.4rem; border-radius: 50px; border: 1px solid rgba(255,255,255,0.1); }
.avatar { width: 28px; height: 28px; background: var(--accent); border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #1f2937; }
.user-email-text { font-size: 0.85rem; color: #f3f4f6; font-weight: 500; }

/* Dashboard Grid */
.dashboard-grid { padding: 2rem; max-width: 1300px; margin: 0 auto; display: flex; flex-direction: column; gap: 2rem; flex: 1; width: 100%; }
.summary-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 1.5rem; margin-bottom: 1.5rem; }
.card, .panel { background: var(--panel-bg); padding: 1.5rem; border-radius: var(--radius); border: 1px solid var(--border-color); box-shadow: var(--shadow); }

.card-header { display: flex; align-items: center; gap: 10px; margin-bottom: 0.5rem; }
.card-header h3 { font-size: 0.85rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin: 0; }
.card-icon { width: 22px; height: 22px; }
.icon-bank { stroke: var(--bank-color); }
.icon-in { stroke: var(--accent); }
.icon-out { stroke: var(--warning); }
.icon-util { stroke: var(--text-main); }

.card .amount { font-size: 1.8rem; margin: 0.2rem 0 0.5rem 0; font-weight: 700; }
.card-note { font-size: 0.75rem; color: var(--text-muted); font-family: var(--font-mono); font-weight: 600; display: block;}
.highlight-card { background: #f8fafc; border-left: 4px solid var(--accent); }
.bank-card { border-top: 4px solid var(--bank-color); background: #f0fdf4; } 

.text-positive { color: var(--accent); }
.text-negative { color: var(--error); }
.text-bank { color: var(--bank-color); }

/* Barra Salud Financiera */
.health-container { background: var(--panel-bg); padding: 1.5rem; border-radius: var(--radius); border: 1px solid var(--border-color); box-shadow: var(--shadow); }
.health-header { display: flex; justify-content: space-between; margin-bottom: 0.8rem; font-size: 0.9rem; }
.health-title { font-weight: 600; color: var(--text-main); }
.health-ratio { color: var(--text-muted); font-family: var(--font-mono); font-weight: 600; }
.health-bar-bg { width: 100%; height: 12px; background: #e5e7eb; border-radius: 10px; overflow: hidden; position: relative; }
.health-bar-fill { height: 100%; width: 0%; background: var(--accent); border-radius: 10px; transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.4s ease; }

/* Gráfico CSS */
.chart-section .panel-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border-color); padding-bottom: 1rem; margin-bottom: 1rem;}
.chart-section .panel-header h2 { font-size: 1.1rem; }
.chart-container { height: 220px; display: flex; align-items: flex-end; gap: 12px; padding-top: 20px; border-bottom: 2px solid var(--border-color); margin-bottom: 10px; }
.chart-column { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; position: relative; }
.bar-group { width: 100%; display: flex; align-items: flex-end; gap: 4px; height: 100%; }
.bar { flex: 1; border-radius: 4px 4px 0 0; min-height: 2px; transition: height 0.6s ease; cursor: pointer; }
.bar-in { background: #10b981; opacity: 0.9; }
.bar-out { background: #ef4444; opacity: 0.9; }
.bar:hover { opacity: 1; filter: brightness(1.1); }
.month-label { font-size: 0.75rem; color: var(--text-muted); font-weight: 600; }
.chart-legend { display: flex; gap: 1.5rem; justify-content: center; margin-top: 1.5rem; font-size: 0.85rem; font-weight: 500; }
.legend-item { display: flex; align-items: center; gap: 6px; }
.dot { width: 12px; height: 12px; border-radius: 3px; }
.bg-positive { background: #10b981; }
.bg-negative { background: #ef4444; }

/* Tabla */
.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.panel-header h2 { font-size: 1.2rem; color: var(--text-main); }
.table-responsive { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th, td { padding: 1rem; border-bottom: 1px solid var(--border-color); font-size: 0.95rem; }
th { color: var(--text-muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; }
.badge { padding: 0.35rem 0.85rem; border-radius: 50px; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;}
.badge-paid { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.badge-pending { background: #fef3c7; color: #d97706; border: 1px solid #fde68a; }
.badge-tax { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.btn-mark-paid { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; padding: 0.4rem 0.8rem; border-radius: 6px; font-size: 0.75rem; font-weight: 700; cursor: pointer; transition: var(--transition); font-family: var(--font-ui); }
.btn-mark-paid:hover { background: #166534; color: white; transform: translateY(-1px); }

/* Resumen Anual */
.annual-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 2rem; }
.annual-stat label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.5rem; font-weight: 600; }
.annual-stat p { font-size: 1.6rem; font-weight: 700; font-family: var(--font-mono); }

/* Modales */
.modern-modal { border: none; border-radius: 16px; padding: 0; width: 95%; max-width: 680px; box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25); margin: auto; background: #ffffff;}
.modern-modal::backdrop { background: rgba(17, 24, 39, 0.7); backdrop-filter: blur(5px); }
.modal-header { background: #f8fafc; padding: 1.5rem 2rem; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; border-radius: 16px 16px 0 0;}
.modal-title-group { display: flex; align-items: center; gap: 12px; }
.modal-header h3 { font-size: 1.3rem; color: var(--text-main); font-weight: 700; margin: 0; }
.btn-close { background: none; border: none; font-size: 2rem; line-height: 1; color: var(--text-muted); cursor: pointer; transition: var(--transition); border-radius: 50%; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; }
.btn-close:hover { background: #fee2e2; color: var(--error); }
.modal-body { padding: 2rem; max-height: 80vh; overflow-y: auto;}
.section-title { font-size: 0.9rem; color: var(--text-main); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 1rem; padding-bottom: 0.5rem; border-bottom: 2px solid var(--border-color); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem 1.5rem; margin-bottom: 1.5rem; }
.form-group { display: flex; flex-direction: column; }
label { font-size: 0.85rem; color: #4b5563; margin-bottom: 0.5rem; font-weight: 600; }

input, select { width: 100%; background: #f9fafb; border: 1px solid #d1d5db; color: var(--text-main); padding: 0.8rem 1rem; border-radius: 8px; font-size: 0.95rem; outline: none; transition: var(--transition); font-family: var(--font-ui); }
input:focus, select:focus { background: #ffffff; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15); }

.financial-section { margin-top: 2rem; }
.calc-box { background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 12px; padding: 1.5rem; }
.math-grid { grid-template-columns: 1fr 1fr 1fr; margin-bottom: 0; }
.calc-result { background: #e5e7eb; border-color: #d1d5db; color: #4b5563; cursor: not-allowed; }
.strong-result { background: #ffffff; border: 2px solid var(--accent); color: var(--accent); font-weight: 700; font-size: 1.1rem; }

.form-actions { margin-top: 2.5rem; display: flex; justify-content: flex-end; }
button { cursor: pointer; border: none; border-radius: 8px; font-weight: 600; font-family: var(--font-ui); transition: var(--transition); }
.btn-primary-action { background: var(--accent); color: white; padding: 0.7rem 1.5rem; box-shadow: 0 4px 6px -1px rgba(16, 185, 129, 0.2); }
.btn-primary-action:hover { transform: translateY(-2px); background: var(--accent-hover); box-shadow: 0 6px 8px -1px rgba(16, 185, 129, 0.3); }
.btn-secondary { background: transparent; color: white; border: 1px solid #4b5563; padding: 0.6rem 1.2rem; }
.btn-secondary:hover { background: rgba(255,255,255,0.1); border-color: white; }
.btn-confirm { background: #1f2937; color: white; width: 100%; padding: 1.2rem; font-size: 1.1rem; letter-spacing: 0.5px; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);}
.btn-confirm:hover { background: #111827; transform: translateY(-1px); }

.main-footer { margin-top: auto; padding: 2rem; background: #fff; border-top: 1px solid var(--border-color); text-align: center; font-size: 0.85rem; color: var(--text-muted); }
.main-footer span { color: var(--accent); font-weight: 700; }


/* Badge de Notificación Admin */
.notif-wrapper { position: relative; display: flex; align-items: center; }
.badge-notif {
    position: absolute; top: -5px; right: -5px;
    background: var(--error); color: white;
    font-size: 0.65rem; font-weight: 700;
    min-width: 18px; height: 18px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%; border: 2px solid #1f2937;
}

/* Estados de Rendición */
.badge-approved { background: #dcfce7; color: #166534; }
.badge-rejected { background: #fee2e2; color: #991b1b; }

/* Botones de acción pequeña */
.btn-action-small { padding: 4px 8px; font-size: 0.75rem; margin-right: 4px; border-radius: 4px; }
.btn-approve { background: var(--accent); color: white; }
.btn-reject { background: var(--error); color: white; }

/* ... (Todo lo anterior se mantiene igual) ... */

/* MATA ANGUSTIA (Loader) */
.loader-overlay {
    position: fixed; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%;
    background: rgba(17, 24, 39, 0.75); 
    backdrop-filter: blur(5px);
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    justify-content: center;
    z-index: 99999; 
    color: white;
}

.loader-overlay.hidden { 
    display: none !important; 
}

.spinner {
    width: 48px; 
    height: 48px;
    border: 4px solid rgba(255,255,255,0.2);
    border-radius: 50%;
    border-top-color: var(--accent);
    animation: spin 1s cubic-bezier(0.55, 0.15, 0.45, 0.85) infinite;
    margin-bottom: 1.5rem;
}

@keyframes spin { 
    to { transform: rotate(360deg); } 
}

/* ========================================================= */
/* MEJORAS CYBERPUNK APPSTACK - BUSCADOR Y BOTONES ORDENADOS */
/* ========================================================= */

.header-with-search {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

/* Buscador Tech */
.cyber-search-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px 12px;
    transition: all 0.3s ease;
}

.cyber-search-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.2);
}

.cyber-search-wrapper svg {
    color: var(--text-muted);
    margin-right: 8px;
}

.cyber-search-wrapper input {
    background: transparent;
    border: none;
    color: var(--text-color);
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    outline: none;
    width: 240px;
    padding: 4px 0;
}

#search-indicator {
    position: absolute;
    right: -10px;
    top: -10px;
    font-size: 0.65rem;
    background: var(--warning);
    color: #000;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: bold;
    text-transform: uppercase;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.7); }
    70% { transform: scale(1.05); box-shadow: 0 0 0 4px rgba(245, 158, 11, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(245, 158, 11, 0); }
}

/* ========================================================= */
/* FIX ALINEACIÓN Y CORTES DE LÍNEA EN LA TABLA */
/* ========================================================= */

/* Evita que los títulos como "Monto Base" se partan y descuadren */
.cyber-table th {
    white-space: nowrap; 
    vertical-align: middle; 
}

.cyber-table th.sortable {
    cursor: pointer;
    transition: color 0.2s;
    user-select: none;
}

.cyber-table th.sortable:hover {
    color: var(--accent);
}

.cyber-table th.active {
    color: var(--accent);
}

.sort-indicator {
    display: inline-block;
    width: 12px;
    font-family: monospace;
}

/* REDISEÑO DE BOTONES DE ACCIÓN */
.action-group {
    display: flex;
    gap: 6px;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: nowrap; /* Evita que los botones colapsen hacia abajo */
}

/* Botón "Aplicar Pago" Cyberpunk */
.btn-cyber-pay {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid var(--accent);
    color: var(--accent);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap; /* LA MAGIA: Obliga al texto a estar en una línea */
    flex-shrink: 0; /* Evita que la tabla aplaste el botón */
}

.btn-cyber-pay:hover {
    background: var(--accent);
    color: white;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.5);
}

.btn-cyber-pay svg {
    width: 14px;
    height: 14px;
}

/* Botones cuadrados de Iconos (Editar y Borrar) */
.btn-cyber-icon {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 4px 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    flex-shrink: 0;
}

.btn-cyber-icon:hover {
    background: var(--bg-hover);
    border-color: #9ca3af;
    transform: translateY(-1px);
}

.btn-cyber-icon.danger {
    border-color: rgba(239, 68, 68, 0.3);
    color: var(--error);
}

.btn-cyber-icon.danger:hover {
    background: var(--error);
    color: white;
    border-color: var(--error);
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.4);
}
/* ========================================================= */
/* MEJORA UX: BARRA SUPERIOR FIJA (STICKY HEADER) - FIX DARK */
/* ========================================================= */

.topbar {
    position: sticky;
    top: 0;
    z-index: 100; /* Asegura que flote por encima de todas las tarjetas y tablas */
    /* Volvemos al tono oscuro original, pero con un 95% de opacidad para el blur */
    background-color: rgba(31, 41, 55, 0.95); 
    backdrop-filter: blur(12px); /* Efecto vidrio tech */
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05); /* Borde sutil para separar */
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3); /* Sombra oscura para dar profundidad */
}

/* Pequeño ajuste para que los modales no queden detrás del header al hacer scroll */
.modern-modal {
    z-index: 200; 
}

/* ========================================================= */
/* FIX PARA QUE LA FECHA NO SE ROMPA EN DOS LÍNEAS           */
/* ========================================================= */
.cyber-table td {
    vertical-align: middle;
}

.cyber-table td:first-child {
    white-space: nowrap !important; /* Fuerza a la fecha a quedarse en 1 sola línea */
}
/* ========================================================= */
/* NUEVA ETIQUETA PARA NOTAS DE CRÉDITO "APLICADAS"          */
/* ========================================================= */
.badge-applied {
    background: rgba(59, 130, 246, 0.15); /* Azul Tech */
    color: #3b82f6;
    border: 1px solid rgba(59, 130, 246, 0.3);
}
/* ========================================================= */
/* FIX DEFINITIVO: ENGRANAJE CORTADO (FUERZA BRUTA)          */
/* ========================================================= */
.header-actions .btn-icon {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 42px !important;
    height: 42px !important;
    padding: 0 !important;
    box-sizing: border-box !important;
}

.header-actions .btn-icon svg {
    margin: auto !important;
    padding: 0 !important;
    display: block !important;
    flex-shrink: 0 !important;
}

/* ========================================================= */
/* CAMPOS BLOQUEADOS (READONLY) EN CALCULADORA               */
/* ========================================================= */
.clp-input[readonly], 
.amount-input[readonly] {
    background-color: var(--bg-hover);
    border-color: transparent;
    color: var(--text-muted);
    cursor: not-allowed;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.05);
}

