function createLoading(message = '文件加载中...') {
    const overlay = document.createElement('div');
    overlay.className = 'loading-overlay';
    overlay.innerHTML = `
        <div class="loading-spinner"></div>
        <p>${message}</p>
    `.trim();

    // Body 在某些 hybrid WebView 中可能尚未生成，需等待可用后再挂载遮罩层
    const mountOverlay = () => {
        const host = document.body || document.documentElement;
        if (!host) {
            return false;
        }
        host.appendChild(overlay);
        return true;
    };

    if (!mountOverlay()) {
        const handleReady = () => {
            if (mountOverlay()) {
                document.removeEventListener('DOMContentLoaded', handleReady);
            }
        };

        if (document.readyState === 'loading') {
            document.addEventListener('DOMContentLoaded', handleReady);
        } else {
            handleReady();
        }
    }

    return {
        show() {
            overlay.classList.remove('hidden');
        },
        hide() {
            overlay.classList.add('hidden');
            setTimeout(() => overlay.remove(), 200);
        }
    };
}
