:root {
  --font-sans: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f4f6fc;
  --border: #ecedf4;
  --text: #131728;
  --muted: #83879c;
  --primary: #3366ff;
  --primary-2: #37c3e8;
  --primary-ink: #ffffff;
  --income: #17a673;
  --income-bg: #e8f6ef;
  --expense: #ef4b4b;
  --expense-bg: #fdecec;
  --amber: #f2a516;
  --violet: #7c66f2;
  --shadow: 0 1px 2px rgba(17,20,40,.03), 0 12px 30px -16px rgba(17,20,40,.14);
  --shadow-sm: 0 1px 2px rgba(17,20,40,.05);
  --radius: 20px;
  --radius-sm: 12px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0c0e16;
  --surface: #14171f;
  --surface-2: #1a1e29;
  --border: #252a36;
  --text: #edeef4;
  --muted: #8b90a4;
  --primary: #5b86ff;
  --primary-2: #47cdee;
  --income: #34d399;
  --income-bg: #10241d;
  --expense: #fb7185;
  --expense-bg: #2c1a20;
  --amber: #f4b64c;
  --violet: #9d8bf7;
  --shadow: 0 1px 2px rgba(0,0,0,.25), 0 16px 40px -22px rgba(0,0,0,.6);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { max-width: 100%; overflow-x: hidden; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-weight: 400;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  line-height: 1.55;
  letter-spacing: -.006em;
}

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

/* ---- Top nav ---- */
.nav {
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  backdrop-filter: saturate(1.2) blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.nav-inner {
  max-width: 1120px; margin: 0 auto; padding: 0 22px;
  display: flex; align-items: center; gap: 10px; height: 64px;
}
.brand { font-weight: 600; font-size: 18px; letter-spacing: -.02em; display: flex; align-items: center; gap: 10px; }
.brand .dot {
  width: 27px; height: 27px; border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  display: inline-block; box-shadow: 0 6px 14px -5px color-mix(in srgb, var(--primary) 55%, transparent);
}
.nav-links { display: flex; gap: 2px; margin-left: 22px; }
.nav-links a {
  padding: 9px 15px; border-radius: 999px; color: var(--muted); font-weight: 500; font-size: 15px;
  transition: color .15s, background .15s;
}
.nav-links a.active { background: var(--surface-2); color: var(--text); }
.nav-links a:hover { color: var(--text); }
.nav-spacer { flex: 1; }
.nav .logout { color: var(--muted); font-size: 14px; font-weight: 500; }
.nav .logout:hover { color: var(--expense); }

.theme-toggle {
  width: 38px; height: 38px; border-radius: 11px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); cursor: pointer; display: inline-flex;
  align-items: center; justify-content: center; margin-right: 6px; box-shadow: var(--shadow-sm);
  transition: color .15s, border-color .15s;
}
.theme-toggle:hover { color: var(--text); border-color: var(--primary); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .ic-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .ic-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .ic-moon { display: none; }

.nav-burger {
  display: none; width: 38px; height: 38px; border-radius: 11px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; align-items: center; justify-content: center;
  margin-left: 6px; box-shadow: var(--shadow-sm);
}
.nav-burger svg { width: 20px; height: 20px; }

@media (max-width: 720px) {
  .nav-burger { display: inline-flex; }
  .nav-links {
    position: absolute; top: 64px; left: 0; right: 0; margin-left: 0;
    flex-direction: column; gap: 2px; padding: 8px;
    background: var(--surface); border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow); display: none;
  }
  .nav.open .nav-links { display: flex; }
  .nav-links a { padding: 12px 14px; border-radius: 10px; }
}

/* ---- Layout ---- */
.wrap { max-width: 1120px; margin: 0 auto; padding: 30px 22px 66px; }
.page-head { display: flex; align-items: center; gap: 14px; margin: 4px 0 24px; flex-wrap: wrap; }
.page-head h1 { font-size: 25px; margin: 0; letter-spacing: -.025em; font-weight: 600; }
.month-nav { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.month-nav a, .month-nav span {
  display: inline-flex; align-items: center; justify-content: center;
  height: 40px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 500; font-size: 14px;
  box-shadow: var(--shadow-sm);
}
.month-nav a.arrow { width: 40px; padding: 0; color: var(--muted); }
.month-nav a:hover { border-color: var(--primary); color: var(--primary); }

/* ---- Cards / grid ---- */
.grid { display: grid; gap: 18px; }
.kpis { grid-template-columns: repeat(4, 1fr); }
.cols-2 { grid-template-columns: 1.6fr 1fr; align-items: stretch; }
.col-stack { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.col-stack > .card { flex: 0 0 auto; }
@media (max-width: 860px) { .kpis { grid-template-columns: repeat(2, 1fr); } .cols-2 { grid-template-columns: 1fr; } }
@media (max-width: 480px) { .kpis { grid-template-columns: 1fr; } }

/* Money flow chart */
.chart { width: 100%; height: auto; display: block; }
.chart-legend { display: flex; gap: 18px; margin-bottom: 6px; }
.chart-legend .lg { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); font-weight: 500; }
.chart-legend .lg::before { content: ""; width: 9px; height: 9px; border-radius: 3px; }
.chart-legend .lg.income::before { background: var(--income); }
.chart-legend .lg.expense::before { background: var(--expense); }
.card-head { display: flex; align-items: center; justify-content: space-between; margin: 0 0 16px; }
.card-head h2 { margin: 0; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow);
}
.card h2 { font-size: 14px; margin: 0 0 18px; color: var(--muted); font-weight: 500; letter-spacing: 0; }

/* ---- KPI cards with colored accent ---- */
.kpi { position: relative; padding-left: 24px; overflow: hidden; }
.kpi::before { content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 4px; border-radius: 999px; background: var(--primary); }
.kpi.k-balance::before { background: linear-gradient(var(--primary), var(--primary-2)); }
.kpi.k-income::before  { background: var(--income); }
.kpi.k-expense::before { background: var(--amber); }
.kpi.k-net::before     { background: var(--violet); }
.kpi .label { font-size: 13px; color: var(--muted); font-weight: 500; }
.kpi .value { font-size: 27px; font-weight: 600; letter-spacing: -.02em; margin-top: 9px; font-variant-numeric: tabular-nums; }
.kpi .value.pos { color: var(--income); }
.kpi .value.neg { color: var(--expense); }
.kpi .value.primary { color: var(--primary); }

/* ---- Accounts list ---- */
.acct { display: flex; justify-content: space-between; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--border); }
.acct:last-child { border-bottom: none; }
.acct .name { font-weight: 500; }
.acct .bal { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---- Category bars ---- */
.bar-row { margin-bottom: 16px; }
.bar-row:last-child { margin-bottom: 0; }
.bar-top { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 8px; font-weight: 500; }
.bar-top .amt { font-weight: 600; font-variant-numeric: tabular-nums; }
.bar-track { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-2)); border-radius: 999px; }

/* ---- Table ---- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll .tx-table { min-width: 440px; }
.tx-table { width: 100%; border-collapse: collapse; }
.tx-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 0 8px 12px; font-weight: 500; }
.tx-table td { padding: 14px 8px; border-top: 1px solid var(--border); font-size: 15px; vertical-align: middle; }
.tx-table tr:first-child td { border-top: none; }
.tx-date { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx-amt { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx-amt.income { color: var(--income); }
.tx-amt.expense { color: var(--expense); }
.pill { display: inline-block; padding: 4px 11px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.pill.income { background: var(--income-bg); color: var(--income); }
.pill.expense { background: var(--expense-bg); color: var(--expense); }
.pill.pessoal { background: var(--surface-2); color: var(--muted); }
.pill.empresa { background: color-mix(in srgb, var(--primary) 14%, transparent); color: var(--primary); }
.tx-desc { color: var(--muted); font-size: 13px; margin-top: 2px; }
.empty { color: var(--muted); text-align: center; padding: 30px 0; }

.scope-totals { display: flex; gap: 22px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.scope-totals .st { font-size: 14px; color: var(--muted); }
.scope-totals .st b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.acct .meta { display: flex; align-items: center; gap: 10px; }
.acct-actions form { display: inline; }

/* ---- Buttons / forms ---- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; height: 44px; padding: 0 20px;
  border-radius: 13px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-weight: 500; font-size: 15px; cursor: pointer; font-family: inherit;
  box-shadow: var(--shadow-sm); transition: transform .05s, border-color .15s, filter .15s;
}
.btn:hover { border-color: var(--primary); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: var(--primary-ink); border-color: transparent;
  box-shadow: 0 10px 22px -12px color-mix(in srgb, var(--primary) 70%, transparent);
}
.btn.primary:hover { filter: brightness(1.05); }
.btn.icon-del { height: 36px; width: 36px; padding: 0; justify-content: center; color: var(--muted); box-shadow: none; }
.btn.icon-del:hover { color: var(--expense); border-color: var(--expense); }

.form-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; align-items: end; }
@media (max-width: 760px) { .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; } }
.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field.span-2 { grid-column: span 2; }
.field label { font-size: 13px; color: var(--muted); font-weight: 500; }
.input, select.input {
  height: 44px; padding: 0 13px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-size: 15px; font-family: inherit;
  width: 100%; min-width: 0;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, select.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); }

.seg { display: inline-flex; flex-wrap: wrap; max-width: 100%; gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 4px; box-shadow: var(--shadow-sm); }
.seg a { padding: 8px 15px; border-radius: 9px; font-size: 14px; font-weight: 500; color: var(--muted); white-space: nowrap; }
.seg a.active { background: var(--surface-2); color: var(--text); }

@media (max-width: 480px) {
  .wrap { padding: 22px 14px 60px; }
  .card { padding: 18px; }
  .page-head h1 { font-size: 22px; }
}

/* ---- Login ---- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 400px; text-align: center; padding: 34px; }
.login-card .dot { width: 46px; height: 46px; border-radius: 14px; background: linear-gradient(135deg, var(--primary), var(--primary-2)); margin: 0 auto 18px; box-shadow: 0 12px 26px -12px color-mix(in srgb, var(--primary) 65%, transparent); }
.login-card h1 { font-size: 22px; margin: 0 0 4px; font-weight: 600; }
.login-card p { color: var(--muted); margin: 0 0 24px; font-size: 15px; }
.login-card .input { text-align: center; margin-bottom: 12px; }
.login-card .btn { width: 100%; justify-content: center; }
.error { background: var(--expense-bg); color: var(--expense); padding: 11px; border-radius: 12px; font-size: 14px; margin-bottom: 14px; font-weight: 500; }

.section-gap { margin-top: 18px; }
