:root {
  --bg: #0f172a; --panel: #1e293b; --card: #ffffff; --ink: #0f172a;
  --muted: #64748b; --line: #e2e8f0; --brand: #4f46e5; --brand-d: #4338ca;
  --green: #16a34a; --red: #dc2626; --soft: #f8fafc;
  --radius: 12px; --shadow: 0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.04);
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--soft); color: var(--ink); font-size: 14px; line-height: 1.5;
}
a { color: var(--brand); text-decoration: none; }
.muted { color: var(--muted); }
.sm { font-size: 12.5px; }
.big { font-size: 22px; font-weight: 700; }
.hidden { display: none !important; }
.r { text-align: right; }
.centered { text-align: center; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 60px;
  background: var(--bg); color: #e2e8f0; position: sticky; top: 0; z-index: 10;
}
.topbar .brand { font-weight: 700; color: #fff; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { color: #cbd5e1; padding: 8px 12px; border-radius: 8px; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav a.on { background: var(--brand); color: #fff; }
.userbox { display: flex; align-items: center; gap: 12px; }
.userbox .muted { color: #94a3b8; }
.nav-burger { display: none; background: none; border: 0; color: #fff; font-size: 24px; line-height: 1; cursor: pointer; padding: 6px 8px; margin-left: auto; }

.container { max-width: 1120px; margin: 0 auto; padding: 24px; }
.footer { text-align: center; padding: 24px; }

/* Cards & layout */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card h3 { margin: 0 0 14px; font-size: 15px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.page-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 18px; }
.page-head h1 { margin: 0; font-size: 22px; }
.filters, .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.stack { display: flex; flex-direction: column; gap: 10px; }
@media (max-width: 860px) {
  .grid-2 { grid-template-columns: 1fr; }
  /* Mobile top bar: brand + burger on the first row; nav and user actions
     collapse into a full-width menu below, toggled by the burger. */
  .topbar { flex-wrap: wrap; height: auto; min-height: 56px; padding: 10px 16px; column-gap: 12px; row-gap: 0; align-items: center; }
  .brand { order: 1; }
  .nav-burger { display: block; order: 2; margin-left: auto; }
  .nav { order: 3; flex: 0 0 100%; display: none; flex-direction: column; gap: 2px; }
  .userbox { order: 4; flex: 0 0 100%; display: none; }
  .topbar.open .nav { display: flex; }
  .topbar.open .nav a { padding: 12px 10px; border-radius: 8px; }
  .topbar.open .userbox { display: flex; justify-content: space-between; align-items: center; padding-top: 8px; margin-top: 8px; border-top: 1px solid rgba(255,255,255,.1); }
  .topbar.open .userbox .muted { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%; }
  .container { padding: 16px; }
}

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(4,1fr); gap: 14px; margin-bottom: 18px; }
.kpi { padding: 18px 20px; position: relative; overflow: hidden; }
.kpi-top { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.kpi-ic { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; font-size: 16px; background: #eef2ff; color: #4f46e5; flex-shrink: 0; }
.kpi-label { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.kpi-val { font-size: 26px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.kpi-val.income { color: var(--green); }
.kpi-val.expense { color: var(--red); }
.kpi-income .kpi-ic { background: #dcfce7; color: #16a34a; }
.kpi-expense .kpi-ic { background: #fee2e2; color: #dc2626; }
.kpi-net .kpi-ic { background: #e0e7ff; color: #4f46e5; }
.kpi-rate .kpi-ic { background: #fef9c3; color: #ca8a04; }
.kpi-assets .kpi-ic { background: #dcfce7; color: #16a34a; }
.kpi-liab .kpi-ic { background: #fee2e2; color: #dc2626; }
/* Highlighted net-worth tile */
.kpi-networth { background: linear-gradient(135deg, #4f46e5, #7c3aed); border-color: transparent; box-shadow: 0 12px 28px -12px rgba(79,70,229,.6); }
.kpi-networth .kpi-label { color: rgba(255,255,255,.85); }
.kpi-networth .kpi-val { color: #fff; }
.kpi-networth .kpi-ic { background: rgba(255,255,255,.2); color: #fff; }

/* Card headers with icon */
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-head .ic { font-size: 16px; line-height: 1; }
.card-head h3 { margin: 0; }
@media (max-width: 800px) { .kpis { grid-template-columns: 1fr 1fr; } }
@media (max-width: 620px) {
  .page-head { align-items: stretch; }
  .page-head h1 { font-size: 20px; }
  /* Filters become a full-width stacked group that's easy to tap */
  .filters { width: 100%; }
  .filters .input, .filters .btn { flex: 1 1 140px; }
  /* Tables: keep readable on small screens; allow side-scroll for wide ones */
  .table th, .table td { padding: 8px 8px; font-size: 13px; }
  .table.compact th, .table.compact td { font-size: 12px; }
  .kpi-val { font-size: 20px; }
  .modal { padding: 18px; }
  .split-line { grid-template-columns: 1fr 90px 26px; }
  .row { gap: 6px; }
}

/* Forms */
.input { padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; font: inherit; background: #fff; color: var(--ink); transition: border-color .15s, box-shadow .15s; }
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79,70,229,.15); }
.input.sm { padding: 7px 10px; font-size: 13px; }
select.input {
  cursor: pointer; appearance: none; -webkit-appearance: none; -moz-appearance: none; padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%2394a3b8' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
}
select.input:disabled { background-color: var(--soft); color: var(--muted); cursor: not-allowed; }
.btn { background: var(--brand); color: #fff; border: 0; padding: 9px 16px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer; transition: background .15s, transform .08s, box-shadow .15s; }
.btn:hover { background: var(--brand-d); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(79,70,229,.3); }
.btn.sm { padding: 6px 14px; font-size: 13px; }
.btn.ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--soft); }
.btn.success { background: #059669; }
.btn.success:hover { background: #047857; }
.btn.block { width: 100%; display: block; text-align: center; }
.btn.google { background: #fff; color: #1f2937; border: 1px solid var(--line); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; color: var(--muted); font-weight: 600; font-size: 11.5px; padding: 10px 12px; border-bottom: 1px solid var(--line); text-transform: uppercase; letter-spacing: .04em; background: var(--soft); position: sticky; top: 0; z-index: 1; }
.table td { padding: 12px 12px; border-bottom: 1px solid #eef1f6; vertical-align: middle; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: #fafbff; }
.table.compact td, .table.compact th { padding: 9px 10px; font-size: 13px; }
.table-scroll { overflow-x: auto; max-height: 600px; -webkit-overflow-scrolling: touch; }
.amount-pos { color: var(--green); font-weight: 600; }
.amount-neg { color: var(--red); font-weight: 600; }

/* Badges & chips */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 600; letter-spacing: .01em; }
.badge.pending { background: #fef3c7; color: #92400e; }
.badge.reconciled { background: #dcfce7; color: #166534; }
.badge.duplicate { background: #fee2e2; color: #991b1b; }
.badge.ignored { background: #e2e8f0; color: #475569; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.list { list-style: none; padding: 0; margin: 0 0 12px; }
.list li { padding: 7px 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips li { border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; }

/* Alerts */
.alert { padding: 10px 14px; border-radius: 8px; background: var(--soft); border: 1px solid var(--line); margin: 8px 0; }
.alert.error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert.info { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.alert.success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }

/* Auth */
.auth-wrap { min-height: 80vh; display: flex; align-items: center; justify-content: center; }
.auth-card { max-width: 380px; width: 100%; text-align: center; }
.auth-card .brand { margin-bottom: 8px; }
.divider { display: flex; align-items: center; text-align: center; color: var(--muted); margin: 16px 0; font-size: 12px; }
.divider::before, .divider::after { content: ''; flex: 1; border-bottom: 1px solid var(--line); }
.divider span { padding: 0 10px; }

/* Budget bars */
.budget-row { padding: 12px 0; border-bottom: 1px solid var(--line); }
.budget-row:last-child { border-bottom: 0; }
.bar { height: 10px; background: var(--line); border-radius: 999px; overflow: hidden; margin: 8px 0; }
.bar-fill { height: 100%; background: var(--brand); border-radius: 999px; transition: width .3s; }
.bar-fill.over { background: var(--red); }

/* Badge for transfers / source */
.badge.transfer { background: #e0e7ff; color: #3730a3; }
.badge.manual { background: #f1f5f9; color: #475569; }
.badge.split { background: #fae8ff; color: #86198f; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { background: #fff; border-radius: var(--radius); padding: 22px; width: 92%; max-width: 480px; max-height: 88vh; overflow: auto; }
.modal h3 { margin-top: 0; }
.modal .row { margin-bottom: 10px; }
.split-line { display: grid; grid-template-columns: 1fr 110px 28px; gap: 8px; margin-bottom: 8px; align-items: center; }
.icon-btn { background: none; border: 0; cursor: pointer; font-size: 16px; color: var(--muted); }
.actions-cell { white-space: nowrap; }
.actions-cell button { margin-left: 4px; }

/* Mapping grid */
.mapping-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.mapping-grid label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
