:root {
  --fundo: #FFFFFF;
  --fundo2: #F1F4F8;
  --tinta: #0B1F3A;
  --tinta2: #3D4F66;
  --borda: #AEB9C8;
  --acento: #C8102E;
  --alerta: #B45309;
  --ok: #0F7B3F;
  --raio: 12px;
  --topo: 52px;
  --abas: 62px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--fundo);
  color: var(--tinta);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Estrutura ---------- */
.topo {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5;
  height: calc(var(--topo) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 16px 0;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--fundo); border-bottom: 1px solid var(--fundo2);
}
.topo h1 { font-size: 20px; margin: 0; }
.sync {
  display: flex; align-items: center; gap: 6px;
  background: none; border: 0; padding: 10px 0 10px 16px; min-height: 44px;
  font-size: 13px; color: var(--tinta2);
}
.sync .ponto { width: 12px; height: 12px; border-radius: 50%; background: var(--ok); }
.sync.pend .ponto { background: #E0A100; }
.sync.off .ponto { background: #8A96A8; }
.sync.erro .ponto { background: var(--acento); }

main {
  padding: calc(var(--topo) + env(safe-area-inset-top)) 16px calc(var(--abas) + env(safe-area-inset-bottom) + 12px);
  max-width: 560px; margin: 0 auto;
  min-height: 100%;
}

.abas {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--abas) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--fundo); border-top: 1px solid var(--borda);
}
.abas button {
  background: none; border: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--tinta2); font-size: 12px;
}
.abas button b { font-size: 22px; line-height: 1; }
.abas button.ativa { color: var(--tinta); font-weight: 700; }
.abas button.ativa b { color: var(--tinta); }

/* ---------- Lançar ---------- */
.lancar {
  display: flex; flex-direction: column; gap: 10px;
  min-height: calc(100dvh - var(--topo) - var(--abas) - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 24px);
  padding-top: 8px;
}
.valor-linha { display: flex; align-items: center; gap: 8px; min-height: 68px; }
.moeda {
  flex: none; min-width: 64px; height: 48px; border-radius: 24px;
  border: 2px solid var(--tinta); background: var(--fundo); font-weight: 700; font-size: 17px;
}
.moeda.brl { background: #FFF3C4; }
.valor {
  flex: 1; text-align: right; font-size: 52px; font-weight: 700; letter-spacing: -1px;
  font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden;
}
.valor.vazio { color: #9AA6B6; }
.detalhes-btn {
  flex: none; height: 48px; padding: 0 12px; border-radius: 24px;
  border: 1px solid var(--borda); background: var(--fundo2); font-size: 14px;
}
.detalhes-btn.cheio { background: var(--tinta); color: #fff; border-color: var(--tinta); }

.cats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.cats button {
  min-height: 64px; border-radius: var(--raio); border: 2px solid var(--borda); background: var(--fundo);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 4px 2px;
  font-size: 13px; font-weight: 600; line-height: 1.1;
}
.cats button i { font-style: normal; font-size: 24px; line-height: 1; }
.cats button.sel { background: var(--tinta); border-color: var(--tinta); color: #fff; }
.cats.falta button { border-color: var(--acento); animation: tremer .35s; }
@keyframes tremer { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }
.seg button {
  min-height: 52px; border-radius: var(--raio); border: 2px solid var(--borda); background: var(--fundo);
  font-weight: 600; font-size: 16px;
}
.seg button.sel { background: var(--tinta); border-color: var(--tinta); color: #fff; }

.teclado {
  flex: 1; display: grid; grid-template-columns: repeat(3, 1fr); grid-auto-rows: minmax(60px, 1fr); gap: 8px;
}
.teclado button {
  border: 0; border-radius: var(--raio); background: var(--fundo2);
  font-size: 30px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.teclado button:active, .cats button:active, .seg button:active { filter: brightness(.88); }

.salvar {
  width: 100%; min-height: 64px; border: 0; border-radius: var(--raio);
  background: var(--tinta); color: #fff; font-size: 22px; font-weight: 700;
}
.salvar[aria-disabled="true"] { background: #C3CBD6; color: #fff; }
.salvar:active { filter: brightness(1.2); }

/* ---------- Cartões e painel ---------- */
.cartao {
  border: 1px solid var(--borda); border-radius: var(--raio); padding: 14px 16px; margin: 12px 0;
}
.rotulo { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--tinta2); font-weight: 600; }
.grande { font-size: 44px; font-weight: 800; letter-spacing: -1px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.medio { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.sub { color: var(--tinta2); font-size: 16px; font-variant-numeric: tabular-nums; }
.duas { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.duas .cartao { margin: 0; }
.estourou { color: var(--acento); }
.bom { color: var(--ok); }

.barra-linha { padding: 10px 0; border-top: 1px solid var(--fundo2); }
.barra-linha:first-of-type { border-top: 0; }
.barra-topo { display: flex; justify-content: space-between; gap: 8px; font-size: 16px; }
.barra-topo b { font-weight: 700; }
.barra-topo span { font-variant-numeric: tabular-nums; color: var(--tinta2); white-space: nowrap; }
.barra { height: 12px; border-radius: 6px; background: var(--fundo2); margin-top: 6px; overflow: hidden; }
.barra > div { height: 100%; background: var(--tinta); border-radius: 6px; }
.barra.quase > div { background: var(--alerta); }
.barra.passou > div { background: var(--acento); }
.barra-linha.passou .barra-topo span { color: var(--acento); font-weight: 700; }

/* ---------- Histórico ---------- */
.filtros { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
select, input[type=text], input[type=password], input[type=date], input[type=number], input:not([type]) {
  width: 100%; min-height: 48px; padding: 8px 12px; border: 2px solid var(--borda); border-radius: 10px;
  background: var(--fundo); font-size: 17px;
}
select:focus, input:focus { outline: none; border-color: var(--tinta); }
.dia { display: flex; justify-content: space-between; align-items: baseline; padding: 16px 0 6px; border-bottom: 2px solid var(--tinta); }
.dia b { font-size: 16px; text-transform: capitalize; }
.dia span { font-weight: 700; font-variant-numeric: tabular-nums; }
.item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: none; border: 0; border-bottom: 1px solid var(--fundo2); padding: 12px 0; min-height: 60px;
}
.item i { font-style: normal; font-size: 24px; width: 32px; text-align: center; flex: none; }
.item .meio { flex: 1; min-width: 0; }
.item .meio b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .meio small { color: var(--tinta2); font-size: 14px; }
.item .dir { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.item .dir small { display: block; font-weight: 400; color: var(--tinta2); font-size: 13px; }
.item .nao-sync { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #E0A100; margin-left: 4px; vertical-align: middle; }
.vazio-txt { text-align: center; color: var(--tinta2); padding: 40px 0; }

/* ---------- Ajustes e formulários ---------- */
.campo { display: block; margin: 12px 0; }
.campo > span { display: block; font-size: 14px; font-weight: 600; color: var(--tinta2); margin-bottom: 4px; }
.orc-linha { display: grid; grid-template-columns: 1fr 130px; align-items: center; gap: 8px; margin: 6px 0; }
.botao {
  display: block; width: 100%; min-height: 52px; margin: 10px 0; border-radius: var(--raio);
  border: 2px solid var(--tinta); background: var(--fundo); font-weight: 700; font-size: 17px;
}
.botao.primario { background: var(--tinta); color: #fff; }
.botao.perigo { border-color: var(--acento); color: var(--acento); }
h2 { font-size: 20px; margin: 24px 0 8px; }
h3 { font-size: 16px; margin: 20px 0 4px; }
.nota { font-size: 14px; color: var(--tinta2); }
.linha { display: flex; gap: 8px; }
.linha > * { flex: 1; }

/* ---------- Folha (modal de baixo) ---------- */
.folha-fundo {
  position: fixed; inset: 0; z-index: 20; background: rgba(11, 31, 58, .45);
  display: flex; align-items: flex-end; justify-content: center;
}
.folha {
  width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto;
  background: var(--fundo); border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
}
.folha h2 { margin-top: 12px; }
.foto-previa { max-width: 100%; max-height: 300px; border-radius: 10px; display: block; margin: 8px 0; border: 1px solid var(--borda); }
.foto-botao { position: relative; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.foto-botao input { position: absolute; inset: 0; opacity: 0; }
.acoes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.acoes .botao { margin: 6px 0; }

/* ---------- Feedback ---------- */
.flash {
  position: fixed; inset: 0; z-index: 30; background: var(--ok); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  font-size: 26px; font-weight: 700; text-align: center; padding: 24px;
  animation: sumir .9s forwards;
}
.flash .check { font-size: 88px; line-height: 1; }
@keyframes sumir { 0%, 55% { opacity: 1; } 100% { opacity: 0; } }
.toast {
  position: fixed; left: 16px; right: 16px; z-index: 25;
  bottom: calc(var(--abas) + env(safe-area-inset-bottom) + 12px);
  max-width: 528px; margin: 0 auto;
  background: var(--tinta); color: #fff; border-radius: var(--raio); padding: 6px 6px 6px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px;
}
.toast button { background: #fff; color: var(--tinta); border: 0; border-radius: 8px; min-height: 44px; padding: 0 16px; font-weight: 700; }

/* ---------- Login ---------- */
.login { position: fixed; inset: 0; z-index: 40; background: var(--fundo); display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-caixa { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; }
.login-caixa h2 { font-size: 28px; margin: 0; }
.login-caixa p { margin: 0; }
.erro-txt { color: var(--acento); font-weight: 600; min-height: 1.4em; }

@media (max-height: 700px) {
  .valor { font-size: 44px; }
  .cats button { min-height: 58px; }
  .cats button i { font-size: 20px; }
}
