/* =====================================================================
   Despesas — paleta pastel em rosa, fundo com padrão de ícones
   ===================================================================== */

:root {
  --fundo:           #fadce5;
  --fundo-2:         #f7ccda;
  --padrao:          url("padrao-claro.svg");
  --superficie:      rgba(255, 255, 255, .93);
  --superficie-1:    #ffffff;
  --vidro:           rgba(255, 255, 255, .45);   /* base do cartão da tabela */
  --vidro-forte:     rgba(251, 228, 236, .80);   /* cabeçalho e rodapé       */
  --linha-clara:     rgba(255, 255, 255, .70);   /* linhas ímpares           */
  --linha-rosa:      rgba(246, 203, 217, .60);   /* linhas pares             */
  --vidro-pago:      rgba(214, 240, 228, .72);   /* linha marcada como paga  */
  --borda:           #f6dde5;
  --borda-forte:     #ecc6d4;
  --texto:           #3d2b32;
  --texto-fraco:     #8f727d;
  --acento:          #c04a6a;
  --acento-claro:    #e07f9c;
  --acento-suave:    #fce8ef;
  --tinta-cabecalho: #fbe4ec;
  --pago:            #2f8f6e;
  --pago-suave:      #e7f6ef;
  --falta:           #b34a34;
  --falta-suave:     #fdeee8;
  --perigo:          #b3243a;
  --marca-check:     #ffffff;
  --faixa-ok:        rgba(214, 240, 228, .72);   /* até 80% do limite  */
  --faixa-perto:     rgba(252, 236, 194, .82);   /* de 80% a 100%      */
  --faixa-estouro:   rgba(250, 212, 206, .88);   /* acima de 100%      */
  --sombra:          0 1px 2px rgba(120, 60, 80, .06), 0 12px 28px -14px rgba(120, 40, 70, .28);
  --sombra-alta:     0 10px 30px -8px rgba(120, 40, 70, .35);
  --raio:            18px;

  /* o app é sempre claro, mesmo com o modo escuro do celular ligado */
  color-scheme: light;
}

* { box-sizing: border-box; }

/* precisa vencer o display das classes abaixo */
[hidden] { display: none !important; }

html { background: var(--fundo); }

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--texto);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  background-color: var(--fundo);
  background-image: var(--padrao), linear-gradient(170deg, var(--fundo-2), var(--fundo) 45%);
  background-size: 340px 340px, cover;
  background-repeat: repeat, no-repeat;
  background-attachment: scroll, fixed;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

.tela { display: block; }
.tela--centro {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

/* -------------------------------------------------------------- texto */
.marca {
  margin: 0;
  font-size: 27px;
  font-weight: 800;
  letter-spacing: -.025em;
  color: var(--acento);
}
.marca--pequena {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 20px;
}
.marca__selo {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  font-size: 16px;
  background: var(--acento-suave);
  border-radius: 11px;
}

.emblema {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  margin: 0 auto 16px;
  font-size: 28px;
  background: linear-gradient(140deg, var(--acento-suave), var(--tinta-cabecalho));
  border-radius: 20px;
  box-shadow: inset 0 0 0 1px var(--borda);
}

.sub {
  margin: 6px 0 22px;
  color: var(--texto-fraco);
  font-size: 14px;
  line-height: 1.55;
}
.tela--centro .marca, .tela--centro .sub { text-align: center; }

.erro {
  margin: 0 0 12px;
  padding: 10px 12px;
  color: var(--perigo);
  font-size: 13.5px;
  line-height: 1.45;
  background: var(--falta-suave);
  border-radius: 10px;
}

/* ------------------------------------------------------------ cartões */
.cartao {
  background: var(--superficie);
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  box-shadow: var(--sombra);
}
.cartao--estreito {
  width: 100%;
  max-width: 390px;
  padding: 30px 26px;
  backdrop-filter: blur(6px);
}
/* translúcido de propósito: é por aqui que o papel de parede aparece */
.cartao--tabela {
  overflow: hidden;
  background: var(--vidro);
}

/* ------------------------------------------------------------- campos */
.campo { display: block; margin-bottom: 16px; }
.campo > span {
  display: block;
  margin-bottom: 7px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: .01em;
  color: var(--texto-fraco);
}
.campo > small {
  display: block;
  margin-top: 7px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--texto-fraco);
}

input[type=text], input[type=password], input[type=number], select {
  width: 100%;
  padding: 12px 13px;
  font-size: 16px;              /* 16px evita o zoom automático no iOS */
  font-family: inherit;
  color: var(--texto);
  background: var(--fundo);
  border: 1.5px solid var(--borda-forte);
  border-radius: 12px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder { color: var(--texto-fraco); opacity: .7; }
input:focus, select:focus {
  border-color: var(--acento);
  box-shadow: 0 0 0 4px var(--acento-suave);
}

/* ------------------------------- interruptor "Lista" e tabela de itens */
.rotulo-valor {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.rotulo-valor > label:first-child { cursor: pointer; }

.chave {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}
.chave em {
  font-size: 11px;
  font-style: normal;
  font-weight: 700;
  letter-spacing: .01em;
  color: var(--texto-fraco);
}
.chave input {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  width: 34px;
  height: 20px;
  margin: 0;
  background: var(--borda-forte);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s;
}
.chave input::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform .15s;
}
.chave input:checked { background: var(--acento); }
.chave input:checked::after { transform: translateX(14px); }
.chave input:focus-visible { box-shadow: 0 0 0 3px var(--acento-suave); }
.chave input:checked + em { color: var(--acento); }

.detalhe {
  border: 1.5px solid var(--borda-forte);
  border-radius: 12px;
  overflow: hidden;
  background: var(--superficie-1);
}
.detalhe__cab {
  display: grid;
  grid-template-columns: 1fr 104px;
  gap: 8px;
  padding: 8px 10px;
  font-size: 10.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--acento);
  background: var(--tinta-cabecalho);
}
.detalhe__cab span:last-child { text-align: right; }

.detalhe__corpo {
  max-height: 168px;      /* ~4 linhas; o resto rola */
  overflow-y: auto;
  overscroll-behavior: contain;
}
.detalhe__linha {
  display: grid;
  grid-template-columns: 1fr 104px;
  gap: 8px;
  padding: 5px 10px;
  border-top: 1px solid var(--borda);
}
.detalhe__corpo .detalhe__linha:first-child { border-top: none; }
.detalhe__linha input {
  padding: 8px 9px;
  font-size: 15px;
  border-width: 1px;
  border-radius: 9px;
}
.detalhe__linha input:last-child { text-align: right; font-variant-numeric: tabular-nums; }

#detalhe-resumo { text-align: right; }

input:disabled {
  color: var(--texto-fraco);
  background: var(--fundo-2);
  cursor: not-allowed;
}

/* prévia do limite da categoria, dentro do formulário de compra */
.limite { margin-top: 9px; }
.limite__texto {
  margin-bottom: 5px;
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--texto-fraco);
}
.limite__texto b { font-variant-numeric: tabular-nums; color: var(--texto); }
.limite__texto .estoura { color: var(--falta); font-weight: 700; }
.limite .cat-barra { margin-top: 0; }

.grade2 { display: grid; grid-template-columns: 92px 1fr; gap: 12px; }
/* Dia | Mês | Valor — o Mês some nos quadros gerais e a coluna colapsa */
.grade-data { display: grid; grid-template-columns: 74px auto 1fr; gap: 10px; }
.grade-data .campo[hidden] { display: none; }
.grade-data #f-mes { padding-left: 8px; padding-right: 4px; }

.alternador {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 18px;
  padding: 12px 14px;
  font-size: 15px;
  font-weight: 700;
  background: var(--acento-suave);
  border-radius: 12px;
  cursor: pointer;
  transition: background .15s;
}
/* fica verde só depois de marcado, para não sugerir que já está pago */
.alternador:has(input:checked) { background: var(--pago-suave); }

/* caixinha de "pago", desenhada à mão — igual na tabela e no formulário */
.marca-pago,
.alternador input {
  appearance: none;
  -webkit-appearance: none;
  display: inline-grid;
  place-content: center;
  width: 20px;
  height: 20px;
  margin: 0;
  background: var(--superficie-1);
  border: 2px solid var(--borda-forte);
  border-radius: 7px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.alternador input { width: 22px; height: 22px; }

.marca-pago::after,
.alternador input::after {
  content: '';
  width: 9px;
  height: 5px;
  border: 2px solid var(--marca-check);
  border-top: 0;
  border-right: 0;
  border-radius: 1px;
  opacity: 0;
  transform: rotate(-45deg) translate(1px, -2px);
  transition: opacity .15s;
}
.marca-pago:checked,
.alternador input:checked {
  background: var(--pago);
  border-color: var(--pago);
}
.marca-pago:checked::after,
.alternador input:checked::after { opacity: 1; }
.marca-pago:focus-visible,
.alternador input:focus-visible { box-shadow: 0 0 0 4px var(--acento-suave); }

/* ------------------------------------------------------------- botões */
.botao {
  padding: 12px 17px;
  font-size: 15px;
  font-family: inherit;
  font-weight: 700;
  color: var(--acento);
  background: var(--superficie-1);
  border: 1.5px solid var(--borda-forte);
  border-radius: 12px;
  cursor: pointer;
  transition: filter .15s, transform .1s;
}
.botao:active { transform: scale(.97); filter: brightness(.96); }
.botao--principal {
  color: #fff;
  background: linear-gradient(135deg, var(--acento-claro), var(--acento));
  border-color: transparent;
  box-shadow: 0 4px 14px -4px rgba(192, 74, 106, .55);
}
.botao--perigo { color: var(--perigo); }

form .botao--principal { width: 100%; }
.linha-botoes {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 22px;
}
.linha-botoes .botao { width: auto; flex: 0 0 auto; }
.espaco { flex: 1; }

.icone {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  font-size: 19px;
  line-height: 1;
  color: var(--acento);
  background: var(--superficie-1);
  border: 1px solid var(--borda);
  border-radius: 13px;
  box-shadow: var(--sombra);
  cursor: pointer;
  transition: transform .1s;
}
.icone:active { transform: scale(.94); }

.fab {
  position: fixed;
  /* à esquerda porque o selo "Powered by Netlify" ocupa o canto direito */
  left: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  width: 58px;
  height: 58px;
  font-size: 30px;
  line-height: 1;
  color: #fff;
  background: linear-gradient(140deg, var(--acento-claro), var(--acento));
  border: none;
  border-radius: 20px;
  box-shadow: 0 10px 24px -6px rgba(192, 74, 106, .6);
  cursor: pointer;
  transition: transform .12s;
  z-index: 20;
}
.fab:active { transform: scale(.93); }

/* --------------------------------------------------------------- topo */
.topo {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: max(12px, env(safe-area-inset-top)) 14px 12px;
  background: color-mix(in srgb, var(--fundo) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--borda);
}
.topo__linha { display: flex; align-items: center; justify-content: space-between; }
.topo__acoes { display: flex; gap: 8px; }

.navmes {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  padding: 5px;
  background: var(--superficie-1);
  border: 1px solid var(--borda);
  border-radius: 15px;
  box-shadow: var(--sombra);
}
.navmes .icone {
  width: 36px;
  height: 36px;
  font-size: 20px;
  border: none;
  border-radius: 11px;
  background: var(--acento-suave);
  box-shadow: none;
}
.navmes__rotulo {
  flex: 1;
  padding: 8px 4px;
  font-size: 17px;
  font-family: inherit;
  font-weight: 800;
  letter-spacing: -.015em;
  color: var(--texto);
  background: none;
  border: none;
  border-radius: 10px;
  cursor: pointer;
}

/* ----------------------------------------------------------- conteúdo */
.conteudo { padding: 16px 12px calc(100px + env(safe-area-inset-bottom)); }

.rodape {
  margin: 14px 6px 0;
  font-size: 12px;
  line-height: 1.55;
  text-align: center;
  color: var(--texto-fraco);
}

/* ------------------------------------------------------------- tabela */
.tabela {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
}
.tabela th {
  padding: 11px 4px;
  font-size: 9.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--acento);
  text-align: left;
  background: var(--vidro-forte);
  border-bottom: 1px solid var(--borda);
  white-space: nowrap;
}
.tabela td {
  padding: 11px 3px;
  border-bottom: 1px solid rgba(192, 74, 106, .10);
  vertical-align: middle;
}
.tabela tbody tr:nth-child(odd)  { background: var(--linha-clara); }
.tabela tbody tr:nth-child(even) { background: var(--linha-rosa); }
.tabela tbody tr:active { background: var(--acento-suave); }

.c-data  { width: 34px; color: var(--texto-fraco); font-size: 11.5px; white-space: nowrap; }
/* compra de outro mês dentro desta fatura */
.c-data--outro { color: var(--acento); font-weight: 700; }
.c-desc  { width: 100%; overflow-wrap: break-word; font-weight: 500; font-size: 16.5px; }
.c-valor { width: 70px; text-align: right; white-space: nowrap; font-weight: 600; }
.c-pago  { width: 26px; text-align: center; }
.c-falta { width: 56px; text-align: right; white-space: nowrap; color: var(--falta); font-weight: 700; }

.tabela th.c-valor, .tabela th.c-falta { text-align: right; }
.tabela th.c-pago { text-align: center; }

.linha--paga { background: var(--vidro-pago) !important; }
.linha--paga .c-desc { color: var(--texto-fraco); }
.linha--paga .c-valor { color: var(--texto-fraco); font-weight: 500; }

.total td {
  padding: 13px 4px 6px;
  font-size: 14px;
  font-weight: 800;
  border-bottom: none;
  background: var(--vidro-forte);
}
.total td:first-child {
  color: var(--texto-fraco);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.total--topo td { border-top: 1.5px solid var(--borda-forte); }
.total--falta td { padding: 6px 4px 14px; color: var(--falta); }
.total--limite td { padding: 6px 4px 14px; color: var(--texto-fraco); font-weight: 700; }
.total--limite td:first-child { color: var(--texto-fraco); }
.total--falta td:first-child { color: var(--falta); }

.vazio { padding: 36px 22px 34px; text-align: center; }
.vazio__emoji { font-size: 34px; }
.vazio p { margin: 12px 0 18px; color: var(--texto-fraco); font-size: 14.5px; line-height: 1.5; }

/* -------------------------------------------------------------- modal */
.fundo {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(60, 25, 40, .45);
  backdrop-filter: blur(2px);
  overflow-y: auto;
  overscroll-behavior: contain;   /* a rolagem da folha não passa para a página */
  animation: surgir .16s ease-out;
}
@keyframes surgir { from { opacity: 0 } to { opacity: 1 } }

.folha {
  width: 100%;
  max-width: 460px;
  /* folga extra embaixo: o selo "Powered by Netlify" fica fixo no rodapé da
     tela e cobriria a fileira de botões */
  padding: 26px 22px calc(80px + env(safe-area-inset-bottom));
  background: var(--superficie-1);
  border: 1px solid var(--borda);
  border-radius: 24px 24px 0 0;
  box-shadow: var(--sombra-alta);
  animation: subir .22s cubic-bezier(.22,1,.36,1);
}
@keyframes subir { from { transform: translateY(22px) } to { transform: none } }
.folha h2 { margin: 0 0 20px; font-size: 20px; letter-spacing: -.015em; }
.folha .sub { margin-bottom: 6px; text-align: left; }

/* -------------------------------------------------------------- aviso */
.aviso {
  position: fixed;
  left: 50%;
  bottom: calc(92px + env(safe-area-inset-bottom));
  z-index: 40;
  max-width: 88vw;
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--acento-claro), var(--acento));
  border-radius: 14px;
  box-shadow: var(--sombra-alta);
  transform: translateX(-50%);
  animation: surgir .16s ease-out;
}

/* --------------------------------------------------------------- abas */
.linha-abas {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}
.abas {
  display: flex;
  gap: 6px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.filtro {
  flex: 0 0 auto;
  /* estreito de propósito: dividir a linha com as abas num celular é apertado.
     O nome inteiro da categoria filtrada aparece no rodapé da tabela. */
  max-width: 100px;
  padding: 9px 8px;
  font-size: 12.5px;
  text-overflow: ellipsis;
  font-family: inherit;
  font-weight: 700;
  color: var(--acento);
  background: var(--superficie-1);
  border: 1px solid var(--borda);
  border-radius: 999px;
  outline: none;
}
.filtro:focus { border-color: var(--acento); box-shadow: 0 0 0 3px var(--acento-suave); }
.filtro.filtro--ativo {
  color: #fff;
  background: linear-gradient(135deg, var(--acento-claro), var(--acento));
  border-color: transparent;
}
.abas::-webkit-scrollbar { display: none; }

.aba {
  flex: 0 0 auto;
  padding: 9px 13px;
  font-size: 13.5px;
  font-family: inherit;
  font-weight: 700;
  white-space: nowrap;
  color: var(--acento);
  background: var(--superficie-1);
  border: 1px solid var(--borda);
  border-radius: 999px;
  cursor: pointer;
  transition: transform .1s;
}
.aba:active { transform: scale(.96); }
.aba[aria-selected="true"] {
  color: #fff;
  background: linear-gradient(135deg, var(--acento-claro), var(--acento));
  border-color: transparent;
  box-shadow: 0 4px 12px -4px rgba(192, 74, 106, .5);
}

/* ------------------------------------------- linhas coloridas do cartão */
.linha--ok      { background: var(--faixa-ok) !important; }
.linha--perto   { background: var(--faixa-perto) !important; }
.linha--estouro { background: var(--faixa-estouro) !important; }

.cat-icone {
  margin-right: 6px;
  font-size: 15px;
}

/* --------------------------------------------------- lista de categorias */
.lista-cat {
  margin: 0 0 4px;
  padding: 0;
  list-style: none;
  max-height: 52vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.lista-cat li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--borda);
  cursor: pointer;
}
.lista-cat li:last-child { border-bottom: none; }
.lista-cat li:active { background: var(--acento-suave); }
.cat-nome  { flex: 1; font-size: 15px; font-weight: 600; }
.cat-olho  { flex: 0 0 auto; }
.cat--oculta { opacity: .55; }
.cat-gasto {
  flex: 0 0 122px;
  font-size: 12.5px;
  line-height: 1.35;
  text-align: right;
  color: var(--texto-fraco);
  white-space: nowrap;
}
.cat-gasto b { font-variant-numeric: tabular-nums; }
.cat-barra {
  width: 100%;
  height: 5px;
  margin-top: 5px;
  background: var(--acento-suave);
  border-radius: 999px;
  overflow: hidden;
}
.cat-barra i { display: block; height: 100%; border-radius: 999px; }
.cat-info { flex: 1; min-width: 0; }

/* --------------------------------------------------- escolha do ícone */
.icones {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.icones button {
  width: 42px;
  height: 42px;
  font-size: 20px;
  line-height: 1;
  background: var(--fundo);
  border: 1.5px solid var(--borda-forte);
  border-radius: 12px;
  cursor: pointer;
}
.icones button[aria-pressed="true"] {
  background: var(--acento-suave);
  border-color: var(--acento);
  box-shadow: 0 0 0 3px var(--acento-suave);
}

/* ------------------------------------------------------ telas maiores */
@media (min-width: 400px) {
  .conteudo { padding-left: 16px; padding-right: 16px; }
  .tabela { font-size: 15px; }
  .tabela th { font-size: 10.5px; letter-spacing: .06em; }
  .tabela td { padding: 12px 8px; }
  .tabela th, .total td { padding-left: 8px; padding-right: 8px; }
  .c-data  { width: 52px; font-size: 13px; }
  .c-desc  { font-size: 17.5px; }
  .c-valor { width: 88px; }
  .c-pago  { width: 42px; }
  .c-falta { width: 84px; }
  .marca-pago { width: 21px; height: 21px; }
}

@media (min-width: 560px) {
  body { background-size: 420px 420px, cover; }
  .fundo { align-items: center; padding: 24px; }
  .folha { border-radius: 24px; }
  .conteudo { max-width: 720px; margin: 0 auto; }
  .topo { padding-left: max(16px, calc(50vw - 360px)); padding-right: max(16px, calc(50vw - 360px)); }
}

