<?php
$is_spa = isset($_SERVER['HTTP_X_SPA_REQUEST']) && $_SERVER['HTTP_X_SPA_REQUEST'] === 'true';
if ($is_spa) return;

// 🔥 DESTRUCTOR DE CACHÉ JS
$v = '1.2.2'; // Incrementé la versión para forzar la recarga del app.js
?>
</div> 

<script src="https://accounts.google.com/gsi/client" async defer></script>

<script src="https://unpkg.com/lucide@latest"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>

<script src="/assets/js/app.js?v=<?php echo $v; ?>"></script>

<script>
// =========================================================================
// ESCUCHAR TECLA ESCAPE PARA CERRAR MODALES GLOBALMENTE
// =========================================================================
document.addEventListener('keydown', function(e) {
    if (e.key === 'Escape' || e.keyCode === 27) {
        const modals = document.querySelectorAll('.product-modal-backdrop');
        for (let i = modals.length - 1; i >= 0; i--) {
            const modal = modals[i];
            
            if (window.getComputedStyle(modal).display !== 'none') {
                const activeLayer = modal.querySelector('.opp-view-layer.active');
                if (activeLayer && activeLayer.id !== 'layer-main' && typeof window.switchOppLayer === 'function') {
                    window.switchOppLayer('layer-main');
                    return; 
                }

                modal.dispatchEvent(new MouseEvent('click', {
                    bubbles: true,
                    cancelable: true,
                    view: window
                }));
                break; 
            }
        }
    }
});
</script>

</body>
</html>