<!-- 1. Botón HTML con estilo personalizado -->
<div style="text-align: center; margin: 20px 0;">
  <a id="btn-open-zoho" href="zohobooks://" style="
    display: inline-block;
    background-color: #1565C0;
    color: #ffffff;
    padding: 14px 28px;
    font-size: 16px;
    font-weight: bold;
    border-radius: 6px;
    text-decoration: none;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    transition: background-color 0.3s ease;
  ">
    Abrir en la App de Zoho Books
  </a>
</div>

<!-- 2. Script de detección y redirección -->
<script>
  document.addEventListener("DOMContentLoaded", function() {
    var btn = document.getElementById('btn-open-zoho');
    if (!btn) return;

    btn.addEventListener('click', function(e) {
      var isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
      if (!isMobile) return; // Si es escritorio, deja pasar la navegación normal o abre zohobooks:// si el SO lo soporta

      e.preventDefault();

      var userAgent = navigator.userAgent || navigator.vendor || window.opera;
      var appScheme = "zohobooks://";
      var playStoreUrl = "https://play.google.com/store/apps/details?id=com.zoho.books";
      var appStoreUrl = "https://apps.apple.com/app/zoho-books-accounting-app/id588048092";

      var storeUrl = playStoreUrl;
      if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
        storeUrl = appStoreUrl;
      }

      var startTime = Date.now();
      window.location.href = appScheme;

      setTimeout(function() {
        if (Date.now() - startTime < 2000) {
          window.location.href = storeUrl;
        }
      }, 1500);
    });
  });
</script>