:root {
  --bg: #ffffff;
  --text: #1b1b1f;
  --muted: #86868c;
  --faint: #c9c9cf;
  --line: #e7e7eb;
  --soft: #F4EFE5;
  --accent: #354C2A;
  --pos: #97d77f;
  --neg: #f5a898;
  --dark: #1e1e1e;
  --danger: #c4441a;
  --top-h: 76px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body {
  font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  font-variant-numeric: tabular-nums;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, select { font: inherit; color: inherit; }
svg { display: block; flex-shrink: 0; }
.hide { display: none !important; }

#app {
  height: 100vh; height: 100dvh;
  max-width: 520px; margin: 0 auto;
  display: flex; flex-direction: column;
  position: relative; overflow: hidden;
}

/* ---------- Topo ---------- */
.topbar {
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  display: grid; grid-template-columns: 52px 1fr 52px; align-items: center;
  border-bottom: 1px solid var(--line); background: var(--bg);
}
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; }
.icon-btn:active { background: var(--soft); }
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn.big svg { width: 38px; height: 38px; }
.month { display: flex; align-items: center; justify-content: center; gap: 6px; }
.month span { font-size: 30px; font-weight: 700; letter-spacing: -.02em; min-width: 124px; text-align: center; }
.month .icon-btn svg { width: 22px; height: 22px; }

.content { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; position: relative; }

/* ---------- Navegação ---------- */
.nav {
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
  border-top: 1px solid var(--line); background: var(--bg);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav > button:not(.fab) {
  position: relative; height: 68px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font-size: 15px; font-weight: 700;
}
.nav > button svg { width: 26px; height: 26px; }
.nav > button.ativo { color: var(--accent); }
.nav > button.ativo::before {
  content: ''; position: absolute; top: -1px; left: 8%; right: 8%; height: 3px; background: var(--accent);
}
.fab {
  justify-self: center; width: 62px; height: 62px; border-radius: 50%;
  background: var(--dark); color: #fff; display: grid; place-items: center;
  box-shadow: 0 4px 14px rgba(0,0,0,.18);
}
.fab svg { width: 28px; height: 28px; }
.fab:active { transform: scale(.94); }

/* ---------- Saldos ---------- */
.thead {
  position: sticky; top: 0; z-index: 2; background: var(--bg);
  display: grid; grid-template-columns: 68px 1fr 1fr; align-items: center;
  height: 70px; border-bottom: 1px solid var(--line);
  color: var(--muted); font-weight: 700; font-size: 18px;
}
.thead > div:first-child { text-align: center; }
.thead .r { text-align: right; padding-right: 18px; }
.pill {
  display: inline-flex; align-items: center; gap: 8px;
  height: 50px; padding: 0 14px 0 12px; margin-left: 2px;
  border: 2px solid var(--line); border-radius: 26px;
  font-weight: 700; font-size: 18px; color: var(--text); background: var(--bg);
  white-space: nowrap;
}
.pill .chev svg { width: 20px; height: 20px; color: var(--muted); }

.row {
  display: grid; grid-template-columns: 68px 1fr 1fr; height: 63px;
  border-bottom: 1px solid var(--line); width: 100%; text-align: left;
}
.row > div { display: flex; align-items: center; }
.c-dia { justify-content: center; font-size: 20px; border-right: 1px solid var(--line); }
.c-dia.fds { background: var(--soft); }
.row.hoje .c-dia { background: var(--dark); color: #fff; font-weight: 700; }
.row.hoje { border-bottom-color: #555; }
.c-mov { gap: 8px; padding: 0 12px 0 16px; font-size: 18px; justify-content: space-between; }
.c-mov span { text-align: right; }
.c-mov.zero span { color: var(--faint); }
.c-saldo { justify-content: flex-end; padding-right: 18px; font-size: 18px; font-weight: 500; }
.c-saldo.pos { background: var(--pos); }
.c-saldo.neg { background: var(--neg); }
.c-saldo.vazio { color: var(--faint); }
.row:active .c-mov { background: var(--soft); }

.banner {
  margin: 12px 14px; padding: 14px 16px; border-radius: 16px; background: var(--soft);
  display: flex; gap: 12px; align-items: flex-start; font-size: 15px; line-height: 1.4;
}
.banner b { display: block; font-size: 16px; margin-bottom: 2px; }
.banner .grow { flex: 1; }
.banner .acao { margin-top: 10px; display: inline-block; background: var(--dark); color: #fff; padding: 9px 14px; border-radius: 20px; font-weight: 700; font-size: 14px; }
.banner .icon-btn { width: 32px; height: 32px; margin: -4px -6px 0 0; }
.banner .icon-btn svg { width: 18px; height: 18px; }

/* ---------- Listas genéricas ---------- */
.sec-title { padding: 22px 20px 16px; color: var(--muted); font-weight: 700; font-size: 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; }
.sec-title .grow { flex: 1; }
.sec-title .icon-btn { width: 40px; height: 40px; color: var(--text); }
.sec-title .icon-btn.on { background: var(--soft); }

.item {
  width: 100%; display: flex; align-items: center; gap: 14px;
  padding: 22px 20px; border-bottom: 1px solid var(--line); text-align: left; min-height: 72px;
}
button.item:active { background: var(--soft); }
.item .grow { flex: 1; min-width: 0; }
.item .t { font-size: 21px; font-weight: 700; }
.item .v { font-size: 21px; font-weight: 500; text-align: right; white-space: nowrap; }
.item .s { font-size: 17px; color: var(--muted); text-align: right; margin-top: 6px; display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
.item .chevr svg { width: 20px; height: 20px; color: var(--faint); }
.item.col { align-items: stretch; }
.item .lhs { display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 0; }
.item .rhs { display: flex; flex-direction: column; align-items: flex-end; }
.neg-txt { color: var(--danger); }

.formula { display: flex; align-items: center; gap: 3px; color: var(--muted); font-weight: 700; font-size: 15px; }
.bar { width: 136px; height: 22px; border: 2.5px solid #5e9e5b; border-radius: 12px; overflow: hidden; }
.bar i { display: block; height: 100%; background: #a6d84b; }

.search { display: flex; align-items: center; gap: 14px; padding: 0 20px; height: 72px; border-bottom: 1px solid var(--line); }
.search svg { width: 26px; height: 26px; }
.search input { border: 0; outline: 0; flex: 1; font-size: 19px; background: transparent; }
.search input::placeholder { color: var(--muted); }

.vazio-msg { padding: 40px 24px; text-align: center; color: var(--muted); font-size: 16px; line-height: 1.5; }

/* ---------- Páginas internas ---------- */
.pagebar {
  padding: calc(env(safe-area-inset-top) + 14px) 10px 14px;
  display: grid; grid-template-columns: 48px 1fr 48px; align-items: center;
  border-bottom: 1px solid var(--line);
}
.pagebar h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -.01em; padding-left: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pagebar.centro h1 { text-align: center; padding: 0; }
.content.cinza { background: var(--soft); }
.content.cinza .item { background: var(--soft); border-color: #dfe2e8; }
.prev-foot { padding: 20px 20px calc(env(safe-area-inset-bottom) + 20px); border-top: 1px solid var(--line); background: var(--bg); }
.prev-foot .lin { display: flex; justify-content: space-between; align-items: center; font-size: 21px; font-weight: 700; min-height: 44px; }
.prev-foot .lin .val { font-weight: 500; }
.prev-foot hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.prev-foot .big { text-align: right; font-size: 34px; font-weight: 800; }
.prev-foot .muted { text-align: right; color: var(--muted); margin: 2px 0 0; }

.selwrap { position: relative; display: inline-flex; align-items: center; gap: 8px; font-weight: 500; }
.selwrap svg { width: 20px; height: 20px; color: var(--muted); }
.overlay-input {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; -webkit-appearance: none; appearance: none; border: 0; font-size: 16px;
}

.texto { padding: 18px 20px; font-size: 16px; line-height: 1.55; color: #444; }
.texto ol { padding-left: 22px; margin: 8px 0; }
.texto li { margin: 8px 0; }
.campo { padding: 0 20px; }
.campo label.lbl { display: block; font-weight: 700; margin: 18px 0 8px; font-size: 16px; }
.money-in { display: flex; align-items: center; gap: 8px; border-bottom: 2px solid var(--line); padding: 8px 0; }
.money-in span { font-size: 30px; font-weight: 800; }
.money-in input { border: 0; outline: 0; font-size: 34px; font-weight: 700; width: 100%; background: transparent; }
.money-in input::placeholder, .f-valor input::placeholder { color: #d4d4d8; }
.txt-in { width: 100%; border: 2px solid var(--line); border-radius: 14px; padding: 13px 14px; font-size: 17px; outline: 0; background: var(--bg); }
.txt-in:focus { border-color: #b9b9c0; }
.check { display: flex; align-items: center; gap: 10px; margin-top: 14px; font-size: 16px; }
.check input { width: 22px; height: 22px; accent-color: var(--dark); }
.date-box { position: relative; display: flex; align-items: center; justify-content: space-between; border: 2px solid var(--line); border-radius: 14px; padding: 13px 14px; font-size: 17px; }
.date-box svg { width: 20px; height: 20px; color: var(--muted); }

.opcoes { display: flex; flex-direction: column; gap: 10px; }
.opcao { display: flex; align-items: center; gap: 12px; border: 2px solid var(--line); border-radius: 16px; padding: 14px; text-align: left; }
.opcao.on { border-color: var(--dark); }
.opcao .radio { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--faint); flex-shrink: 0; }
.opcao.on .radio { border: 7px solid var(--dark); }
.opcao b { display: block; }
.opcao small { color: var(--muted); font-size: 14px; }

.btn-main {
  flex: 1; height: 62px; border-radius: 31px; background: var(--dark); color: #fff;
  font-weight: 700; font-size: 19px; display: grid; place-items: center;
}
.btn-main:active { filter: brightness(.92); }
.btn-sec { flex: 1; height: 56px; border-radius: 28px; background: var(--soft); font-weight: 700; font-size: 17px; }
.btn-danger { color: var(--danger); }
.btn-row { display: flex; gap: 10px; padding: 20px; }

/* ---------- Sheets ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,0);
  display: flex; align-items: flex-end; justify-content: center; transition: background .22s;
}
.overlay.open { background: rgba(0,0,0,.32); }
.sheet {
  width: 100%; max-width: 520px; max-height: calc(100dvh - env(safe-area-inset-top) - 24px);
  background: var(--bg); border-radius: 28px 28px 0 0;
  display: flex; flex-direction: column; overflow: hidden;
  transform: translateY(100%); transition: transform .26s cubic-bezier(.2,.8,.2,1);
  padding-bottom: env(safe-area-inset-bottom);
}
.overlay.open .sheet { transform: none; }
.sheet.full { height: calc(100dvh - env(safe-area-inset-top) - 10px); }
.sh-head { display: flex; align-items: center; justify-content: space-between; padding: 22px 16px 18px 24px; border-bottom: 1px solid var(--line); }
.sh-head h2 { margin: 0; font-size: 28px; font-weight: 700; }
.sh-head .sub { color: var(--muted); font-size: 15px; margin-top: 2px; }
.sh-body { overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.sh-foot { padding: 14px 20px 18px; border-top: 1px solid var(--line); display: flex; gap: 10px; }
.opt { width: 100%; display: flex; align-items: center; gap: 18px; padding: 26px 24px; border-bottom: 1px solid var(--line); font-size: 21px; font-weight: 700; text-align: left; }
.opt:last-child { border-bottom: 0; }
.opt:active { background: var(--soft); }
.opt .grow { flex: 1; }
.opt .ok svg { width: 22px; height: 22px; color: var(--accent); }
.sheet-msg { padding: 8px 24px 4px; color: #555; font-size: 16px; line-height: 1.5; }

/* Lançamentos */
.oc { width: 100%; display: flex; align-items: center; gap: 14px; padding: 14px 20px; border-bottom: 1px solid var(--line); text-align: left; }
.oc:active { background: var(--soft); }
.oc-txt { flex: 1; min-width: 0; }
.oc-txt b { display: block; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.oc-txt small { display: block; color: var(--muted); font-size: 14px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.oc-val { font-size: 17px; font-weight: 700; white-space: nowrap; }
.oc-val.pos { color: #3f8a3c; }
.oc.fixo { cursor: default; }
.oc.fixo:active { background: none; }
.dia-sep { padding: 14px 20px 6px; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.total-lin { display: flex; justify-content: space-between; padding: 16px 20px; font-weight: 700; font-size: 18px; }

/* Formulário */
.form { display: flex; flex-direction: column; height: 100%; }
.f-valor { display: flex; align-items: center; gap: 8px; padding: 28px 18px 26px 24px; border-bottom: 1px solid var(--line); }
.f-valor span { font-size: 42px; font-weight: 800; letter-spacing: -.02em; }
.f-valor input { flex: 1; min-width: 0; border: 0; outline: 0; font-size: 42px; font-weight: 700; background: transparent; caret-color: #777; letter-spacing: -.02em; }
.f-row {
  position: relative; display: flex; align-items: center; gap: 14px; width: 100%;
  min-height: 76px; padding: 0 24px; border-bottom: 1px solid var(--line); text-align: left; font-size: 21px;
}
.f-row svg { width: 28px; height: 28px; }
.f-row b { font-weight: 700; }
.f-row .f-val { margin-left: auto; font-size: 20px; }
.f-row .chev { color: var(--faint); }
.f-row .chev svg { width: 22px; height: 22px; }
.f-row b + .chev { margin-left: auto; }
.f-row input.plain { flex: 1; border: 0; outline: 0; font-size: 21px; background: transparent; min-width: 0; }
.f-row input.plain::placeholder { color: var(--muted); }
.f-row small { color: var(--muted); font-size: 14px; }
.f-chips { margin-left: auto; display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; max-width: 62%; }
.chip { display: inline-flex; align-items: center; padding: 5px 10px; border-radius: 12px; font-size: 14px; font-weight: 700; color: #333; }
.f-spacer { flex: 1; }
.f-foot { display: flex; gap: 10px; padding: 18px 20px 18px; border-top: 1px solid var(--line); }
.f-foot .del { width: 62px; height: 62px; border-radius: 50%; background: var(--soft); display: grid; place-items: center; color: var(--danger); }
.f-foot .del svg { width: 24px; height: 24px; }
.shake { animation: shake .35s; }
@keyframes shake { 20%,60% { transform: translateX(-6px); } 40%,80% { transform: translateX(6px); } }

.tp-new { display: flex; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); }
.tp-new .txt-in { flex: 1; }
.tp-new button { padding: 0 18px; border-radius: 14px; background: var(--soft); font-weight: 700; }
.cores { display: flex; flex-wrap: wrap; gap: 12px; padding: 4px 0; }
.cor { width: 42px; height: 42px; border-radius: 50%; border: 3px solid transparent; }
.cor.on { border-color: var(--dark); }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 96px); z-index: 99;
  transform: translate(-50%, 20px); opacity: 0; transition: .22s;
  background: var(--dark); color: #fff; padding: 12px 18px; border-radius: 22px; font-weight: 700; font-size: 15px;
  white-space: nowrap; pointer-events: none;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 540px) {
  body { background: #f3f3f5; }
  #app { background: var(--bg); box-shadow: 0 0 0 1px var(--line); }
}

/* Montserrat é mais larga que DM Sans: valores numa linha só */
.c-mov, .c-saldo { font-size: 16px; letter-spacing: -0.3px; }
.c-mov span, .c-saldo { white-space: nowrap; }
.item .v { letter-spacing: -0.3px; }


/* =========================================================
   Desktop (≥ 1000 px): trilho lateral, tabela por tipo, painel
   ========================================================= */
body.desk { background: var(--bg); }
.desk #app { max-width: none; flex-direction: row; box-shadow: none; }
.desk .main { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.desk .topbar { padding: 10px 24px; }
.desk .icon-btn:hover, .desk button.item:hover, .desk .opt:hover, .desk .oc:not(.fixo):hover { background: var(--soft); }

.rail {
  width: 236px; flex-shrink: 0; display: flex; flex-direction: column; gap: 4px;
  padding: 24px 14px 20px; border-right: 1px solid var(--line); background: var(--soft);
}
.rail .marca { font-weight: 800; font-size: 20px; letter-spacing: -.01em; padding: 0 12px 20px; }
.rail .novo {
  display: flex; align-items: center; gap: 10px; height: 48px; padding: 0 16px; margin-bottom: 16px;
  border-radius: 14px; background: var(--dark); color: #fff; font-weight: 700; font-size: 15px;
}
.rail .novo svg { width: 20px; height: 20px; }
.rail .novo:hover { filter: brightness(1.15); }
.rail .navb { display: flex; align-items: center; gap: 12px; height: 46px; padding: 0 12px; border-radius: 12px; font-weight: 700; font-size: 16px; }
.rail .navb svg { width: 22px; height: 22px; }
.rail .navb:hover { background: rgba(0,0,0,.045); }
.rail .navb.ativo { background: var(--bg); color: var(--accent); box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.rail .atalhos { margin-top: auto; padding: 0 12px; color: var(--muted); font-size: 12px; line-height: 2; }
.rail kbd { display: inline-block; min-width: 20px; padding: 0 5px; border: 1px solid var(--faint); border-radius: 5px; background: var(--bg); font: 600 11px/18px inherit; text-align: center; color: var(--text); }

/* Páginas e listas centralizadas */
.desk .main > .pagebar > *, .desk .content > :not(.split), .desk .prev-foot > * { max-width: 760px; margin-left: auto; margin-right: auto; }
.desk .main > .pagebar { padding: 14px 24px; }
.desk .content > :not(.split) { width: 100%; }
.desk .content > .banner { width: auto; }

/* Tabela de saldos com uma coluna por tipo */
.split { display: grid; grid-template-columns: minmax(0, 1fr) 390px; align-items: start; }
.tabela { min-width: 0; }
.tabela .banner { margin: 14px 18px; }
.dthead, .dfoot { display: grid; align-items: center; background: var(--bg); }
.dthead { position: sticky; top: 0; z-index: 2; height: 54px; border-bottom: 1px solid var(--line); color: var(--muted); font-weight: 700; font-size: 12.5px; }
.dthead > div, .dfoot > div { display: flex; align-items: center; justify-content: flex-end; gap: 6px; padding: 0 12px; white-space: nowrap; overflow: hidden; }
.dthead > div span { overflow: hidden; text-overflow: ellipsis; }
.dthead > div:first-child, .dfoot > div:first-child { justify-content: center; }
.dfoot { height: 52px; font-weight: 700; font-size: 14px; border-top: 2px solid var(--line); position: sticky; bottom: 0; }
.drow { display: grid; width: 100%; height: 46px; border-bottom: 1px solid var(--line); text-align: left; }
.drow > div { display: flex; align-items: center; justify-content: flex-end; padding: 0 12px; font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; }
.drow > div.zero { color: var(--faint); font-weight: 400; }
.drow .c-dia { justify-content: center; gap: 6px; font-size: 16px; border-right: 1px solid var(--line); }
.drow .c-dia small { color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; }
.drow.hoje .c-dia { background: var(--dark); color: #fff; }
.drow.hoje .c-dia small { color: #bbb; }
.drow .c-saldo { font-size: 15px; padding-right: 16px; }
.drow:hover > div:not(.c-saldo):not(.c-dia) { background: var(--soft); }

.painel { position: sticky; top: 0; max-height: calc(100dvh - 65px); overflow-y: auto; border-left: 1px solid var(--line); }
.painel .sec-title { font-size: 14px; padding: 16px 18px 12px; }
.painel .item { padding: 15px 18px; min-height: 0; gap: 10px; }
.painel .item .t, .painel .item .v { font-size: 16px; }
.painel .item .s { font-size: 13px; margin-top: 4px; }
.painel .formula { font-size: 13px; }
.painel .formula svg { width: 17px; height: 17px; }
.painel .bar { width: 90px; height: 18px; }
@media (max-width: 1439px) {
  .split { grid-template-columns: minmax(0, 1fr); }
  .painel { display: none; }
}

/* Janelas no centro em vez de gaveta */
.desk .overlay { align-items: center; padding: 24px; }
.desk .sheet { border-radius: 22px; max-height: 88vh; transform: translateY(16px) scale(.98); opacity: 0; transition: transform .2s, opacity .2s; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.desk .overlay.open .sheet { transform: none; opacity: 1; }
.desk .sheet.full { height: min(800px, 90vh); }
.desk .toast { bottom: 32px; }
.dthead { height: 62px; }
.dthead > div:not(:first-child):not(:last-child) { flex-direction: column; align-items: flex-end; justify-content: center; gap: 3px; }
.dthead > div span { font-size: 11.5px; line-height: 1.15; text-align: right; white-space: normal; overflow: visible; }
.drow:focus:not(:focus-visible), .rail button:focus:not(:focus-visible) { outline: none; }
