:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #efeee9;
  --line: #e2e1db;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #8a8983;
  --brand: #2a78d6;
  --brand-ink: #ffffff;
  --brand-soft: #e3eefb;
  --income: #2a78d6;   /* série 1 */
  --expense: #eb6834;  /* série 2 */
  --good: #0d7a3a;
  --good-soft: #e1f3e7;
  --warn: #9a6200;
  --warn-soft: #fbf0d6;
  --bad: #c62f2f;
  --bad-soft: #fbe4e3;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --radius: 14px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110; --surface: #1a1a19; --surface-2: #252523; --line: #2f2f2c;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86;
    --brand: #3987e5; --brand-soft: #1b2b40;
    --income: #3987e5; --expense: #d95926;
    --good: #4cc27a; --good-soft: #15291d; --warn: #e3a83a; --warn-soft: #2e2512; --bad: #ef6b6b; --bad-soft: #351819;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #252523; --line: #2f2f2c;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86;
  --brand: #3987e5; --brand-soft: #1b2b40;
  --income: #3987e5; --expense: #d95926;
  --good: #4cc27a; --good-soft: #15291d; --warn: #e3a83a; --warn-soft: #2e2512; --bad: #ef6b6b; --bad-soft: #351819;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 600; color: var(--text-2); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pos { color: var(--good); }
.neg { color: var(--bad); }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.app { min-height: 100dvh; }
.sidebar { display: none; }
.main { padding: 16px 16px calc(var(--nav-h) + var(--safe-b) + 24px); max-width: 1180px; margin: 0 auto; }
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; min-height: 40px; flex-wrap: wrap; }
.topbar h1 { flex: 1 0 auto; max-width: 100%; }
.topbar .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(5, 1fr);
}
.bottomnav a, .bottomnav button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 11px; background: none; border: 0; cursor: pointer;
}
.bottomnav a.on { color: var(--brand); font-weight: 600; }
.bottomnav svg { width: 22px; height: 22px; }
.bottomnav .fab {
  width: 52px; height: 52px; border-radius: 50%; margin: -18px auto 0; background: var(--brand); color: var(--brand-ink);
  box-shadow: 0 4px 14px color-mix(in srgb, var(--brand) 45%, transparent); display: grid; place-items: center;
}
.bottomnav .fab svg { width: 26px; height: 26px; }

@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: 236px 1fr; }
  .sidebar {
    display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100dvh; overflow-y: auto;
    padding: 20px 12px; border-right: 1px solid var(--line); background: var(--surface);
  }
  .sidebar .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; padding: 4px 10px 18px; }
  .sidebar a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; color: var(--text-2); }
  .sidebar a:hover { background: var(--surface-2); }
  .sidebar a.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
  .sidebar svg { width: 19px; height: 19px; flex: none; }
  .sidebar .new { margin: 0 4px 14px; justify-content: center; }
  .sidebar .sep { height: 1px; background: var(--line); margin: 10px 6px; }
  .main { padding: 28px 32px 48px; width: 100%; }
  .bottomnav { display: none; }
}

/* ---------- Componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card + .card { margin-top: 12px; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card-h a, .card-h button.link { font-size: 13px; }
.grid { display: grid; gap: 12px; }
.grid > .card + .card { margin-top: 0; }
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; min-width: 0; box-shadow: var(--shadow); }
.kpi .l { font-size: 12px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.kpi .v { font-size: 20px; font-weight: 700; margin-top: 2px; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.hero { grid-column: 1 / -1; background: linear-gradient(135deg, #1f5fb0, #2a78d6 60%, #3d8be0); color: #fff; border: 0; }
.kpi.hero .l, .kpi.hero .s { color: rgba(255,255,255,.85); }
.kpi.hero .v { font-size: 30px; }
.kpi.hero .row { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 8px; font-size: 13px; }
.kpi.hero .row b { display: block; font-size: 15px; }
@media (min-width: 640px) { .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 900px) {
  .grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .span2 { grid-column: span 2; }
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 40px; padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 550; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad); }
.btn.sm { height: 32px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn svg { width: 18px; height: 18px; }
.btn:disabled { opacity: .55; cursor: default; }
button.link { background: none; border: 0; color: var(--brand); cursor: pointer; padding: 0; }
.iconbtn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; }
.iconbtn svg { width: 18px; height: 18px; }

.monthnav { display: inline-flex; align-items: center; gap: 2px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; height: 40px; }
.monthnav button { width: 36px; height: 38px; border: 0; background: none; cursor: pointer; color: var(--text-2); font-size: 18px; }
.monthnav span { min-width: 108px; text-align: center; font-weight: 600; text-transform: capitalize; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; height: 32px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: 13px; color: var(--text-2); }
.chip.on { background: var(--text); color: var(--surface); border-color: var(--text); }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { height: 34px; border: 0; border-radius: 8px; background: none; cursor: pointer; font-weight: 550; color: var(--text-2); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg button.on[data-v="despesa"] { color: var(--expense); }
.seg button.on[data-v="receita"] { color: var(--income); }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--brand-soft); color: var(--brand); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; display: inline-block; }

/* Listas */
.list { display: flex; flex-direction: column; }
.item { display: flex; align-items: center; gap: 12px; padding: 11px 2px; border-bottom: 1px solid var(--line); min-width: 0; }
.item:last-child { border-bottom: 0; }
.item.tap { cursor: pointer; border-radius: 8px; }
.item.tap:hover { background: var(--surface-2); }
.item .ic { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; flex: none; font-size: 18px; background: var(--surface-2); }
.item .bd { flex: 1; min-width: 0; }
.item .t { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .d { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .r { text-align: right; flex: none; }
.item .amt { font-weight: 650; white-space: nowrap; }
.daygroup { font-size: 12px; font-weight: 600; color: var(--muted); padding: 14px 2px 4px; display: flex; justify-content: space-between; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.empty .big { font-size: 34px; display: block; margin-bottom: 6px; }

@media (max-width: 639px) {
  h1 { font-size: 20px; }
  .topbar .btn { padding: 0 11px; }
  .kpi .v { font-size: 18px; }
}
.item .d.wrap { white-space: normal; }

/* Barras (magnitude, uma cor) */
.bars { display: flex; flex-direction: column; gap: 12px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; align-items: center; }
.bar-row .lb { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 14px; }
.bar-row .lb span.n { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .vl { font-size: 14px; font-weight: 600; text-align: right; white-space: nowrap; }
.bar-row .track { grid-column: 1 / -1; height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; position: relative; }
.bar-row .fill { height: 100%; border-radius: 99px; background: var(--brand); min-width: 3px; }
.bar-row .fill.income { background: var(--income); }
.bar-row .fill.expense { background: var(--expense); }
.bar-row .fill.warn { background: var(--warn); }
.bar-row .fill.bad { background: var(--bad); }
.bar-row .sub { grid-column: 1 / -1; font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.bar-row .limit { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--text-2); }

/* Gráfico mês a mês */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 220px; overflow: visible; }
.chart .grid-l { stroke: var(--line); stroke-width: 1; }
.chart .ax { fill: var(--muted); font-size: 11px; }
.chart .b-in { fill: var(--income); }
.chart .b-out { fill: var(--expense); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover, .chart .hit.on { fill: color-mix(in srgb, var(--text) 6%, transparent); }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--text-2); flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.tip {
  position: absolute; pointer-events: none; background: var(--text); color: var(--surface); padding: 8px 10px; border-radius: 8px;
  font-size: 12.5px; line-height: 1.5; white-space: nowrap; transform: translate(-50%, -100%); z-index: 5; box-shadow: var(--shadow);
}
.tip b { display: block; text-transform: capitalize; }
.stack { display: flex; height: 12px; border-radius: 99px; overflow: hidden; gap: 2px; background: var(--surface); margin: 4px 0 12px; }
.stack div { height: 100%; }

/* Cartões de crédito */
.ccard { border-radius: 16px; padding: 16px; color: #fff; position: relative; overflow: hidden; cursor: pointer; min-height: 150px; display: flex; flex-direction: column; justify-content: space-between; box-shadow: var(--shadow); }
.ccard::after { content: ""; position: absolute; right: -40px; top: -40px; width: 160px; height: 160px; border-radius: 50%; background: rgba(255,255,255,.12); }
.ccard .nm { font-weight: 700; font-size: 17px; }
.ccard .meta { font-size: 12px; opacity: .9; }
.ccard .big { font-size: 22px; font-weight: 700; }
.ccard .lim { height: 6px; background: rgba(255,255,255,.3); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.ccard .lim div { height: 100%; background: #fff; border-radius: 99px; }
.cards-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

/* Formulários */
.form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .field > .lbl { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.input, select.input, textarea.input {
  width: 100%; height: 44px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); outline: none; min-width: 0;
}
textarea.input { height: 72px; padding: 10px 12px; resize: vertical; }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.input.money { font-size: 26px; font-weight: 700; height: 56px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.hint { font-size: 12.5px; color: var(--muted); }
.err { color: var(--bad); font-size: 13px; min-height: 0; }
.filters { display: grid; gap: 8px; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 12px; }
.filters .input { height: 38px; font-size: 14px; }
@media (min-width: 900px) { .filters { grid-template-columns: repeat(6, minmax(0, 1fr)); } }

/* Folha (modal) */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.42); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet {
  background: var(--surface); width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto; border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(20px + var(--safe-b)); animation: up .2s ease-out;
}
.sheet .grab { width: 40px; height: 4px; border-radius: 9px; background: var(--line); margin: 4px auto 10px; }
.sheet-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 8px; }
.sheet-f { display: flex; gap: 8px; margin-top: 16px; position: sticky; bottom: calc(-20px - var(--safe-b)); background: var(--surface); padding: 10px 0 0; }
.sheet-f .btn { flex: 1; height: 46px; }
@media (min-width: 640px) {
  .sheet-bg { align-items: center; }
  .sheet { border-radius: 20px; padding: 18px 22px 22px; }
  .sheet .grab { display: none; }
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 14px); transform: translateX(-50%); background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 10px; z-index: 60; font-size: 14px; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
@media (min-width: 900px) { .toast { bottom: 24px; } }

/* Login */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: 100%; max-width: 380px; padding: 24px; }
.auth .logo { display: flex; align-items: center; gap: 10px; font-size: 22px; font-weight: 750; margin-bottom: 4px; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tbl th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 4px; border-bottom: 1px solid var(--line); }
table.tbl td { padding: 8px 4px; border-bottom: 1px solid var(--line); }
table.tbl td.r, table.tbl th.r { text-align: right; white-space: nowrap; }
.scroll-x { overflow-x: auto; }
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 12px; font-size: 14px; margin-bottom: 8px; }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.bad { background: var(--bad-soft); color: var(--bad); }
.morelist a { display: flex; align-items: center; gap: 12px; padding: 14px 4px; border-bottom: 1px solid var(--line); color: var(--text); }
.morelist a:last-child { border-bottom: 0; }
.morelist svg { width: 20px; height: 20px; color: var(--brand); }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatches label { width: 30px; height: 30px; border-radius: 50%; cursor: pointer; display: grid; place-items: center; }
.swatches input { display: none; }
.swatches input:checked + span { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text); }
.swatches span { width: 26px; height: 26px; border-radius: 50%; display: block; }
