:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface2: #232733;
    --border: #2d3141;
    --text: #e4e6ed;
    --text2: #8b8fa3;
    --primary: #4f8cff;
    --primary-hover: #3a7ae8;
    --income: #34d399;
    --income-bg: rgba(52,211,153,0.12);
    --expense: #f87171;
    --expense-bg: rgba(248,113,113,0.12);
    --balance: #fbbf24;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); line-height: 1.5; }
.hidden { display: none !important; }

/* Auth page */
.auth-page { display: flex; justify-content: center; align-items: center; min-height: 100vh; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; width: 380px; box-shadow: var(--shadow); text-align: center; }
.auth-card h1 { font-size: 1.8rem; margin-bottom: 0.2rem; }
.auth-card .subtitle { color: var(--text2); margin-bottom: 1.5rem; }

.tabs { display: flex; gap: 0; margin-bottom: 1.5rem; border-bottom: 1px solid var(--border); }
.tab { flex: 1; padding: 0.5rem; background: none; border: none; color: var(--text2); cursor: pointer; font-size: 0.95rem; border-bottom: 2px solid transparent; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.auth-form { display: flex; flex-direction: column; gap: 0.8rem; }

input, select, textarea {
    padding: 0.65rem 0.8rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.95rem;
    outline: none;
    width: 100%;
}
input:focus, select:focus { border-color: var(--primary); }

.btn { padding: 0.6rem 1.2rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface2); color: var(--text); cursor: pointer; font-size: 0.9rem; text-decoration: none; display: inline-flex; align-items: center; gap: 0.3rem; }
.btn:hover { background: var(--border); }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.small { padding: 0.3rem 0.7rem; font-size: 0.8rem; }
.btn.danger { background: var(--expense); color: #fff; border-color: var(--expense); }

.error { color: var(--expense); font-size: 0.85rem; margin-top: 0.5rem; padding: 0.5rem; background: var(--expense-bg); border-radius: var(--radius); }

/* Navbar */
.navbar { display: flex; align-items: center; gap: 1.5rem; padding: 0.8rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100; }
.logo { font-weight: 700; font-size: 1.1rem; }
.nav-links { display: flex; gap: 0.5rem; }
.nav-links a { padding: 0.4rem 0.8rem; color: var(--text2); text-decoration: none; border-radius: var(--radius); font-size: 0.9rem; }
.nav-links a:hover, .nav-links a.active { color: var(--primary); background: rgba(79,140,255,0.1); }
.nav-user { margin-left: auto; display: flex; align-items: center; gap: 0.8rem; color: var(--text2); font-size: 0.9rem; }

.container { max-width: 1100px; margin: 1.5rem auto; padding: 0 1rem; }

/* Summary cards */
.summary-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1.5rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.2rem; }
.card-label { font-size: 0.85rem; color: var(--text2); margin-bottom: 0.3rem; }
.card-value { font-size: 1.6rem; font-weight: 700; }
.income-card .card-value { color: var(--income); }
.expense-card .card-value { color: var(--expense); }
.balance-card .card-value { color: var(--balance); }

.grid-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1.5rem; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1rem; }
@media (max-width: 768px) { .grid-2col, .summary-cards, .settings-grid { grid-template-columns: 1fr; } }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.2rem; }
.panel h3 { margin-bottom: 1rem; font-size: 1rem; }
.panel .link { display: inline-block; margin-top: 0.8rem; color: var(--primary); text-decoration: none; font-size: 0.85rem; }
.panel form { display: flex; flex-direction: column; gap: 0.6rem; }
.panel form label { font-size: 0.85rem; color: var(--text2); }

.quick-form { display: flex; flex-direction: column; gap: 0.6rem; }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.toolbar-actions { display: flex; gap: 0.5rem; align-items: center; }

.filters { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; align-items: center; }
.filters select, .filters input { width: auto; min-width: 140px; }
.search-input { min-width: 200px !important; }

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.data-table th { background: var(--surface2); padding: 0.7rem 1rem; text-align: left; font-size: 0.85rem; color: var(--text2); font-weight: 600; }
.data-table td { padding: 0.65rem 1rem; border-top: 1px solid var(--border); font-size: 0.9rem; }
.data-table tr:hover td { background: rgba(79,140,255,0.04); }

.badge { padding: 0.15rem 0.5rem; border-radius: 4px; font-size: 0.78rem; font-weight: 600; }
.badge-income { background: var(--income-bg); color: var(--income); }
.badge-expense { background: var(--expense-bg); color: var(--expense); }
.badge-transfer { background: rgba(79,140,255,0.12); color: var(--primary); }

.btn-delete { background: none; border: none; color: var(--text2); cursor: pointer; font-size: 1rem; }
.btn-delete:hover { color: var(--expense); }

.pagination { display: flex; justify-content: center; gap: 0.3rem; margin-top: 1rem; }
.pagination button { padding: 0.4rem 0.7rem; background: var(--surface); border: 1px solid var(--border); color: var(--text); border-radius: var(--radius); cursor: pointer; font-size: 0.85rem; }
.pagination button.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; justify-content: center; align-items: center; z-index: 200; }
.modal-content { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); width: 420px; max-width: 95vw; box-shadow: var(--shadow); }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.2rem; border-bottom: 1px solid var(--border); }
.btn-close { background: none; border: none; color: var(--text2); font-size: 1.3rem; cursor: pointer; }
.modal-content form { padding: 1.2rem; display: flex; flex-direction: column; gap: 0.6rem; }
.modal-content label { font-size: 0.85rem; color: var(--text2); }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.5rem; }

.cat-row { display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.cat-row:last-child { border-bottom: none; }
.cat-name { display: flex; align-items: center; gap: 0.5rem; }
.cat-bar { height: 6px; border-radius: 3px; background: var(--primary); margin-top: 0.3rem; transition: width 0.3s; }

.bar-chart { display: flex; gap: 0.5rem; align-items: flex-end; height: 200px; padding: 0.5rem 0; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar { width: 100%; max-width: 60px; border-radius: 4px 4px 0 0; transition: height 0.3s; }
.bar.expense { background: var(--expense); }
.bar.income { background: var(--income); }
.bar-label { font-size: 0.7rem; color: var(--text2); margin-top: 0.3rem; text-align: center; }
.bar-value { font-size: 0.7rem; color: var(--text); margin-bottom: 0.2rem; }

.period-selector { display: flex; align-items: center; gap: 0.8rem; font-size: 1rem; font-weight: 600; }

.tx-item { display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.tx-item:last-child { border-bottom: none; }
.tx-item-left { display: flex; flex-direction: column; }
.tx-item-desc { font-size: 0.9rem; }
.tx-item-cat { font-size: 0.78rem; color: var(--text2); }
.tx-item-amount { font-weight: 600; font-size: 0.95rem; }
.tx-item-amount.income { color: var(--income); }
.tx-item-amount.expense { color: var(--expense); }

/* Toast */
.toast { position: fixed; bottom: 1.5rem; right: 1.5rem; padding: 0.8rem 1.2rem; border-radius: var(--radius); font-size: 0.9rem; z-index: 300; animation: slideIn 0.3s; box-shadow: var(--shadow); }
.toast.success { background: var(--success); color: #fff; }
.toast.error { background: var(--expense); color: #fff; }
.toast.info { background: var(--primary); color: #fff; }
@keyframes slideIn { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Budget cards */
.budget-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.budget-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.budget-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.budget-card-title { font-weight: 600; display: flex; align-items: center; gap: 0.4rem; }
.budget-card-amounts { display: flex; justify-content: space-between; font-size: 0.85rem; color: var(--text2); margin-bottom: 0.5rem; }
.budget-progress { height: 8px; background: var(--surface2); border-radius: 4px; overflow: hidden; margin-bottom: 0.3rem; }
.budget-progress-bar { height: 100%; border-radius: 4px; transition: width 0.3s; }
.budget-progress-bar.ok { background: var(--income); }
.budget-progress-bar.warn { background: var(--warning); }
.budget-progress-bar.over { background: var(--expense); }
.budget-card-footer { display: flex; justify-content: space-between; align-items: center; font-size: 0.8rem; }
.budget-card-footer .over { color: var(--expense); font-weight: 600; }
.budget-card-actions-inline { display: flex; gap: 0.3rem; }
.budget-delete { background: none; border: none; color: var(--text2); cursor: pointer; font-size: 0.8rem; }
.budget-delete:hover { color: var(--expense); }
.budget-edit { background: none; border: none; color: var(--text2); cursor: pointer; font-size: 0.8rem; }
.budget-edit:hover { color: var(--primary); }

/* 2FA */
.tfa-qr { display: flex; justify-content: center; margin: 0.5rem 0; }
.tfa-qr svg { max-width: 200px; max-height: 200px; background: #fff; border-radius: var(--radius); padding: 0.5rem; }
.tfa-secret { margin: 0.5rem 0; }

/* Trend chart */
.trend-chart { display: flex; gap: 2px; align-items: flex-end; height: 150px; padding: 0.5rem 0; position: relative; }
.trend-chart-inner { display: flex; gap: 2px; align-items: flex-end; width: 100%; height: 100%; }
.trend-bar-group { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 1px; }
.trend-bar { width: 100%; max-width: 30px; border-radius: 2px 2px 0 0; transition: height 0.3s; min-height: 2px; }
.trend-bar.income { background: var(--income); }
.trend-bar.expense { background: var(--expense); }
.trend-bar.balance { background: var(--balance); opacity: 0.6; }
.trend-label { font-size: 0.6rem; color: var(--text2); margin-top: 0.2rem; writing-mode: vertical-lr; transform: rotate(180deg); max-height: 40px; overflow: hidden; }
.trend-legend { display: flex; gap: 1rem; justify-content: center; margin-top: 0.5rem; font-size: 0.75rem; color: var(--text2); }
.trend-legend span { display: flex; align-items: center; gap: 0.3rem; }
.trend-dot { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.trend-avg-line { position: absolute; left: 0; right: 0; border-top: 2px dashed var(--primary); opacity: 0.7; pointer-events: none; z-index: 1; }
.trend-avg-label { position: absolute; right: 4px; font-size: 0.65rem; color: var(--primary); font-weight: 600; background: var(--bg); padding: 0 4px; border-radius: 3px; transform: translateY(-100%); pointer-events: none; }

/* Accounts */
.accounts-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.account-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.2rem; }
.account-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.6rem; }
.account-card-title { font-weight: 600; font-size: 1rem; display: flex; align-items: center; gap: 0.4rem; }
.account-card-balance { font-size: 1.8rem; font-weight: 700; color: var(--text); margin-bottom: 0.5rem; }
.account-progress { height: 8px; background: var(--surface2); border-radius: 4px; overflow: hidden; margin-bottom: 0.4rem; }
.account-progress-bar { height: 100%; border-radius: 4px; background: var(--primary); transition: width 0.3s; }
.account-progress-bar.warn { background: var(--warning); }
.account-progress-bar.ok { background: var(--income); }
.account-goal-info { display: flex; justify-content: space-between; font-size: 0.85rem; color: var(--text2); margin-bottom: 0.3rem; }
.account-goal-date { font-size: 0.8rem; color: var(--text2); }
.account-goal-reached { font-size: 0.85rem; color: var(--income); font-weight: 600; margin-top: 0.3rem; }
.account-card-actions { display: flex; gap: 0.3rem; margin-top: 0.8rem; justify-content: flex-end; }

/* Input row (inline fields) */
.input-row { display: flex; gap: 0.5rem; }
.input-row input { flex: 1; }
.input-row select { width: auto; min-width: 100px; flex-shrink: 0; }

/* Currency badge on amounts */
.tx-currency { font-size: 0.7rem; color: var(--text2); margin-left: 0.3rem; }
.conversion-preview { margin-top: 0.5rem; padding: 0.6rem 0.8rem; background: rgba(79,140,255,0.1); border: 1px solid rgba(79,140,255,0.3); border-radius: var(--radius); font-size: 0.85rem; color: var(--primary); }
.conversion-preview .arrow { margin: 0 0.4rem; }

/* Currency tabs */
.currency-tabs { display: flex; gap: 0.3rem; margin-bottom: 1rem; }
.currency-tab { padding: 0.4rem 1rem; border-radius: var(--radius); background: var(--surface2); border: 1px solid var(--border); color: var(--text2); cursor: pointer; font-size: 0.85rem; transition: all 0.2s; }
.currency-tab:hover { color: var(--text); border-color: var(--primary); }
.currency-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
