    </main>

    <script src="<?php echo BOOTSTRAP_JAVACRIPT; ?>"></script>

    <?php
    // Dynamic Footer Loading System
    // Whitelist of allowed footer styles for security
    $allowedFooterStyles = ['default', 'extended', 'minimal', 'simple', 'vertical', 'custom'];
    $footerStyle = defined('STYLE_FOOTER') ? strtolower(STYLE_FOOTER) : 'default';

    // Validate against whitelist
    if (!in_array($footerStyle, $allowedFooterStyles)) {
        error_log("Invalid STYLE_FOOTER value detected: " . htmlspecialchars($footerStyle, ENT_QUOTES, 'UTF-8') . " - using default");
        $footerStyle = 'default';
    }

    $footerFile = __DIR__ . '/footers/footer_' . $footerStyle . '.php';
    
    // Validate file path is within allowed directory
    $realFooterFile = realpath($footerFile);
    $allowedDir = realpath(__DIR__ . '/footers/');

    // Security check: ensure file is within allowed directory
    if ($realFooterFile === false || $allowedDir === false || strpos($realFooterFile, $allowedDir) !== 0) {
        error_log("Security: Attempted to access invalid footer file path");
        $footerFile = __DIR__ . '/footers/footer_default.php';
    }
    
    // Fallback to default if file doesn't exist
    if (!file_exists($footerFile)) {
        $footerFile = __DIR__ . '/footers/footer_default.php';
    }
    
    // Final validation before include
    $realFooterFile = realpath($footerFile);
    if ($realFooterFile && $allowedDir && strpos($realFooterFile, $allowedDir) === 0 && file_exists($realFooterFile)) {
        include $realFooterFile;
    } else {
        // Ultimate fallback - basic footer
        echo '<footer class="mt-auto py-3">
            <div class="container text-center">
            <p class="mb-0">&copy; ' . date('Y') . ' ' . SITE_NAME . '. ' . ($lang_navigation['FOOTER_ALL_RIGHTS_RESERVED'] ?? 'All rights reserved.') . ' ' . ($lang_navigation['FOOTER_POWERED_BY'] ?? 'Powered by') . ' <a href="https://supportengine.cloud" target="_blank">' . ($lang_navigation['FOOTER_SUPPORTENGINE_LINK_TEXT'] ?? 'SupportEngine') . '</a></p>
            </div>
        </footer>';
    }
    ?>

    <script>
        // Enable Bootstrap tooltips
        var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
        var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
            return new bootstrap.Tooltip(tooltipTriggerEl)
        })

        // Enable Bootstrap popovers
        var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'))
        var popoverList = popoverTriggerList.map(function (popoverTriggerEl) {
            return new bootstrap.Popover(popoverTriggerEl)
        })
    </script>
    <?php if (CHAT_LIVECHATINC_ID !== ''): ?>
    <!-- LiveChat Integration -->
    <script>
      window.__lc = window.__lc || {};
      window.__lc.license = "<?php echo CHAT_LIVECHATINC_ID; ?>";
      (function(n,t,c){
        function i(n){return e._h?e._h.apply(null,n):e._q.push(n)}
        var e={_q:[],_h:null,_v:"2.0",on:function(){i(["on", c.call(arguments)])},once:function(){i(["once", c.call(arguments)])},
        off:function(){i(["off", c.call(arguments)])},get:function(){if(!e._h)throw new Error("[LiveChatWidget] You can't use getters before load.");return i(["get", c.call(arguments)])},
        call:function(){i(["call", c.call(arguments)])},init:function(){var n=t.createElement("script");
        n.async=!0,n.type="text/javascript",n.src="https://cdn.livechatinc.com/tracking.js",t.head.appendChild(n)}};
        !n.__lc.asyncInit&&e.init(),n.LiveChatWidget=n.LiveChatWidget||e
      })(window,document,[].slice)
    </script>
    <noscript>
      <a href="https://www.livechat.com/chat-with/<?php echo CHAT_LIVECHATINC_ID; ?>/" rel="nofollow">
        <?php echo $lang_navigation['CHAT_WITH_US_NOSCRIPT'] ?? 'Chat with us'; ?>
      </a><?php echo $lang_navigation['POWERED_BY_LIVECHAT_NOSCRIPT'] ?? ', powered by LiveChat'; ?>
    </noscript>
<?php endif; ?>

<?php if (CHAT_CHATBASE_ID !== ''): ?>
    <!-- Chatbase Chatbot Embed -->
    <script>
      window.chatbaseConfig = {
        chatbotId: "<?php echo CHAT_CHATBASE_ID; ?>",
        // Additional configuration options can be added here
      };
    </script>
    <script src="https://www.chatbase.co/embed.min.js" defer></script>
<?php endif; ?>

<?php if (CHAT_JOTFORM_ID !== ''): ?>
    <script
        src="https://cdn.jotfor.ms/agent/embedjs/<?php echo CHAT_JOTFORM_ID; ?>/embed.js?skipWelcome=1&maximizable=1">
    </script>
<?php endif; ?>

<?php if (CHAT_CHATVIVE_ID !== ''): ?>
   <script src="https://messenger.svc.chative.io/static/v1.0/channels/<?php echo CHAT_CHATVIVE_ID; ?>/messenger.js?mode=livechat" defer="defer"></script>
<?php endif; ?>

<?php if (!empty(CHAT_DANTE_ID)): ?>
    <!-- Dante AI Chatbot Embed -->
    <script
        src="https://cdn.dante-ai.com/widget/<?php echo htmlspecialchars(CHAT_DANTE_ID, ENT_QUOTES, 'UTF-8'); ?>.js"
        defer>
    </script>
<?php endif; ?>
 <?php
    // Custom JavaScript code injection
    if (defined('CUSTOM_JAVASCRIPT_FOOTER') && !empty(CUSTOM_JAVASCRIPT_FOOTER)) {
    $decodedValue = base64_decode(CUSTOM_JAVASCRIPT_FOOTER, true);
    // Validate decoded content is valid base64
    if ($decodedValue === false) {
        error_log("Invalid base64 encoded CUSTOM_JAVASCRIPT_FOOTER in footer.php");
        $decodedValue = '';
    }
    echo $decodedValue;
    }
    ?>
</body>
</html>
