: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;
  --sobre-primaria: #ffffff;
  --linha: #eef3ef;
  --item-comprado: #fcfdfb;
  --barra-fundo: rgba(255, 255, 255, 0.96);
  --campo-fundo: #ffffff;
}

/* Visual "Elegante": verde escuro com dourado (escolhido em Configurações) */
:root[data-visual="elegante"] {
  --fundo: #0e2a1e;
  --superficie: #153828;
  --texto: #f4ecd6;
  --texto-suave: #b9b190;
  --verde: #c9a45c;
  --verde-escuro: #e3ca8c;
  --verde-claro: #1d4733;
  --verde-borda: #2f5d45;
  --vermelho: #e8806f;
  --vermelho-claro: #3a1f1c;
  --aviso-ok: #1d4733;
  --aviso-erro: #3a1f1c;
  --sobre-primaria: #10281d;
  --linha: #1f4331;
  --item-comprado: #112f22;
  --barra-fundo: rgba(14, 42, 30, 0.96);
  --campo-fundo: #0f2f21;
  --sombra: 0 6px 20px rgba(0, 0, 0, 0.45);
}

* { 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-linha {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.btn-config {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 50%;
  background: var(--verde-claro);
  font-size: 1.3rem;
  cursor: pointer;
}
.topo h1 {
  margin: 0;
  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: var(--sobre-primaria);
}

/* ---------- 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 var(--linha);
}
.item.comprado .item-nome {
  text-decoration: line-through;
  color: var(--texto-suave);
}
.item.comprado { background: var(--item-comprado); }

.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 var(--sobre-primaria);
  border-bottom: 3px solid var(--sobre-primaria);
  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; }

.qtd-controle {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
}
.qtd-btn {
  width: 40px;
  height: 40px;
  border: 1.5px solid var(--verde-borda);
  border-radius: 50%;
  background: var(--superficie);
  color: var(--verde-escuro);
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}
.qtd-btn:disabled { opacity: 0.35; cursor: default; }
.qtd-valor {
  min-width: 30px;
  text-align: center;
  font-weight: 700;
  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: var(--sobre-primaria);
  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: var(--sobre-primaria);
}
.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: var(--barra-fundo);
  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: var(--campo-fundo);
  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; }
.escolha-envio {
  margin: 0;
  padding: 10px 14px;
  border: 1.5px solid var(--verde-borda);
  border-radius: 12px;
  display: grid;
  gap: 10px;
}
.escolha-envio legend { padding: 0 6px; font-weight: 600; font-size: 0.95rem; }
.escolha-envio label { display: flex; align-items: center; gap: 10px; min-height: 40px; cursor: pointer; }
.escolha-envio input { width: 20px; height: 20px; accent-color: var(--verde); }
.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; }
}

/* ---------- Tela de abertura ---------- */
.abertura {
  position: fixed;
  inset: 0;
  z-index: 50;
  transition: opacity 0.5s ease;
}
.abertura.some { opacity: 0; pointer-events: none; }
.abertura-fresco {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: #e6fef0;
}
.abertura-fresco img { width: 100%; display: block; }
.abertura-topo { max-height: 42vh; object-fit: cover; object-position: center bottom; }
.abertura-base { max-height: 38vh; object-fit: cover; object-position: center top; }
.abertura-texto { text-align: center; padding: 0 20px; }
.abertura-texto h2 {
  margin: 0;
  font-size: 2rem;
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #0f5b2c;
}
.abertura-texto h2 b { display: block; color: #14a346; }
.abertura-texto p { margin: 10px 0 0; color: #1f3d2b; font-size: 1rem; }

.abertura-elegante {
  display: none;
  height: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 16px;
  padding: 0 28px;
  background: radial-gradient(circle at 50% 30%, #1f5a3d 0%, #0e2a1e 72%);
}
.abertura-elegante h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2.3rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.15;
  background: linear-gradient(#f6e8b8, #c9a45c);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.abertura-elegante p { margin: 0; color: #d8cfae; font-size: 1rem; }
.abertura-elegante .filete {
  width: 110px;
  height: 2px;
  background: linear-gradient(90deg, transparent, #c9a45c, transparent);
}
:root[data-visual="elegante"] .abertura-fresco { display: none; }
:root[data-visual="elegante"] .abertura-elegante { display: flex; }

/* ---------- Configurações ---------- */
.opcao-visual { align-items: flex-start !important; }
.opcao-visual small { display: block; font-weight: 400; color: var(--texto-suave); }

.btn-recolher {
  display: block;
  width: 100%;
  margin: 10px 0 0;
  min-height: 40px;
  padding: 0 16px;
  border: 1.5px solid var(--verde-borda);
  border-radius: 999px;
  background: var(--superficie);
  color: var(--verde-escuro);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-recolher[hidden] { display: none; }

.rodape {
  margin: 22px 0 0;
  text-align: center;
  font-size: 0.8rem;
  color: var(--texto-suave);
}
