  <!-- ─── Core JS Libraries (deferred) ─── -->
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js" defer></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.19/js/intlTelInput.min.js" defer></script>
  <!-- libs.js contains: AOS, Parallax, mCustomScrollbar, slick, owl, fancybox, isotope, lazy -->
  <script src="assets/js/libs.js" defer></script>
  <script src="assets/js/functions.js" defer></script>
  <script src="assets/js/init.js" defer></script>
  <script src="https://kit.fontawesome.com/cf76be5a2b.js" crossorigin="anonymous" defer></script>

  <!-- ─── Delayed Live Chat ─── -->
  <script>
    function loadLiveChat() {
      if (window.liveChatLoaded) return;
      window.liveChatLoaded = true;

      var isMobile = /mobi/i.test(navigator.userAgent);
      window.__lc = window.__lc || {};
      window.__lc.license = 19624712;
      window.__lc.group   = isMobile ? 1 : 0;
      window.__lc.integration_name = 'manual_onboarding';
      window.__lc.product_name     = 'livechat';

      (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 = true; n.type = 'text/javascript';
            n.src = 'https://cdn.livechatinc.com/tracking.js';
            t.head.appendChild(n);
          }
        };
        if (!n.__lc.asyncInit) e.init();
        n.LiveChatWidget = n.LiveChatWidget || e;
      }(window, document, [].slice));

      var checkLC = setInterval(function () {
        if (typeof LiveChatWidget !== 'undefined' && LiveChatWidget.on) {
          clearInterval(checkLC);
          LiveChatWidget.on('new_event', function (ev) {
            if (ev.type === 'message' || ev.type === 'rich_message') LiveChatWidget.call('maximize');
          });
          LiveChatWidget.on('customer_message', function () { LiveChatWidget.call('maximize'); });
        }
      }, 100);
    }

    /* Load after 5s or on first interaction */
    window.addEventListener('load', function () { setTimeout(loadLiveChat, 5000); });
    window.addEventListener('scroll',     loadLiveChat, { once: true });
    window.addEventListener('mousemove',  loadLiveChat, { once: true });
    window.addEventListener('touchstart', loadLiveChat, { once: true });

    /* Chat toggle handler */
    var isLiveChatOpen = localStorage.getItem('liveChatOpen') === 'true';
    function handleChatToggle(e) {
      e.preventDefault();
      loadLiveChat();
      var check = setInterval(function () {
        if (typeof LiveChatWidget !== 'undefined') {
          clearInterval(check);
          if (isLiveChatOpen) { LiveChatWidget.call('minimize'); }
          else                { LiveChatWidget.call('maximize'); }
          isLiveChatOpen = !isLiveChatOpen;
          localStorage.setItem('liveChatOpen', isLiveChatOpen);
        }
      }, 100);
    }

    /* Phone (intlTelInput) + jQuery init */
    function initPageScripts() {
      if (typeof window.jQuery === 'undefined') { setTimeout(initPageScripts, 100); return; }

      $(document).ready(function () {
        /* Chat links */
        $(document).on('click', '.chat-trigger, a[href*="Tawk_API.toggle"]', handleChatToggle);

        /* intlTelInput on all .phone-number fields */
        if (typeof window.intlTelInput !== 'undefined') {
          $('.phone-number').each(function () {
            var input = this;
            var iti = window.intlTelInput(input, {
              separateDialCode: true,
              initialCountry: 'auto',
              geoIpLookup: function (cb) {
                $.get('https://get.geojs.io/v1/ip/country.json', function (r) {
                  cb((r && r.country) ? r.country : 'us');
                }, 'json').fail(function () {
                  $.get('https://ipapi.co/jsonp/', function (r) {
                    cb((r && r.country) ? r.country : 'us');
                  }, 'jsonp').fail(function () { cb('us'); });
                });
              },
              utilsScript: 'https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.19/js/utils.js'
            });

            function syncCountry() {
              var cd   = iti.getSelectedCountryData();
              var form = $(input).closest('form');
              if (form.length) {
                form.find('.hdnCountryName').val(cd.name     || '');
                form.find('.hdnCountryCode').val(cd.dialCode || '');
              }
            }
            input.addEventListener('countrychange', syncCountry);
            setTimeout(syncCountry, 1000);

            $(input).closest('form').on('submit', function (ev) {
              if (typeof iti !== 'undefined' && !iti.isValidNumber()) {
                ev.preventDefault();
                alert('Please enter a valid phone number for the selected country.');
                input.focus();
                return false;
              }
              syncCountry();
            });
          });
        }

        /* AOS */
        if (typeof AOS !== 'undefined') {
          AOS.init({ disable: 'mobile', once: true });
        }

      });
    }
    initPageScripts();
  </script>