:root {
  --bg: #f4f5f7; --panel: #ffffff; --ink: #111827; --muted: #6b7280; --line: #e5e7eb;
  --accent: #2563eb; --accent-soft: #dbeafe; --pos: #15803d; --neg: #b91c1c; --warn: #b45309;
  --chip: #f9fafb; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 1px 3px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --panel: #171a21; --ink: #e5e7eb; --muted: #9ca3af; --line: #272b35;
    --accent: #60a5fa; --accent-soft: #1e293b; --pos: #4ade80; --neg: #f87171; --warn: #fbbf24;
    --chip: #1d212a; --shadow: none;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.pos { color: var(--pos); } .neg { color: var(--neg); } .muted { color: var(--muted); } .warn { color: var(--warn); }
small { font-size: 12px; }

.top { position: sticky; top: 0; z-index: 20; display: flex; gap: 16px; align-items: center; padding: 10px 20px;
  background: var(--panel); border-bottom: 1px solid var(--line); overflow-x: auto; }
.brand { display: flex; align-items: center; gap: 8px; flex: none; }
.logo { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 700; font-size: 12px; }
.balances { display: flex; gap: 8px; flex: 1; }
.bal { flex: none; min-width: 128px; padding: 6px 12px; border-radius: 10px; background: var(--chip); border: 1px solid var(--line); border-left: 4px solid var(--c, var(--line)); }
.bal .l { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.bal .v { font-size: 16px; font-weight: 650; font-variant-numeric: tabular-nums; }
.bal .s { font-size: 11px; color: var(--muted); }
.bal.highlight { background: var(--accent-soft); }

.tabs { display: flex; gap: 4px; align-items: center; padding: 8px 20px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.tabs > button { border: 0; background: none; padding: 8px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 550; }
.tabs > button.active { background: var(--accent-soft); color: var(--accent); }
.tabs .spacer { flex: 1; }
.month-picker { display: flex; align-items: center; gap: 2px; }
.month-picker button { border: 1px solid var(--line); background: var(--panel); border-radius: 6px; width: 30px; height: 32px; cursor: pointer; }
.month-picker input { border: 1px solid var(--line); background: var(--panel); border-radius: 6px; height: 32px; padding: 0 6px; }
button.primary { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 8px 14px; font-weight: 600; cursor: pointer; }
button.ghost, .btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 10px; cursor: pointer; }
button.link { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 2px 4px; }
button.danger { color: var(--neg); }

main { padding: 20px; max-width: 1400px; margin: 0 auto; }
.grid { display: grid; gap: 16px; }
.g-dash { grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); }
@media (max-width: 980px) { .g-dash { grid-template-columns: 1fr; } }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); }
.panel h2 { margin: 0 0 12px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.panel h2 .right { margin-left: auto; font-weight: 400; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; }
.kv .big { font-size: 22px; font-weight: 700; }
.stat-row { display: flex; gap: 16px; flex-wrap: wrap; }
.stat { flex: 1; min-width: 120px; }
.stat .l { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
td { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr.forecast td { color: var(--muted); font-style: italic; }
tr.forecast.pendente td { color: var(--warn); }
tr.total td { font-weight: 700; border-top: 2px solid var(--line); }
tr.daysep td { background: var(--chip); font-size: 12px; font-weight: 600; padding: 4px 8px; }
.tag { display: inline-flex; align-items: center; gap: 6px; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--chip); border: 1px solid var(--line); white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c, #999); flex: none; }
td select.inline { border: 1px solid transparent; background: transparent; max-width: 170px; padding: 2px; border-radius: 6px; }
td select.inline:hover { border-color: var(--line); }
td input.budget { width: 110px; text-align: right; border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 4px 6px; }
td input.budget.inherited { color: var(--muted); font-style: italic; }

.bar { position: relative; height: 8px; border-radius: 999px; background: var(--chip); border: 1px solid var(--line); overflow: hidden; min-width: 80px; }
.bar > i { position: absolute; inset: 0 auto 0 0; background: var(--c, var(--accent)); border-radius: 999px; }
.bar > b { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--ink); opacity: .5; }
.bar.over > i { background: var(--neg); }
.catline { display: grid; grid-template-columns: 150px 1fr 190px; gap: 10px; align-items: center; padding: 5px 0; }
.catline .n { display: flex; align-items: center; gap: 6px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.filters input, .filters select, .form input, .form select, .form textarea { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 9px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; cursor: pointer; background: var(--panel); user-select: none; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--panel); color: var(--ink); width: min(560px, 94vw); }
dialog::backdrop { background: rgba(0,0,0,.35); }
.form { padding: 20px; display: grid; gap: 12px; }
.form h3 { margin: 0; }
.form label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.form label > * { font-size: 14px; color: var(--ink); min-width: 0; width: 100%; }
.form label > small { font-size: 12px; color: var(--muted); width: auto; }
.grid > * { min-width: 0; }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: var(--panel); padding: 8px; cursor: pointer; }
.seg button.on { background: var(--accent); color: #fff; }

.quick { display: grid; grid-template-columns: 110px 1fr 170px 150px 160px 130px auto; gap: 8px; }
@media (max-width: 980px) { .quick { grid-template-columns: 1fr 1fr; } }
.quick input, .quick select { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 9px; min-width: 0; }

.list-item { display: flex; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item .d { width: 46px; font-size: 12px; color: var(--muted); }
.list-item .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chart { width: 100%; height: 180px; display: block; }
.notice { padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); margin-bottom: 12px; }
.steps { margin: 0; padding-left: 20px; } .steps li { margin: 4px 0; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50; max-width: 90vw; }
#toast.show { opacity: 1; }
.scroll { max-height: 70vh; overflow: auto; }
code { background: var(--chip); padding: 1px 5px; border-radius: 4px; }
@media (max-width: 600px) { .catline { grid-template-columns: 1fr 1fr; } .catline .bar { grid-column: 1 / -1; grid-row: 2; } main { padding: 12px; } }
.bal.click { cursor: pointer; } .bal.click:hover { border-color: var(--accent); }
.bill { display: flex; gap: 10px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.bill:last-of-type { border-bottom: 0; }
.bill input { width: 18px; height: 18px; accent-color: var(--pos); flex: none; }
.bill .d { width: 52px; font-size: 12px; color: var(--muted); }
.bill .t { flex: 1; }
.bill.done { opacity: .45; }
.bill.done .t { text-decoration: line-through; }
.pct { display: inline-block; min-width: 44px; padding: 1px 6px; border-radius: 6px; background: var(--chip); border: 1px solid var(--line); font-size: 12px; }
.bill .link { flex: none; font-size: 12px; opacity: .6; }
.bill:hover .link { opacity: 1; }

/* gráfico do fluxo */
.fchart { position: relative; width: 100%; margin: 8px 0 4px; }
.fchart svg { display: block; font-size: 11px; }
.fchart .band-a { fill: var(--panel); }
.fchart .band-b { fill: var(--accent); fill-opacity: .07; }
.fchart .mline { stroke: var(--accent); stroke-opacity: .45; stroke-width: 1.5; }
.fchart .mlabel { fill: var(--accent); font-weight: 650; font-size: 12px; text-transform: capitalize; }
.fchart .grid { stroke: var(--line); }
.fchart .zero { stroke: var(--neg); stroke-dasharray: 4 4; opacity: .6; }
.fchart .ylabel, .fchart .dlabel { fill: var(--muted); font-variant-numeric: tabular-nums; }
.fchart .dlabel.first { fill: var(--ink); font-weight: 650; }
.fchart .tick { stroke: var(--muted); opacity: .6; }
.fchart .future { fill: var(--ink); fill-opacity: .025; }
.fchart .today { stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 3 3; }
.fchart .todaylabel { fill: var(--accent); font-size: 11px; }
.fchart .bline { fill: none; stroke: var(--accent); stroke-width: 2.2; }
.fchart .pt { stroke: var(--panel); stroke-width: 2; cursor: pointer; }
.fchart .pt.up { fill: var(--pos); } .fchart .pt.down { fill: var(--neg); }
.fchart .pt.fc { fill-opacity: .55; }
.fchart .pt.more { stroke: currentColor; stroke-width: 1.5; color: var(--ink); }
.fchart .pt.on { r: 7; }
.fchart .reason { font-size: 11px; paint-order: stroke; stroke: var(--panel); stroke-width: 3px; stroke-linejoin: round; }
.fchart .reason.up { fill: var(--pos); } .fchart .reason.down { fill: var(--neg); }
.fchart .reason.fc { font-style: italic; opacity: .8; }
.fchart .hover { stroke: var(--ink); stroke-opacity: .25; }
.ftip { position: absolute; z-index: 30; min-width: 240px; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; box-shadow: 0 6px 20px rgba(0,0,0,.18); font-size: 13px; }
.ftip .h { font-weight: 650; margin-bottom: 4px; }
.ftip .r { display: flex; gap: 10px; justify-content: space-between; padding: 3px 0; border-bottom: 1px dashed var(--line); }
.ftip .r.fc { font-style: italic; }
.ftip .r b { white-space: nowrap; font-variant-numeric: tabular-nums; }
.ftip .f { display: flex; justify-content: space-between; gap: 10px; margin-top: 4px; font-size: 12px; color: var(--muted); }

/* previsto x realizado: categorias com sub-itens */
.btable tr.cat { cursor: pointer; }
.btable tr.cat:hover td { background: var(--chip); }
.btable .caret { display: inline-block; width: 16px; color: var(--muted); font-size: 12px; }
.btable tr.sub td { font-size: 13px; padding-top: 5px; padding-bottom: 5px; border-bottom-style: dashed; }
.btable tr.sub td:first-child { padding-left: 40px; }
.btable tr.sub.done .t { text-decoration: line-through; opacity: .55; }
.btable tr.sub.open .t { font-weight: 600; }
.btable .subl { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; margin-right: 6px; }
.btable .subl input { width: 16px; height: 16px; accent-color: var(--pos); }
.btable tr.sub .link { font-size: 12px; opacity: .65; } .btable tr.sub:hover .link { opacity: 1; }
.btable tr.sub input.budget { width: 100px; }
.bar.thin { height: 5px; }
.btable select.payacc { font-size: 12px; max-width: 160px; color: var(--muted); }
.btable select.payacc:hover, .btable select.payacc:focus { color: var(--ink); }
.paidon { color: var(--pos); font-weight: 600; text-decoration: none; display: inline-block; margin-left: 4px; }
.bill.done .paidon { opacity: 1; }
dialog.wide { width: min(980px, 96vw); }
.stmt { max-height: 55vh; }
.smonth { padding: 0 10px; font-weight: 600; text-transform: capitalize; min-width: 150px; text-align: center; }
.chip.wal b { font-variant-numeric: tabular-nums; }
.invbox { padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--chip); }

/* pizza de gastos (Painel) */
.pie { display: grid; grid-template-columns: minmax(200px, 300px) 1fr; gap: 18px; align-items: center; margin: 6px 0 8px; }
@media (max-width: 700px) { .pie { grid-template-columns: 1fr; } .pie svg { max-width: 280px; margin: 0 auto; } }
.pie svg { width: 100%; height: auto; overflow: visible; }
.pie .slice { cursor: pointer; transition: opacity .15s; }
.pie .slice path { stroke: var(--panel); stroke-width: 1.5; }
.pie .slice:hover path { filter: brightness(1.08); }
.pie .slice.dim { opacity: .22; }
.pie .plabel { font-size: 11px; font-weight: 700; fill: #fff; text-anchor: middle; dominant-baseline: middle; pointer-events: none; paint-order: stroke; stroke: rgba(0,0,0,.25); stroke-width: 2px; }
.pie .pcenter { font-size: 12px; fill: var(--muted); text-anchor: middle; }
.pie .pcenter2 { font-size: 16px; font-weight: 700; fill: var(--ink); text-anchor: middle; }
.plegend { display: grid; gap: 2px; }
.pleg { display: grid; grid-template-columns: 10px 1fr auto; gap: 8px; align-items: center; padding: 5px 6px; border-radius: 6px; }
.pleg.click { cursor: pointer; }
.pleg.click:hover { background: var(--bg); }
.pleg.sub { padding-left: 14px; }
.pleg b { font-variant-numeric: tabular-nums; }
.pleg-h { display: flex; align-items: center; gap: 8px; padding: 4px 6px 6px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.pleg-h .muted { margin-left: auto; }
#piePanel .month-picker .smonth { min-width: 120px; font-size: 13px; }
.billnote { color: var(--muted); font-size: 11px; word-break: break-all; user-select: all; }

/* comparar meses */
.cmpn { margin: 2px 0 6px; }
.cmpn .chip { font-size: 12px; padding: 2px 9px; }
.cmpwrap { overflow-x: auto; margin: 4px 0 6px; }
.cmpwrap svg { display: block; margin: 0 auto; }
.cmpwrap .cgrid { stroke: var(--line); stroke-dasharray: 3 3; }
.cmpwrap .cbase { stroke: var(--muted); opacity: .5; }
.cmpwrap .cylab { font-size: 10px; fill: var(--muted); }
.cmpwrap .cval { font-size: 10px; font-weight: 650; fill: var(--ink); text-anchor: middle; font-variant-numeric: tabular-nums; }
.cmpwrap .cmon { font-size: 10px; fill: var(--muted); text-anchor: middle; }
.cmpwrap .cgname { font-size: 12px; font-weight: 600; fill: var(--ink); text-anchor: middle; }
.cmpwrap rect:hover { filter: brightness(1.1); }
.cmpfilter { margin: 4px 0 8px; border-top: 1px solid var(--line); padding-top: 8px; }
.cmpfilter summary { cursor: pointer; font-size: 13px; font-weight: 600; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.cmpfilter summary .right { margin-left: auto; font-weight: 400; font-size: 12px; }
.cmprow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.cmprow:last-child { border-bottom: 0; }
.cmpsubs { flex-basis: 100%; padding-left: 14px; }
.chip.cmpchip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 3px 10px; }
.chip.cmpchip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); flex: none; }
.chip.cmpchip.on { background: color-mix(in srgb, var(--c) 16%, var(--panel)); border-color: var(--c); color: var(--ink); }
.chip.cmpchip.sub { font-size: 11px; padding: 2px 8px; }
.cmpmore { font-size: 12px; }

/* ---------------------------------------------------------------- versão web / celular */
[hidden] { display: none !important; }
.splash { position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 12px; background: var(--bg); z-index: 100; color: var(--muted); }
.logo.big { width: 64px; height: 64px; border-radius: 16px; font-size: 22px; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(360px, 100%); display: grid; gap: 14px; }
.login label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.login input { font-size: 16px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--ink); }
.login button { padding: 12px; font-size: 16px; }
.login p { margin: 0; }
.tabs svg { display: none; width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabs .short { display: none; }
.toolbar { display: flex; gap: 8px; align-items: center; padding: 8px 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
.toolbar .spacer { flex: 1; }
.panel { min-width: 0; }
.panel > table, .panel > .btable { display: block; overflow-x: auto; }

@media (max-width: 760px) {
  body { font-size: 15px; -webkit-tap-highlight-color: transparent; }
  .top { padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); gap: 10px; }
  .brand strong { display: none; }
  .logo { width: 26px; height: 26px; font-size: 11px; }
  .bal { min-width: 0; padding: 4px 10px; }
  .bal .v { font-size: 15px; }
  .bal .s { display: none; }
  .tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; flex-wrap: nowrap; gap: 0; padding: 4px 4px max(4px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--line); border-bottom: 0; box-shadow: 0 -2px 8px rgba(0,0,0,.06); }
  .tabs > button { flex: 1; display: grid; justify-items: center; gap: 2px; padding: 6px 2px; font-size: 11px; border-radius: 10px; min-width: 0; }
  .tabs > button.active { background: none; }
  .tabs svg { display: block; }
  .tabs .full { display: none; }
  .tabs .short { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .toolbar { padding: 8px 12px; }
  .month-picker input { width: 150px; }
  #btnNew { position: fixed; right: 16px; bottom: calc(72px + env(safe-area-inset-bottom)); z-index: 31; width: 56px; height: 56px; border-radius: 50%;
    padding: 0; font-size: 28px; line-height: 1; box-shadow: 0 4px 12px rgba(37,99,235,.4); }
  #btnNew .lbl { display: none; }
  main { padding: 10px 10px calc(150px + env(safe-area-inset-bottom)); }
  .panel { padding: 12px; border-radius: 12px; }
  .grid { gap: 10px; }
  #toast { bottom: calc(140px + env(safe-area-inset-bottom)); }
  dialog { width: 100vw; max-width: 100vw; max-height: 92vh; margin: auto 0 0; border-radius: 16px 16px 0 0; }
  .form { padding: 16px; }
  .form .row { grid-template-columns: 1fr; }
  .form input, .form select, .form textarea, .filters input, .filters select { font-size: 16px; }
  .filters { gap: 8px; }
  .filters > select, .filters > input { flex: 1 1 45%; min-width: 0; }
  /* lançamentos viram cartões */
  table.txtable thead { display: none; }
  table.txtable, table.txtable tbody { display: block; }
  table.txtable tr { display: grid; grid-template-columns: auto 1fr auto; grid-template-areas: "desc desc val" "date acc edit" "cat cat cat"; gap: 2px 8px;
    padding: 10px 2px; border-bottom: 1px solid var(--line); }
  table.txtable td { border: 0; padding: 0; }
  table.txtable td:nth-child(1) { grid-area: date; font-size: 12px; color: var(--muted); align-self: center; }
  table.txtable td:nth-child(2), table.txtable td:nth-child(4) { display: none; }
  table.txtable td:nth-child(3) { grid-area: desc; font-weight: 550; }
  table.txtable td:nth-child(5) { grid-area: acc; font-size: 12px; align-self: center; }
  table.txtable td:nth-child(6) { grid-area: cat; }
  table.txtable td:nth-child(6) select { width: 100%; }
  table.txtable td:nth-child(7) { grid-area: val; font-weight: 650; }
  table.txtable td:nth-child(8) { grid-area: edit; text-align: right; }
  table.txtable td[colspan] { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  html, body { overflow-x: hidden; }
  .fchart, .cmpwrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tabs { z-index: 60; }
  #btnNew { z-index: 61; }
}
