<script>
    window.DealFlow = window.DealFlow || {};

    window.DealFlow.showToast = function (message) {
        var toast = document.createElement('div');
        toast.style.cssText = 'position:fixed;bottom:20px;left:50%;transform:translateX(-50%);background:var(--text-primary,#333);color:var(--background,#fff);padding:12px 24px;border-radius:8px;font-size:14px;z-index:9999;box-shadow:0 4px 12px rgba(0,0,0,.15);';
        toast.textContent = message;
        document.body.appendChild(toast);
        setTimeout(function () {
            toast.style.opacity = '0';
            toast.style.transition = 'opacity .3s ease';
            setTimeout(function () { toast.remove(); }, 300);
        }, 3000);
    };

    window.DealFlow.rollbackDragDrop = function (card, sourceStage, targetStage, originalStageId, updateStageCounts) {
        var sourceDropzone = sourceStage.querySelector('[data-stage-dropzone]');
        if (sourceDropzone) {
            sourceDropzone.appendChild(card);
        }
        card.setAttribute('data-current-stage-id', originalStageId);
        var stageSelect = card.querySelector('[data-stage-select]');
        if (stageSelect) {
            stageSelect.value = originalStageId;
        }
        if (typeof updateStageCounts === 'function') {
            updateStageCounts(sourceStage, 1);
            updateStageCounts(targetStage, -1);
        }
        var targetEmpty = targetStage.querySelector('[data-stage-dropzone]');
        if (targetEmpty && targetEmpty.children.length === 0) {
            var emptyEl = document.createElement('div');
            emptyEl.className = 'dealflow-pipeline-stage__empty';
            emptyEl.textContent = 'No deals';
            targetEmpty.appendChild(emptyEl);
        }
    };
</script>
