<script>
    function horario() {
        const ahora = new Date();

        // Hora actual en Madrid, sin formato de 12h
        const opciones = {
            timeZone: "Europe/Madrid",
            hour12: false,
            hour: "2-digit",
            minute: "2-digit",
        };
        const horaMadridStr = ahora.toLocaleTimeString("es-ES", opciones);

        const [horaStr, minutoStr] = horaMadridStr.split(":");
        const hora = parseInt(horaStr, 10);
        const minuto = parseInt(minutoStr, 10);
        const minutosActuales = hora * 60 + minuto;

        const inicio = 24 * 60; // 24:00
        const fin = 9 * 60 + 59; // 09:59

        return minutosActuales >= inicio || minutosActuales <= fin;
    }
</script><script>
    (() => {
        const header = document.querySelector("#preloaded-header");
        if (!header) {
            return;
        }
        header.style.display = "none";
    })();
</script>
<div class="custom-header">
	<div class="custom-header-logo">
		<a href="/"><img alt="logo" class="main-header__logo" src="/library/logo_sportium_notagline_transparente.svg" /></a></div>
	<hub2-logged-out>
	<div class="custom-header-buttons">
		<div class="custom-header-buttons-row">
			<a class="btn_lgn btn btn_action_login btn_size_small" href="javascript:Playtech.API.popup.showPopup('login');">Entrar</a> <a class="btn_rgstr btn btn_action_sign-up btn_size_small" href="/register">Regístrate </a></div>
	</div>
	</hub2-logged-out> <hub2-logged-in>
	<div>
		<!--<div style="float: right">
            <div class="desktop-close">
                <hub2-logout></hub2-logout></div>
        </div>-->
		<div class="main-header__icon main-header__icon--deposit">
			<span class="fn-replacer js-replacer js-replacer-inline header-deposit-button-replacer"><a class="btn_dpstr btn btn_action_deposit fn-redirect btn_size_small" href="/monedero/depositar">Depositar</a> </span></div>
		<div>
			<div class="main-header__user-balance fn-main-header-user-balance" onclick="showBalances()">
				<a class="main-header__icon main-header__icon--balance fn-main-header-balance" href="javascript:void(0);"><span class="main-header__balance-icon micon-header-user-balance"></span> <span class="val_type_user_balance fn-replacer js-replacer js-replacer-inline casino-gaming-balance-replacer"> <span class="headerSaldo saldoTotal"></span> </span> </a>
				<div class="header-balance-popup">
					<div>
						<a class="main-header__icon main-header__icon--balance fn-main-header-balance" href="javascript:void(0);">Saldo Total Jugable: <span class="saldoTotal"></span></a></div>
					<div>
						<a class="main-header__icon main-header__icon--balance fn-main-header-balance" href="javascript:void(0);">Saldo real: <span class="saldo real"><hub2-balance-calc args="WITHDRAWABLE_BALANCE"></hub2-balance-calc></span></a></div>
					<div>
						<a class="main-header__icon main-header__icon--balance fn-main-header-balance" href="javascript:void(0);">Bono Rollover Sports: <span class="saldo bonoSports"><hub2-sportsbook-balance type="sportsBonus"></hub2-sportsbook-balance></span></a></div>
					<div>
						<a class="main-header__icon main-header__icon--balance fn-main-header-balance" href="javascript:void(0);">Apuestas Gratis Sports: <span class="saldo freebet"><hub2-sportsbook-balance type="sportsToken"></hub2-sportsbook-balance></span></a></div>
					<div>
						<a class="main-header__icon main-header__icon--balance fn-main-header-balance" href="javascript:void(0);">Bono Casino: <span class="saldo bonoCasino"><hub2-balance-calc args="BONUS_BALANCE"></hub2-balance-calc></span></a></div>
					<div>
						<a class="main-header__icon main-header__icon--balance fn-main-header-balance" href="javascript:void(0);">Ganancias pendientes bono casino : <span class="saldo pendientesCasino"><hub2-bonus-pending-winnings></hub2-bonus-pending-winnings></span></a></div>
					<a class="btn btn_dpstr main-header__icon deposit" href="/monedero/depositar">DEPOSITAR</a><br />
					<a class="btn btn_dpstr main-header__icon deposit" href="/myaccount/saldo">MI CUENTA</a>
					<div class="close-session">
						<hub2-logout type="btn"></hub2-logout></div>
				</div>
			</div>
		</div>
		<a class="main-header__icon main-header__icon--username" href="/monedero/depositar"><span class="main-header__user-name"><span class="main-header__user-name--welcome-msg">Bienvenido/a,</span> <span class="main-header__user-name--name"> <hub2-user-info property="username"></hub2-user-info> </span> </span> </a> <a class="header-club" href="/club-sportium"><img src="/library/iconos/Club_SP_41x44px.png" /></a> <span aria-label="Inbox" class="fn-open-inbox wc-header-inbox" tabindex="0"> <span> <hub2-unread-messages-count></hub2-unread-messages-count></span> </span></div>
	</hub2-logged-in></div>
<style type="text/css">
.desktop .menu__nav-wrapper, .desktop .menu__secondlevel-nav{
        max-width: 90%!important;
    }

    .custom-header-buttons{
        margin-top: 2px!important;
    }

    a.btn_lgn.btn.btn_action_login.btn_size_small,
    a.btn_rgstr.btn.btn_action_sign-up.btn_size_small {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        height: 2rem;
        min-width: 7rem;
        padding: 0 14px;
        font-size: 1rem;
        line-height: 1;
        border-radius: 3px;
        font-weight: 400;
        box-sizing: border-box;
        letter-spacing: 0.025em;
    }


    a.btn_lgn.btn.btn_action_login.btn_size_small {
        box-shadow: none !important;
        border: 1px solid #FFF;
        border-radius: 3px;
        background: transparent !important;
        text-shadow: none;
        color: #FFF;
        transition: all 0.3s ease;
    }
    a.btn_lgn.btn.btn_action_login.btn_size_small:hover {
        background: #fff!important;
        color: #2C2E39;
    }
    a.btn_rgstr.btn.btn_action_sign-up.btn_size_small {
        background: #249D16 !important;
        border: none !important;
        border-radius: 3px;
        color: #fff !important;
        text-shadow: none;
        transition: background 0.3s ease;
        box-shadow: none !important;
    }

    a.btn_rgstr.btn.btn_action_sign-up.btn_size_small:hover {
        background: #2BBA1A !important;
    }

    a.btn_dpstr{
        background: #249D16 !important;
        border: none !important;
        border-radius: 3px;
        padding: 9px 20px;
        line-height: normal;
        font-weight: 300;
        color: #fff !important;
        text-shadow: none;
        transition: background 0.3s ease;
        font-size: 1em;
    }

    a.btn_dpstr:hover {
        background: #2BBA1A !important;
    }

    .header-club img {
        width: 35px;
    }

    .custom-header-buttons,
    .header-balance-popup div span.saldo,
    .header-balance-popup div span.saldoTotal,
    .header-club {
        float: right;
    }

    .block-content {
        width: 100%;
        height: 1000px;
        opacity: 1;
        position: fixed;
        display: none;
        z-index: 10;
        top: 0;
    }

    .main-header__icon.main-header__icon--balance.fn-main-header-balance.sports-balance {
        display: none;
    }

    .custom-header {
        background: 0;
        font-size: inherit;
        height: 4.2em;
        margin: auto;
        max-width: 90%;
        padding: 10px 0 0;
    }

    .close-session,
    .main-header__icon.deposit {
        font-size: 1.2em;
        color: #fff;
        float: left;
        text-align: center;
    }

    .custom-header-logo {
        float: left;
    }

    .header-balance-popup {
        position: absolute;
        width: 25em;
        background-color: #ebebeb;
        margin: 4em auto 0;
        display: none;
        padding: 2em 1em 3em;
        line-height: 25px;
        z-index: 100;
        right: 20%;
        border-radius: 1em;
    }

    .main-header__icon.deposit {
        background-image: linear-gradient(to top, #759c05, #abce41);
        padding: 0.5em 5em;
        width: 100%;
        margin: 0 auto 1em;
        font-family: DINCondensedRegular;
    }

    .main-header__icon.deposit:hover {
        color: #fff;
    }

    .close-session {
        /*background-image: linear-gradient(to top, #767676, #929292);*/
        padding: 0 !important;
        /*margin: 15px auto;*/
        width: 100%;
    }

    .btn_type_logout,
    .btn_type_logout:hover {
        background: 0;
        background-image: none !important;
        text-indent: 0;
        width: 100%;
        font-size: 1em;
        text-align: center;
    }

    .header-balance-popup div,
    .user-balance {
        font-size: 1.3em;
        font-family: DINCondensedRegular;
    }

    .user-balance {
        float: right;
        width: 50%;
        text-align: right;
        padding: 0.3em 1.2em 0.6em 0;
    }

    .desktop .main-header__logo {
        height: 2.4rem !important;
        margin-top: 0.5rem;
    }

    .header-balance-popup div:not(.close-session) {
        background-color: #fff;
        margin-bottom: 10px;
        padding: 0 1em 1.5em;
        color: #000;
    }

    .main-header__menu {
        height: 2.5em;
        min-width: 2.5em;
        background-size: 400%;
        overflow: hidden;
        background-position: 0 -80em;
        float: left;
        position: relative;
        margin: 0.5em 0 0 0.5em;
    }

    .main-header__menu.fn-close-menu {
        margin: 0;
    }

    .header-balance-popup a {
        width: 100%;
    }

    .header-balance-popup div a,
    .header-balance-popup div a:hover {
        color: #000 !important;
    }

    .wc-header-inbox {
        cursor: pointer;
        display: flex;
        width: 3rem;
        height: 37.5px;
        background-image: url(/sportium_sportium_theme/images/ic_WL_sprite.png);
        background-repeat: no-repeat;
        background-size: 11rem;
        background-position: 0 -71.3rem;
        float: right;
        margin-right: 1rem;
    }

    .wc-header-inbox:hover {
        background-position: -2.75rem -71.3rem;
    }

    #inboxContainer {
        z-index: 10000;
        position: absolute;
    }

    .MainNavigationBar {
        position: fixed;
        width: 100%;
        z-index: 10 !important;
    }

    #sports main {
        margin-top: 32px !important;
    }

    .close-session .cms-logout-button button {
        background: transparent !important;
        border: 1px solid #000 !important;
        border-radius: 3px !important;
        line-height: normal;
        color: #000 !important;
        text-shadow: none;
        transition: background 0.3s ease;
        box-shadow: none !important;
        padding: 0.3em;
        text-indent: 0;
        width: 100%;
        font-size: 1em;
        text-align: center;
        font-family: 'Saira Condensed' !important;
        font-weight: 800 !important;
        text-transform: uppercase;
    }
    .close-session .cms-logout-button button:hover {
        background: #000 !important;
        color: white !important;
    }</style>
<script type="text/javascript">
    jQuery(document).ready(function () {
        jQuery("body").append('<div class="block-content"></div>');
        jQuery(".block-content").click(function () {
            jQuery(".header-balance-popup").toggle();
            jQuery(".block-content").toggle();
        });
    });
    function showBalances() {
        jQuery(".header-balance-popup").toggle();
        jQuery(".block-content").toggle();
    }
    function logoButton() {
        if (window.location.href.indexOf("apuestas") > 0) {
            if (window.location.href.indexOf("/promociones") > 0) {
                Playtech.API.common.navigate("/apuestas");
            } else if (window.location.href.indexOf("/apuestas-deportivas") > 0) {
                Playtech.API.common.navigate("/apuestas");
            } else{
                Sportsbook.navigate("toHome");
            }
        } else if (window.location.href.indexOf("casino") > 0) {
            Playtech.API.common.navigate("/casino");
        } else if (window.location.href.indexOf("slots") > 0) {
            Playtech.API.common.navigate("/slots");
        } else if (window.location.href.indexOf("poker") > 0) {
            Playtech.API.common.navigate("/poker");
        } else if (window.location.href.indexOf("ruleta") > 0) {
            Playtech.API.common.navigate("/casino");
        } else{
            Playtech.API.common.navigate("/apuestas");
        }
    }
    function promotionButton() {
        if (window.location.href.indexOf("apuestas") > 0) {
            // Está en Sports → ir a promociones de apuestas
            Playtech.API.common.navigate("/promociones/apuestas");
        } else if (window.location.href.indexOf("poker") > 0) {
            // Está en Poker → ir a promociones de poker
            Playtech.API.common.navigate("/poker/promociones");
        } else if (window.location.href.indexOf("casino") > 0 || window.location.href.indexOf("slots") > 0) {
            // Está en Casino o Slots → ir a promociones de casino
            Playtech.API.common.navigate("/casino/promociones");
        } else {
            // Home sin loguear → ir a promociones de bienvenida
            Playtech.API.common.navigate("/bienvenida/promociones");
        }
    }
    function calcBalance() {
        total =
            parseFloat(
                jQuery(".saldo.real").text().replace("€ ", "").replace(",", "")
            ) +
            parseFloat(
                jQuery(".saldo.bonoSports").text().replace("€ ", "").replace(",", "")
            ) +
            parseFloat(
                jQuery(".saldo.bonoCasino").text().replace("€ ", "").replace(",", "")
            ) +
            parseFloat(
                jQuery(".saldo.freebet").text().replace("€ ", "").replace(",", "")
            ) +
            parseFloat(
                jQuery(".saldo.pendientesCasino")
                    .text()
                    .replace("€ ", "")
                    .replace(",", "")
            );
        if (!isNaN(total)) {
            jQuery(".saldoTotal").empty();
            jQuery(".saldoTotal").html(decimales(total));
        } else {
            jQuery(".saldoTotal").empty();
            jQuery(".saldoTotal").html("---");
        }
    }
    function decimales(s) {
        var num = new Intl.NumberFormat("en-US", {
            style: "currency",
            currency: "EUR",
        }).format(s);
        if (num.indexOf("NaN") < 0) {
            return num.substring(1, num.length) + " €";
        } else {
            return "---";
        }
    }
    var balanceInterval = setInterval(function () {
        calcBalance();

        if (jQuery(".saldo.bonoSports").text() == "€ 0.00") {
            jQuery(".saldo.bonoSports").parent().parent().hide();
        } else {
            jQuery(".saldo.bonoSports").parent().parent().show();
        }
    }, 1000);
</script><script>
    var headerInterval = setInterval(function () {
        if (jQuery('a[class*="header-club"]').length > 1) {
            jQuery('a[class*="header-club"]')[1].remove();
        }
    }, 1000);
</script><script>
    function openInbox() {
        const { inboxWidget = {} } = window.Playtech.Variables || {};

        const searchParams = new URLSearchParams(window.location.search);
        const hideInboxByUrl = searchParams.get("hideInbox") === "1";
        const button = document.querySelector(".fn-open-inbox");
        const showInbox =
            inboxWidget.showIcon && inboxWidget.enabled && !hideInboxByUrl;

        if (!inboxWidget.enabled || !window.Communication) {
            console.log("inbox not enabled");
        }

        const { inbox, chat } = window.Communication.API;

        if (!inbox) {
            console.log("inbox not found");
        }

        const status = inbox.getWindowStatus() || {};

        if (status.close) {
            inbox.showInboxTab();
        }

        if (status.hide) {
            chat && chat.minimize && chat.minimize();

            inbox.maximize();
        }
    }
    jQuery(document).on("click", ".custom-header .fn-open-inbox", function () {
        openInbox();
    });
</script><script defer>
    function liveChatWidgetProps() {
        return {
            chatButtonProps: {
                controlProps: {
                    hideChatTextContainer: true,
                },
                styleProps: {
                    generalStyleProps: {
                        minWidth: "60px",
                        width: "60px",
                        height: "60px",
                    },
                },
            },
        };
    }

    function isLiveChatLoaded() {
        return !!document.getElementById("Microsoft_Omnichannel_LCWidget");
    }
    function initHelpChat() {
        if (!isLiveChatLoaded()) {
            var script = document.createElement("script");
            script.id = "Microsoft_Omnichannel_LCWidget";
            script.src =
                "https://oc-cdn-public-eur.azureedge.net/livechatwidget/scripts/LiveChatBootstrapper.js";
            script.setAttribute(
                "data-app-id",
                "290565ed-031c-4018-b34e-5013df22f7d4"
            );
            script.setAttribute("data-lcw-version", "prod");
            script.setAttribute(
                "data-org-id",
                "941a1817-c9b6-ef11-8a67-000d3a3a0267"
            );
            script.setAttribute(
                "data-org-url",
                "https://m-941a1817-c9b6-ef11-8a67-000d3a3a0267.eu.omnichannelengagementhub.com"
            );
            script.setAttribute("data-customization-callback", "liveChatWidgetProps");
            document.body.appendChild(script);
        }
    }

    function shouldEnableChatButton() {
        const userModelStr = sessionStorage.getItem("userModel");
        const userModel = userModelStr ? JSON.parse(userModelStr) : null;

        if (Playtech.API.user.isLoggedIn()) {
            if (!horario()) {
                return true;

                if (window.location.pathname.includes("/ayuda")) {
                    //return true;
                }

                if (userModel) {
                    const { vipLevel, custom05 } = userModel.userDetails;
                    if (
                        vipLevel > 1 ||
                        ["VIP NIVEL 1", "ELITE", "KEY ACCOUNT"].includes(custom05)
                    ) {
                        return true;
                    }
                }
            }
            return false;
        }
    }

    if (shouldEnableChatButton() && !isLiveChatLoaded() && !isApp()) {
        initHelpChat();
    }

    Playtech.on("WEB_CONTENT_RENDERED", ([wc]) => {
        if (
            wc == "AYUDA_TEST_STAGE" &&
            shouldEnableChatButton() &&
            !isLiveChatLoaded()
        ) {
            jQuery(document)
                .on("click", "#help_contact_button_chat", function () {
                    initHelpChat();
                })
                .data("initialized", true);
        }
    });

    Playtech.on("LOGGED_OUT", () => {
        const liveChatScript = document.getElementById(
            "Microsoft_Omnichannel_LCWidget"
        );
        if (liveChatScript) {
            liveChatScript.remove();
        }

        const liveChatIframe = document.getElementById(
            "Microsoft_Omnichannel_LCWidget_Chat_Iframe_Window"
        );
        if (liveChatIframe) {
            liveChatIframe.remove();
        }
    });

    Playtech.on("LOGGED_IN", () => {
        if (shouldEnableChatButton() && !isLiveChatLoaded()) {
            initHelpChat();
        }
    });

    window.addEventListener("lcw:ready", function handleLivechatReadyEvent() {
        Microsoft.Omnichannel.LiveChatWidget.SDK.setContextProvider(
            function contextProvider() {
                const context = { NombreUsuario: Playtech.fetchUserDetails().username };
                return context;
            }
        );
        let registeredContextProvider =
            Microsoft.Omnichannel.LiveChatWidget.SDK.getContextProvider();
    });

    function openChat() {
        if (!horario()) {
            initHelpChat();
        } else {
            Playtech.API.popup.showPopup({
                title: 'Servicio no disponible',
                content: 'Actualmente estamos fuera de servicio. Nuestro horario de atención es de 10:00 a 24:00 horas.'
            });
        }
    }
    function isApp() {
        const userAgent = navigator.userAgent || navigator.vendor || window.opera;

        // Detectar WebView o Flutter WebView
        const isFlutterWebView = /wv|WebView|Flutter/i.test(userAgent);

        // Detectar si es iOS (iPhone o iPad)
        const isIOS = /iPhone|iPad|iPod/i.test(userAgent) && !window.MSStream;

        // Detectar si es un WebView de iOS (generalmente usado por apps)
        const isIOSWebView = /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(userAgent);

        // Retorna true si es un Flutter WebView o un WebView de una app nativa de iOS
        return isFlutterWebView || (isIOS && isIOSWebView);
    }
</script><script>
    (function () {
        const searchParams = new URLSearchParams(window.location.search);
        if (searchParams.get("hideInbox") === "1") {
            document.body.classList.add("hide-inbox-icon");
        }
    })();
</script>
<style type="text/css">
body.hide-inbox-icon .fn-open-inbox {
        display: none !important;
    }</style>
<script>
    function logoClickHandler(e) {
        e.preventDefault();
        logoButton();
    }

    function promotionClickHandler(e) {
        e.preventDefault();
        promotionButton();
    }

    Playtech.on("WEB_CONTENT_RENDERED", function () {

        const logoLink = document.querySelector(".custom-header-logo a");
        if (!logoLink) return;

        // Si está logueado → interceptar el clic del logo
        if (Playtech.API.user.isLoggedIn()) {
            logoLink.addEventListener("click", logoClickHandler);
        }
        // Si NO está logueado → comportamiento estándar
        else {
            logoLink.href = "/";
        }

        // Interceptar el botón de Promociones para hacerlo contextual
        const promotionLink = document.querySelector(".cms-menu-desktop-first-level li.promociones a");
        if (promotionLink) {
            promotionLink.addEventListener("click", promotionClickHandler);
        }

    });

    // Cuando se desloguea → restaurar comportamiento normal
    Playtech.on("LOGGED_OUT", function () {
        const logoLink = document.querySelector(".custom-header-logo a");
        if (logoLink) {
            // Ahora sí elimina correctamente el handler del logo
            logoLink.removeEventListener("click", logoClickHandler);
            logoLink.href = "/";
        }

        // Restaurar comportamiento del botón de promociones
        const promotionLink = document.querySelector(".cms-menu-desktop-first-level li.promociones a");
        if (promotionLink) {
            promotionLink.removeEventListener("click", promotionClickHandler);
            promotionLink.href = "/casino/promociones";
        }
    });
</script><!-- INBOX STYLE -->
<style type="text/css">
/* Contenedor del icono */
    .wc-header-inbox {
        position: relative;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 43px;
        height: 43px;
        cursor: pointer;
        background-image: none !important;
    }

    /* Icono Material insertado como pseudo-elemento */
    .wc-header-inbox::before {
        content: "";
        display: block;
        width: 43px;
        height: 43px;
        background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" height="43px" viewBox="0 -960 960 960" width="43px" fill="%23e3e3e3"><path d="M179.7-202.54q-23.42 0-40.15-16.73-16.73-16.73-16.73-40.17v-441.12q0-23.44 16.73-40.17t40.15-16.73h600.6q23.42 0 40.15 16.73 16.73 16.73 16.73 40.17v441.12q0 23.44-16.73 40.17t-40.15 16.73H179.7ZM480-484.06 155.26-699v439.41q0 10.77 6.92 17.69 6.92 6.93 17.69 6.93h600.26q10.77 0 17.69-6.93 6.92-6.92 6.92-17.69V-699L480-484.06Zm0-36.48 311.03-204.49H169.64L480-520.54ZM155.26-699v-26.03V-259.59q0 10.77 6.92 17.69 6.92 6.93 17.69 6.93h-24.61V-699Z"/></svg>');
        background-size: contain;
        background-repeat: no-repeat;
        background-position: center;
    }
    /* Estilo del badge */
    .unreadmessagescount-replacer {
        position: absolute;
        top: 0px;
        right: -5px;

        background: white;
        color: #d10b1c;   /* rojo Sportium */

        min-width: 15px;
        height: 15px;
        padding: 0 5px;

        border-radius: 50px;
        font-size: 12px;
        font-weight: 700;

        display: flex;
        align-items: center;
        justify-content: center;

        box-shadow: 0 0 0 2px #d10b1c; /* aro para que se integre con cabecera roja */
    }

    /* Ocultar el badge cuando no hay mensajes */
    .unreadmessagescount-replacer:not(.has-message) {
        display: none;
    }
.custom-header .has-message {
    position: absolute;
    top: 0px;
    right: -5px;
    background: white;
    color: #d10b1c;
    min-width: 15px;
    height: 15px;
    padding: 0 5px;
    border-radius: 50px;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 0 2px #d10b1c;
}</style>