:root {
  --fundo: #f3f2f7;
  --superficie: #ffffff;
  --superficie-2: #efeef4;
  --texto: #16151c;
  --texto-2: #5d5b6a;
  --borda: #e2e0ea;
  --perigo: #c62828;
  --sucesso: #2e7d32;
  --destaque: #4a3aa7;
  --sombra: 0 1px 2px rgb(20 10 60 / 0.05), 0 6px 20px rgb(20 10 60 / 0.06);
  /* Cor segue a categoria (paleta validada para daltonismo no tema claro). */
  --cor-C: #4a3aa7;
  --cor-T: #2a78d6;
  --cor-L: #1baf7a;
  --cor-P: #eb6834;
  --tom-C: #ecebfb;
  --tom-T: #e3effc;
  --tom-L: #dcf5ec;
  --tom-P: #fdebe3;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fundo: #0f0e14;
    --superficie: #1a1922;
    --superficie-2: #24232e;
    --texto: #eeedf5;
    --texto-2: #a3a1b3;
    --borda: #302e3c;
    --perigo: #ef5350;
    --sucesso: #66bb6a;
    --destaque: #a597f0;
    --sombra: none;
    --cor-C: #9b59d0;
    --cor-T: #3987e5;
    --cor-L: #199e70;
    --cor-P: #d95926;
    --tom-C: #2c2240;
    --tom-T: #182a44;
    --tom-L: #12302a;
    --tom-P: #3a2014;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--fundo); color: var(--texto);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent; overflow-x: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
main { max-width: 560px; margin: 0 auto; padding: calc(14px + env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom)); display: grid; gap: 14px; }
.num { font-variant-numeric: tabular-nums; }
.sutil { color: var(--texto-2); font-size: 0.85rem; }

.cab { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 4px 2px 0; }
.cab h1 { margin: 0; font-size: 1.45rem; letter-spacing: -0.01em; }

.cartao { background: var(--superficie); border-radius: 20px; padding: 16px; box-shadow: var(--sombra); display: grid; gap: 12px; min-width: 0; }
.cartao h2 { margin: 0; font-size: 1rem; }
.cartao-cab { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }

/* Ranking */
.rank { display: grid; gap: 12px; list-style: none; margin: 0; padding: 0; }
.rank li { display: grid; grid-template-columns: 26px 1fr auto; column-gap: 10px; row-gap: 6px; align-items: center; }
.pos { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 0.8rem; background: var(--superficie-2); }
.rank li:first-child .pos { background: var(--cor); color: #fff; }
.rank .nome { font-weight: 600; }
.rank .falta { font-weight: 700; font-size: 0.9rem; text-align: right; }
.rank .falta small { display: block; font-weight: 500; color: var(--texto-2); font-size: 0.72rem; }
.trilho { grid-column: 2 / 4; position: relative; height: 10px; border-radius: 99px; background: var(--superficie-2); }
.trilho i { position: absolute; inset: 0 auto 0 0; border-radius: 99px; background: var(--cor); }
.trilho b { position: absolute; top: -4px; bottom: -4px; width: 3px; border-radius: 2px; background: var(--texto); }

.alternar { display: flex; gap: 4px; background: var(--superficie-2); border-radius: 99px; padding: 3px; }
.alternar button { border: 0; background: none; border-radius: 99px; padding: 4px 12px; font-size: 0.8rem; font-weight: 600; color: var(--texto-2); }
.alternar button[aria-pressed="true"] { background: var(--superficie); color: var(--texto); box-shadow: var(--sombra); }

table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { padding: 7px 4px; text-align: right; border-bottom: 1px solid var(--borda); white-space: nowrap; }
th:first-child, td:first-child, th:nth-child(2), td:nth-child(2) { text-align: left; }
th { font-weight: 600; color: var(--texto-2); font-size: 0.75rem; }
.ponto { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--cor); margin-right: 6px; }

/* Botões */
.linha { display: grid; grid-template-columns: 1fr repeat(3, 58px); gap: 6px; align-items: center; }
.linha .rot { font-weight: 600; display: flex; align-items: center; min-width: 0; }
.linha .rot small { color: var(--texto-2); font-weight: 500; margin-left: 6px; font-size: 0.75rem; }
.bt {
  height: 46px; border: 0; border-radius: 14px; font-weight: 800; font-size: 0.92rem;
  background: var(--tom); color: var(--texto); transition: transform 0.08s;
}
.bt:active { transform: scale(0.93); }
.ajustes { border: 1.5px dashed var(--borda); border-radius: 16px; padding: 10px; display: grid; gap: 8px; }
.ajustes .bt { background: var(--superficie-2); }

.hist { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.hist li { display: flex; align-items: center; gap: 8px; font-size: 0.88rem; }
.hist li span:nth-child(2) { flex: 1; }
.hist button { border: 1px solid var(--borda); background: var(--superficie); border-radius: 10px; padding: 4px 10px; font-size: 0.8rem; }
details summary { cursor: pointer; font-weight: 600; }

.aviso {
  position: fixed; left: 50%; bottom: calc(78px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: max-content; max-width: calc(100% - 32px); display: flex; align-items: center; gap: 14px;
  background: var(--texto); color: var(--fundo); padding: 10px 16px; border-radius: 14px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s; font-size: 0.9rem; z-index: 10;
}
.aviso.visivel { opacity: 1; pointer-events: auto; }
.aviso button { border: 0; background: none; color: #b8adff; font-weight: 800; text-transform: uppercase; font-size: 0.8rem; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .aviso button { color: #4a3aa7; } }
@media (prefers-reduced-motion: reduce) { .bt { transition: none; } }

:root { --verde: #2e7d32; --vermelho: #c62828; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --verde: #66bb6a; --vermelho: #ef6b6b; } }
.verde { color: var(--verde); }
.vermelho { color: var(--vermelho); }

/* Abas */
.abas {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 5;
  display: flex; gap: 4px; padding: 5px; border-radius: 99px; background: var(--superficie); box-shadow: 0 4px 24px rgb(20 10 60 / 0.16);
  border: 1px solid var(--borda);
}
.abas button { border: 0; background: none; border-radius: 99px; padding: 9px 18px; font-weight: 600; color: var(--texto-2); }
.abas button[aria-current="page"] { background: var(--destaque); color: #fff; }

/* Projetos */
.filtros { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.filtros button {
  flex: none; border: 1.5px solid var(--borda); background: var(--superficie); border-radius: 99px;
  padding: 7px 14px; font-weight: 600; font-size: 0.88rem;
}
.filtros button[aria-pressed="true"] { background: var(--cor, var(--destaque)); border-color: transparent; color: #fff; }
.totais { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.totais div { background: var(--superficie); border-radius: 14px; padding: 8px; display: grid; gap: 2px; border-top: 3px solid var(--cor); box-shadow: var(--sombra); }
.totais .sutil { font-size: 0.72rem; }
.projs { list-style: none; margin: 0; padding: 0; display: grid; }
.proj { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--borda); }
.proj:last-child { border-bottom: 0; }
.circulo {
  width: 30px; height: 30px; flex: none; border-radius: 50%; border: 2px solid var(--cor); background: none;
  font-weight: 800; color: #fff; display: grid; place-items: center; padding: 0;
}
.proj.feito .circulo { background: var(--cor); }
.proj.feito .proj-nome { color: var(--texto-2); }
.proj-corpo { flex: 1; min-width: 0; border: 0; background: none; text-align: left; padding: 2px 0; display: grid; gap: 1px; }
.proj-nome { font-weight: 600; overflow-wrap: anywhere; }
.proj-corpo .ponto { width: 7px; height: 7px; }
.fab {
  position: fixed; right: max(16px, calc(50% - 264px)); bottom: calc(78px + env(safe-area-inset-bottom)); z-index: 6;
  width: 56px; height: 56px; border-radius: 18px; border: 0; background: var(--destaque); color: #fff;
  font-size: 1.8rem; font-weight: 500; box-shadow: 0 6px 20px rgb(74 58 167 / 0.35);
}
.vermelho-fab { background: var(--vermelho) !important; color: #fff; box-shadow: 0 6px 20px rgb(198 40 40 / 0.3); }

/* Folha que sobe */
#folha[hidden] { display: none; }
.folha-fundo { position: fixed; inset: 0; background: rgb(10 8 20 / 0.5); z-index: 20; }
.folha {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-width: 560px; margin: 0 auto;
  background: var(--superficie); border-radius: 24px 24px 0 0; padding: 10px 16px calc(18px + env(safe-area-inset-bottom));
  display: grid; gap: 12px; max-height: 92vh; overflow-y: auto; animation: subir 0.22s ease-out;
}
@keyframes subir { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .folha { animation: none; } }
.alca { width: 40px; height: 5px; border-radius: 99px; background: var(--borda); justify-self: center; }
.folha h2 { margin: 0; font-size: 1.1rem; }
.folha input[type="text"], .folha input[type="date"] {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 14px; border: 1.5px solid var(--borda);
  background: var(--superficie-2); color: var(--texto); font: inherit;
}
.folha input:focus-visible { outline: 2px solid var(--destaque); outline-offset: 1px; }
.campo { display: grid; gap: 4px; font-size: 0.82rem; color: var(--texto-2); font-weight: 600; }
.tamanhos { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; }
.tamanhos button { border: 1.5px solid var(--borda); background: var(--superficie); border-radius: 10px; padding: 8px 0; font-weight: 700; font-size: 0.85rem; }
.tamanhos button[aria-pressed="true"] { background: var(--destaque); color: #fff; border-color: transparent; }
.salvar { border: 0; border-radius: 14px; padding: 14px; font-weight: 700; background: var(--destaque); color: #fff; }
.excluir { border: 0; background: none; color: var(--vermelho); font-weight: 600; padding: 6px; }
.erro { margin: 0; color: var(--vermelho); font-size: 0.85rem; }

/* Dinheiro */
.saldo { grid-template-columns: 1fr auto; align-items: end; }
.saldo strong { display: block; font-size: 2rem; letter-spacing: -0.02em; }
.legenda { display: flex; align-items: center; gap: 5px; font-size: 0.75rem; color: var(--texto-2); }
.legenda i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-left: 6px; }
.entrou { background: var(--verde); }
.saiu { background: var(--vermelho); }
.grafico-meses {
  display: flex; gap: 6px; overflow-x: auto; scroll-snap-type: x proximity; padding: 4px 2px 2px;
  scrollbar-width: thin; border-bottom: 1px solid var(--borda);
}
.mes { flex: 0 0 56px; scroll-snap-align: end; border: 0; background: none; border-radius: 12px; padding: 6px 4px; display: grid; gap: 4px; }
.mes.ativo { background: var(--superficie-2); outline: 2px solid var(--destaque); }
.barras { height: 110px; display: flex; align-items: flex-end; justify-content: center; gap: 4px; }
.barras i { width: 14px; border-radius: 4px 4px 0 0; display: block; }
.rot-mes { font-size: 0.75rem; color: var(--texto-2); font-weight: 600; }
.resumo, .extrato { list-style: none; margin: 0; padding: 0; display: grid; }
.resumo li { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--borda); font-size: 0.92rem; }
.resumo li.total { border-bottom: 0; font-weight: 700; }
.extrato li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--borda); }
.extrato li:last-child { border-bottom: 0; }
.extrato .ic { width: 28px; height: 28px; flex: none; border-radius: 50%; background: var(--superficie-2); display: grid; place-items: center; font-size: 0.8rem; }
.extrato .corpo { flex: 1; min-width: 0; display: grid; font-size: 0.92rem; overflow-wrap: anywhere; }
.extrato .corpo .sutil { font-size: 0.75rem; }
.extrato b { white-space: nowrap; }
.mini { border: 1px solid var(--borda); background: var(--superficie); border-radius: 8px; padding: 2px 8px; }
