// Lightweight on-demand script loader (kept small for synchronous include at startup)
window.neoAssets = {
    _promises: {},

    loadScript(src) {
        if (this._promises[src]) return this._promises[src];

        const existing = document.querySelector(`script[data-neo-src="${src}"]`);
        if (existing) {
            this._promises[src] = Promise.resolve();
            return this._promises[src];
        }

        this._promises[src] = new Promise((resolve, reject) => {
            const s = document.createElement('script');
            s.src = src;
            s.dataset.neoSrc = src;
            s.onload = () => resolve();
            s.onerror = () => reject(new Error(`Failed to load: ${src}`));
            document.head.appendChild(s);
        });

        return this._promises[src];
    },

    async ensureChartReady() {
        await this.loadScript('lib/js/echarts.min.js');
        if (!window.neoChart) {
            await this.loadScript('js/chart-interop.js');
        }
    },

    async ensureExcelGrid() {
        if (!window.excelGrid) {
            await this.loadScript('js/excel-grid.js');
        }
    }
};

window.neoBoot = {
    hide() {
        document.documentElement.classList.add('neo-app-ready');
        const overlay = document.getElementById('neo-boot-overlay');
        if (overlay) overlay.remove();
    }
};
