<style>
#botao-whats-auto {
  background-color: #25D366;
  color: white;
  padding: 12px 20px;
  border-radius: 6px;
  text-decoration: none;
  font-weight: bold;
  display: inline-block;
  margin-top: 20px;
}
#botao-whats-auto:hover {
  background-color: #1DA851;
}
</style>

<script>
function esperarElemento(selector, callback) {
  const el = document.querySelector(selector);
  if (el) {
    callback(el);
  } else {
    setTimeout(() => esperarElemento(selector, callback), 500);
  }
}

function inserirBotaoWhats() {
  const jaTem = document.querySelector('#botao-whats-auto');
  if (jaTem) return;

  const telefone = "51999751217"; // <-- Seu número aqui (sem +55)

  esperarElemento('.product__name', (tituloEl) => {
    esperarElemento('.product__info', (infoEl) => {
      const nomeProduto = tituloEl.textContent.trim();
      const link = `https://wa.me/55${telefone}?text=Olá, tenho interesse nesse produto: ${encodeURIComponent(nomeProduto)}`;

      const botao = document.createElement('a');
      botao.id = 'botao-whats-auto';
      botao.href = link;
      botao.target = '_blank';
      botao.innerText = 'Comprar via WhatsApp';

      infoEl.appendChild(botao);
    });
  });
}

// Detecta quando muda a URL (SPA)
let urlAnterior = location.href;
setInterval(() => {
  if (location.href !== urlAnterior) {
    urlAnterior = location.href;
    setTimeout(inserirBotaoWhats, 1000);
  }
}, 500);

// Também roda no carregamento inicial
document.addEventListener('DOMContentLoaded', () => {
  setTimeout(inserirBotaoWhats, 1000);
});
</script>