/* Folha que sobe de baixo, campos de formulário e a tela de entrar. */

dialog.folha {
  position: fixed;
  inset: auto 0 var(--teclado, 0px);
  width: 100%;
  max-width: var(--largura-maxima);
  max-height: calc(100dvh - var(--teclado, 0px) - env(safe-area-inset-top) - 12px);
  margin: 0 auto;
  padding: 0;
  border: 0;
  border-radius: 22px 22px 0 0;
  background: var(--superficie);
  color: var(--texto);
  overflow: hidden;
  box-shadow: 0 -12px 40px -12px rgb(0 0 0 / 0.35);
}
dialog.folha::backdrop { background: rgb(20 17 13 / 0.5); }
dialog.folha[open] { display: flex; }
.folha > form { display: flex; flex-direction: column; flex: 1; min-height: 0; width: 100%; }

.folha-topo { display: flex; align-items: center; justify-content: space-between; padding: 10px 8px 4px 20px; }
.folha-topo h2 { font-size: 17px; font-weight: 650; }
.folha-corpo { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 20px 14px; display: grid; gap: 12px; align-content: start; }
.folha-rodape { padding: 10px 20px calc(env(safe-area-inset-bottom) + 14px); border-top: 1px solid var(--borda); background: var(--superficie); }
.folha-acoes { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px; margin: 0 -10px; }

.campo { display: grid; gap: 6px; min-width: 0; }
.campo > label, .rotulo-campo { font-size: 13px; font-weight: 600; color: var(--texto-suave); }

.entrada {
  width: 100%;
  min-height: 50px;
  padding: 0 14px;
  border: 1px solid var(--borda);
  border-radius: var(--raio-p);
  background: var(--fundo);
  font-size: 16px; /* abaixo de 16 px o iOS dá zoom ao focar */
  appearance: none;
}
select.entrada {
  padding-right: 36px;
  background-image: linear-gradient(45deg, transparent 50%, var(--texto-suave) 50%), linear-gradient(135deg, var(--texto-suave) 50%, transparent 50%);
  background-position: calc(100% - 19px) 50%, calc(100% - 14px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}
.entrada:focus-visible { outline-offset: 0; }
/* No valor o foco é o cursor piscando mais um traço embaixo; a moldura inteira pesava. */
.entrada-valor:focus-visible { outline: none; }

/* Valor: "R$" pequeno fora do campo, número grande; o traço embaixo é o foco. */
.valor-linha { display: flex; justify-content: center; align-items: baseline; gap: 8px; min-height: 54px; cursor: text; }
.valor-linha:focus-within { box-shadow: inset 0 -2px 0 var(--destaque); }
.valor-linha .moeda { font-size: 20px; font-weight: 600; color: var(--texto-suave); }
.entrada-valor {
  min-width: 4ch;
  min-height: 52px;
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 42px;
  font-weight: 680;
  letter-spacing: -0.03em;
  caret-color: var(--destaque);
}
.entrada-valor.zerado { color: var(--texto-suave); }

.opcoes { display: flex; flex-wrap: wrap; gap: 8px; }
.folha .chip { min-height: var(--toque); }
.chip .ponto { background: var(--cor); }
.chip[aria-pressed="true"] .ponto { background: currentColor; }
.campo-escolha > .entrada { margin-top: 2px; }

/* Grade de categorias: as 12 cabem entre o valor e o Salvar com o teclado aberto (390×500). */
.campo-categoria .opcoes { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 2px 6px; }
.categoria {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 3px;
  min-height: 72px;
  padding: 4px 2px 3px;
  border: 1.5px solid transparent;
  border-radius: 14px;
  background: none;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.15;
  text-align: center;
  white-space: nowrap;
  color: var(--texto-suave);
}
.categoria .selo { width: 48px; height: 48px; border-radius: 14px; background: color-mix(in srgb, var(--cor) 24%, transparent); }
.categoria .selo .icone { width: 23px; height: 23px; }
.categoria[aria-pressed="true"] { border-color: var(--cor); background: color-mix(in srgb, var(--cor) 10%, transparent); color: var(--texto); }
.categoria[aria-pressed="true"] .selo { background: var(--cor); color: var(--superficie); }

/* O que falta fica marcado no rótulo da seção; "Salvar" esmaece enquanto falta algo. */
.campo.faltando .rotulo-campo, .campo.faltando > label, .campo.faltando .moeda { color: var(--negativo); }
.botao[aria-disabled="true"] { opacity: 0.45; }

.campo-marcar { grid-template-columns: auto 1fr; align-items: center; gap: 12px; min-height: var(--toque); }
.campo-marcar input { width: 24px; height: 24px; margin: 0; accent-color: var(--destaque); }
.campo-marcar label { font-size: 16px; font-weight: 500; color: var(--texto); }

.erro-form { color: var(--negativo); font-size: 14.5px; font-weight: 600; }
.erro-form:empty { display: none; }
.folha-rodape .erro-form { margin-bottom: 10px; }
.nota-form { font-size: 13.5px; }

/* ---------- entrar ---------- */

.entrar {
  display: grid;
  align-content: center;
  gap: 32px;
  min-height: 100dvh;
  padding: calc(env(safe-area-inset-top) + 24px) 24px calc(env(safe-area-inset-bottom) + 24px);
}
.entrar-topo { display: grid; gap: 6px; }
.marca { border-radius: 16px; margin-bottom: 14px; }
.entrar-form { display: grid; gap: 16px; }
.entrar-form .entrada { background: var(--superficie); min-height: 54px; }
.entrar-form .nota { display: flex; gap: 8px; align-items: flex-start; font-size: 13.5px; }
.entrar-form .nota .icone { margin-top: 1px; }
.pergunta { font-size: 18px; font-weight: 650; }
.quem { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.quem-botao { flex-direction: column; gap: 10px; min-height: 124px; border-radius: var(--raio); font-size: 17px; }
.quem-botao .selo { width: 52px; height: 52px; font-size: 20px; }

@media (prefers-reduced-motion: no-preference) {
  /* A folha sobe de onde o botão de lançar está: explica de onde veio. */
  dialog.folha[open] { animation: subir 0.28s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
  dialog.folha[open]::backdrop { animation: escurecer 0.28s ease-out both; }
  @keyframes subir { from { transform: translateY(100%); } }
  @keyframes escurecer { from { opacity: 0; } }
}
