:root {
  --azul: #1f4e8c;
  --azul-escuro: #163a69;
  --azul-claro: #e8f0fb;
  --verde: #1b7a3a;
  --verde-escuro: #145c2b;
  --vermelho: #b3261e;
  --fundo: #eef1f5;
  --branco: #ffffff;
  --texto: #1a1d21;
  --texto-2: #4a5260;
  --borda: #c3cad5;
  --borda-leve: #dde2e9;
  --raio: 14px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { font-size: 19px; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--fundo);
  color: var(--texto);
  line-height: 1.4;
}

/* ---------- Estrutura ---------- */

.topo {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--azul);
  color: #fff;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top));
}
.topo h1 { margin: 0 auto; max-width: 560px; font-size: 1.15rem; }

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(100px + env(safe-area-inset-bottom));
}

h2 { font-size: 1.05rem; margin: 24px 0 10px; }

.menu {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--branco);
  border-top: 1px solid var(--borda);
  padding-bottom: env(safe-area-inset-bottom);
}
.menu a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 66px;
  padding: 8px 2px;
  color: var(--texto-2);
  text-decoration: none;
  font-size: 0.75rem;
  font-weight: 700;
}
.menu a svg { width: 28px; height: 28px; }
.menu a.ativo { color: var(--azul); box-shadow: inset 0 4px 0 var(--azul); background: var(--azul-claro); }

/* ---------- Botões ---------- */

.botao {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 58px;
  margin: 10px 0;
  padding: 12px 18px;
  border: 2px solid transparent;
  border-radius: var(--raio);
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.botao svg { width: 28px; height: 28px; flex-shrink: 0; }
.botao:active { transform: scale(0.98); }
.botao:disabled { opacity: 0.6; }
.botao-principal { background: var(--azul); color: #fff; }
.botao-sucesso { background: var(--verde); color: #fff; }
.botao-secundario { background: var(--branco); color: var(--azul); border-color: var(--azul); }
.botao-perigo { background: var(--branco); color: var(--vermelho); border-color: var(--vermelho); }
.dialogo-botoes .botao-perigo { background: var(--vermelho); color: #fff; }
.botao-gigante { min-height: 74px; font-size: 1.15rem; }
.botao-pequeno { min-height: 50px; margin: 0; font-size: 0.95rem; }

/* ---------- Início ---------- */

.cartoes { display: grid; gap: 12px; margin: 8px 0; }
.cartao {
  background: var(--branco);
  border: 1px solid var(--borda-leve);
  border-radius: var(--raio);
  padding: 14px 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}
.cartao-rotulo { font-weight: 700; color: var(--texto-2); font-size: 0.9rem; }
.cartao-valor { font-size: 1.75rem; font-weight: 800; color: var(--azul-escuro); font-variant-numeric: tabular-nums; }
.cartao-sub { font-size: 0.85rem; color: var(--texto-2); }
.cartao-diarias { margin-top: 4px; font-size: 0.95rem; }

/* ---------- Formulários ---------- */

.formulario { display: flex; flex-direction: column; }
.campo { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; padding: 0; border: 0; min-width: 0; }
.campo > span, .campo legend { font-weight: 700; padding: 0; margin-bottom: 6px; }
.campo legend { margin-bottom: 6px; }

input, select, textarea {
  width: 100%;
  min-height: 58px;
  padding: 12px 14px;
  border: 2px solid var(--borda);
  border-radius: 12px;
  background: var(--branco);
  color: var(--texto);
  font: inherit;
  font-size: 1.05rem;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid #8db4e8; border-color: var(--azul); }
input[type="date"] { padding-inline: 10px; }
small { color: var(--texto-2); font-size: 0.85rem; }

.contador { display: grid; grid-template-columns: 64px 1fr 64px; gap: 8px; }
.contador input { text-align: center; font-size: 1.35rem; font-weight: 800; }
.botao-contador {
  min-height: 58px;
  border: 2px solid var(--azul);
  border-radius: 12px;
  background: var(--branco);
  color: var(--azul);
  font-size: 1.9rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}
.botao-contador:active { background: var(--azul-claro); }

.total-box, .total-geral {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 10px 0;
  padding: 14px 16px;
  border-radius: var(--raio);
  font-weight: 700;
}
.total-box { background: #e6f2ea; border: 2px solid #9fd0ae; }
.total-box strong { font-size: 1.6rem; color: var(--verde-escuro); font-variant-numeric: tabular-nums; }
.total-geral { background: var(--azul-claro); border: 2px solid #a9c3e8; }
.total-geral strong { font-size: 1.4rem; color: var(--azul-escuro); white-space: nowrap; }

.opcoes-situacao { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.opcao { position: relative; }
.opcao input { position: absolute; opacity: 0; width: 1px; height: 1px; min-height: 0; }
.opcao span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 58px;
  border: 2px solid var(--borda);
  border-radius: 12px;
  background: var(--branco);
  font-weight: 700;
  cursor: pointer;
}
.opcao input:checked + span { background: var(--azul); border-color: var(--azul); color: #fff; }
.opcao input:focus-visible + span { outline: 3px solid #8db4e8; }

.erro {
  margin: 10px 0;
  padding: 12px 14px;
  border: 1px solid #f3b8b2;
  border-radius: 12px;
  background: #fde8e6;
  color: #8c1d17;
  font-weight: 700;
}
.erro[hidden] { display: none; }
.info { margin: 10px 0; padding: 12px 14px; border-radius: 12px; background: var(--azul-claro); }
.vazio { text-align: center; color: var(--texto-2); padding: 20px 8px; }
.escondido { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* ---------- Listas ---------- */

.lista { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.item-lista {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 62px;
  padding: 12px 16px;
  border: 1px solid var(--borda-leve);
  border-radius: var(--raio);
  background: var(--branco);
  color: var(--texto);
  font-weight: 700;
  text-decoration: none;
}
.item-acao { color: var(--azul); font-size: 0.9rem; flex-shrink: 0; }
.lista-inativos .item-lista { background: #f5f6f8; color: var(--texto-2); }

.filtros {
  padding: 6px 14px 14px;
  border: 1px solid var(--borda-leve);
  border-radius: var(--raio);
  background: var(--branco);
}
.linha-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.linha-datas { display: grid; grid-template-columns: 1fr; column-gap: 10px; }
@media (min-width: 440px) { .linha-datas { grid-template-columns: 1fr 1fr; } }

.resumo-filtro { display: grid; grid-template-columns: auto auto 1fr; gap: 8px; margin: 14px 0; }
.resumo-filtro div {
  padding: 8px 10px;
  border: 1px solid var(--borda-leve);
  border-radius: 12px;
  background: var(--branco);
  min-width: 0;
}
.resumo-filtro span { display: block; font-size: 0.75rem; color: var(--texto-2); font-weight: 700; }
.resumo-filtro b { font-size: 1rem; white-space: nowrap; }

.lista-pagamentos { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.pagamento {
  padding: 12px 14px;
  border: 1px solid var(--borda-leve);
  border-radius: var(--raio);
  background: var(--branco);
}
.pagamento-topo { display: flex; justify-content: space-between; gap: 10px; font-weight: 700; color: var(--texto-2); }
.pagamento-total { color: var(--verde-escuro); font-size: 1.15rem; white-space: nowrap; }
.pagamento-nome { font-weight: 800; font-size: 1.05rem; margin-top: 2px; }
.pagamento-calculo { color: var(--texto-2); }
.pagamento-obs { margin-top: 6px; padding: 6px 10px; border-left: 4px solid var(--borda); background: #f5f6f8; font-size: 0.9rem; }
.pagamento-acoes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }

/* ---------- Fechamento ---------- */

.tabela {
  width: 100%;
  border-collapse: collapse;
  background: var(--branco);
  border-radius: var(--raio);
  overflow: hidden;
  font-size: 0.95rem;
}
.tabela th, .tabela td { padding: 10px 8px; border-bottom: 1px solid #e3e7ed; text-align: left; }
.tabela .num { text-align: right; white-space: nowrap; }
.tabela thead th { background: #e3eaf4; }
.tabela tfoot th { background: #d6e2f3; }
.botoes-relatorio { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- Backup ---------- */

.painel {
  margin-bottom: 16px;
  padding: 4px 16px 10px;
  border: 1px solid var(--borda-leve);
  border-radius: var(--raio);
  background: var(--branco);
}

/* ---------- Diálogo e aviso ---------- */

dialog {
  width: min(92vw, 480px);
  max-width: none;
  max-height: 90vh;
  padding: 20px;
  border: 0;
  border-radius: 18px;
  color: var(--texto);
}
dialog::backdrop { background: rgba(10, 20, 35, 0.55); }
dialog h2 { margin-top: 0; font-size: 1.2rem; }
dialog.sucesso h2 { color: var(--verde-escuro); }
dialog.alerta h2 { color: #8a5300; }
dialog.perigo h2 { color: var(--vermelho); }
.dialogo-msg p { margin: 8px 0; }
.dialogo-botoes .botao { margin: 10px 0 0; }

.resumo { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 10px 0; padding: 12px; border-radius: 12px; background: #f5f6f8; }
.resumo dt { color: var(--texto-2); }
.resumo dd { margin: 0; font-weight: 700; }
.resumo .destaque { color: var(--verde-escuro); font-size: 1.15rem; }

/* ---------- Sincronização com a nuvem ---------- */

#faixa-sincronia {
  margin: 12px -16px -14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 700;
}
#faixa-sincronia[hidden] { display: none; }
#faixa-sincronia.faixa-alerta { background: #fff4d6; color: #6b4300; border-bottom: 2px solid #f0c75e; }
#faixa-sincronia.faixa-erro { background: #fde8e6; color: #8c1d17; border-bottom: 2px solid #f3b8b2; }
#faixa-sincronia.faixa-info { background: var(--azul-claro); color: var(--azul-escuro); border-bottom: 2px solid #a9c3e8; }
.botao-faixa {
  flex-shrink: 0;
  min-height: 44px;
  padding: 6px 14px;
  border: 2px solid currentColor;
  border-radius: 10px;
  background: #fff;
  color: inherit;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.etiqueta-pendente {
  display: inline-block;
  margin: 4px 0 0 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #fff4d6;
  color: #6b4300;
  font-size: 0.75rem;
  font-weight: 800;
  vertical-align: middle;
}
.pagamento > .etiqueta-pendente { margin-left: 0; }

.aviso-nao-enviado {
  margin: 10px 0;
  padding: 12px 14px;
  border: 1px solid #f0c75e;
  border-radius: 12px;
  background: #fff4d6;
  color: #5c3a00;
}

.linha-nuvem { margin: 6px 2px; font-size: 0.85rem; color: var(--texto-2); }
.linha-nuvem-offline { color: #6b4300; font-weight: 700; }

body.sem-menu .menu { display: none; }

#aviso {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  z-index: 20;
  max-width: 90vw;
  white-space: nowrap;
  padding: 12px 22px;
  border-radius: 999px;
  background: #1a1d21;
  color: #fff;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 20px);
  transition: opacity 0.2s, transform 0.2s;
}
#aviso.visivel { opacity: 1; transform: translate(-50%, 0); }
