:root {
    /* Paleta de colores - Premium Dark Mode */
    --bg-main: #070913;
    --bg-darker: #05060b;
    --card-bg: rgba(16, 22, 38, 0.65);
    --card-border: rgba(255, 255, 255, 0.07);
    --card-hover-border: rgba(99, 102, 241, 0.25);
    
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    
    --primary: #6366f1;
    --primary-gradient: linear-gradient(135deg, #6366f1, #8b5cf6);
    --primary-glow: rgba(99, 102, 241, 0.35);
    
    --success: #10b981;
    --success-gradient: linear-gradient(135deg, #10b981, #059669);
    --success-glow: rgba(16, 185, 129, 0.25);
    
    --danger: #ef4444;
    --danger-gradient: linear-gradient(135deg, #ef4444, #dc2626);
    --danger-glow: rgba(239, 68, 68, 0.25);
    
    --warning: #f59e0b;
    
    /* Layout */
    --border-radius-sm: 8px;
    --border-radius-md: 16px;
    --border-radius-lg: 24px;
    --transition-speed: 0.3s;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    display: flex;
    justify-content: center;
}

/* ==========================================
   ESTILOS DE CONTENEDORES Y AUTH
   ========================================== */

.auth-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    width: 100%;
    padding: 20px;
    background: radial-gradient(circle at top right, rgba(99, 102, 241, 0.12), transparent 45%),
                radial-gradient(circle at bottom left, rgba(16, 185, 129, 0.08), transparent 45%);
}

.auth-card {
    background: var(--card-bg);
    backdrop-filter: blur(16px);
    border: 1px solid var(--card-border);
    border-radius: var(--border-radius-lg);
    width: 100%;
    max-width: 440px;
    padding: 40px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
    animation: fadeIn 0.5s ease;
}

.auth-alert-box {
    padding: 12px 16px;
    border-radius: var(--border-radius-sm);
    margin-bottom: 25px;
    font-size: 13px;
    text-align: center;
    animation: fadeIn 0.3s ease;
}

.auth-alert-box.error {
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #f87171;
}

.auth-alert-box.success {
    background: rgba(16, 185, 129, 0.12);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: #34d399;
}

.auth-header {
    text-align: center;
    margin-bottom: 30px;
}

.auth-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 60px;
    background: var(--primary-gradient);
    border-radius: var(--border-radius-md);
    font-size: 32px;
    color: white;
    margin-bottom: 15px;
    box-shadow: 0 8px 16px var(--primary-glow);
}

.auth-header h2 {
    font-size: 26px;
    font-weight: 700;
    margin-bottom: 5px;
    background: linear-gradient(135deg, #ffffff, #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.auth-header p {
    color: var(--text-secondary);
    font-size: 14px;
}

.auth-form {
    display: none;
}

.auth-form.active {
    display: block;
}

.auth-form h3 {
    font-size: 18px;
    margin-bottom: 20px;
    font-weight: 600;
    border-left: 3px solid var(--primary);
    padding-left: 10px;
}

.auth-switch {
    text-align: center;
    margin-top: 20px;
    font-size: 14px;
    color: var(--text-secondary);
}

.auth-switch a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}

.auth-switch a:hover {
    text-decoration: underline;
}

/* ==========================================
   FORMULARIOS E INPUTS
   ========================================== */

.input-group {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
}

.input-group label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-wrapper i {
    position: absolute;
    left: 15px;
    font-size: 20px;
    color: var(--text-muted);
}

input[type="email"],
input[type="password"],
input[type="number"],
input[type="text"],
input[type="date"],
select {
    width: 100%;
    background-color: rgba(5, 6, 11, 0.6);
    border: 1px solid var(--card-border);
    color: var(--text-primary);
    padding: 12px 16px;
    border-radius: var(--border-radius-sm);
    font-size: 15px;
    transition: all var(--transition-speed);
    outline: none;
}

.input-wrapper input {
    padding-left: 45px;
}

input:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-glow);
    background-color: rgba(5, 6, 11, 0.8);
}

.form-row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

/* Botones */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    font-size: 15px;
    font-weight: 600;
    border-radius: var(--border-radius-sm);
    border: none;
    cursor: pointer;
    transition: all var(--transition-speed);
    text-decoration: none;
    gap: 8px;
}

.btn-primary {
    background: var(--primary-gradient);
    color: white;
    box-shadow: 0 4px 12px var(--primary-glow);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px var(--primary-glow);
}

.btn-success {
    background: var(--success-gradient);
    color: white;
    box-shadow: 0 4px 12px var(--success-glow);
}

.btn-success:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px var(--success-glow);
}

.btn-danger {
    background: var(--danger-gradient);
    color: white;
    box-shadow: 0 4px 12px var(--danger-glow);
}

.btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px var(--danger-glow);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--card-border);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

.w-full { width: 100%; }
.mt-20 { margin-top: 20px; }
.text-success { color: var(--success) !important; }

/* ==========================================
   ESTRUCTURA DE LA APLICACIÓN (DESPUÉS DEL LOGIN)
   ========================================== */

.app-wrapper {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 1100px; /* Ancho responsivo adaptable a escritorio */
    min-height: 100vh;
    background-color: var(--bg-darker);
    border-left: 1px solid var(--card-border);
    border-right: 1px solid var(--card-border);
    position: relative;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: rgba(11, 15, 25, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--card-border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-brand i {
    font-size: 24px;
    color: var(--primary);
}

.header-brand h1 {
    font-size: 20px;
    font-weight: 700;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 12px;
}

#user-display-email {
    font-size: 13px;
    color: var(--text-secondary);
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#logout-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    transition: color var(--transition-speed);
}

#logout-btn:hover {
    color: var(--danger);
}

/* Navegación Inferior */
.app-nav-bar {
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: 72px;
    background: rgba(11, 15, 25, 0.95);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--card-border);
    position: sticky;
    bottom: 0;
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom);
}

.nav-tab-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 20%;
    height: 100%;
    cursor: pointer;
    transition: all var(--transition-speed);
    gap: 4px;
}

.nav-tab-btn i {
    font-size: 22px;
}

.nav-tab-btn span {
    font-size: 11px;
    font-weight: 500;
}

.nav-tab-btn.active {
    color: var(--primary);
    text-shadow: 0 0 10px rgba(99, 102, 241, 0.4);
}

/* Área de Contenido */
.app-content {
    flex: 1;
    padding: 20px;
    padding-bottom: 40px;
    overflow-y: auto;
}

.content-view {
    display: none;
    animation: fadeIn 0.4s ease;
}

.content-view.active {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ==========================================
   VISTA: PANEL (DASHBOARD)
   ========================================== */

/* Grid de resumen de saldos */
.financial-summary-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 15px;
}

@media (min-width: 480px) {
    .financial-summary-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

.summary-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--border-radius-md);
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.summary-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
}

.summary-card.balance::before { background: var(--primary); }
.summary-card.income::before { background: var(--success); }
.summary-card.expense::before { background: var(--danger); }

.card-label {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.card-info h2 {
    font-size: 20px;
    font-weight: 700;
    margin-top: 4px;
}

.card-icon {
    font-size: 26px;
    opacity: 0.35;
}

/* Grid de Gráficos y Transacción Rápida */
.dashboard-details-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}

@media (min-width: 520px) {
    .dashboard-details-grid {
        grid-template-columns: 1.1fr 0.9fr;
    }
}

.details-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--border-radius-md);
    padding: 20px;
}

.details-card h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 15px;
    color: var(--text-primary);
}

.chart-wrapper {
    position: relative;
    width: 100%;
    height: 180px;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Tablas */
.table-responsive {
    width: 100%;
    overflow-x: auto;
}

.transaction-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    text-align: left;
}

.transaction-table th {
    color: var(--text-secondary);
    font-weight: 500;
    padding: 10px;
    border-bottom: 1px solid var(--card-border);
}

.transaction-table td {
    padding: 12px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.transaction-table tr:last-child td {
    border-bottom: none;
}

.tx-amount {
    font-weight: 600;
}

.tx-amount.gasto { color: var(--danger); }
.tx-amount.ingreso { color: var(--success); }

.badge-tipo {
    font-size: 10px;
    text-transform: uppercase;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
}
.badge-tipo.gasto { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.badge-tipo.ingreso { background: rgba(16, 185, 129, 0.15); color: var(--success); }

.tx-actions {
    display: flex;
    gap: 8px;
}

.tx-actions button {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    transition: color var(--transition-speed);
}

.btn-edit-tx { color: var(--primary); }
.btn-delete-tx { color: var(--text-muted); }
.btn-delete-tx:hover { color: var(--danger); }

/* ==========================================
   VISTA: HISTORIAL CON FILTROS
   ========================================== */

.filter-card {
    margin-bottom: 20px;
}

.filters-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 15px;
}

.filter-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ==========================================
   VISTA: CHAT CON IA (CONVERSACION)
   ========================================== */

.chat-container-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--border-radius-md);
    height: 480px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-header {
    padding: 15px;
    background: rgba(11, 15, 25, 0.5);
    border-bottom: 1px solid var(--card-border);
    display: flex;
    align-items: center;
    gap: 12px;
}

.assistant-avatar {
    width: 38px;
    height: 38px;
    background: var(--primary-gradient);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: white;
}

.assistant-info h3 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 2px;
}

.online-indicator {
    font-size: 11px;
    color: var(--success);
    display: flex;
    align-items: center;
    gap: 4px;
}

.online-indicator .dot {
    width: 6px;
    height: 6px;
    background-color: var(--success);
    border-radius: 50%;
    display: inline-block;
    box-shadow: 0 0 6px var(--success);
}

.chat-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.message {
    display: flex;
    max-width: 85%;
}

.message.assistant {
    align-self: flex-start;
}

.message.user {
    align-self: flex-end;
}

.msg-bubble {
    padding: 12px 16px;
    border-radius: var(--border-radius-md);
    font-size: 14px;
    line-height: 1.5;
}

.message.assistant .msg-bubble {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--card-border);
    color: var(--text-primary);
    border-top-left-radius: 2px;
}

.message.assistant ul {
    margin-top: 8px;
    margin-left: 20px;
}

.message.user .msg-bubble {
    background: var(--primary-gradient);
    color: white;
    border-top-right-radius: 2px;
    box-shadow: 0 4px 10px rgba(99, 102, 241, 0.2);
}

.chat-input-bar {
    display: flex;
    padding: 12px;
    background: rgba(5, 6, 11, 0.4);
    border-top: 1px solid var(--card-border);
    gap: 10px;
}

.chat-input-bar input {
    flex: 1;
}

.chat-send-btn {
    width: 46px;
    height: 46px;
    background: var(--primary-gradient);
    border: none;
    border-radius: var(--border-radius-sm);
    color: white;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--transition-speed);
}

.chat-send-btn:hover {
    transform: scale(1.05);
}

/* Indicador de escritura / carga */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 8px;
    align-items: center;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.3s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

/* ==========================================
   MODAL DE EDICIÓN
   ========================================== */

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(5, 6, 11, 0.85);
    backdrop-filter: blur(8px);
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.modal-content {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--border-radius-lg);
    width: 100%;
    max-width: 450px;
    padding: 25px;
    animation: scaleUp 0.3s ease;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.close-modal-btn {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-muted);
    cursor: pointer;
    transition: color var(--transition-speed);
}

.close-modal-btn:hover {
    color: var(--text-primary);
}

/* ==========================================
   CONFIGURACION Y ELEMENTOS EXTRA
   ========================================== */

.settings-card {
    text-align: center;
}

.profile-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 25px;
}

.avatar-large {
    font-size: 80px;
    color: var(--primary);
    margin-bottom: 10px;
}

.profile-text h4 {
    font-size: 18px;
    font-weight: 600;
}

.profile-text p {
    color: var(--text-secondary);
    font-size: 13px;
    margin-top: 4px;
}

.divider {
    border: 0;
    height: 1px;
    background: var(--card-border);
    margin: 20px 0;
}

.settings-options {
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.option-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.02);
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--card-border);
}

.option-desc strong {
    font-size: 14px;
    display: block;
}

.option-desc p {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.option-status i {
    font-size: 22px;
}

/* ==========================================
   ANIMACIONES
   ========================================== */

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes scaleUp {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

/* ==========================================
   CARACTERÍSTICAS V2: IMPORTACIÓN CSV Y LLAVES API
   ========================================== */

.csv-import-section {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px dashed var(--card-border);
}

.csv-import-section h4 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text-secondary);
}

.csv-import-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.file-name-label {
    font-size: 13px;
    color: var(--text-muted);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-sm {
    padding: 8px 16px;
    font-size: 13px;
}

.settings-desc {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 6px;
    text-align: left;
}

.key-status-alert {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: rgba(99, 102, 241, 0.08);
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: var(--border-radius-sm);
    margin-top: 15px;
    font-size: 13px;
    text-align: left;
}

.key-status-alert.active {
    background: rgba(16, 185, 129, 0.08);
    border-color: rgba(16, 185, 129, 0.25);
    color: var(--success);
}

.help-guide {
    margin-top: 25px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--card-border);
    border-radius: var(--border-radius-sm);
    text-align: left;
}

.help-guide h4 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
}

.help-guide ol {
    padding-left: 20px;
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.help-guide a {
    color: var(--primary);
    text-decoration: none;
}

.help-guide a:hover {
    text-decoration: underline;
}

/* --- ESTILOS ADICIONALES PARA PESTAÑAS DE ENTRADA RÁPIDA (HUCHAI IA) --- */

.form-header-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--card-border);
    padding-bottom: 12px;
}

.form-tab-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 13.5px;
    font-weight: 600;
    padding: 8px 16px;
    cursor: pointer;
    border-radius: var(--border-radius-sm);
    transition: all var(--transition-speed) ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.form-tab-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.04);
}

.form-tab-btn.active {
    color: #a5b4fc;
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid rgba(99, 102, 241, 0.25);
}

.form-panel {
    display: none;
    animation: fadeIn 0.3s ease;
}

.form-panel.active {
    display: block;
}

.panel-desc {
    font-size: 12.5px;
    color: var(--text-secondary);
    margin-bottom: 16px;
    line-height: 1.5;
}

#ai-quick-input {
    width: 100%;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--card-border);
    border-radius: var(--border-radius-sm);
    color: var(--text-primary);
    padding: 12px;
    font-family: inherit;
    font-size: 13.5px;
    resize: none;
    outline: none;
    transition: border-color var(--transition-speed);
    line-height: 1.4;
    margin-bottom: 10px;
}

#ai-quick-input:focus {
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.04);
}

.ai-response-box {
    margin-top: 15px;
    padding: 12px 16px;
    border-radius: var(--border-radius-sm);
    font-size: 13px;
    line-height: 1.5;
    animation: fadeIn 0.3s ease;
}

.ai-response-box.success {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.25);
    color: #34d399;
}

.ai-response-box.error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.25);
    color: #f87171;
}

.ai-warning-box {
    background: rgba(245, 158, 11, 0.08);
    border: 1px solid rgba(245, 158, 11, 0.25);
    color: #fbbf24;
    padding: 14px 18px;
    border-radius: var(--border-radius-sm);
    font-size: 13px;
    line-height: 1.5;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: fadeIn 0.3s ease;
    margin-bottom: 16px;
}

.ai-warning-box i {
    font-size: 18px;
    flex-shrink: 0;
}


