:root {
  color-scheme: light;
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #f7f8f5;
  --line: #e4e5df;
  --line-strong: #cfd0c8;
  --ink: #111512;
  --ink-2: #4f5550;
  --muted: #858a84;
  --brand: #0e7a55;
  --brand-ink: #ffffff;
  --brand-soft: #e3f3ec;
  --pos: #0b7a3b;
  --neg: #c2362f;
  --warn: #9a6400;
  --warn-soft: #fdf1d8;
  --neg-soft: #fbe7e5;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: #e8e8e2;
  --shadow: 0 1px 2px rgba(17, 21, 18, .06), 0 4px 16px rgba(17, 21, 18, .05);
  --radius: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1110;
  --surface: #191c1a;
  --surface-2: #212522;
  --line: #2a2e2b;
  --line-strong: #3a3f3b;
  --ink: #f3f5f2;
  --ink-2: #c1c6c0;
  --muted: #8b918b;
  --brand: #22a472;
  --brand-ink: #06140e;
  --brand-soft: #173026;
  --pos: #3cc47a;
  --neg: #f0706a;
  --warn: #f2b73d;
  --warn-soft: #33290f;
  --neg-soft: #3a1b19;
  --series-1: #3987e5;
  --series-2: #d95926;
  --grid: #262a27;
  --shadow: none;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1110; --surface: #191c1a; --surface-2: #212522; --line: #2a2e2b; --line-strong: #3a3f3b;
    --ink: #f3f5f2; --ink-2: #c1c6c0; --muted: #8b918b; --brand: #22a472; --brand-ink: #06140e; --brand-soft: #173026;
    --pos: #3cc47a; --neg: #f0706a; --warn: #f2b73d; --warn-soft: #33290f; --neg-soft: #3a1b19;
    --series-1: #3987e5; --series-2: #d95926; --grid: #262a27; --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.num { font-variant-numeric: tabular-nums; }
.pos { color: var(--pos); } .neg { color: var(--neg); } .muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- estrutura ---------- */
.shell { min-height: 100vh; display: flex; }
.side { display: none; }
.main { flex: 1; min-width: 0; padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
.top {
  position: sticky; top: 0; z-index: 20; background: var(--brand); color: var(--brand-ink);
  padding: calc(10px + env(safe-area-inset-top)) 16px 14px;
}
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.top h1 { font-size: 17px; margin: 0; font-weight: 650; }
.icon-btn { background: transparent; border: 0; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: inherit; }
.icon-btn:hover { background: rgba(255,255,255,.12); }
.month {
  display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 6px;
}
.month button { background: rgba(255,255,255,.14); border: 0; color: inherit; width: 34px; height: 34px; border-radius: 50%; font-size: 18px; }
.month span { min-width: 150px; text-align: center; font-weight: 600; text-transform: capitalize; }
.content { padding: 16px; max-width: 1080px; margin: 0 auto; display: grid; gap: 14px; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: var(--surface);
  border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabbar button {
  background: none; border: 0; display: grid; justify-items: center; gap: 2px; padding: 6px 0;
  font-size: 11px; color: var(--muted); border-radius: 12px;
}
.tabbar button svg { width: 22px; height: 22px; }
.tabbar button.on { color: var(--brand); font-weight: 600; }
.tabbar .fab {
  width: 54px; height: 54px; margin: -24px auto 0; border-radius: 50%; background: var(--brand); color: var(--brand-ink);
  box-shadow: 0 6px 18px rgba(14,122,85,.35); display: grid; place-items: center; padding: 0;
}
.tabbar .fab svg { width: 26px; height: 26px; }

@media (min-width: 900px) {
  .tabbar { display: none; }
  .main { padding-bottom: 32px; }
  .side {
    display: flex; flex-direction: column; width: 240px; flex: none; background: var(--surface);
    border-right: 1px solid var(--line); padding: 20px 14px; position: sticky; top: 0; height: 100vh; gap: 4px;
  }
  .brand { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 20px; letter-spacing: -.3px; padding: 4px 10px 18px; }
  .brand svg { width: 34px; height: 34px; }
  .side .novo { margin: 0 0 14px; }
  .side a {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; color: var(--ink-2);
    text-decoration: none; font-weight: 500;
  }
  .side a svg { width: 20px; height: 20px; }
  .side a:hover { background: var(--surface-2); }
  .side a.on { background: var(--brand-soft); color: var(--brand); font-weight: 650; }
  .top { position: static; background: transparent; color: var(--ink); padding: 22px 24px 0; max-width: 1128px; margin: 0 auto; }
  .top .icon-btn:hover { background: var(--surface-2); }
  .top h1 { font-size: 22px; }
  .top .only-mobile { display: none; }
  .mini-brand svg { display: none; }
  .month { justify-content: flex-start; margin-top: 10px; }
  .month button { background: var(--surface); border: 1px solid var(--line); }
  .month span { min-width: 140px; }
  .content { padding: 18px 24px; }
  .grid-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .grid-3 { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); }
}

/* ---------- cartões de conteúdo ---------- */
.grid-2, .grid-3 { display: grid; gap: 14px; align-items: start; grid-template-columns: minmax(0, 1fr); }
.grid-2 > *, .grid-3 > *, .content > * { min-width: 0; }
.content { grid-template-columns: minmax(0, 1fr); }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); overflow: hidden; }
.card-h { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; gap: 8px; }
.card-h h2 { font-size: 15px; margin: 0; font-weight: 650; }
.card-h .link { background: none; border: 0; color: var(--brand); font-weight: 600; font-size: 13px; padding: 4px; }
.card-b { padding: 6px 16px 16px; }

.hero { padding: 18px 16px 16px; }
.hero small { color: var(--muted); font-size: 13px; }
.hero .big { font-size: 32px; font-weight: 700; letter-spacing: -.5px; margin: 2px 0 12px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; display: flex; gap: 10px; align-items: center; min-width: 0; }
.tile .dot { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.tile .dot svg { width: 18px; height: 18px; }
.tile.rec .dot { background: var(--brand-soft); color: var(--pos); }
.tile.des .dot { background: var(--neg-soft); color: var(--neg); }
.tile small { display: block; color: var(--muted); font-size: 12px; }
.tile b { font-size: 16px; white-space: nowrap; }
.prev { margin-top: 12px; display: flex; justify-content: space-between; align-items: center; font-size: 14px; color: var(--ink-2); border-top: 1px dashed var(--line); padding-top: 12px; }
.prev b { font-size: 16px; white-space: nowrap; }
.prev > span { flex: 1; min-width: 0; }
.prev small { font-size: 12px; }

/* ---------- listas ---------- */
.list, .hbar { display: grid; grid-template-columns: minmax(0, 1fr); }
.list > *, .hbar > * { min-width: 0; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 16px; border-top: 1px solid var(--line); min-height: 60px; background: none; border-left: 0; border-right: 0; border-bottom: 0; width: 100%; text-align: left; }
.list > .row:first-child { border-top: 0; }
button.row:hover { background: var(--surface-2); }
.ic { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; flex: none; font-size: 17px; }
.row .t { flex: 1; min-width: 0; }
.row .t b { display: block; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .t small { color: var(--muted); font-size: 12.5px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .v { text-align: right; white-space: nowrap; font-weight: 600; }
.row .v small { display: block; font-weight: 500; font-size: 12px; color: var(--muted); }
.day { padding: 12px 16px 4px; font-size: 12px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; background: var(--surface); }
.check {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line-strong); background: none; flex: none;
  display: grid; place-items: center; color: transparent; padding: 0;
}
.check.on { background: var(--pos); border-color: var(--pos); color: #fff; }
.check svg { width: 14px; height: 14px; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px; }
.badge.ok { background: var(--brand-soft); color: var(--pos); }
.badge.late { background: var(--neg-soft); color: var(--neg); }
.badge.open { background: var(--warn-soft); color: var(--warn); }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

/* faturas em carrossel */
.scroller { display: flex; gap: 10px; overflow-x: auto; padding: 4px 16px 16px; scroll-snap-type: x mandatory; scrollbar-width: none; }
.scroller::-webkit-scrollbar { display: none; }
.fat { flex: 0 0 172px; scroll-snap-align: start; border-radius: 14px; padding: 12px; background: var(--surface-2); border: 1px solid var(--line); text-align: left; }
.fat .bar { height: 4px; border-radius: 4px; margin-bottom: 10px; }
.fat b { display: block; font-size: 17px; margin: 2px 0 6px; }
.fat small { color: var(--muted); font-size: 12px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* barras de categoria e orçamento */
.hbar { display: grid; gap: 12px; }
.hbar-row { display: grid; gap: 5px; }
.hbar-top { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.hbar-top span:first-child { display: flex; gap: 8px; align-items: center; min-width: 0; }
.track { height: 8px; border-radius: 8px; background: var(--surface-2); overflow: hidden; }
.fill { height: 100%; border-radius: 8px; background: var(--series-1); }
.fill.over { background: var(--neg); }
.fill.warn { background: var(--warn); }

/* chips */
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px 0; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 7px 14px; font-size: 13.5px; font-weight: 550; color: var(--ink-2); }
.chip.on { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.search { width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 11px 14px; outline: none; }
.search:focus { border-color: var(--brand); }

/* botões */
.btn { border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 650; background: var(--brand); color: var(--brand-ink); display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.ghost { background: var(--surface-2); color: var(--ink); }
.btn.danger { background: var(--neg-soft); color: var(--neg); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }

/* ---------- cartão de crédito ---------- */
.cc { margin: 0 16px 14px; border-radius: 18px; padding: 16px; color: #fff; position: relative; overflow: hidden; }
.cc::after { content: ""; position: absolute; right: -40px; top: -40px; width: 160px; height: 160px; border-radius: 50%; background: rgba(255,255,255,.12); }
.cc small { opacity: .85; font-size: 12.5px; }
.cc .big { font-size: 28px; font-weight: 700; margin: 2px 0 10px; }
.cc .meta { display: flex; justify-content: space-between; font-size: 13px; opacity: .92; gap: 8px; flex-wrap: wrap; }

/* ---------- gráficos ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .gridl { stroke: var(--grid); stroke-width: 1; }
.chart .base { stroke: var(--line-strong); stroke-width: 1; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--ink-2); padding: 0 16px 6px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.tip {
  position: absolute; pointer-events: none; background: var(--ink); color: var(--surface); padding: 8px 10px; border-radius: 10px;
  font-size: 12.5px; line-height: 1.5; white-space: nowrap; transform: translate(-50%, -100%); opacity: 0; transition: opacity .12s; z-index: 5;
}
.tip.show { opacity: 1; }
.tip i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

/* ---------- folha (modal) ---------- */
.veil { 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: 520px; max-height: 92vh; overflow-y: auto; border-radius: 22px 22px 0 0;
  padding: 8px 16px calc(18px + env(safe-area-inset-bottom)); animation: up .2s ease-out;
}
@media (min-width: 700px) { .veil { align-items: center; } .sheet { border-radius: 22px; } }
.grab { width: 40px; height: 4px; border-radius: 4px; background: var(--line-strong); margin: 4px auto 10px; }
.sheet h3 { margin: 4px 0 12px; font-size: 17px; }
.seg { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { border: 0; background: none; padding: 9px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.seg.tipo button.on.d { color: var(--neg); } .seg.tipo button.on.r { color: var(--pos); }
.valor-in { display: flex; align-items: baseline; justify-content: center; gap: 6px; margin: 16px 0 8px; }
.valor-in span { font-size: 22px; color: var(--muted); font-weight: 600; }
.valor-in input { border: 0; outline: none; background: none; font-size: 40px; font-weight: 700; width: 220px; text-align: center; }
.field { display: grid; gap: 6px; margin-top: 12px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea { width: 100%; border: 1px solid var(--line); background: var(--surface-2); border-radius: 12px; padding: 11px 12px; outline: none; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--brand); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.catgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.catgrid button { border: 1px solid var(--line); background: var(--surface-2); border-radius: 12px; padding: 8px 4px; font-size: 11.5px; display: grid; justify-items: center; gap: 3px; color: var(--ink-2); min-width: 0; }
.catgrid button span:last-child { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.catgrid button.on { border-color: var(--brand); background: var(--brand-soft); color: var(--ink); font-weight: 600; }
.catgrid .e { font-size: 18px; }
.toggle { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; font-weight: 550; }
.sw { width: 46px; height: 28px; border-radius: 99px; background: var(--line-strong); border: 0; position: relative; padding: 0; }
.sw::after { content: ""; position: absolute; left: 3px; top: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: left .15s; }
.sw.on { background: var(--brand); } .sw.on::after { left: 21px; }
.actions { display: grid; gap: 8px; margin-top: 18px; }

.toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 12px; z-index: 60; font-size: 14px; animation: up .2s; max-width: calc(100% - 32px); }
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
.toast { animation: none; }
@keyframes fade { from { opacity: 0; } }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, var(--brand), #0a4f38); }
.login form { background: var(--surface); padding: 28px 22px; border-radius: 22px; width: 100%; max-width: 360px; display: grid; gap: 12px; }
.login h1 { margin: 0; font-size: 22px; }
.login p { margin: 0 0 6px; color: var(--muted); }
.err { color: var(--neg); font-size: 14px; min-height: 20px; }

.set-row { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); }
.set-row:first-child { border-top: 0; }
.set-row .t { flex: 1; min-width: 0; }
.set-row small { color: var(--muted); display: block; font-size: 12.5px; }
.note { font-size: 13px; color: var(--ink-2); background: var(--warn-soft); border-radius: 12px; padding: 10px 12px; }
.proto-banner { background: var(--warn-soft); color: var(--warn); font-size: 12.5px; text-align: center; padding: 6px 12px; font-weight: 600; }

.mini-brand { display: inline-flex; align-items: center; gap: 8px; font-size: 19px; font-weight: 750; letter-spacing: -.3px; }
.mini-brand svg { width: 26px; height: 26px; border-radius: 8px; box-shadow: 0 0 0 1.5px rgba(255,255,255,.55); }
.login-logo svg { width: 64px; height: 64px; }
.login-logo { margin-bottom: 4px; }
.login h1 { font-size: 26px; letter-spacing: -.5px; }
