/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #e0e7ff;
    --income: #10b981;
    --income-light: #d1fae5;
    --expense: #ef4444;
    --expense-light: #fee2e2;
    --neutral: #6b7280;
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e5e7eb;
    --text: #111827;
    --text-muted: #9ca3af;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
    --radius: 12px;
    --radius-sm: 8px;
}

html, body { height: 100%; font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 15px; color: var(--text); background: var(--bg); }

/* ===== AUTH PAGE ===== */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); padding: 1rem; }

.auth-container { background: var(--surface); border-radius: 20px; padding: 2.5rem; width: 100%; max-width: 420px; box-shadow: 0 25px 50px rgba(0,0,0,.2); }

.auth-logo { text-align: center; margin-bottom: 2rem; }
.auth-logo svg { margin-bottom: .75rem; }
.auth-logo h1 { font-size: 1.75rem; font-weight: 800; color: var(--primary); margin-bottom: .25rem; }
.auth-logo p { color: var(--neutral); font-size: .9rem; }

.auth-tabs { display: flex; background: var(--bg); border-radius: var(--radius-sm); padding: 4px; margin-bottom: 1.5rem; gap: 4px; }
.tab-btn { flex: 1; padding: .6rem; border: none; background: transparent; border-radius: 6px; cursor: pointer; font-weight: 600; font-size: .9rem; color: var(--neutral); transition: all .2s; }
.tab-btn.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }

.auth-form { display: flex; flex-direction: column; gap: 1rem; }
.auth-form.hidden { display: none; }

.form-group { display: flex; flex-direction: column; gap: .4rem; }
.form-group label { font-weight: 600; font-size: .85rem; color: var(--text); }
.form-group input { padding: .75rem 1rem; border: 2px solid var(--border); border-radius: var(--radius-sm); font-size: .95rem; transition: border-color .2s; outline: none; }
.form-group input:focus { border-color: var(--primary); }

.btn-primary { width: 100%; padding: .85rem; background: var(--primary); color: white; border: none; border-radius: var(--radius-sm); font-size: 1rem; font-weight: 600; cursor: pointer; transition: background .2s; margin-top: .5rem; }
.btn-primary:hover { background: var(--primary-dark); }

.alert { padding: .75rem 1rem; border-radius: var(--radius-sm); font-size: .9rem; margin-bottom: 1rem; }
.alert.hidden { display: none; }
.alert.error { background: var(--expense-light); color: #b91c1c; border: 1px solid #fca5a5; }
.alert.success { background: var(--income-light); color: #065f46; border: 1px solid #6ee7b7; }

/* ===== NAVBAR ===== */
.navbar { position: sticky; top: 0; z-index: 100; background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 1.5rem; height: 60px; display: flex; align-items: center; justify-content: space-between; box-shadow: var(--shadow); }
.nav-brand { display: flex; align-items: center; gap: .6rem; font-size: 1.2rem; font-weight: 800; color: var(--primary); }
.nav-links { display: flex; align-items: center; gap: 1rem; }
.nav-link { text-decoration: none; color: var(--neutral); font-weight: 500; padding: .4rem .75rem; border-radius: var(--radius-sm); transition: all .2s; font-size: .9rem; }
.nav-link:hover { color: var(--primary); background: var(--primary-light); }
.nav-link.active { color: var(--primary); background: var(--primary-light); font-weight: 600; }
.nav-user { font-size: .85rem; color: var(--neutral); }
.btn-logout { padding: .4rem .9rem; background: transparent; border: 1.5px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; font-size: .85rem; color: var(--neutral); transition: all .2s; }
.btn-logout:hover { border-color: var(--expense); color: var(--expense); }

/* ===== CHAT PAGE ===== */
.app-page { display: flex; flex-direction: column; height: 100vh; }
.chat-layout { flex: 1; display: flex; justify-content: center; overflow: hidden; padding: 1rem; }
.chat-container { width: 100%; max-width: 800px; display: flex; flex-direction: column; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-md); overflow: hidden; border: 1px solid var(--border); }

.chat-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: .75rem; background: var(--surface); }
.ai-avatar svg { display: block; }
.chat-header h2 { font-size: 1rem; font-weight: 700; }
.status-online { font-size: .8rem; color: var(--income); }

.chat-messages { flex: 1; overflow-y: auto; padding: 1.25rem; display: flex; flex-direction: column; gap: .75rem; background: var(--bg); }

.message { display: flex; }
.message.user { justify-content: flex-end; }
.message.assistant { justify-content: flex-start; }

.message-bubble { max-width: 75%; padding: .75rem 1rem; border-radius: 18px; line-height: 1.55; font-size: .95rem; }
.message.user .message-bubble { background: var(--primary); color: white; border-bottom-right-radius: 4px; }
.message.assistant .message-bubble { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-bottom-left-radius: 4px; box-shadow: var(--shadow); }

/* Typing indicator */
.typing { display: flex; align-items: center; gap: 5px; padding: .75rem 1.1rem; }
.typing span { width: 8px; height: 8px; background: var(--neutral); border-radius: 50%; animation: bounce 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-6px); } }

.chat-input-area { padding: .75rem 1rem; border-top: 1px solid var(--border); background: var(--surface); }
.chat-input-wrapper { display: flex; gap: .5rem; align-items: flex-end; background: var(--bg); border: 2px solid var(--border); border-radius: 14px; padding: .5rem .5rem .5rem .75rem; transition: border-color .2s; }
.chat-input-wrapper:focus-within { border-color: var(--primary); }
.chat-input-wrapper textarea { flex: 1; border: none; background: transparent; resize: none; outline: none; font-size: .95rem; line-height: 1.5; max-height: 120px; font-family: inherit; }
.btn-send { width: 36px; height: 36px; background: var(--primary); color: white; border: none; border-radius: 10px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: background .2s; flex-shrink: 0; }
.btn-send:hover { background: var(--primary-dark); }
.btn-send:disabled { opacity: .5; cursor: not-allowed; }
.input-hint { font-size: .75rem; color: var(--text-muted); margin-top: .4rem; text-align: center; }

/* ===== DASHBOARD ===== */
.dashboard-container { flex: 1; overflow-y: auto; width: 100%; max-width: 1200px; margin: 0 auto; padding: 1.5rem; }
.dashboard-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 1.5rem; flex-wrap: wrap; gap: 1rem; }
.dashboard-header h1 { font-size: 1.6rem; font-weight: 800; }
.month-label { color: var(--neutral); font-size: .95rem; margin-top: .25rem; }
.month-selector { display: flex; align-items: center; gap: .6rem; font-size: .9rem; color: var(--neutral); }
.month-selector select { padding: .5rem .75rem; border: 1.5px solid var(--border); border-radius: var(--radius-sm); font-size: .9rem; outline: none; cursor: pointer; }

/* Summary cards */
.summary-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.card { background: var(--surface); border-radius: var(--radius); padding: 1.25rem; display: flex; align-items: center; gap: 1rem; box-shadow: var(--shadow); border: 1px solid var(--border); }
.card-icon { width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.4rem; font-weight: 800; flex-shrink: 0; }
.card-income .card-icon { background: var(--income-light); color: var(--income); }
.card-expense .card-icon { background: var(--expense-light); color: var(--expense); }
.card-positive .card-icon { background: var(--income-light); color: var(--income); }
.card-negative .card-icon { background: var(--expense-light); color: var(--expense); }
.card-neutral .card-icon { background: var(--primary-light); color: var(--primary); }
.card-invest .card-icon { background: #d1fae5; color: #059669; font-size: 1.2rem; }
.card-invest .card-value { color: #059669; }
.card-info { display: flex; flex-direction: column; gap: .2rem; min-width: 0; }
.card-label { font-size: .8rem; color: var(--neutral); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.card-value { font-size: 1.25rem; font-weight: 800; white-space: nowrap; }
.card-income .card-value { color: var(--income); }
.card-expense .card-value { color: var(--expense); }
.card-positive .card-value { color: var(--income); }
.card-negative .card-value { color: var(--expense); }

/* Dashboard grid */
.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1.25rem; margin-bottom: 1.5rem; }
.dashboard-section { background: var(--surface); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); border: 1px solid var(--border); }
.dashboard-section h2 { font-size: 1rem; font-weight: 700; margin-bottom: 1rem; color: var(--text); }
.empty-state { color: var(--text-muted); font-size: .9rem; padding: 1rem 0; }

/* Bar list */
.bar-list { display: flex; flex-direction: column; gap: .85rem; }
.bar-item {}
.bar-meta { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: .35rem; font-size: .88rem; }
.bar-label { font-weight: 600; }
.bar-value { color: var(--neutral); }
.bar-value em { font-style: normal; font-size: .8rem; color: var(--text-muted); }
.bar-track { height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--primary), #8b5cf6); border-radius: 99px; transition: width .5s ease; }

/* Pill list */
.pill-list { display: flex; flex-direction: column; gap: .65rem; }
.pill-item { display: flex; align-items: center; gap: .75rem; padding: .6rem .75rem; background: var(--bg); border-radius: var(--radius-sm); }
.pill-icon { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 1rem; flex-shrink: 0; }
.pay-icon { background: var(--primary-light); color: var(--primary); }
.person-icon { background: #fef3c7; color: #d97706; font-weight: 800; font-size: .9rem; }
.pill-info { flex: 1; min-width: 0; }
.pill-name { display: block; font-weight: 600; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill-value { font-size: .82rem; color: var(--neutral); }
.pill-pct { font-size: .85rem; font-weight: 700; color: var(--primary); background: var(--primary-light); padding: .2rem .6rem; border-radius: 99px; flex-shrink: 0; }

/* Balance visual */
.balance-visual { display: flex; flex-direction: column; gap: 1rem; }
.balance-bar-wrap { display: flex; align-items: center; gap: .75rem; }
.balance-label-left { width: 70px; font-size: .85rem; font-weight: 600; color: var(--neutral); text-align: right; flex-shrink: 0; }
.balance-bar { flex: 1; height: 28px; background: var(--bg); border-radius: 8px; overflow: hidden; }
.balance-fill { height: 100%; border-radius: 8px; display: flex; align-items: center; padding: 0 .75rem; font-size: .8rem; font-weight: 700; color: white; min-width: 60px; transition: width .5s ease; }
.balance-fill.income { background: var(--income); }
.balance-fill.expense { background: var(--expense); }
.saldo-final { text-align: center; font-weight: 800; font-size: 1.1rem; padding: .75rem; border-radius: var(--radius-sm); margin-top: .25rem; }
.saldo-final.positive { background: var(--income-light); color: #065f46; }
.saldo-final.negative { background: var(--expense-light); color: #b91c1c; }

/* Transactions table */
.transactions-section { background: var(--surface); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); border: 1px solid var(--border); }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; flex-wrap: wrap; gap: .75rem; }
.section-header h2 { font-size: 1rem; font-weight: 700; }
.filter-btns { display: flex; gap: .4rem; }
.filter-btn { padding: .35rem .85rem; border: 1.5px solid var(--border); background: transparent; border-radius: 99px; cursor: pointer; font-size: .82rem; font-weight: 600; color: var(--neutral); transition: all .2s; }
.filter-btn.active { background: var(--primary); border-color: var(--primary); color: white; }

.table-wrapper { overflow-x: auto; }
.transactions-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.transactions-table th { text-align: left; padding: .6rem .75rem; font-size: .78rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; border-bottom: 2px solid var(--border); white-space: nowrap; }
.transactions-table td { padding: .7rem .75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.transactions-table tr:last-child td { border-bottom: none; }
.transactions-table tbody tr:hover { background: var(--bg); }
.desc-cell { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--text-muted); }

.badge { padding: .25rem .65rem; border-radius: 99px; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.badge-receita { background: var(--income-light); color: #065f46; }
.badge-despesa { background: var(--expense-light); color: #b91c1c; }
.badge-investimento { background: #d1fae5; color: #065f46; }
.badge-aporte { background: #d1fae5; color: #059669; }
.badge-retirada { background: #fef3c7; color: #b45309; }

.amount-cell { font-weight: 700; white-space: nowrap; }
.amount-cell.receita { color: var(--income); }
.amount-cell.despesa { color: var(--expense); }

.btn-delete { background: transparent; border: none; color: var(--text-muted); font-size: 1.2rem; cursor: pointer; padding: .2rem .5rem; border-radius: 6px; line-height: 1; transition: all .15s; }
.btn-delete:hover { background: var(--expense-light); color: var(--expense); }

.empty-transactions { text-align: center; padding: 3rem 1rem; color: var(--neutral); }
.empty-transactions p { margin-bottom: 1rem; }
.empty-transactions .btn-primary { display: inline-block; width: auto; padding: .7rem 1.5rem; text-decoration: none; }

/* ===== PROFILE ===== */
.profile-container { flex: 1; overflow-y: auto; max-width: 680px; width: 100%; margin: 0 auto; padding: 1.5rem; display: flex; flex-direction: column; gap: 1.25rem; }
.profile-container h1 { font-size: 1.6rem; font-weight: 800; margin-bottom: .25rem; }
.profile-card { background: var(--surface); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow); border: 1px solid var(--border); }
.profile-card h2 { font-size: 1rem; font-weight: 700; margin-bottom: 1rem; display: flex; align-items: center; }
.profile-desc { color: var(--neutral); font-size: .9rem; margin-bottom: 1rem; line-height: 1.5; }
.profile-card .form-group { margin-bottom: .85rem; }
.password-wrap { display: flex; align-items: center; border: 2px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; transition: border-color .2s; background: var(--surface); }
.password-wrap:focus-within { border-color: var(--primary); }
.password-wrap input { flex: 1; border: none; outline: none; padding: .75rem; font-size: .95rem; background: transparent; }
.btn-eye { background: none; border: none; cursor: pointer; padding: 0 .75rem; color: var(--neutral); display: flex; align-items: center; flex-shrink: 0; }
.btn-eye:hover { color: var(--primary); }
.phone-input-wrap { display: flex; align-items: center; border: 2px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; transition: border-color .2s; }
.phone-input-wrap:focus-within { border-color: var(--primary); }
.phone-prefix { padding: .75rem .75rem .75rem 1rem; background: var(--bg); color: var(--neutral); font-weight: 600; border-right: 1px solid var(--border); }
.phone-input-wrap input { border: none; flex: 1; padding: .75rem; outline: none; font-size: .95rem; }
.whatsapp-actions { display: flex; gap: .75rem; align-items: center; margin-top: .5rem; }
.btn-remove-wa { padding: .7rem 1.2rem; background: transparent; border: 1.5px solid var(--expense); color: var(--expense); border-radius: var(--radius-sm); cursor: pointer; font-weight: 600; font-size: .9rem; transition: all .2s; }
.btn-remove-wa:hover { background: var(--expense-light); }
.wa-status { display: inline-flex; align-items: center; gap: .4rem; margin-top: .85rem; padding: .5rem .85rem; background: var(--income-light); color: #065f46; border-radius: 99px; font-size: .85rem; font-weight: 600; }
.wa-status.connected svg { stroke: var(--income); }
.wa-instructions { margin-top: 1.25rem; padding-top: 1.25rem; border-top: 1px solid var(--border); }
.wa-instructions h3 { font-size: .9rem; font-weight: 700; margin-bottom: .75rem; color: var(--neutral); text-transform: uppercase; letter-spacing: .05em; }
.wa-instructions ol { padding-left: 1.25rem; color: var(--text); font-size: .9rem; line-height: 2; }
.wa-instructions strong { color: var(--primary); }
.wa-example { margin-top: .85rem; background: var(--bg); border-radius: var(--radius-sm); padding: .85rem 1rem; font-size: .88rem; line-height: 1.9; }
.wa-example p { margin: 0; }

/* Upcoming bills */
.upcoming-bills { background: var(--surface); border-radius: var(--radius); border: 1px solid #fbbf24; box-shadow: var(--shadow); padding: 1.25rem; margin-bottom: 1.5rem; }
.upcoming-bills h2 { font-size: 1rem; font-weight: 700; margin-bottom: 1rem; color: #92400e; }
.bills-list { display: flex; flex-direction: column; gap: .6rem; }
.bill-item { display: flex; align-items: center; gap: .85rem; padding: .75rem 1rem; background: var(--bg); border-radius: var(--radius-sm); border-left: 4px solid #fbbf24; }
.bill-item.bill-urgent { border-left-color: #f97316; background: #fff7ed; }
.bill-item.bill-today { border-left-color: #ef4444; background: #fef2f2; }
.bill-icon { font-size: 1.2rem; flex-shrink: 0; }
.bill-info { flex: 1; min-width: 0; }
.bill-name { display: block; font-weight: 600; font-size: .9rem; }
.bill-cat { display: block; font-size: .8rem; color: var(--neutral); }
.bill-right { text-align: right; flex-shrink: 0; }
.bill-amount { display: block; font-weight: 700; font-size: .95rem; color: var(--expense); }
.bill-due { display: block; font-size: .8rem; color: var(--neutral); margin-top: .1rem; }
.bill-expires { display: block; font-size: .75rem; color: #9ca3af; margin-top: .1rem; }

/* Export button */
.export-btn-wrap { margin-top: .75rem; }
.btn-export {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    padding: .5rem 1rem;
    background: #16a34a;
    color: white;
    border-radius: 8px;
    font-size: .85rem;
    font-weight: 600;
    text-decoration: none;
    transition: background .2s;
}
.btn-export:hover { background: #15803d; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--neutral); }

/* Responsive */
@media (max-width: 600px) {
    .navbar { padding: 0 1rem; }
    .nav-user { display: none; }
    .dashboard-container { padding: .75rem; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .summary-cards { grid-template-columns: 1fr 1fr; }
    .message-bubble { max-width: 90%; }
    .chat-layout { padding: .5rem; }
}
