:root {
  --fundo: #fbfbf7;
  --superficie: #ffffff;
  --texto: #2b3a30;
  --texto-suave: #6d7b71;
  --verde: #4f9d69;
  --verde-escuro: #3d7f53;
  --verde-claro: #e6f2ea;
  --verde-borda: #cfe4d6;
  --vermelho: #b5483c;
  --vermelho-claro: #fbeae7;
  --aviso-ok: #e6f2ea;
  --aviso-erro: #fbeae7;
  --sombra: 0 6px 20px rgba(43, 58, 48, 0.12);
  --raio: 14px;
  --barra-inferior: 76px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--fundo);
  color: var(--texto);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 17px;
  line-height: 1.35;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

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

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  padding: calc(env(safe-area-inset-top) + 12px) 14px calc(var(--barra-inferior) + env(safe-area-inset-bottom) + 24px);
}

/* ---------- Topo ---------- */
.topo {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--fundo);
  padding: 4px 0 10px;
}
.topo h1 {
  margin: 0 0 8px;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.progresso-resumo #contador {
  margin: 0 0 6px;
  font-size: 0.95rem;
  color: var(--texto-suave);
}
.barra {
  height: 10px;
  border-radius: 999px;
  background: var(--verde-borda);
  overflow: hidden;
}
.barra-preenchida {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--verde);
  transition: width 0.25s ease;
}

.filtros {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.filtro {
  flex: 1;
  min-height: 46px;
  border: 1.5px solid var(--verde-borda);
  background: var(--superficie);
  border-radius: 999px;
  font-weight: 600;
  color: var(--texto-suave);
  cursor: pointer;
}
.filtro.ativo {
  background: var(--verde);
  border-color: var(--verde);
  color: #fff;
}

/* ---------- Avisos ---------- */
.aviso {
  margin: 8px 0;
  padding: 12px 14px;
  border-radius: var(--raio);
  font-size: 0.95rem;
}
.aviso.ok { background: var(--aviso-ok); color: var(--verde-escuro); }
.aviso.erro { background: var(--aviso-erro); color: var(--vermelho); }
.aviso[hidden] { display: none; }
.link-aviso {
  border: 0;
  background: none;
  padding: 0;
  font-weight: 700;
  text-decoration: underline;
  color: inherit;
  cursor: pointer;
}

/* ---------- Setores e itens ---------- */
.lista { margin-top: 6px; }

.setor {
  background: var(--superficie);
  border: 1px solid var(--verde-borda);
  border-radius: var(--raio);
  margin-bottom: 12px;
  overflow: hidden;
}
.setor-topo {
  display: flex;
  align-items: stretch;
}
.setor-cab {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 10px 14px;
  border: 0;
  background: var(--verde-claro);
  text-align: left;
  cursor: pointer;
}
.setor-icone { font-size: 1.25rem; }
.setor-nome {
  flex: 1;
  min-width: 0;
  font-weight: 700;
  font-size: 0.92rem;
  letter-spacing: 0.02em;
  overflow-wrap: anywhere;
}
.setor-contagem {
  font-size: 0.85rem;
  color: var(--verde-escuro);
  font-weight: 600;
  white-space: nowrap;
}
.seta { color: var(--verde-escuro); width: 14px; text-align: center; }
.setor-editar {
  width: 52px;
  border: 0;
  background: var(--verde-claro);
  border-left: 1px solid var(--verde-borda);
  color: var(--verde-escuro);
  font-size: 1.1rem;
  cursor: pointer;
}

.itens {
  list-style: none;
  margin: 0;
  padding: 0;
}
.item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 60px;
  padding: 6px 12px 6px 6px;
  border-top: 1px solid #eef3ef;
}
.item.comprado .item-nome {
  text-decoration: line-through;
  color: var(--texto-suave);
}
.item.comprado { background: #fcfdfb; }

.marca {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  flex: 0 0 auto;
  cursor: pointer;
}
.marca input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
}
.caixa {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  border: 2px solid var(--verde);
  background: var(--superficie);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}
.marca input:checked + .caixa { background: var(--verde); }
.marca input:checked + .caixa::after {
  content: "";
  width: 9px;
  height: 16px;
  border-right: 3px solid #fff;
  border-bottom: 3px solid #fff;
  transform: rotate(45deg) translate(-2px, -2px);
}
.marca input:focus-visible + .caixa { outline: 3px solid var(--verde-borda); outline-offset: 2px; }

.item-texto {
  flex: 1;
  min-width: 0;
  min-height: 52px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding: 4px 6px;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}
.item-nome { overflow-wrap: anywhere; font-size: 1rem; }
.item-qtd { font-size: 0.85rem; color: var(--texto-suave); }

.vazio-setor, .vazio {
  margin: 0;
  padding: 14px;
  color: var(--texto-suave);
  font-size: 0.95rem;
}
.vazio { text-align: center; padding: 28px 16px; background: var(--superficie); border-radius: var(--raio); border: 1px dashed var(--verde-borda); }

/* ---------- Ações fixas ---------- */
.acoes-principais {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}
.btn-adicionar {
  min-height: 60px;
  border: 0;
  border-radius: var(--raio);
  background: var(--verde);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  box-shadow: var(--sombra);
  cursor: pointer;
}
.btn-secundario, .btn-primario, .btn-perigo, .btn-whatsapp {
  min-height: 52px;
  padding: 0 16px;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid var(--verde-borda);
  background: var(--superficie);
  color: var(--verde-escuro);
}
.btn-primario {
  background: var(--verde);
  border-color: var(--verde);
  color: #fff;
}
.btn-perigo {
  background: var(--vermelho-claro);
  border-color: #e9b8b0;
  color: var(--vermelho);
}
.btn-whatsapp {
  background: #25d366;
  border-color: #25d366;
  color: #fff;
}

.barra-inferior {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  max-width: 560px;
  margin: 0 auto;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--verde-borda);
  backdrop-filter: blur(6px);
}
.barra-inferior button {
  min-height: 58px;
  border: 0;
  border-radius: 12px;
  background: var(--verde-claro);
  color: var(--verde-escuro);
  font-size: 0.85rem;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
}
.barra-inferior span[aria-hidden] { font-size: 1.25rem; }

/* ---------- Modal ---------- */
.modal-fundo {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(20, 30, 24, 0.42);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.modal-fundo[hidden] { display: none; }
.modal {
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--superficie);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--sombra);
  padding: 16px 18px calc(18px + env(safe-area-inset-bottom));
}
@media (min-width: 720px) {
  .modal-fundo { align-items: center; }
  .modal { border-radius: 20px; }
}
.modal-cab {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.modal-cab h2 {
  margin: 0;
  font-size: 1.25rem;
}
.fechar {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--verde-claro);
  color: var(--verde-escuro);
  font-size: 1.1rem;
  cursor: pointer;
}
.form { display: grid; gap: 14px; }
.campo { display: grid; gap: 6px; font-weight: 600; font-size: 0.95rem; }
.campo small { font-weight: 400; color: var(--texto-suave); }
.campo input, .campo select {
  width: 100%;
  min-height: 52px;
  padding: 10px 14px;
  border: 1.5px solid var(--verde-borda);
  border-radius: 12px;
  background: #fff;
  font-size: 1rem;
  font-weight: 400;
}
.campo input:focus, .campo select:focus {
  outline: 3px solid var(--verde-borda);
  border-color: var(--verde);
}
.linha-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.erro-campo {
  margin: 0;
  color: var(--vermelho);
  font-weight: 600;
  font-size: 0.95rem;
}
.erro-campo[hidden] { display: none; }
.acoes-modal {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 4px;
}
.acoes-modal .btn-perigo { margin-right: auto; }
.acoes-verticais { flex-direction: column; justify-content: stretch; }
.acoes-verticais button { width: 100%; }
.texto-modal { margin: 0; line-height: 1.45; }
.aviso-texto { color: var(--vermelho); font-weight: 600; }
.erros-backup { margin: 0; padding-left: 20px; color: var(--vermelho); }
.previa {
  margin: 0;
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  padding: 14px;
  border-radius: 12px;
  background: var(--fundo);
  border: 1px solid var(--verde-borda);
  font-family: inherit;
  font-size: 0.95rem;
}

/* ---------- Telas maiores ---------- */
@media (min-width: 720px) {
  html, body { font-size: 18px; }
  .app { padding-top: 24px; }
  .topo h1 { font-size: 1.75rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
