:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #6f6e69;
  --border: rgba(11, 11, 11, 0.12);
  --grid: #e1e0d9;
  --accent: #1c5cab;
  --accent-text: #ffffff;
  --pos: #006300;
  --neg: #c02626;
  --entrada: #0f7a3d;
  --entrada-bg: #e6f4ec;
  --saida: #b42323;
  --saida-bg: #fbeaea;
  --s-ent-pj: #2a78d6;
  --s-ent-cpf: #1baf7a;
  --s-sai-pj: #e34948;
  --s-sai-cpf: #4a3aa7;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.04);
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #242422;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #a09f98;
    --border: rgba(255, 255, 255, 0.12);
    --grid: #2c2c2a;
    --accent: #5598e7;
    --accent-text: #0b0b0b;
    --pos: #2fbf4a;
    --neg: #ff6b6b;
    --entrada: #3fcf7a;
    --entrada-bg: #12301f;
    --saida: #ff7b7b;
    --saida-bg: #3a1717;
    --s-ent-pj: #3987e5;
    --s-ent-cpf: #199e70;
    --s-sai-pj: #e66767;
    --s-sai-cpf: #9085e9;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d; --surface: #1a1a19; --surface-2: #242422; --text: #ffffff; --text-2: #c3c2b7; --muted: #a09f98;
  --border: rgba(255,255,255,0.12); --grid: #2c2c2a; --accent: #5598e7; --accent-text: #0b0b0b; --pos: #2fbf4a; --neg: #ff6b6b;
  --entrada: #3fcf7a; --entrada-bg: #12301f; --saida: #ff7b7b; --saida-bg: #3a1717;
  --s-ent-pj: #3987e5; --s-ent-cpf: #199e70; --s-sai-pj: #e66767; --s-sai-cpf: #9085e9; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.4; -webkit-text-size-adjust: 100%; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

/* topo */
.topo { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border); }
.topo-in { max-width: 1100px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; }
.marca { font-weight: 700; font-size: 17px; margin-right: auto; }
.abas { display: flex; gap: 4px; }
.aba { border: 0; background: none; padding: 8px 12px; border-radius: 10px; cursor: pointer; color: var(--text-2); font-weight: 600; }
.aba[aria-current="page"] { background: var(--surface-2); color: var(--text); }
.sair { border: 1px solid var(--border); background: none; border-radius: 10px; padding: 7px 12px; cursor: pointer; color: var(--text-2); }

main { max-width: 1100px; margin: 0 auto; padding: 16px 16px 96px; }
h2 { font-size: 18px; margin: 24px 0 10px; }
h2:first-child { margin-top: 4px; }

/* botões grandes */
.botoes-lanc { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 18px; }
.btn-lanc { border: 2px solid transparent; border-radius: var(--radius); padding: 16px 8px; font-size: 17px; font-weight: 700; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 76px; justify-content: center; }
.btn-lanc small { font-weight: 600; font-size: 13px; opacity: .85; }
.btn-lanc .sinal { font-size: 22px; line-height: 1; }
.btn-lanc.entrada { background: var(--entrada-bg); color: var(--entrada); border-color: color-mix(in srgb, var(--entrada) 35%, transparent); }
.btn-lanc.saida { background: var(--saida-bg); color: var(--saida); border-color: color-mix(in srgb, var(--saida) 35%, transparent); }
.btn-lanc:active { transform: scale(.98); }

/* filtros */
.filtros { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; box-shadow: var(--shadow); }
.campo { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.campo > span { font-size: 13px; color: var(--text-2); font-weight: 600; }
.campo input, .campo select { height: 44px; border: 1px solid var(--border); border-radius: 10px; padding: 0 10px; background: var(--surface); min-width: 0; width: 100%; }
.campo input:focus, .campo select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.filtros .campo { flex: 1 1 150px; }
.filtros .campo.largo { flex: 2 1 220px; }

.btn { height: 44px; border-radius: 10px; padding: 0 16px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn.primario { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.perigo { background: var(--neg); color: #fff; border-color: transparent; }
.btn.link { border: 0; background: none; color: var(--accent); padding: 0 6px; }
.btn:disabled { opacity: .6; cursor: default; }

/* cartões */
.cartoes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.cartao { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.cartao .rot { font-size: 13px; color: var(--text-2); font-weight: 600; }
.cartao .val { font-size: 21px; font-weight: 700; margin-top: 2px; overflow-wrap: anywhere; }
.cartao.geral { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 6px; }
.cartao.geral .val { font-size: 28px; }
.grupo-conta { display: contents; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* gráficos */
.graficos { display: grid; grid-template-columns: 3fr 2fr; gap: 12px; margin-top: 12px; }
.painel-graf { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.painel-graf h3 { margin: 0 0 8px; font-size: 15px; }
.graf-cab { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.graf-cab h3 { margin: 0; }
.caixa-graf { position: relative; height: 280px; }
.caixa-pizza { position: relative; height: 220px; }
.legenda { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.legenda li { display: flex; align-items: center; gap: 8px; }
.legenda .cor { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.legenda .nome { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.legenda .v { color: var(--text-2); }
.legenda-barras { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.legenda-barras span { display: inline-flex; align-items: center; gap: 6px; }
.legenda-barras .cor { width: 12px; height: 12px; border-radius: 3px; }
.vazio { color: var(--muted); text-align: center; padding: 28px 8px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: none; padding: 6px 12px; cursor: pointer; font-size: 14px; color: var(--text-2); }
.seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); font-weight: 700; }
details.tabela-graf { margin-top: 10px; font-size: 14px; }
details.tabela-graf summary { cursor: pointer; color: var(--accent); }
.tabela-rolagem { overflow-x: auto; }
.tabela-graf table { border-collapse: collapse; width: 100%; margin-top: 6px; }
.tabela-graf th, .tabela-graf td { padding: 4px 8px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
.tabela-graf th:first-child, .tabela-graf td:first-child { text-align: left; }

/* lista de lançamentos */
.lista { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.item { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 12px 14px; border-bottom: 1px solid var(--grid); cursor: pointer; }
.item:last-child { border-bottom: 0; }
.item:hover { background: var(--surface-2); }
.item .desc { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.item .valor { font-weight: 700; text-align: right; white-space: nowrap; }
.item .info { font-size: 13px; color: var(--text-2); grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.etq { font-size: 12px; font-weight: 700; padding: 1px 7px; border-radius: 6px; border: 1px solid var(--border); color: var(--text-2); }
.etq.entrada { color: var(--entrada); background: var(--entrada-bg); border-color: transparent; }
.etq.saida { color: var(--saida); background: var(--saida-bg); border-color: transparent; }
.totais { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 12px 2px; font-size: 15px; }
.totais b { font-weight: 700; }
.acoes-lista { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 14px 0 8px; flex-wrap: wrap; }
.acoes-lista h2 { margin: 0; }

/* categorias */
.cat-linha { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--grid); }
.cat-linha:last-child { border-bottom: 0; }
.cat-linha .nome { flex: 1; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.cat-linha .usos { font-size: 13px; color: var(--muted); }
.nova-cat { display: flex; gap: 8px; margin-bottom: 12px; }
.nova-cat input { flex: 1; height: 44px; border: 1px solid var(--border); border-radius: 10px; padding: 0 12px; background: var(--surface); min-width: 0; }

/* janela (formulário) */
dialog { border: 0; border-radius: 18px; padding: 0; width: min(520px, calc(100vw - 24px)); background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.45); }
.dlg-cab { padding: 16px 18px 8px; display: flex; align-items: center; gap: 10px; }
.dlg-cab h3 { margin: 0; font-size: 19px; flex: 1; }
.fechar { border: 0; background: none; font-size: 26px; line-height: 1; cursor: pointer; color: var(--text-2); padding: 4px 8px; }
.dlg-corpo { padding: 6px 18px 4px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dlg-corpo .inteiro { grid-column: 1 / -1; }
.dlg-rodape { padding: 14px 18px 18px; display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.dlg-rodape .esq { margin-right: auto; }
.campo-valor input { font-size: 22px; font-weight: 700; height: 52px; }
.escolha { display: flex; gap: 6px; flex-wrap: wrap; }
.escolha label { flex: 1 1 auto; }
.escolha input { position: absolute; opacity: 0; pointer-events: none; }
.escolha span { display: block; text-align: center; padding: 10px 8px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 14px; }
.escolha input:checked + span { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.escolha input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.escolha.tipo input[value="entrada"]:checked + span { background: var(--entrada); color: #fff; }
.escolha.tipo input[value="saida"]:checked + span { background: var(--saida); color: #fff; }
.erro { color: var(--neg); font-weight: 600; font-size: 14px; min-height: 1em; margin: 0; }

.aviso { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; z-index: 100; box-shadow: 0 4px 16px rgba(0,0,0,.25); max-width: calc(100vw - 32px); }

/* login */
.login-pag { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-caixa { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 24px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; }
.login-caixa h1 { margin: 0; font-size: 22px; }
.login-caixa p { margin: 0; color: var(--text-2); }

/* celular */
@media (max-width: 760px) {
  .topo-in { padding: 8px 16px; }
  .abas { position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--border); justify-content: space-around; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); z-index: 30; }
  .aba { flex: 1; padding: 10px 4px; font-size: 14px; }
  .botoes-lanc { grid-template-columns: 1fr 1fr; }
  .cartoes { grid-template-columns: 1fr 1fr; }
  .cartao .val { font-size: 18px; }
  .cartao.saldo-conta { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
  .graficos { grid-template-columns: 1fr; }
  .caixa-graf { height: 240px; }
  .dlg-corpo { grid-template-columns: 1fr; }
  dialog { width: 100vw; max-width: 100vw; max-height: 100dvh; margin: auto 0 0; border-radius: 18px 18px 0 0; }
  .filtros .campo { flex: 1 1 calc(50% - 10px); }
  .filtros .campo.largo { flex-basis: 100%; }
}

/* cartões de crédito e parcelas */
.cartao.futuras { grid-column: 1 / -1; }
.cartao.futuras small { font-weight: 400; color: var(--muted); }
.futuras-linha { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 6px; }
.futuras-linha > div { min-width: 0; }
.futuras-linha .mini { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.futuras-linha .val { font-size: 19px; }
.bloco-credito { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 12px; border-radius: 12px; background: var(--surface-2); }
.bloco-credito .inteiro { grid-column: 1 / -1; }
.previa { margin: 0; font-size: 17px; font-weight: 700; }
.previa small { display: block; font-size: 13px; font-weight: 400; color: var(--text-2); margin-top: 2px; }
.info-parcela { margin: 0; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); font-size: 14px; color: var(--text-2); }
.etq.parc { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.dica { margin: 0; font-size: 13px; color: var(--text-2); }
.dlg-rodape.coluna { flex-direction: column; align-items: stretch; }
.tabela-fat { border-collapse: collapse; width: 100%; font-size: 14px; }
.tabela-fat th, .tabela-fat td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
.tabela-fat th:first-child, .tabela-fat td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); }
.tabela-fat thead th { color: var(--text-2); font-weight: 600; font-size: 13px; }
.tabela-fat tfoot td { font-weight: 700; border-bottom: 0; }
.tabela-fat .zero { color: var(--muted); }
.tabela-fat .sub { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.cartao-linha { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--grid); cursor: pointer; }
.cartao-linha:last-child { border-bottom: 0; }
.cartao-linha:hover { background: var(--surface-2); }
.cartao-linha .nome { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.cartao-linha .det { font-size: 13px; color: var(--text-2); font-weight: 400; display: block; }
.cartao-linha.inativo { opacity: .6; }
@media (max-width: 760px) {
  .bloco-credito { grid-template-columns: 1fr 1fr; }
  .futuras-linha .val { font-size: 16px; }
  .aba { font-size: 13px; padding: 10px 2px; }
}
.dlg-rodape.coluna-inv { flex-direction: column-reverse; align-items: stretch; }
