<?php
@header('Content-Type: text/html; charset=UTF-8');
include dirname(__DIR__) . '/includes/common.php';
if($islogin != 1) {
    exit("<script>window.location.href='./login.php';</script>");
}

// 授权检测 - 仅在登录后进入管理员页面时检测
$auth_api_url = 'https://sqz.dadxb.cn/api/verify.php';
$current_domain = $_SERVER['HTTP_HOST'] ?? '';
$current_domain = preg_replace('/:\d+$/', '', $current_domain);

// 白名单页面（不需要检测授权的页面）
$auth_whitelist = ['login.php', 'ajax.php'];
$current_page = basename($_SERVER['PHP_SELF']);

// 检测授权（跳过白名单页面）
if (!in_array($current_page, $auth_whitelist) && !isset($_GET['act']) && !isset($_GET['export_import_act'])) {
    if (session_status() === PHP_SESSION_NONE) {
        session_start();
    }
    
    // 每次进入后台都重新检测授权，不使用缓存（确保授权状态实时更新）
    $api_url = $auth_api_url . '?domain=' . urlencode($current_domain);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $api_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    $response = curl_exec($ch);
    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    
    $result = json_decode($response, true);
    $auth_valid = false;
    if ($result && isset($result['success']) && $result['success'] && isset($result['data']['is_valid']) && $result['data']['is_valid']) {
        $auth_valid = true;
    }
    
    // 未授权时跳转到无授权页面
    if (!$auth_valid) {
        header('Location: ./unauthorized.php');
        exit;
    }
}

$CURRENT_PAGE = basename($_SERVER['PHP_SELF']);
$CURRENT_BIZ = (isset($_GET['biz']) && $_GET['biz'] === 'dg') ? 'dg' : 'cloud';
$VERSION_NAME_DG = preg_replace('/版$/u', '', ($conf['version_name_dg'] ?? '代挂'));

function checkIfActive($pages) {
    $current = basename($_SERVER['PHP_SELF'], '.php');
    $pageArr = explode(',', $pages);
    $active = in_array($current, $pageArr);
    return [$active ? 'active' : '', $active ? 'font-semibold text-blue-600' : 'text-gray-700'];
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo htmlspecialchars($conf['sitename'] ?? '管理后台'); ?> - 管理后台</title>
    <script src="../assets/js/tailwind.js"></script>
    <link rel="stylesheet" href="../assets/css/bootstrap.min.css">
    <script src="../assets/js/jquery.min.js"></script>
    <script src="../assets/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="../assets/css/all.min.css">
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#3b82f6',
                        secondary: '#64748b'
                    }
                }
            }
        };
        document.addEventListener('DOMContentLoaded', function() {
            const userMenuContainer = document.getElementById('userMenuContainer');
            const userMenu = document.getElementById('userMenu');
            let menuTimeout;
            if (userMenuContainer && userMenu) {
                userMenuContainer.addEventListener('mouseenter', function() {
                    clearTimeout(menuTimeout);
                    userMenu.classList.remove('hidden');
                });
                userMenuContainer.addEventListener('mouseleave', function(e) {
                    menuTimeout = setTimeout(function() {
                        userMenu.classList.add('hidden');
                    }, 300);
                });
                userMenu.addEventListener('mouseenter', function() {
                    clearTimeout(menuTimeout);
                });
                document.addEventListener('click', function(e) {
                    if (!userMenuContainer.contains(e.target)) {
                        userMenu.classList.add('hidden');
                    }
                });
            }
        });
    </script>
    <style>
        .sidebar-link.active { background-color: #eff6ff; color: #2563eb; }
        .sidebar-link:hover { background-color: #f8fafc; }
        .submenu a.active { background-color: #eff6ff; }
        .submenu { display: none; }
        .submenu.open { display: block; }
        .chevron { transition: transform 0.2s; }
        .chevron.open { transform: rotate(180deg); }
        @media (max-width: 768px) {
            .sidebar { transform: translateX(-100%); position: fixed; top: 64px; bottom: 0; left: 0; width: 14rem; overflow-y: auto; -webkit-overflow-scrolling: touch; z-index: 30; padding-bottom: 80px; }
            .sidebar.open { transform: translateX(0); }
        }
        .table-responsive { display: block; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
        .table-responsive table { min-width: 100%; }
        .btn-sm { white-space: nowrap; }
        .badge { white-space: nowrap; }
        @media (max-width: 768px) {
            .table-responsive { -webkit-overflow-scrolling: touch; overflow-x: scroll; overflow-y: hidden; }
            .table-responsive table { min-width: 800px; }
        }
    </style>
</head>
<body class="bg-gray-100 min-h-screen">
    <nav class="bg-white shadow-sm fixed top-0 left-0 right-0 z-50">
        <div class="px-4 h-16 flex items-center justify-between">
            <div class="flex items-center">
                <button id="sidebarToggle" class="p-2 rounded-lg hover:bg-gray-100 lg:hidden">
                    <i class="fas fa-bars text-gray-600"></i>
                </button>
                <span class="ml-3 text-xl font-semibold text-gray-800"><?php echo htmlspecialchars($conf['sitename'] ?? '管理后台'); ?></span>
            </div>
            <div class="flex items-center space-x-4">
                <a href="../" target="_blank" class="text-gray-600 hover:text-blue-600">
                    <i class="fas fa-external-link-alt"></i> 前台
                </a>
                <div class="relative" id="userMenuContainer">
                    <button class="flex items-center space-x-2 p-2 rounded-lg hover:bg-gray-100">
                        <img src="//q4.qlogo.cn/headimg_dl?dst_uin=<?php echo $conf['qq'] ?? '1223134470'; ?>&amp;spec=100" class="w-6 h-6 rounded-full border-2 border-white shadow-sm">
                        <span class="hidden md:block text-gray-700"><?php echo htmlspecialchars($conf['admin_user'] ?? 'Admin'); ?></span>
                    </button>
                    <div id="userMenu" class="absolute right-0 mt-2 w-48 bg-white rounded-lg shadow-lg py-2 hidden">
                        <a href="./account.php" class="block px-4 py-2 text-gray-700 hover:bg-gray-100">
                            <i class="fas fa-cog mr-2"></i>账户设置
                        </a>
                        <a href="./login.php?logout" class="block px-4 py-2 text-red-600 hover:bg-gray-100">
                            <i class="fas fa-sign-out-alt mr-2"></i>退出登录
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </nav>

    <aside id="sidebar" class="sidebar fixed left-0 top-16 w-56 h-[calc(100vh-4rem)] bg-white shadow-sm overflow-y-auto z-40 transition-transform lg:translate-x-0">
        <nav class="p-4 space-y-1">
            <div class="text-xs font-semibold text-gray-400 uppercase tracking-wider mb-2 px-3">概览</div>
            <a href="./index.php" class="sidebar-link flex items-center px-3 py-2 rounded-lg text-gray-700 <?php echo checkIfActive('index')[0]; ?>">
                <i class="fas fa-home w-5 mr-3"></i>控制面板
            </a>

            <div class="text-xs font-semibold text-gray-400 uppercase tracking-wider mb-2 px-3 mt-6">美化设置</div>
            <a href="./optimize.php" class="sidebar-link flex items-center px-3 py-2 rounded-lg text-gray-700 <?php echo checkIfActive('optimize')[0]; ?>">
                <i class="fas fa-magic w-5 mr-3"></i>小荠菜优化
            </a>

            <div class="text-xs font-semibold text-gray-400 uppercase tracking-wider mb-2 px-3 mt-6">数据管理</div>
            <a href="./qqlist.php" class="sidebar-link flex items-center px-3 py-2 rounded-lg text-gray-700 <?php echo ($CURRENT_PAGE === 'qqlist.php' && $CURRENT_BIZ === 'cloud') ? 'active' : ''; ?>">
                <i class="fas fa-cloud w-5 mr-3"></i>云端QQ列表
            </a>
            <?php if(($conf['dg_open'] ?? '0') == '1'): ?>
            <a href="./qqlist.php?biz=dg" class="sidebar-link flex items-center px-3 py-2 rounded-lg text-gray-700 <?php echo ($CURRENT_PAGE === 'qqlist.php' && $CURRENT_BIZ === 'dg') ? 'active' : ''; ?>">
                <i class="fas fa-link w-5 mr-3"></i><?php echo htmlspecialchars($VERSION_NAME_DG); ?>QQ列表
            </a>
            <?php endif; ?>
            <a href="./qzone.php" class="sidebar-link flex items-center px-3 py-2 rounded-lg text-gray-700 <?php echo checkIfActive('qzone')[0]; ?>">
                <i class="fas fa-bolt w-5 mr-3"></i>秒赞QQ列表
            </a>
            <a href="./user.php" class="sidebar-link flex items-center px-3 py-2 rounded-lg text-gray-700 <?php echo checkIfActive('user')[0]; ?>">
                <i class="fas fa-users w-5 mr-3"></i>用户管理
            </a>
            <a href="./tixian.php" class="sidebar-link flex items-center px-3 py-2 rounded-lg text-gray-700 <?php echo checkIfActive('tixian')[0]; ?>">
                <i class="fas fa-money-bill-wave w-5 mr-3"></i>提现管理
            </a>
            <a href="./record.php" class="sidebar-link flex items-center px-3 py-2 rounded-lg text-gray-700 <?php echo checkIfActive('record')[0]; ?>">
                <i class="fas fa-list w-5 mr-3"></i>收支明细
            </a>
            <a href="./kami.php" class="sidebar-link flex items-center px-3 py-2 rounded-lg text-gray-700 <?php echo checkIfActive('kami')[0]; ?>">
                <i class="fas fa-ticket-alt w-5 mr-3"></i>卡密管理
            </a>

            <div class="text-xs font-semibold text-gray-400 uppercase tracking-wider mb-2 px-3 mt-6">框架管理</div>
            <div class="group">
                <button onclick="toggleSubmenu('interfaceMenu')" class="w-full flex items-center justify-between px-3 py-2 rounded-lg text-gray-700 hover:bg-gray-100 sidebar-link">
                    <div class="flex items-center"><i class="fas fa-server w-5 mr-3"></i>接口管理</div>
                    <i id="interfaceChevron" class="fas fa-chevron-down chevron"></i>
                </button>
                <div id="interfaceMenu" class="pl-4 mt-1 space-y-1 submenu">
                    <a href="./login_class.php" class="block px-3 py-2 rounded-lg hover:bg-gray-100 text-sm <?php echo checkIfActive('login_class')[0]; ?> <?php echo checkIfActive('login_class')[1]; ?>">
                        <i class="far fa-circle w-3 mr-2 text-[10px]"></i>接口分类
                    </a>
                    <a href="./loginapi.php" class="block px-3 py-2 rounded-lg hover:bg-gray-100 text-sm <?php echo checkIfActive('loginapi')[0]; ?> <?php echo checkIfActive('loginapi')[1]; ?>">
                        <i class="far fa-circle w-3 mr-2 text-[10px]"></i>接口列表
                    </a>
                    <a href="./frame_data.php" class="block px-3 py-2 rounded-lg hover:bg-gray-100 text-sm <?php echo checkIfActive('frame_data')[0]; ?> <?php echo checkIfActive('frame_data')[1]; ?>">
                        <i class="far fa-circle w-3 mr-2 text-[10px]"></i>框架QQ清理
                    </a>
                    <a href="./node_link.php" class="block px-3 py-2 rounded-lg hover:bg-gray-100 text-sm <?php echo checkIfActive('node_link')[0]; ?> <?php echo checkIfActive('node_link')[1]; ?>">
                        <i class="far fa-circle w-3 mr-2 text-[10px]"></i>对接节点
                    </a>
                </div>
            </div>
            <a href="./frame_conf.php" class="sidebar-link flex items-center px-3 py-2 rounded-lg text-gray-700 <?php echo checkIfActive('frame_conf')[0]; ?>">
                <i class="fas fa-cog w-5 mr-3"></i>初始配置
            </a>

            <div class="text-xs font-semibold text-gray-400 uppercase tracking-wider mb-2 px-3 mt-6">商品管理</div>
            <a href="./vip.php" class="sidebar-link flex items-center px-3 py-2 rounded-lg text-gray-700 <?php echo checkIfActive('vip')[0]; ?>">
                <i class="fas fa-crown w-5 mr-3"></i>用户等级
            </a>
            <a href="./goods.php" class="sidebar-link flex items-center px-3 py-2 rounded-lg text-gray-700 <?php echo checkIfActive('goods')[0]; ?>">
                <i class="fas fa-box w-5 mr-3"></i>商品列表
            </a>

            <div class="text-xs font-semibold text-gray-400 uppercase tracking-wider mb-2 px-3 mt-6">功能配置</div>
            <a href="./cron.php" class="sidebar-link flex items-center px-3 py-2 rounded-lg text-gray-700 <?php echo checkIfActive('cron')[0]; ?>">
                <i class="fas fa-clock w-5 mr-3"></i>监控管理
            </a>
            <a href="./qzone_config.php" class="sidebar-link flex items-center px-3 py-2 rounded-lg text-gray-700 <?php echo checkIfActive('qzone_config')[0]; ?>">
                <i class="fas fa-bolt w-5 mr-3"></i>秒赞系统
            </a>
            <div class="group">
                <button onclick="toggleSubmenu('mailMenu')" class="w-full flex items-center justify-between px-3 py-2 rounded-lg text-gray-700 hover:bg-gray-100 sidebar-link">
                    <div class="flex items-center"><i class="fas fa-envelope w-5 mr-3"></i>发信提醒</div>
                    <i id="mailChevron" class="fas fa-chevron-down chevron"></i>
                </button>
                <div id="mailMenu" class="pl-4 mt-1 space-y-1 submenu">
                    <a href="./mail.php" class="block px-3 py-2 rounded-lg hover:bg-gray-100 text-sm <?php echo checkIfActive('mail')[0]; ?> <?php echo checkIfActive('mail')[1]; ?>">
                        <i class="far fa-circle w-3 mr-2 text-[10px]"></i>发信配置
                    </a>
                </div>
            </div>
            <a href="./message.php" class="sidebar-link flex items-center px-3 py-2 rounded-lg text-gray-700 <?php echo checkIfActive('message')[0]; ?>">
                <i class="fas fa-bell w-5 mr-3"></i>站内通知
            </a>
            <a href="./customer_service.php" class="sidebar-link flex items-center px-3 py-2 rounded-lg text-gray-700 <?php echo checkIfActive('customer_service')[0]; ?>">
                <i class="fas fa-headset w-5 mr-3"></i>在线客服
            </a>
            <div class="group">
                <button onclick="toggleSubmenu('articleMenu')" class="w-full flex items-center justify-between px-3 py-2 rounded-lg text-gray-700 hover:bg-gray-100 sidebar-link">
                    <div class="flex items-center"><i class="fas fa-newspaper w-5 mr-3"></i>文章管理</div>
                    <i id="articleChevron" class="fas fa-chevron-down chevron"></i>
                </button>
                <div id="articleMenu" class="pl-4 mt-1 space-y-1 submenu">
                    <a href="./articleClass.php" class="block px-3 py-2 rounded-lg hover:bg-gray-100 text-sm <?php echo checkIfActive('articleClass')[0]; ?> <?php echo checkIfActive('articleClass')[1]; ?>">
                        <i class="far fa-circle w-3 mr-2 text-[10px]"></i>文章分类
                    </a>
                    <a href="./article.php" class="block px-3 py-2 rounded-lg hover:bg-gray-100 text-sm <?php echo checkIfActive('article')[0]; ?> <?php echo checkIfActive('article')[1]; ?>">
                        <i class="far fa-circle w-3 mr-2 text-[10px]"></i>添加文章
                    </a>
                </div>
            </div>

            <div class="text-xs font-semibold text-gray-400 uppercase tracking-wider mb-2 px-3 mt-6">系统设置</div>
            <div class="group">
                <button onclick="toggleSubmenu('systemMenu')" class="w-full flex items-center justify-between px-3 py-2 rounded-lg text-gray-700 hover:bg-gray-100 sidebar-link">
                    <div class="flex items-center"><i class="fas fa-cog w-5 mr-3"></i>系统设置</div>
                    <i id="systemChevron" class="fas fa-chevron-down chevron"></i>
                </button>
                <div id="systemMenu" class="pl-4 mt-1 space-y-1 submenu">
                    <a href="./site.php" class="block px-3 py-2 rounded-lg hover:bg-gray-100 text-sm <?php echo checkIfActive('site')[0]; ?> <?php echo checkIfActive('site')[1]; ?>">
                        <i class="far fa-circle w-3 mr-2 text-[10px]"></i>网站信息配置
                    </a>
                    <a href="./gonggao.php" class="block px-3 py-2 rounded-lg hover:bg-gray-100 text-sm <?php echo checkIfActive('gonggao')[0]; ?> <?php echo checkIfActive('gonggao')[1]; ?>">
                        <i class="far fa-circle w-3 mr-2 text-[10px]"></i>网站公告配置
                    </a>
                    <a href="./carousel.php" class="block px-3 py-2 rounded-lg hover:bg-gray-100 text-sm <?php echo checkIfActive('carousel')[0]; ?> <?php echo checkIfActive('carousel')[1]; ?>">
                        <i class="far fa-circle w-3 mr-2 text-[10px]"></i>轮播图片管理
                    </a>
                    <a href="./fenzhan.php" class="block px-3 py-2 rounded-lg hover:bg-gray-100 text-sm <?php echo checkIfActive('fenzhan')[0]; ?> <?php echo checkIfActive('fenzhan')[1]; ?>">
                        <i class="far fa-circle w-3 mr-2 text-[10px]"></i>分站信息配置
                    </a>
                    <a href="./pay.php" class="block px-3 py-2 rounded-lg hover:bg-gray-100 text-sm <?php echo checkIfActive('pay')[0]; ?> <?php echo checkIfActive('pay')[1]; ?>">
                        <i class="far fa-circle w-3 mr-2 text-[10px]"></i>支付接口配置
                    </a>
                    <a href="./template.php" class="block px-3 py-2 rounded-lg hover:bg-gray-100 text-sm <?php echo checkIfActive('template')[0]; ?> <?php echo checkIfActive('template')[1]; ?>">
                        <i class="far fa-circle w-3 mr-2 text-[10px]"></i>首页模板设置
                    </a>
                    <a href="./quick.php" class="block px-3 py-2 rounded-lg hover:bg-gray-100 text-sm <?php echo checkIfActive('quick')[0]; ?> <?php echo checkIfActive('quick')[1]; ?>">
                        <i class="far fa-circle w-3 mr-2 text-[10px]"></i>快捷登录配置
                    </a>
                    <a href="./account.php" class="block px-3 py-2 rounded-lg hover:bg-gray-100 text-sm <?php echo checkIfActive('account')[0]; ?> <?php echo checkIfActive('account')[1]; ?>">
                        <i class="far fa-circle w-3 mr-2 text-[10px]"></i>平台安全配置
                    </a>
                    <a href="./node_auth.php" class="block px-3 py-2 rounded-lg hover:bg-gray-100 text-sm <?php echo checkIfActive('node_auth')[0]; ?> <?php echo checkIfActive('node_auth')[1]; ?>">
                        <i class="far fa-circle w-3 mr-2 text-[10px]"></i>跨站授权管理
                    </a>
                    <a href="./update.php" class="block px-3 py-2 rounded-lg hover:bg-gray-100 text-sm <?php echo checkIfActive('update')[0]; ?> <?php echo checkIfActive('update')[1]; ?>">
                        <i class="far fa-circle w-3 mr-2 text-[10px]"></i>检查版本更新
                    </a>
                </div>
            </div>
        </nav>
    </aside>

    <main class="lg:ml-56 pt-16 min-h-screen">
        <div class="p-1">

<div id="toastWrap" class="fixed top-6 left-1/2 -translate-x-1/2 z-[9999] flex flex-col items-center gap-2"></div>

<div id="loadingOverlay" class="fixed inset-0 z-50 hidden bg-white/30 flex items-center justify-center">
    <div class="w-10 h-10 border-4 border-indigo-200 border-t-indigo-600 rounded-full animate-spin"></div>
</div>

<script>
function showToast(message, type = 'info', duration = 3000) {
    const toastWrap = document.getElementById('toastWrap') || (() => {
        const wrap = document.createElement('div');
        wrap.id = 'toastWrap';
        wrap.className = 'fixed top-6 left-1/2 -translate-x-1/2 z-[9999] flex flex-col items-center gap-2';
        document.body.appendChild(wrap);
        return wrap;
    })();
    const toast = document.createElement('div');
    let bgClass = 'bg-gray-800';
    if (type === 'success') bgClass = 'bg-green-600';
    if (type === 'error') bgClass = 'bg-red-600';
    if (type === 'warning') bgClass = 'bg-yellow-600';
    toast.className = bgClass + ' text-white px-4 py-2 rounded-lg shadow-lg flex items-center gap-2 transform transition-all duration-300 ease-in-out opacity-0 translate-y-[-10px]';
    toast.innerHTML = '<i class="fas fa-' + (type === 'success' ? 'check' : type === 'error' ? 'exclamation' : type === 'warning' ? 'exclamation-triangle' : 'info') + '"></i><span>' + message + '</span>';
    toastWrap.appendChild(toast);
    setTimeout(function() { toast.classList.remove('opacity-0', 'translate-y-[-10px]'); }, 10);
    setTimeout(function() {
        toast.classList.add('opacity-0', 'translate-y-[-10px]');
        setTimeout(function() { toastWrap.removeChild(toast); }, 300);
    }, duration);
}

function showLoading() { document.getElementById('loadingOverlay').classList.remove('hidden'); }
function hideLoading() { document.getElementById('loadingOverlay').classList.add('hidden'); }
function showMsg(msg, icon) { showToast(msg, icon === 2 ? 'error' : icon === 3 ? 'warning' : 'success'); }

// HTML转义函数
function escHtml(s) {
    var d = document.createElement('div');
    d.textContent = s;
    return d.innerHTML;
}

// 属性转义函数
function escAttr(s) {
    return String(s).replace(/[&<>"']/g, function(m) {
        return {'&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;'}[m];
    });
}

window.addEventListener('load', function() {
    function toggleSubmenu(menuId) {
        const menu = document.getElementById(menuId);
        const chevronId = menuId.replace('Menu', 'Chevron');
        const chevron = document.getElementById(chevronId);
        if (menu && chevron) {
            if (menu.classList.contains('open')) {
                menu.classList.remove('open');
                chevron.classList.remove('open');
            } else {
                menu.classList.add('open');
                chevron.classList.add('open');
            }
        }
    }

    function toggleSidebar() {
        const sidebar = document.getElementById('sidebar');
        if (sidebar) sidebar.classList.toggle('open');
    }

    const current = '<?php echo basename($_SERVER['PHP_SELF'], '.php'); ?>';
    const submenus = {
        'interfaceMenu': ['login_class', 'loginapi', 'frame_data', 'node_link'],
        'mailMenu': ['mail'],
        'articleMenu': ['articleClass', 'article'],
        'systemMenu': ['site', 'gonggao', 'fenzhan', 'pay', 'template', 'quick', 'account', 'node_auth', 'update', 'carousel']
    };

    for (const [menuId, pages] of Object.entries(submenus)) {
        if (pages.includes(current)) {
            const menu = document.getElementById(menuId);
            const chevronId = menuId.replace('Menu', 'Chevron');
            const chevron = document.getElementById(chevronId);
            if (menu) menu.classList.add('open');
            if (chevron) chevron.classList.add('open');
            break;
        }
    }

    const sidebarToggle = document.getElementById('sidebarToggle');
    if (sidebarToggle) {
        sidebarToggle.onclick = toggleSidebar;
        sidebarToggle.addEventListener('click', toggleSidebar);
    }

    document.addEventListener('click', function(event) {
        const sidebar = document.getElementById('sidebar');
        const sidebarToggle = document.getElementById('sidebarToggle');
        if (window.innerWidth < 1024 && sidebar && sidebarToggle && !sidebar.contains(event.target) && !sidebarToggle.contains(event.target)) {
            sidebar.classList.remove('open');
        }
    });

    window.toggleSubmenu = toggleSubmenu;
    window.toggleSidebar = toggleSidebar;
    window.showToast = showToast;
    window.showLoading = showLoading;
    window.hideLoading = hideLoading;
    window.showMsg = showMsg;
});
</script>
