/* ═══ iframe detection + auto-redirect ═══
   When a page is loaded inside main.html's iframe,
   hide its own sidebar + adjust main margin.
   When accessed directly (not in iframe), redirect to main.html. */
(function() {
    if (window.self !== window.top) {
        // Inside iframe - just mark it
        document.documentElement.classList.add('in-iframe');
    } else {
        // Accessed directly - redirect to main.html unless already on main.html
        var path = window.location.pathname;
        var filename = path.split('/').pop();
        // Don't redirect main.html itself, chatbot pages, or test pages
        var noRedirect = ['main.html', 'chatbot.html', 'test_sp.html', 'test_db.html'];
        if (filename && filename.endsWith('.html') && noRedirect.indexOf(filename) === -1) {
            // Preserve any query string
            var qs = window.location.search;
            window.location.replace('/static/main.html?page=' + filename + (qs ? '&' + qs.substring(1) : ''));
        }
    }
})();
