(function () {
    window.h4bsMirrorPatchesLoaded = true;
    var autoplayMeta = new WeakMap();
    var nativeWatchdogTimers = new WeakMap();
    var mirrorImageRatioCache = Object.create(null);
    var mirrorServiceIconMap = {
        "fa-toolbox": "dashicons-admin-tools",
        "fa-tools": "dashicons-hammer",
        "fa-hand-holding-heart": "dashicons-heart",
        "fa-server": "dashicons-database",
        "fa-lock": "dashicons-lock",
        "fa-shipping-fast": "dashicons-performance"
    };

    function isMirrorPage() {
        return (
            document.body instanceof HTMLElement &&
            document.body.classList.contains("h4bs-mirror-page")
        );
    }

    function getSliderWidgets() {
        return Array.from(
            document.querySelectorAll(
                ".h4bs-mirror-content .elementor-widget-slides," +
                    " .h4bs-mirror-content .elementor-widget-image-carousel," +
                    " .h4bs-mirror-content .elementor-widget-testimonial-carousel," +
                    " .h4bs-mirror-content .elementor-widget-reviews"
            )
        ).filter(function (node) {
            return node instanceof HTMLElement;
        });
    }

    function getPreferredSliderRoot(widget) {
        if (!(widget instanceof HTMLElement)) {
            return null;
        }
        var candidates = Array.from(
            widget.querySelectorAll(".elementor-main-swiper, .swiper-container")
        ).filter(function (node) {
            return node instanceof HTMLElement;
        });
        if (!candidates.length) {
            return null;
        }
        var withNative = candidates.find(function (node) {
            return (
                node.swiper &&
                typeof node.swiper.slideNext === "function" &&
                typeof node.swiper.slideTo === "function"
            );
        });
        if (withNative) {
            return withNative;
        }
        var initialized = candidates.find(function (node) {
            return node.classList.contains("swiper-initialized");
        });
        if (initialized) {
            return initialized;
        }
        var mainSwiper = candidates.find(function (node) {
            return node.classList.contains("elementor-main-swiper");
        });
        return mainSwiper || candidates[0] || null;
    }

    function getSliderRoots() {
        var seen = new Set();
        var roots = [];
        getSliderWidgets().forEach(function (widget) {
            var root = getPreferredSliderRoot(widget);
            if (!(root instanceof HTMLElement) || seen.has(root)) {
                return;
            }
            seen.add(root);
            roots.push(root);
        });
        return roots;
    }

    function isVisibleElement(node) {
        if (!(node instanceof HTMLElement)) {
            return false;
        }
        var style = window.getComputedStyle(node);
        if (style.display === "none" || style.visibility === "hidden") {
            return false;
        }
        var opacity = Number(style.opacity || "1");
        return !Number.isFinite(opacity) || opacity > 0.01;
    }

    function isReviewRoot(root) {
        return (
            root instanceof HTMLElement &&
            root.closest(".elementor-widget-reviews") instanceof HTMLElement
        );
    }

    function getSlides(root) {
        if (!(root instanceof HTMLElement)) {
            return [];
        }
        return Array.from(root.querySelectorAll(".swiper-slide, .h4bs-slide")).filter(function (slide) {
            return slide instanceof HTMLElement;
        });
    }

    function extractBackgroundImageUrl(value) {
        if (typeof value !== "string") {
            return "";
        }
        var match = value.match(/url\((['"]?)(.*?)\1\)/i);
        if (!match || !match[2]) {
            return "";
        }
        return String(match[2]).trim();
    }

    function getSlideBackgroundImageUrl(slide) {
        if (!(slide instanceof HTMLElement)) {
            return "";
        }
        var bgNode = slide.querySelector(".swiper-slide-bg");
        if (bgNode instanceof HTMLElement) {
            var inlineValue = bgNode.style.backgroundImage || "";
            if (!inlineValue) {
                inlineValue = window.getComputedStyle(bgNode).backgroundImage || "";
            }
            var parsed = extractBackgroundImageUrl(inlineValue);
            if (parsed !== "") {
                return parsed;
            }
        }
        var slideInline = slide.style.backgroundImage || "";
        if (!slideInline) {
            slideInline = window.getComputedStyle(slide).backgroundImage || "";
        }
        return extractBackgroundImageUrl(slideInline);
    }

    function getImageRatioFromNode(node) {
        if (!(node instanceof HTMLImageElement)) {
            return null;
        }
        var naturalWidth = Number(node.naturalWidth || 0);
        var naturalHeight = Number(node.naturalHeight || 0);
        if (naturalWidth > 0 && naturalHeight > 0) {
            return naturalHeight / naturalWidth;
        }
        return null;
    }

    function getSlideImageRatio(slide) {
        if (!(slide instanceof HTMLElement)) {
            return null;
        }
        var imageCandidates = Array.from(
            slide.querySelectorAll(".swiper-slide-bg img, .swiper-slide-image, img")
        );
        for (var i = 0; i < imageCandidates.length; i += 1) {
            var ratio = getImageRatioFromNode(imageCandidates[i]);
            if (ratio && Number.isFinite(ratio) && ratio > 0) {
                return ratio;
            }
        }
        return null;
    }

    function setMirrorSlideHeight(root, pixelHeight) {
        if (!(root instanceof HTMLElement)) {
            return;
        }
        if (!Number.isFinite(pixelHeight) || pixelHeight <= 0) {
            return;
        }
        var viewportHeight = Math.max(
            window.innerHeight || 0,
            document.documentElement ? document.documentElement.clientHeight || 0 : 0
        );
        var dynamicMax = Math.min(1600, Math.max(700, Math.round(viewportHeight * 0.82)));
        var clamped = Math.max(220, Math.min(dynamicMax, Math.round(pixelHeight)));
        var value = String(clamped) + "px";
        root.style.setProperty("--h4-mirror-slide-height", value);
        var container = getSliderContainer(root);
        if (container instanceof HTMLElement) {
            container.style.setProperty("--h4-mirror-slide-height", value);
        }
        var widget = root.closest(".elementor-widget-slides");
        if (widget instanceof HTMLElement) {
            widget.classList.add("has-h4bs-mirror-auto-height");
            widget.style.setProperty("--h4-mirror-slide-height", value);
        }
    }

    function requestImageRatio(url, callback) {
        if (typeof callback !== "function" || !url) {
            return;
        }
        if (Object.prototype.hasOwnProperty.call(mirrorImageRatioCache, url)) {
            callback(mirrorImageRatioCache[url]);
            return;
        }
        var probe = new Image();
        probe.decoding = "async";
        probe.onload = function () {
            var width = Number(probe.naturalWidth || 0);
            var height = Number(probe.naturalHeight || 0);
            var ratio = width > 0 && height > 0 ? height / width : null;
            mirrorImageRatioCache[url] = ratio;
            callback(ratio);
        };
        probe.onerror = function () {
            mirrorImageRatioCache[url] = null;
            callback(null);
        };
        probe.src = url;
    }

    function applyMirrorAutoHeight(root) {
        if (!(root instanceof HTMLElement) || isReviewRoot(root)) {
            return;
        }
        var slides = getSlides(root);
        if (!slides.length) {
            return;
        }
        var activeSlide =
            slides.find(function (slide) {
                return (
                    slide.classList.contains("swiper-slide-active") ||
                    slide.classList.contains("h4bs-mirror-slide-active") ||
                    slide.classList.contains("is-active")
                );
            }) || slides[0];
        if (!(activeSlide instanceof HTMLElement)) {
            return;
        }

        var renderWidth = Math.max(
            root.clientWidth || 0,
            activeSlide.clientWidth || 0,
            (getSliderContainer(root) || root).clientWidth || 0
        );
        if (renderWidth < 32) {
            return;
        }

        var directRatio = getSlideImageRatio(activeSlide);
        if (directRatio && Number.isFinite(directRatio) && directRatio > 0) {
            setMirrorSlideHeight(root, renderWidth * directRatio);
            return;
        }

        var bgUrl = getSlideBackgroundImageUrl(activeSlide);
        if (bgUrl === "") {
            return;
        }
        requestImageRatio(bgUrl, function (ratio) {
            if (!Number.isFinite(ratio) || ratio <= 0) {
                return;
            }
            if (!(root instanceof HTMLElement) || !document.contains(root)) {
                return;
            }
            var widthNow = Math.max(
                root.clientWidth || 0,
                activeSlide.clientWidth || 0,
                (getSliderContainer(root) || root).clientWidth || 0
            );
            if (widthNow < 32) {
                return;
            }
            setMirrorSlideHeight(root, widthNow * ratio);
        });
    }

    function patchServiceIcons() {
        if (!isMirrorPage()) {
            return;
        }
        var keys = Object.keys(mirrorServiceIconMap);
        if (!keys.length) {
            return;
        }
        var selector = keys
            .map(function (key) {
                return ".h4bs-mirror-content i." + key;
            })
            .join(", ");
        Array.from(document.querySelectorAll(selector)).forEach(function (node) {
            if (!(node instanceof HTMLElement)) {
                return;
            }
            var mapped = "";
            keys.some(function (key) {
                if (node.classList.contains(key)) {
                    mapped = mirrorServiceIconMap[key] || "";
                    return true;
                }
                return false;
            });
            if (!mapped) {
                return;
            }
            if (node.dataset.h4bsDashiconPatched === "1") {
                return;
            }
            node.className = "dashicons " + mapped + " h4bs-mirror-dashicon";
            node.dataset.h4bsDashiconPatched = "1";
            node.setAttribute("aria-hidden", "true");
        });
    }

    function getSliderContainer(root) {
        if (!(root instanceof HTMLElement)) {
            return null;
        }
        return (
            root.closest(
                ".elementor-widget-slides, .elementor-widget-reviews, .elementor-widget-image-carousel, .elementor-widget-testimonial-carousel"
            ) ||
            root.closest(".elementor-swiper") ||
            root.parentElement ||
            root
        );
    }

    function parseNumber(value) {
        if (typeof value === "number" && Number.isFinite(value)) {
            return value;
        }
        if (typeof value === "string") {
            var parsed = Number(value);
            if (Number.isFinite(parsed)) {
                return parsed;
            }
        }
        return null;
    }

    function parseJsonSafe(raw) {
        if (typeof raw !== "string" || !raw.trim()) {
            return null;
        }
        try {
            return JSON.parse(raw);
        } catch (error) {
            return null;
        }
    }

    function getWidgetSettings(root) {
        if (!(root instanceof HTMLElement)) {
            return null;
        }
        var widget = root.closest(".elementor-widget");
        if (!(widget instanceof HTMLElement)) {
            return null;
        }
        return parseJsonSafe(widget.getAttribute("data-settings"));
    }

    function getReviewPerView(root, slideCount) {
        var settings = getWidgetSettings(root) || {};
        var viewport = Math.max(window.innerWidth || 0, document.documentElement ? document.documentElement.clientWidth || 0 : 0);
        var desktop = parseNumber(settings.slides_per_view);
        var tablet = parseNumber(settings.slides_per_view_tablet);
        var mobile = parseNumber(settings.slides_per_view_mobile);
        var perView = 1;

        if (viewport < 768) {
            perView = mobile || tablet || 1;
            perView = Math.min(perView, 1);
        } else if (viewport < 1280) {
            perView = tablet || mobile || desktop || 2;
            perView = Math.min(perView, 2);
        } else {
            perView = desktop || tablet || 3;
            perView = Math.min(perView, 3);
        }
        if (typeof slideCount === "number" && slideCount > 0) {
            perView = Math.min(perView, slideCount);
        }
        return Math.max(1, Math.round(perView));
    }

    function getReviewGapPx(root) {
        var settings = getWidgetSettings(root) || {};
        var viewport = Math.max(window.innerWidth || 0, document.documentElement ? document.documentElement.clientWidth || 0 : 0);
        var raw = settings.space_between;
        if (viewport < 768) {
            raw = settings.space_between_mobile || settings.space_between_tablet || settings.space_between;
        } else if (viewport < 1280) {
            raw = settings.space_between_tablet || settings.space_between_mobile || settings.space_between;
        }

        var gap = parseNumber(raw);
        if (gap === null && raw && typeof raw === "object") {
            gap = parseNumber(raw.size);
        }
        if (!Number.isFinite(gap)) {
            gap = 10;
        }
        return Math.max(0, Math.min(48, Math.round(gap)));
    }

    function getAutoplayDelay(root, allowForceFallbackAutoplay) {
        if (allowForceFallbackAutoplay === undefined) {
            allowForceFallbackAutoplay = true;
        }
        var settings = getWidgetSettings(root) || {};
        var slides = getSlides(root);
        var autoplayEnabled =
            settings.autoplay === true ||
            settings.autoplay === "yes" ||
            settings.autoplay === "true" ||
            settings.loop === true ||
            settings.loop === "yes";
        if (!autoplayEnabled && allowForceFallbackAutoplay && slides.length > 1) {
            // Mirror fallback should keep hero/review sliders rotating even if
            // Elementor's runtime settings object is missing or partial.
            autoplayEnabled = true;
        }
        if (!autoplayEnabled) {
            return 0;
        }
        var configured = parseNumber(settings.autoplay_speed);
        if (configured && configured >= 1000) {
            return Math.round(configured);
        }
        return isReviewRoot(root) ? 5000 : 4300;
    }

    function stabilizeHeroShell(root) {
        if (!(root instanceof HTMLElement)) {
            return;
        }
        var wrapper = root.querySelector(".swiper-wrapper");
        root.style.marginLeft = "0";
        root.style.marginRight = "0";
        root.style.overflow = "hidden";
        if (wrapper instanceof HTMLElement) {
            wrapper.style.alignItems = "stretch";
        }
    }

    function stabilizeHeroFallbackSlider(root) {
        if (!(root instanceof HTMLElement) || isReviewRoot(root)) {
            return;
        }
        var wrapper = root.querySelector(".swiper-wrapper");
        if (wrapper instanceof HTMLElement) {
            wrapper.style.display = "flex";
            wrapper.style.alignItems = "stretch";
            wrapper.style.gap = "0";
            wrapper.style.transform = "none";
            wrapper.style.transition = "none";
        }
        stabilizeHeroShell(root);
    }

    function clearAutoplay(root) {
        if (!(root instanceof HTMLElement)) {
            return;
        }
        var meta = autoplayMeta.get(root);
        if (meta && meta.id) {
            window.clearInterval(meta.id);
        }
        autoplayMeta.delete(root);
    }

    function createNavButton(direction) {
        var button = document.createElement("button");
        button.type = "button";
        button.className =
            "elementor-swiper-button elementor-swiper-button-" +
            direction +
            " h4bs-mirror-nav-injected";
        button.setAttribute(
            "aria-label",
            direction === "prev" ? "Previous Slide" : "Next Slide"
        );
        var icon = document.createElement("span");
        icon.className = "h4bs-mirror-nav-glyph";
        icon.textContent = direction === "prev" ? "\u2039" : "\u203A";
        button.appendChild(icon);
        return button;
    }

    function findExistingNavButton(container, direction) {
        if (!(container instanceof HTMLElement)) {
            return null;
        }
        var selector =
            direction === "prev"
                ? ".elementor-swiper-button-prev, .swiper-button-prev"
                : ".elementor-swiper-button-next, .swiper-button-next";
        var candidates = Array.from(container.querySelectorAll(selector)).filter(function (node) {
            if (!(node instanceof HTMLElement)) {
                return false;
            }
            if (node.closest(".swiper-wrapper") instanceof HTMLElement) {
                return false;
            }
            if (node.closest(".swiper-slide") instanceof HTMLElement) {
                return false;
            }
            return true;
        });
        if (!candidates.length) {
            return null;
        }
        var injected = candidates.filter(function (node) {
            return node.classList.contains("h4bs-mirror-nav-injected");
        });
        var pool = injected.length ? injected : candidates;
        var chosen = pool.find(isVisibleElement) || pool[0] || null;
        // Drop orphan duplicates from previous patch cycles.
        pool.forEach(function (node) {
            if (node !== chosen && node.classList.contains("h4bs-mirror-nav-injected")) {
                node.remove();
            }
        });
        return chosen;
    }

    function ensureNavigation(root) {
        var container = getSliderContainer(root);
        if (!(container instanceof HTMLElement)) {
            return null;
        }

        var computed = window.getComputedStyle(container);
        if (computed.position === "static") {
            container.style.position = "relative";
        }

        var prev = findExistingNavButton(container, "prev");
        var next = findExistingNavButton(container, "next");

        if (!(prev instanceof HTMLElement)) {
            prev = createNavButton("prev");
            container.appendChild(prev);
        }
        if (!(next instanceof HTMLElement)) {
            next = createNavButton("next");
            container.appendChild(next);
        }

        prev.classList.add("elementor-swiper-button", "elementor-swiper-button-prev");
        next.classList.add("elementor-swiper-button", "elementor-swiper-button-next");

        return {
            prev: prev,
            next: next,
            container: container
        };
    }

    function getActiveSlideIndex(slides) {
        var activeIndex = slides.findIndex(function (slide) {
            return (
                slide.classList.contains("swiper-slide-active") ||
                slide.classList.contains("h4bs-mirror-slide-active") ||
                slide.classList.contains("is-active")
            );
        });
        return activeIndex >= 0 ? activeIndex : 0;
    }

    function setActiveSlide(root, index) {
        if (!(root instanceof HTMLElement)) {
            return;
        }
        var slides = getSlides(root);
        if (!slides.length) {
            return;
        }
        var reviewMode = isReviewRoot(root);
        var perView = reviewMode ? getReviewPerView(root, slides.length) : 1;
        var gapPx = reviewMode ? getReviewGapPx(root) : 0;
        var wrapper = root.querySelector(".swiper-wrapper");
        if (reviewMode && wrapper instanceof HTMLElement) {
            wrapper.style.display = "flex";
            wrapper.style.alignItems = "stretch";
            wrapper.style.gap = String(gapPx) + "px";
        }
        var safeIndex = ((index % slides.length) + slides.length) % slides.length;
        if (reviewMode) {
            var maxLead = Math.max(0, slides.length - perView);
            safeIndex = Math.max(0, Math.min(index, maxLead));
        }

        root.classList.add("h4bs-mirror-fallback");
        if (reviewMode) {
            root.classList.add("h4bs-mirror-fallback-review");
        }

        slides.forEach(function (slide, idx) {
            var isActive = idx === safeIndex;
            var isVisible = reviewMode ? idx >= safeIndex && idx < safeIndex + perView : isActive;
            slide.classList.toggle("swiper-slide-active", isActive);
            slide.classList.toggle("h4bs-mirror-slide-active", isActive);
            slide.style.setProperty("display", isVisible ? "block" : "none", "important");
            slide.style.visibility = isVisible ? "visible" : "hidden";
            slide.style.opacity = isVisible ? "1" : "0";
            slide.setAttribute("aria-hidden", isVisible ? "false" : "true");
            if (reviewMode) {
                if (isVisible) {
                    var width = "calc((100% - " + Math.max(0, (perView - 1) * gapPx) + "px) / " + perView + ")";
                    slide.style.flex = "0 0 " + width;
                    slide.style.maxWidth = width;
                    slide.style.width = "auto";
                    slide.style.minWidth = "0";
                    slide.style.margin = "0";
                    slide.style.boxSizing = "border-box";
                    slide.style.paddingLeft = "0";
                    slide.style.paddingRight = "0";
                    slide.style.borderWidth = "";
                } else {
                    slide.style.flex = "0 0 0px";
                    slide.style.maxWidth = "0";
                    slide.style.width = "0";
                    slide.style.minWidth = "0";
                    slide.style.margin = "0";
                    slide.style.paddingLeft = "0";
                    slide.style.paddingRight = "0";
                    slide.style.borderWidth = "0";
                }
            } else {
                if (isVisible) {
                    slide.style.flex = "";
                    slide.style.maxWidth = "100%";
                    slide.style.width = "100%";
                    slide.style.margin = "0";
                    slide.style.padding = "";
                } else {
                    slide.style.flex = "0 0 0px";
                    slide.style.maxWidth = "0";
                    slide.style.width = "0";
                    slide.style.margin = "0";
                    slide.style.padding = "0";
                }
            }
        });
        root.dataset.h4bsMirrorActiveIndex = String(safeIndex);
        root.dataset.h4bsMirrorPerView = String(perView);
        applyMirrorAutoHeight(root);
    }

    function fallbackSlide(root, direction) {
        if (!(root instanceof HTMLElement)) {
            return;
        }
        var slides = getSlides(root);
        if (!slides.length) {
            return;
        }
        var reviewMode = isReviewRoot(root);
        var perView = reviewMode ? getReviewPerView(root, slides.length) : 1;
        var current = Number(root.dataset.h4bsMirrorActiveIndex || getActiveSlideIndex(slides));
        if (!Number.isFinite(current)) {
            current = getActiveSlideIndex(slides);
        }
        var nextIndex = current;
        if (reviewMode) {
            var maxLead = Math.max(0, slides.length - perView);
            if (direction > 0) {
                nextIndex = current >= maxLead ? 0 : current + 1;
            } else if (direction < 0) {
                nextIndex = current <= 0 ? maxLead : current - 1;
            } else {
                nextIndex = Math.max(0, Math.min(current, maxLead));
            }
        } else {
            nextIndex = slides.length < 2 ? current : (current + direction + slides.length) % slides.length;
        }
        setActiveSlide(root, nextIndex);
    }

    function clearFallbackStyles(root) {
        if (!(root instanceof HTMLElement)) {
            return;
        }
        root.classList.remove("h4bs-mirror-fallback");
        root.classList.remove("h4bs-mirror-fallback-review");
        root.style.removeProperty("min-height");
        delete root.dataset.h4bsMirrorFallbackInit;

        var wrapper = root.querySelector(".swiper-wrapper");
        if (wrapper instanceof HTMLElement) {
            [
                "display",
                "gap",
                "align-items",
                "transform",
                "transition",
                "min-height"
            ].forEach(function (prop) {
                wrapper.style.removeProperty(prop);
            });
        }

        getSlides(root).forEach(function (slide) {
            slide.classList.remove("h4bs-mirror-slide-active");
            [
                "display",
                "visibility",
                "opacity",
                "flex",
                "max-width",
                "width",
                "min-width",
                "margin",
                "padding",
                "box-sizing",
                "border-width"
            ].forEach(function (prop) {
                slide.style.removeProperty(prop);
            });
        });
    }

    function ensureFallbackAutoplay(root) {
        if (!(root instanceof HTMLElement)) {
            return;
        }
        var delay = getAutoplayDelay(root, true);
        if (delay < 1000) {
            clearAutoplay(root);
            return;
        }

        // Normalize visibility to current active state without forcing index reset.
        var slides = getSlides(root);
        if (!slides.length) {
            clearAutoplay(root);
            return;
        }
        var currentIndex = Number(root.dataset.h4bsMirrorActiveIndex || "");
        if (!Number.isFinite(currentIndex)) {
            currentIndex = getActiveSlideIndex(slides);
        }
        setActiveSlide(root, currentIndex);

        var existing = autoplayMeta.get(root);
        if (existing && existing.delay === delay) {
            return;
        }
        if (existing && existing.id) {
            window.clearInterval(existing.id);
        }
        var timer = window.setInterval(function () {
            fallbackSlide(root, 1);
        }, delay);
        autoplayMeta.set(root, { id: timer, delay: delay });
    }

    function bindButton(root, button, direction) {
        if (!(button instanceof HTMLElement)) {
            return;
        }
        if (button.dataset.h4bsMirrorPatchBound === "1") {
            return;
        }

        button.dataset.h4bsMirrorPatchBound = "1";
        button.addEventListener("pointerdown", function (event) {
            event.preventDefault();
            event.stopPropagation();
            if (typeof event.stopImmediatePropagation === "function") {
                event.stopImmediatePropagation();
            }
        }, true);
        button.addEventListener("click", function (event) {
            event.preventDefault();
            event.stopPropagation();
            if (typeof event.stopImmediatePropagation === "function") {
                event.stopImmediatePropagation();
            }
            var now = Date.now();
            var last = Number(root.dataset.h4bsMirrorLastNavTs || "0");
            if (Number.isFinite(last) && now - last < 180) {
                return;
            }
            root.dataset.h4bsMirrorLastNavTs = String(now);
            fallbackSlide(root, direction);
            clearAutoplay(root);
            ensureFallbackAutoplay(root);
        }, true);
    }

    function stabilizeReviewSlider(root) {
        if (!(root instanceof HTMLElement)) {
            return;
        }
        if (!isReviewRoot(root)) {
            return;
        }

        var wrapper = root.querySelector(".swiper-wrapper");
        if (!(wrapper instanceof HTMLElement)) {
            return;
        }

        var slides = getSlides(root);
        if (!slides.length) {
            return;
        }

        wrapper.style.display = "flex";
        wrapper.style.gap = String(getReviewGapPx(root)) + "px";
        wrapper.style.alignItems = "stretch";
        wrapper.style.justifyContent = "flex-start";
        wrapper.style.transform = "none";
        wrapper.style.transition = "none";

        var maxHeight = 0;
        slides.forEach(function (slide) {
            var style = window.getComputedStyle(slide);
            if (style.display === "none" || style.visibility === "hidden" || Number(style.opacity || "1") < 0.01) {
                return;
            }
            maxHeight = Math.max(maxHeight, slide.getBoundingClientRect().height);
        });

        if (maxHeight > 0) {
            root.style.minHeight = Math.ceil(maxHeight) + "px";
            wrapper.style.minHeight = Math.ceil(maxHeight) + "px";
        }
        root.style.marginLeft = "0";
        root.style.marginRight = "0";
        root.style.overflow = "hidden";
    }

    function scheduleNativeWatchdog(root) {
        if (!(root instanceof HTMLElement)) {
            return;
        }
        if (nativeWatchdogTimers.has(root)) {
            return;
        }
        var slides = getSlides(root);
        if (slides.length < 2) {
            return;
        }
        var delay = getAutoplayDelay(root, true);
        if (!Number.isFinite(delay) || delay < 1000) {
            delay = isReviewRoot(root) ? 5000 : 4300;
        }
        var observeAfter = Math.min(10000, Math.max(2600, delay + 1200));
        var timer = window.setTimeout(function () {
            nativeWatchdogTimers.delete(root);
            if (!(root instanceof HTMLElement) || !document.contains(root)) {
                return;
            }
            var slides = getSlides(root);
            if (slides.length < 2) {
                return;
            }
            var indexBefore = getActiveSlideIndex(slides);
            window.setTimeout(function () {
                if (!(root instanceof HTMLElement) || !document.contains(root)) {
                    return;
                }
                var afterSlides = getSlides(root);
                if (afterSlides.length < 2) {
                    return;
                }
                var indexAfter = getActiveSlideIndex(afterSlides);
                if (indexAfter === indexBefore) {
                    // Native slider appears initialized but stalled. Fall back safely.
                    var nav = ensureNavigation(root);
                    if (!nav) {
                        return;
                    }
                    bindButton(root, nav.prev, -1);
                    bindButton(root, nav.next, 1);
                    clearFallbackStyles(root);
                    fallbackSlide(root, 0);
                    if (isReviewRoot(root)) {
                        stabilizeReviewSlider(root);
                    } else {
                        stabilizeHeroFallbackSlider(root);
                    }
                    ensureFallbackAutoplay(root);
                }
            }, Math.max(1200, Math.round(observeAfter * 0.45)));
        }, observeAfter);
        nativeWatchdogTimers.set(root, timer);
    }

    function runPatches() {
        if (!isMirrorPage()) {
            return;
        }
        patchServiceIcons();

        getSliderRoots().forEach(function (root) {
            var isReview = isReviewRoot(root);
            var hasNativeClass = root.classList.contains("swiper-initialized");
            var hasNativeSwiper =
                root.swiper &&
                typeof root.swiper.slideNext === "function" &&
                typeof root.swiper.slideTo === "function";

            if (hasNativeSwiper) {
                clearAutoplay(root);
                clearFallbackStyles(root);
                if (isReview) {
                    stabilizeReviewSlider(root);
                    scheduleNativeWatchdog(root);
                } else {
                    stabilizeHeroShell(root);
                    applyMirrorAutoHeight(root);
                    scheduleNativeWatchdog(root);
                }
                root.dataset.h4bsMirrorSliderInit = "native";
                return;
            }

            var nav = ensureNavigation(root);
            if (!nav) {
                return;
            }

            if (hasNativeClass) {
                var staleWrapper = root.querySelector(".swiper-wrapper");
                if (staleWrapper instanceof HTMLElement) {
                    staleWrapper.style.transform = "none";
                    staleWrapper.style.transition = "none";
                }
            }
            bindButton(root, nav.prev, -1);
            bindButton(root, nav.next, 1);

            var initialized = root.dataset.h4bsMirrorFallbackInit === "1";
            if (!initialized) {
                var slides = getSlides(root);
                if (slides.length) {
                    setActiveSlide(root, getActiveSlideIndex(slides));
                }
                root.dataset.h4bsMirrorFallbackInit = "1";
            }

            if (isReview) {
                stabilizeReviewSlider(root);
            } else {
                stabilizeHeroFallbackSlider(root);
                applyMirrorAutoHeight(root);
            }
            ensureFallbackAutoplay(root);
            root.dataset.h4bsMirrorSliderInit = hasNativeClass ? "fallback-native-class" : "fallback";
        });
        patchServiceIcons();
    }

    if (document.readyState === "loading") {
        document.addEventListener("DOMContentLoaded", runPatches, { once: true });
    } else {
        runPatches();
    }

    window.addEventListener("load", runPatches);
    window.setTimeout(runPatches, 900);
    window.setTimeout(runPatches, 2200);
    var resizeTimer = null;
    window.addEventListener("resize", function () {
        if (resizeTimer) {
            window.clearTimeout(resizeTimer);
        }
        resizeTimer = window.setTimeout(runPatches, 220);
    });

    if (typeof MutationObserver !== "undefined") {
        var observer = new MutationObserver(function () {
            runPatches();
        });
        var observerTarget = document.documentElement || document.body;
        if (observerTarget && typeof observerTarget.nodeType === "number") {
            observer.observe(observerTarget, {
                childList: true,
                subtree: true
            });
        }
        window.setTimeout(function () {
            observer.disconnect();
        }, 12000);
    }
})();
