class LoadingSpinner {
    static create(message = 'Loading...') {
        const spinner = document.createElement('div');
        spinner.className = 'loading-spinner';
        spinner.style.cssText = `
            position: fixed;
            inset: 0;
            background: rgba(255, 255, 255, 0.9);
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            z-index: 9999;
            gap: 16px;
        `;

        spinner.innerHTML = `
            <div style="
                width: 48px;
                height: 48px;
                border: 4px solid #f0f0f0;
                border-top-color: var(--primary, #0d6efd);
                border-radius: 50%;
                animation: loading-spin 1s linear infinite;
            "></div>
            <p style="color: var(--text-secondary, #666); margin: 0;">${message}</p>
            <style>
                @keyframes loading-spin {
                    to { transform: rotate(360deg); }
                }
            </style>
        `;

        return spinner;
    }

    static show(message = 'Loading...') {
        let spinner = document.getElementById('globalSpinner');
        if (!spinner) {
            spinner = this.create(message);
            spinner.id = 'globalSpinner';
            document.body.appendChild(spinner);
        }
        spinner.style.display = 'flex';
        return spinner;
    }

    static hide() {
        const spinner = document.getElementById('globalSpinner');
        if (spinner) {
            spinner.style.display = 'none';
        }
    }
}

// Usage example:
// LoadingSpinner.show('Saving...');
// LoadingSpinner.hide();
