:root {
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #f8fafc; --border: #e5e7eb;
  --text: #0f172a; --muted: #64748b; --faint: #94a3b8;
  --primary: #0f172a; --primary-text: #ffffff; --accent: #2563eb;
  --pos: #15803d; --pos-bg: #dcfce7; --neg: #b91c1c; --neg-bg: #fee2e2; --warn: #b45309; --warn-bg: #fef3c7;
  --i1: #15803d; --i2: #2563eb; --i3: #64748b; --i4: #d97706; --i5: #dc2626;
  --radius: 14px; --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 1px rgba(15, 23, 42, .03);
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120; --surface: #111827; --surface-2: #0f172a; --border: #1f2937;
    --text: #e5e7eb; --muted: #94a3b8; --faint: #64748b;
    --primary: #e5e7eb; --primary-text: #0b1120; --accent: #60a5fa;
    --pos: #4ade80; --pos-bg: #052e16; --neg: #f87171; --neg-bg: #450a0a; --warn: #fbbf24; --warn-bg: #422006;
    --i1: #4ade80; --i2: #60a5fa; --i3: #94a3b8; --i4: #fbbf24; --i5: #f87171;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.pos { color: var(--pos); } .neg { color: var(--neg); } .warn { color: var(--warn); }
.hidden { display: none !important; }
@media (max-width: 420px) { .hide-sm { display: none; } }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.grid { display: grid; gap: 12px; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--bg);
  padding: max(10px, env(safe-area-inset-top)) 16px 8px; display: flex; align-items: center; gap: 8px;
  border-bottom: 1px solid transparent;
}
.topbar.scrolled { border-bottom-color: var(--border); }
.brand { font-weight: 700; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; }
.brand img { width: 26px; height: 26px; }
.month-nav { display: flex; align-items: center; gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 2px; }
.month-nav button { background: none; border: 0; padding: 6px 10px; border-radius: 999px; cursor: pointer; }
.month-nav button:hover { background: var(--surface-2); }
.month-nav .label { min-width: 92px; text-align: center; font-weight: 600; font-size: 14px; }
.acct-select { max-width: 140px; }
main { padding: 8px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); max-width: 1180px; margin: 0 auto; }
.page-title { font-size: 20px; font-weight: 700; margin: 8px 0 12px; letter-spacing: -.01em; }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border); display: flex;
}
.bottom-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: 11px; font-weight: 500; position: relative; }
.bottom-nav a svg { width: 22px; height: 22px; }
.bottom-nav a.active { color: var(--text); }
.bottom-nav .badge { position: absolute; top: 8px; left: calc(50% + 6px); }
@media (min-width: 900px) {
  .bottom-nav { top: 0; bottom: 0; right: auto; width: 88px; height: auto; flex-direction: column; justify-content: flex-start; padding-top: 72px; border-top: 0; border-right: 1px solid var(--border); }
  .bottom-nav a { flex: 0 0 72px; }
  .topbar, main { margin-left: 88px; }
  main { padding-bottom: 40px; }
}

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card h3 { margin: 0 0 10px; font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.card h3 .spacer + * { font-weight: 500; }
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 760px) { .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.kpi .label { color: var(--muted); font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.hero { padding: 18px; }
.hero .big { font-size: 34px; font-weight: 700; letter-spacing: -.03em; line-height: 1.1; }
.hero .line { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-top: 1px dashed var(--border); font-size: 14px; }
.hero .line:first-of-type { border-top: 0; }
.hero.hero-neg { border-color: color-mix(in srgb, var(--neg) 35%, var(--border)); }
.hero.hero-pos { border-color: color-mix(in srgb, var(--pos) 35%, var(--border)); }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.neg { background: var(--neg-bg); color: var(--neg); }
.pill.pos { background: var(--pos-bg); color: var(--pos); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.gray { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge { background: var(--neg); color: #fff; border-radius: 999px; font-size: 10px; font-weight: 700; padding: 1px 5px; line-height: 1.3; }

.dash-grid { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 960px) { .dash-grid { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); } }

/* barra empilhada por importância */
.stack { display: flex; height: 14px; border-radius: 999px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); }
.stack span { height: 100%; }
.stack-wrap { position: relative; padding-top: 18px; }
.stack-wrap .income-mark { position: absolute; top: 0; bottom: -4px; width: 2px; background: var(--text); }
.stack-wrap .income-mark::before { content: attr(data-label); position: absolute; top: -2px; transform: translateX(-50%); font-size: 11px; font-weight: 600; white-space: nowrap; }
.legend { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; margin-top: 12px; font-size: 14px; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.imp-1 { background: var(--i1); } .imp-2 { background: var(--i2); } .imp-3 { background: var(--i3); } .imp-4 { background: var(--i4); } .imp-5 { background: var(--i5); }
.imp-tag { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); white-space: nowrap; background: var(--surface); cursor: pointer; }

/* listas */
.list { display: flex; flex-direction: column; }
.item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); min-width: 0; }
.item:first-child { border-top: 0; }
.item .main { flex: 1; min-width: 0; }
.item .title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.item .amount { font-weight: 600; text-align: right; }
.item.clickable { cursor: pointer; }
.item.clickable:hover { background: var(--surface-2); margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.check { width: 28px; height: 28px; border-radius: 999px; border: 2px solid var(--border); background: var(--surface); flex: none; cursor: pointer; display: grid; place-items: center; }
.check.on { background: var(--pos); border-color: var(--pos); color: #fff; }
.check.late { border-color: var(--neg); }

.bar { height: 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.bar.over > span { background: var(--neg); }
.bar.near > span { background: var(--i4); }

.forecast { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; align-items: end; height: 150px; margin-top: 6px; }
.forecast .col { display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; min-width: 0; }
.forecast .bars { display: flex; gap: 3px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.forecast .b { width: 40%; max-width: 18px; border-radius: 4px 4px 0 0; min-height: 2px; }
.forecast .b.inc { background: var(--pos); } .forecast .b.exp { background: var(--neg); opacity: .85; }
.forecast .m { font-size: 11px; color: var(--muted); }
.forecast .r { font-size: 11px; font-weight: 600; }

/* ---------- forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; font-size: 14px; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn.danger { color: var(--neg); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); }
input, select, textarea { width: 100%; padding: 9px 11px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 0; border-color: var(--accent); }
input[type=checkbox] { width: auto; }
.form-grid { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.seg { display: flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); }
.seg button { flex: 1; border: 0; background: none; padding: 8px 6px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--primary); color: var(--primary-text); }
.imp-picker { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
.imp-picker button { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 7px 2px; font-size: 11px; font-weight: 600; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.imp-picker button.on { outline: 2px solid var(--text); }

.filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; scrollbar-width: none; }
.filters select, .filters input { width: auto; flex: none; padding: 7px 10px; font-size: 13px; border-radius: 999px; }
.filters input[type=search] { min-width: 150px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 9px 12px; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--text); border-bottom-color: var(--text); }

/* tabela (desktop) */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--border); }
.table td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:hover td { background: var(--surface-2); }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(2, 6, 23, .5); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--surface); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
@media (min-width: 640px) { .modal-bg { align-items: center; } .modal { border-radius: 18px; } }
.modal h2 { margin: 0 0 12px; font-size: 18px; }
.modal .actions { display: flex; gap: 8px; margin-top: 16px; }

#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px); transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
#toast div { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; font-size: 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); max-width: 90vw; }
#toast div.err { background: var(--neg); color: #fff; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 360px; padding: 24px; }

.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 28px 16px; text-align: center; cursor: pointer; background: var(--surface-2); }
.dropzone.drag { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; font-size: 14px; }
.callout { padding: 12px 14px; border-radius: 12px; background: var(--warn-bg); color: var(--warn); font-size: 14px; display: flex; gap: 10px; align-items: center; }
.callout.info { background: color-mix(in srgb, var(--accent) 10%, var(--surface)); color: var(--text); }
