/* Paleta Madrona */
:root {
  --azul: #00b2ff;
  --azul-escuro: #008fcc;
  --grafite: #444444;
  --cinza: #b2bab9;
  --vermelho: #fc745c;
  --verde: #d0ffcc;
  --amarelo: #fff6d3;

  --fundo: #f5f7f7;
  --superficie: #ffffff;
  --texto: var(--grafite);
  --texto-suave: #7a8584;
  --borda: #e3e8e7;

  --topo-seguro: env(safe-area-inset-top, 0px);
  --base-segura: env(safe-area-inset-bottom, 0px);
  --raio: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--fundo);
  color: var(--texto);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  overscroll-behavior-y: none;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--fundo);
  position: relative;
}

/* Cabeçalho */
.topo {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--topo-seguro) + 10px) 12px 10px;
  background: var(--azul);
  color: #fff;
}
.topo h1 { margin: 0; font-size: 1.1rem; font-weight: 600; }
.icone-btn {
  width: 40px; height: 40px; border: 0; border-radius: 50%;
  background: rgba(255,255,255,.18); color: #fff; font-size: 1.6rem; line-height: 1;
}
.icone-btn:active { background: rgba(255,255,255,.35); }

main { padding: 16px 16px calc(96px + var(--base-segura)); }

.tela { display: none; }
.tela.ativa { display: block; }

h2 { font-size: 1rem; margin: 20px 0 10px; }

/* Cartão de total */
.cartao-total {
  background: var(--superficie);
  border-radius: var(--raio);
  padding: 18px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  display: flex; flex-direction: column; gap: 4px;
}
.cartao-total .rotulo { font-size: .85rem; color: var(--texto-suave); }
.cartao-total strong { font-size: 2rem; letter-spacing: -.5px; }
.cartao-total strong.negativo { color: #c7432c; }
.resumo { display: flex; gap: 10px; margin: 8px 0 4px; }
.resumo > div {
  flex: 1; display: flex; flex-direction: column; gap: 2px;
  padding: 8px 10px; border-radius: 12px; background: var(--fundo);
}
.resumo > div:first-child { background: var(--verde); }
.resumo > div:last-child { background: #ffe3dd; }
.resumo .rotulo { font-size: .75rem; }
.pos { color: #2c8a3c; }
.neg { color: #c7432c; }
.comparativo { font-size: .85rem; color: var(--texto-suave); }
.comparativo.subiu { color: #d4553e; }
.comparativo.caiu { color: #2c8a3c; }

/* Lista de despesas */
.dia { margin-top: 18px; }
.dia-titulo {
  display: flex; justify-content: space-between;
  font-size: .8rem; color: var(--texto-suave); margin: 0 4px 6px;
}
.itens { background: var(--superficie); border-radius: var(--raio); overflow: hidden; }
.item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 14px; border: 0; background: none; text-align: left;
  border-bottom: 1px solid var(--borda);
}
.item:last-child { border-bottom: 0; }
.item:active { background: var(--amarelo); }
.item-bolinha {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; font-size: 1.1rem;
}
.item-texto { flex: 1; min-width: 0; }
.item-desc { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.item-meta { display: block; font-size: .8rem; color: var(--texto-suave); }
.item-valor { font-weight: 600; white-space: nowrap; }
.item-valor.pos { color: #2c8a3c; }
.selo-fixa {
  display: inline-block; font-size: .65rem; font-weight: 600; color: var(--azul-escuro);
  background: #e6f7ff; border-radius: 6px; padding: 1px 5px; margin-left: 4px; vertical-align: 1px;
}

.vazio {
  text-align: center; color: var(--texto-suave);
  padding: 40px 16px; background: var(--amarelo); border-radius: var(--raio); margin-top: 18px;
}

/* Relatório */
.barra-linha { margin-bottom: 12px; }
.barra-topo { display: flex; justify-content: space-between; font-size: .9rem; margin-bottom: 4px; }
.barra-topo span:last-child { font-weight: 600; }
.barra-fundo { height: 10px; background: var(--borda); border-radius: 6px; overflow: hidden; }
.barra { height: 100%; background: var(--azul); border-radius: 6px; }
.barra-pct { font-size: .75rem; color: var(--texto-suave); }

.colunas {
  display: flex; align-items: flex-end; gap: 8px; height: 160px;
  background: var(--superficie); border-radius: var(--raio); padding: 14px 12px 8px;
}
.coluna { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.coluna-par { display: flex; gap: 3px; align-items: flex-end; width: 100%; justify-content: center; flex: 1; }
.coluna-barra { width: 45%; max-width: 18px; border-radius: 5px 5px 2px 2px; min-height: 2px; }
.coluna-barra.receita { background: var(--verde); box-shadow: inset 0 0 0 1px #8fd48a; }
.coluna-barra.despesa { background: var(--cinza); }
.coluna.atual .coluna-barra.despesa { background: var(--azul); }
.coluna.atual .coluna-rotulo { color: var(--texto); font-weight: 600; }
.legenda { display: flex; align-items: center; gap: 6px; font-size: .78rem; color: var(--texto-suave); margin: -4px 0 8px; }
.legenda span { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.leg-receita { background: var(--verde); box-shadow: inset 0 0 0 1px #8fd48a; }
.leg-despesa { background: var(--azul); margin-left: 10px; }

/* Lista de fixas (Ajustes) */
.fixa {
  display: flex; align-items: center; gap: 10px; background: var(--superficie);
  padding: 10px 14px; border-bottom: 1px solid var(--borda);
}
.fixa:last-child { border-bottom: 0; }
.fixa .item-texto { font-size: .9rem; }
.btn.pequeno { padding: 6px 10px; font-size: .8rem; }
.coluna-rotulo { font-size: .7rem; color: var(--texto-suave); text-transform: capitalize; }
.coluna-valor { font-size: .65rem; color: var(--texto-suave); white-space: nowrap; }

/* Ajustes */
.aviso { background: var(--amarelo); border-radius: var(--raio); padding: 12px 14px; font-size: .9rem; line-height: 1.4; margin: 0 0 8px; }
.aviso p { margin: 0 0 8px; }
.grupo-botoes { display: flex; flex-direction: column; gap: 8px; }

/* Botões */
.btn {
  display: block; text-align: center;
  border: 1px solid var(--borda); background: var(--superficie);
  padding: 12px 16px; border-radius: 12px; font-weight: 500;
}
.btn:active { background: var(--fundo); }
.btn.primario { background: var(--azul); border-color: var(--azul); color: #fff; }
.btn.primario:active { background: var(--azul-escuro); }
.btn.perigo { color: #c7432c; border-color: var(--vermelho); }

/* Botão flutuante */
.fab {
  position: fixed; z-index: 6;
  right: max(16px, calc(50% - 260px + 16px));
  bottom: calc(76px + var(--base-segura));
  width: 58px; height: 58px; border-radius: 50%; border: 0;
  background: var(--azul); color: #fff; font-size: 2rem; line-height: 1;
  box-shadow: 0 4px 14px rgba(0,178,255,.45);
}
.fab:active { transform: scale(.95); }

/* Abas inferiores */
.abas {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 520px; z-index: 5;
  display: flex; background: var(--superficie);
  border-top: 1px solid var(--borda);
  padding-bottom: var(--base-segura);
}
.aba {
  flex: 1; border: 0; background: none; padding: 8px 0 10px;
  font-size: .72rem; color: var(--texto-suave);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.aba-icone { font-size: 1.25rem; line-height: 1.2; }
.aba.ativa { color: var(--azul); font-weight: 600; }

/* Formulário em folha */
.fundo {
  position: fixed; inset: 0; z-index: 10; background: rgba(0,0,0,.35);
}
.folha {
  position: fixed; z-index: 11; left: 50%; bottom: 0; transform: translateX(-50%);
  width: 100%; max-width: 520px; max-height: 92dvh; overflow-y: auto;
  background: var(--superficie); border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(16px + var(--base-segura));
  animation: subir .22s ease-out;
}
@keyframes subir { from { transform: translate(-50%, 100%); } to { transform: translate(-50%, 0); } }
.folha-alca { width: 40px; height: 5px; border-radius: 3px; background: var(--cinza); margin: 4px auto 8px; }
.folha h2 { margin-top: 4px; }
.folha label, .rotulo-campo { display: block; font-size: .85rem; color: var(--texto-suave); margin-bottom: 12px; }
.rotulo-campo { margin-bottom: 6px; }
.folha input, .folha select {
  display: block; width: 100%; margin-top: 4px;
  padding: 12px; border: 1px solid var(--borda); border-radius: 12px;
  background: var(--fundo); color: var(--texto); font-size: 1rem;
  -webkit-appearance: none; appearance: none; min-height: 48px;
}
.folha input:focus, .folha select:focus { outline: 2px solid var(--azul); outline-offset: 0; border-color: var(--azul); }
#campoValor { font-size: 1.6rem; font-weight: 600; }
.linha { display: flex; gap: 10px; }
.linha label { flex: 1; min-width: 0; }

.categorias { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.cat {
  border: 1px solid var(--borda); background: var(--superficie); border-radius: 12px;
  padding: 8px 4px; font-size: .78rem; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.cat span { font-size: 1.2rem; }
.cat.selecionada { border-color: var(--azul); background: #e6f7ff; font-weight: 600; }

/* Despesa / Receita */
.segmento { display: flex; background: var(--fundo); border-radius: 12px; padding: 4px; margin-bottom: 14px; }
.segmento button {
  flex: 1; border: 0; background: none; padding: 9px 0; border-radius: 9px; font-weight: 500; color: var(--texto-suave);
}
.segmento button.ativo[data-tipo="despesa"] { background: #ffe3dd; color: #c7432c; font-weight: 600; }
.segmento button.ativo[data-tipo="receita"] { background: var(--verde); color: #2c8a3c; font-weight: 600; }

/* Repetir todo mês */
.folha label.interruptor {
  display: flex; align-items: center; gap: 10px; color: var(--texto); font-size: .95rem;
  background: var(--fundo); border-radius: 12px; padding: 12px; margin-bottom: 10px;
}
.folha label.interruptor input {
  width: 22px; height: 22px; min-height: 0; margin: 0; padding: 0; flex-shrink: 0;
  -webkit-appearance: auto; appearance: auto; accent-color: var(--azul);
}
.aviso-fixa {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: #e6f7ff; border-radius: 12px; padding: 10px 12px; margin-bottom: 14px; font-size: .85rem;
}
.link { border: 0; background: none; color: #c7432c; font-weight: 600; padding: 4px; white-space: nowrap; }

.acoes-form { display: flex; gap: 8px; }
.acoes-form .btn { flex: 1; }

/* Aviso rápido */
.toast {
  position: fixed; left: 50%; bottom: calc(150px + var(--base-segura)); z-index: 20;
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--grafite); color: #fff; padding: 10px 16px; border-radius: 20px; font-size: .9rem;
  transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); text-align: center;
}
.toast.visivel { opacity: 1; transform: translateX(-50%) translateY(0); }
