	// Warning
	function MsgWarning(message, options = {})
	{
	    const opt = {
	        title: options.title || "Warning",
	        autoClose: options.autoClose || 0,      // 0 = pas d’auto close
	        showCancel: options.showCancel || false,
					okSelected: options.okSelected || false,
					okText : options.okText || "OK",
					cancelText : options.cancelText || "Cancel",
	        dark: options.dark || false
	    };

	    let modal = document.getElementById("IdcMsgWarning");

	    // ➜ Si la modale n'existe pas, on crée tout
	    if (!modal) {

	        const html = `
	        <div id="IdcMsgWarning" class="modal fade ${opt.dark ? 'bg-dark' : ''}" tabindex="-1">
	            <div class="modal-dialog modal-dialog-centered">
	                <div class="modal-content ${opt.dark ? 'bg-dark text-white' : ''}">

	                    <!-- Header -->
	                    <div class="modal-header ${opt.dark ? 'bg-secondary text-white' : 'bg-light'}">
	                        <h5 class="modal-title fw-bold">${opt.title}</h5>
	                        <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
	                    </div>

	                    <!-- Body -->
	                    <div class="modal-body d-flex gap-3 align-items-center">
	                        <div>
	                            <i class="bi bi-exclamation-triangle-fill text-warning fs-1"></i>
	                        </div>
	                        <span id="IdcMsgWarningText"></span>
	                    </div>

	                    <!-- Footer -->
	                    <div class="modal-footer">

	                        ${opt.showCancel ? `
	                            <button type="button" id="IdcMsgWarning_CANCEL" class="btn btn-outline-secondary">
	                                ${opt.cancelText}
	                            </button>
	                        ` : ''}

	                        <button id="IdcMsgWarning_OK" type="button" class="btn btn-primary" style="background-color:#2F83B0">
	                            ${opt.okText}
	                        </button>

	                    </div>

	                </div>
	            </div>
	        </div>
	        `;

	        $('body').append(html);

	        // OK
	        $(document).on("click", "#IdcMsgWarning_OK", function () {
							if(opt.okSelected != false)
							{
								opt.okSelected();
							}
	            $('#IdcMsgWarning').modal('hide');
	        });

	        // Cancel → juste fermer
	        $(document).on("click", "#IdcMsgWarning_CANCEL", function () {
	            $('#IdcMsgWarning').modal('hide');
	        });

	        // Lorsque la modale se ferme → suppression du DOM
	        $(document).on('hidden.bs.modal', '#IdcMsgWarning', function () {

							$(document).off("click", "#IdcMsgWarning_OK");
    					$(document).off("click", "#IdcMsgWarning_CANCEL");

							$(this).remove();
	        });

	        modal = document.getElementById("IdcMsgWarning");
	    }


			$("#IdcMsgWarningText").html(message);
	    // ➜ Afficher la modale
	    $('#IdcMsgWarning').modal('show');

	    // ➜ Auto close si demandé
	    if (opt.autoClose > 0) {
	        setTimeout(() => {
	            $('#IdcMsgWarning').modal('hide');
	        }, opt.autoClose);
	    }
	}



	// Yes / No

	function MsgYesNo(questionText, onYesFunction, onNoFunction)
	{
	    // 1. Vérifier si la DIV existe
	    if ($('#IdcMsgYesNo').length === 0) {

	        // 2. La créer
	        const modalHtml = `
	        <div id="IdcMsgYesNo" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true" style="z-index:1080 !important;">
	            <div class="modal-dialog" role="document">
	                <div class="modal-content">

	                    <div class="modal-header p-3 pb-3 pt-3 border-bottom bg-light">
	                        <h5 class="fw-bold mb-0">Warning</h5>
	                        <button id="IdcMsgYesNo_Cancel_Button" type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
	                    </div>

	                    <div class="modal-body">
	                        <div class="form-floating mb-3">
	                            <span id="IdcMsgYesNoQuestionText"></span>
	                        </div>
	                    </div>

	                    <div class="modal-footer">
	                        <button id="IdcMsgYesNo_Yes_Button" type="button" class="btn btn-secondary" data-bs-dismiss="modal">Yes</button>
	                        <button id="IdcMsgYesNo_No_Button" type="button" class="btn btn-primary" style="background-color:#2F83B0">No</button>
	                    </div>

	                </div>
	            </div>
	        </div>
	        `;
	        $('body').append(modalHtml);

	        // 3. À la fermeture => supprimer complètement le modal
	        $('#IdcMsgYesNo').on('hidden.bs.modal', function () {
	            $(this).remove();
	        });
	    }

	    // 4. Mettre le texte de la question
	    $('#IdcMsgYesNoQuestionText').text(questionText);

	    // 5. Définir le callback du bouton Yes
	    $('#IdcMsgYesNo_Yes_Button').off('click').on('click', function () {
	        if (typeof onYesFunction === 'function') onYesFunction();
	    });

	    // 6. Définir le callback du bouton No
	    $('#IdcMsgYesNo_No_Button').off('click').on('click', function () {
	        if (typeof onNoFunction === 'function') onNoFunction();
	        $('#IdcMsgYesNo').modal('hide');
	    });

	    // 7. Afficher le modal
	    $('#IdcMsgYesNo').modal('show');
	}


	function MsgYesNo_YesClicked ( event )
	{
	

		if ( event.data.OnYesFunction != null )
			event.data.OnYesFunction ();

		$('#IdcMsgYesNo').modal('hide');
	}

	function MsgYesNo_NoClicked ( event )
	{
		

		if ( event.data.OnNoFunction != null )
			event.data.OnNoFunction ();

		$('#IdcMsgYesNo').modal('hide');
	}



/*
	// Comment
	function DlgComment ( captionText, ident, comment, onValidateFunction, onCancelFunction )
	{
		$('#IdcDlgComment').data ( 'ident', ident );

		$('#IdcDlgCommentEdit').val ( comment );

		$('#IdcDlgCommentCaption').text ( captionText );

		$('#IdcDlgComment_Validate_Button').unbind ( 'click' );
		$('#IdcDlgComment_Validate_Button').click ( {OnValidateFunction: onValidateFunction}, DlgComment_ValidateClicked );

		$('#IdcDlgComment_Cancel_Button').unbind ( 'click' );
		$('#IdcDlgComment_Cancel_Button').click ( {OnCancelFunction: onCancelFunction}, DlgComment_CancelClicked );

		$('#IdcDlgComment_Cross_Button').unbind ( 'click' );
		$('#IdcDlgComment_Cross_Button').click ( {OnCancelFunction: onCancelFunction}, DlgComment_CancelClicked );


		$('#IdcDlgComment').modal('show');
	}

	function DlgComment_ValidateClicked ( event )
	{
		

		if ( event.data.OnValidateFunction != null )
		{
			let text = $('#IdcDlgCommentEdit').val ();
			let ident = $('#IdcDlgComment').data ( 'ident' );

			event.data.OnValidateFunction ( ident, text );
		}

		$('#IdcDlgComment').modal('hide');
	}

	function DlgComment_CancelClicked ( event )
	{
		

		if ( event.data.OnCancelFunction != null )
			event.data.OnCancelFunction ();

		$('#IdcDlgComment').modal('hide');
	}*/

function MsgPopup(messageHTML, mainColor = 'rgba(68, 74, 80, 0.5)', delay = 2000) {
    // Générer un ID unique
    const toastId = 'IdcMsgPopup_' + (crypto?.randomUUID ? crypto.randomUUID() : Date.now() + '_' + Math.floor(Math.random() * 10000));

    // Conteneur toast global (si pas encore créé)
    let container = document.getElementById('IdcMsgPopupContainer');
    if (!container) {
        container = document.createElement('div');
        container.id = 'IdcMsgPopupContainer';
        container.className = 'toast-container position-fixed top-0 end-0 p-3 d-flex flex-column gap-2';
        container.style.zIndex = '10000';
        document.body.appendChild(container);
    }

    // Créer le toast
    const toastEl = document.createElement('div');
    toastEl.id = toastId;
    toastEl.className = 'toast';
    toastEl.role = 'alert';
    toastEl.ariaLive = 'assertive';
    toastEl.ariaAtomic = 'true';

    // Corps du toast
    const toastBody = document.createElement('div');
    toastBody.className = 'toast-body fs-5';
    toastBody.style.backgroundColor = 'transparent';
    toastBody.style.color = 'white';
    toastBody.style.lineHeight = '1.4';
    toastBody.innerHTML = messageHTML;

    // Style glassmorphic
    toastEl.style.backgroundColor = mainColor;
    toastEl.style.backdropFilter = 'blur(10px)';
    toastEl.style.borderRadius = '0.8rem';
    toastEl.style.border = '1px solid rgba(255, 255, 255, 0.2)';
    toastEl.style.padding = '0.5rem 1rem';

    toastEl.appendChild(toastBody);

    // AJOUTER AU DÉBUT pour que le plus récent soit au-dessus
    container.prepend(toastEl);

    // Durée
    toastEl.setAttribute('data-bs-delay', delay);

    // Affichage avec Bootstrap
    const toast = new bootstrap.Toast(toastEl);
    toast.show();

    // Destruction automatique après la durée
    setTimeout(() => {
        toastEl.remove();

        // Supprime le container si plus de toast dedans
        if (container.childElementCount === 0) {
            container.remove();
        }
    }, delay + 500);

    return toastId; // retourne l'ID si besoin
}