<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}知了数学题库系统{% endblock %}</title>
    
    <!-- Favicon -->
    <link rel="icon" type="image/jpeg" href="{{ url_for('static', filename='小猫.jpg') }}">
    
    <!-- Tailwind CSS -->
    <script src="https://cdn.tailwindcss.com"></script>
    
    <!-- KaTeX -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css">
    <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js"></script>
    <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js"></script>
    <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/contrib/auto-render.min.js"></script>
    
    <!-- Remix Icon -->
    <link href="https://cdn.jsdelivr.net/npm/remixicon@3.5.0/fonts/remixicon.css" rel="stylesheet">
    
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
        
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Inter', 'Microsoft YaHei', -apple-system, BlinkMacSystemFont, sans-serif;
            background-color: #F8F9FA;
            color: #1D1D1F;
            overflow-x: hidden;
        }
        
        /* 左侧导航栏 */
        .sidebar {
            position: fixed;
            left: 0;
            top: 0;
            width: 260px;
            height: 100vh;
            background: linear-gradient(180deg, #FFFFFF 0%, #FAFBFC 100%);
            border-right: 1px solid rgba(0, 0, 0, 0.06);
            display: flex;
            flex-direction: column;
            z-index: 1000;
            box-shadow: 2px 0 12px rgba(0, 0, 0, 0.04);
            transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            overflow: visible;
        }
        
        .sidebar.collapsed {
            width: 100px;
            overflow: visible;
        }
        
        .sidebar-header {
            padding: 24px 20px;
            border-bottom: 1px solid rgba(0, 0, 0, 0.06);
            display: flex;
            align-items: center;
            gap: 12px;
            position: relative;
        }
        
        .sidebar.collapsed .sidebar-header {
            padding: 24px 12px;
            justify-content: center;
        }
        
        .sidebar-toggle {
            position: absolute;
            right: -12px;
            top: 50%;
            transform: translateY(-50%);
            width: 24px;
            height: 24px;
            border-radius: 50%;
            background: #FFFFFF;
            border: 1px solid rgba(0, 0, 0, 0.1);
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
            transition: all 0.2s;
            z-index: 10;
        }
        
        .sidebar-toggle:hover {
            background: #F8F9FA;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        }
        
        .sidebar-toggle i {
            font-size: 14px;
            color: #6366F1;
            transition: transform 0.3s;
        }
        
        .sidebar.collapsed .sidebar-toggle i {
            transform: rotate(180deg);
        }
        
        .sidebar-logo {
            width: 40px;
            height: 40px;
            border-radius: 10px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 20px;
            color: white;
            font-weight: 700;
            flex-shrink: 0;
            overflow: hidden;
        }
        
        .sidebar-title {
            flex: 1;
            transition: opacity 0.3s;
            overflow: hidden;
        }
        
        .sidebar.collapsed .sidebar-title {
            opacity: 0;
            width: 0;
            height: 0;
            overflow: hidden;
        }
        
        .sidebar-title-main {
            font-size: 18px;
            font-weight: 700;
            color: #1D1D1F;
            line-height: 1.2;
            white-space: nowrap;
        }
        
        .sidebar-title-sub {
            font-size: 12px;
            color: #86868B;
            margin-top: 2px;
            white-space: nowrap;
        }
        
        .sidebar-nav {
            flex: 1;
            padding: 16px 12px;
            overflow-y: auto;
            overflow-x: visible;
        }
        
        .sidebar.collapsed .sidebar-nav {
            overflow-x: visible;
        }
        
        .nav-section {
            margin-bottom: 24px;
        }
        
        .nav-section-title {
            font-size: 11px;
            font-weight: 600;
            color: #86868B;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            padding: 0 12px;
            margin-bottom: 8px;
            transition: opacity 0.3s;
            white-space: nowrap;
            overflow: hidden;
        }
        
        .sidebar.collapsed .nav-section-title {
            opacity: 0;
            height: 0;
            padding: 0;
            margin: 0;
        }
        
        .nav-item {
            display: flex;
            align-items: center;
            gap: 12px;
            padding: 12px 16px;
            margin-bottom: 4px;
            border-radius: 10px;
            color: #1D1D1F;
            text-decoration: none;
            font-size: 14px;
            font-weight: 500;
            transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
            cursor: pointer;
            position: relative;
        }
        
        .sidebar.collapsed .nav-item {
            padding: 12px;
            justify-content: center;
        }
        
        .nav-item span {
            transition: opacity 0.3s;
            white-space: nowrap;
        }
        
        .sidebar.collapsed .nav-item span {
            opacity: 0;
            width: 0;
            overflow: hidden;
        }
        
        .sidebar.collapsed .nav-item .ml-auto {
            display: none;
        }
        
        /* Tooltip样式 */
        .nav-item-tooltip {
            position: fixed;
            padding: 6px 10px;
            background: #1D1D1F;
            color: #FFFFFF;
            font-size: 12px;
            font-weight: 500;
            border-radius: 6px;
            white-space: nowrap;
            opacity: 0;
            pointer-events: none;
            transition: opacity 0.2s ease-in-out;
            z-index: 99999;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
            visibility: hidden;
        }
        
        .nav-item-tooltip::before {
            content: '';
            position: absolute;
            right: 100%;
            top: 50%;
            transform: translateY(-50%);
            border: 5px solid transparent;
            border-right-color: #1D1D1F;
        }
        
        .sidebar:not(.collapsed) .nav-item-tooltip {
            display: none !important;
        }
        
        .nav-item i {
            font-size: 20px;
            width: 20px;
            height: 20px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #86868B;
            transition: color 0.2s;
        }
        
        .nav-item:hover {
            background: rgba(99, 102, 241, 0.08);
            color: #6366F1;
        }
        
        .nav-item:hover i {
            color: #6366F1;
        }
        
        .nav-item.active {
            background: linear-gradient(135deg, rgba(99, 102, 241, 0.12) 0%, rgba(139, 92, 246, 0.12) 100%);
            color: #6366F1;
            font-weight: 600;
        }
        
        .nav-item.active i {
            color: #6366F1;
        }
        
        .nav-item.active::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 3px;
            height: 20px;
            background: linear-gradient(135deg, #6366F1 0%, #8B5CF6 100%);
            border-radius: 0 2px 2px 0;
        }
        
        /* 主内容区 */
        .main-content {
            margin-left: 260px;
            min-height: 100vh;
            background: #F8F9FA;
            transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            position: relative;
            z-index: 1;
        }
        
        .sidebar.collapsed ~ .main-content {
            margin-left: 100px;
        }
        
        .main-header {
            background: #FFFFFF;
            border-bottom: 1px solid rgba(0, 0, 0, 0.06);
            padding: 16px 32px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            position: sticky;
            top: 0;
            z-index: 100;
            backdrop-filter: blur(20px);
            background: rgba(255, 255, 255, 0.8);
        }
        
        .main-header-title {
            font-size: 20px;
            font-weight: 700;
            color: #1D1D1F;
        }
        
        .main-header-actions {
            display: flex;
            align-items: center;
            gap: 12px;
        }
        
        .main-body {
            padding: 32px;
            max-width: 100%;
        }
        
        .apple-card {
            background: rgba(255, 255, 255, 0.9);
            backdrop-filter: blur(20px);
            border-radius: 16px;
            border: 1px solid rgba(0,0,0,0.06);
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
        }
        
        .apple-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 24px rgba(0,0,0,0.08);
        }

        .btn-apple {
            border-radius: 10px;
            padding: 10px 20px;
            font-weight: 600;
            font-size: 14px;
            transition: all 0.2s;
        }
        
        /* 滚动条样式 */
        .sidebar-nav::-webkit-scrollbar {
            width: 6px;
        }
        
        .sidebar-nav::-webkit-scrollbar-track {
            background: transparent;
        }
        
        .sidebar-nav::-webkit-scrollbar-thumb {
            background: rgba(0, 0, 0, 0.2);
            border-radius: 3px;
        }
        
        .sidebar-nav::-webkit-scrollbar-thumb:hover {
            background: rgba(0, 0, 0, 0.3);
        }

        /* 修复 SVG 在网页中的显示 */
        svg {
            max-width: 100%;
            height: auto;
            margin: 1rem auto;
            display: block;
        }

        /* 题目中的图片尺寸限制 */
        .math-render img,
        #stem-container img,
        .apple-card img:not([class*="rounded-full"]):not([class*="object-cover"]) {
            max-width: 400px !important;
            max-height: 300px !important;
            width: auto !important;
            height: auto !important;
            object-fit: contain;
            display: block;
            margin: 0.5rem auto;
        }

        /* 打印时隐藏 UI 元素 */
        @media print {
            .no-print { display: none !important; }
            .apple-card { border: none; background: white; backdrop-filter: none; }
            body { background: white; }
        }

        /* 数学公式容器样式 */
        .math-render {
            line-height: 1.8;
            font-size: 1.1rem;
        }

        /* 合格率进度条渐变 */
        .progress-gradient {
            background: linear-gradient(to right, #ef4444 0%, #f59e0b 50%, #22c55e 100%);
        }
        
        /* 响应式 */
        @media (max-width: 1024px) {
            .sidebar {
                transform: translateX(-100%);
                transition: transform 0.3s;
            }
            
            .sidebar.collapsed {
                transform: translateX(0);
                width: 100px;
            }
            
            .main-content {
                margin-left: 0;
            }
            
            .sidebar.collapsed ~ .main-content {
                margin-left: 100px;
            }
        }
        
        /* 搜索框折叠样式 */
        .sidebar.collapsed .nav-section form {
            padding: 0 12px;
        }
        
        .sidebar.collapsed .nav-section form input {
            opacity: 0;
            width: 0;
            padding: 0;
        }
        
        .sidebar.collapsed .nav-section form .flex {
            justify-content: center;
        }
        
        .sidebar.collapsed .nav-section form .flex:hover .nav-item-tooltip {
            opacity: 1;
        }
        
        .nav-item {
            position: relative;
        }
        
        /* 修复 SVG 在网页中的显示 */
        svg {
            max-width: 100%;
            height: auto;
            margin: 1rem auto;
            display: block;
        }

        /* 题目中的图片尺寸限制 */
        .math-render img,
        #stem-container img,
        .apple-card img:not([class*="rounded-full"]):not([class*="object-cover"]) {
            max-width: 400px !important;
            max-height: 300px !important;
            width: auto !important;
            height: auto !important;
            object-fit: contain;
            display: block;
            margin: 0.5rem auto;
        }

        /* 打印时隐藏 UI 元素 */
        @media print {
            .no-print { display: none !important; }
            .apple-card { border: none; background: white; backdrop-filter: none; }
            body { background: white; }
            .sidebar { display: none !important; }
            .main-content { margin-left: 0 !important; }
        }

        /* 数学公式容器样式 */
        .math-render {
            line-height: 1.8;
            font-size: 1.1rem;
        }

        /* 合格率进度条渐变 */
        .progress-gradient {
            background: linear-gradient(to right, #ef4444 0%, #f59e0b 50%, #22c55e 100%);
        }
    </style>
</head>
<body class="min-h-screen">

    <!-- 左侧导航栏 -->
    <aside class="sidebar no-print" id="sidebar">
        <div class="sidebar-header">
            <div class="sidebar-logo">
                <img src="{{ url_for('static', filename='小猫.jpg') }}" alt="知了数学" class="w-full h-full object-cover rounded-lg" onerror="this.style.display='none'; this.parentElement.innerHTML='知';">
            </div>
            <div class="sidebar-title">
                <div class="sidebar-title-main">知了数学</div>
                <div class="sidebar-title-sub">题库管理系统</div>
            </div>
            <button class="sidebar-toggle" id="sidebar-toggle" onclick="toggleSidebar()" title="折叠/展开菜单">
                <i class="ri-arrow-left-s-line"></i>
            </button>
        </div>
        
        <nav class="sidebar-nav">
            <div class="nav-section">
                <div class="nav-section-title">主要功能</div>
                <a href="/" class="nav-item {% if request.path == '/' %}active{% endif %}">
                    <i class="ri-home-4-line"></i>
                    <span>首页</span>
                    <div class="nav-item-tooltip">首页</div>
                </a>
                <a href="/question_management" class="nav-item {% if request.path == '/question_management' %}active{% endif %}">
                    <i class="ri-file-list-line"></i>
                    <span>题目管理</span>
                    <div class="nav-item-tooltip">题目管理</div>
                </a>
                <a href="/kp_management" class="nav-item {% if request.path.startswith('/kp_management') %}active{% endif %}">
                    <i class="ri-book-open-line"></i>
                    <span>知识点管理</span>
                    <div class="nav-item-tooltip">知识点管理</div>
                </a>
                <a href="/textbook_management" class="nav-item {% if request.path.startswith('/textbook_management') %}active{% endif %}">
                    <i class="ri-book-2-line"></i>
                    <span>教材管理</span>
                    <div class="nav-item-tooltip">教材管理</div>
                </a>
                <a href="/material_management" class="nav-item {% if request.path.startswith('/material_management') %}active{% endif %}">
                    <i class="ri-folder-line"></i>
                    <span>资料管理</span>
                    <div class="nav-item-tooltip">资料管理</div>
                </a>
            </div>
            
            <div class="nav-section">
                <div class="nav-section-title">常用工具</div>
                <a href="https://math-analysis.chunsunqiuzhu.com" target="_blank" rel="noopener noreferrer" class="nav-item">
                    <i class="ri-file-text-line"></i>
                    <span>试卷解析工具</span>
                    <i class="ri-external-link-line ml-auto text-xs"></i>
                    <div class="nav-item-tooltip">试卷解析工具</div>
                </a>
                <a href="http://192.168.124.8:9300/" target="_blank" rel="noopener noreferrer" class="nav-item">
                    <i class="ri-links-line"></i>
                    <span>题目匹配知识点</span>
                    <i class="ri-external-link-line ml-auto text-xs"></i>
                    <div class="nav-item-tooltip">题目匹配知识点</div>
                </a>
            </div>
            
            <div class="nav-section">
                <div class="nav-section-title">快速操作</div>
                <form action="/search" method="get" class="mb-2 nav-item-form">
                    <div class="flex items-center gap-2 px-4 py-2 bg-gray-50 rounded-lg border border-gray-200 relative">
                        <i class="ri-search-line text-gray-400"></i>
                        <input
                            name="q"
                            type="text"
                            placeholder="搜索题号"
                            class="flex-1 bg-transparent border-none outline-none text-sm"
                            onkeypress="if(event.key==='Enter') this.form.submit()"
                        />
                        <div class="nav-item-tooltip">搜索题号</div>
                    </div>
                </form>
                <form action="/search_id" method="get" class="mb-2 nav-item-form">
                    <div class="flex items-center gap-2 px-4 py-2 bg-gray-50 rounded-lg border border-gray-200 relative">
                        <i class="ri-hashtag text-gray-400"></i>
                        <input
                            name="id"
                            type="text"
                            placeholder="搜索ID"
                            class="flex-1 bg-transparent border-none outline-none text-sm"
                            onkeypress="if(event.key==='Enter') this.form.submit()"
                        />
                        <div class="nav-item-tooltip">搜索ID</div>
                    </div>
                </form>
            </div>
            
            {% block sidebar_extra %}{% endblock %}
        </nav>
    </aside>

    <!-- 主内容区 -->
    <div class="main-content">
        <header class="main-header no-print">
            <div>
                <h1 class="main-header-title">{% block page_title %}知了数学题库管理系统{% endblock %}</h1>
            </div>
            <div class="main-header-actions">
                {% block header_actions %}{% endblock %}
            </div>
        </header>
        
        <main class="main-body">
            {% block content %}{% endblock %}
        </main>
    </div>

    <script>
        // 检查并获取用户姓名
        function getUserName() {
            return localStorage.getItem('user_name') || null;
        }
        
        // 设置用户姓名
        function setUserName(name) {
            if (name && name.trim()) {
                localStorage.setItem('user_name', name.trim());
            }
        }
        
        // 显示姓名输入弹窗
        function showNameInputModal() {
            const userName = getUserName();
            if (userName) {
                return; // 已有姓名，不显示弹窗
            }
            
            const modal = document.createElement('div');
            modal.id = 'name-input-modal';
            modal.style.cssText = 'position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.5);z-index:10000;display:flex;align-items:center;justify-content:center;';
            
            const dialog = document.createElement('div');
            dialog.style.cssText = 'background:white;padding:2rem;border-radius:16px;box-shadow:0 20px 60px rgba(0,0,0,0.3);max-width:400px;width:90%;text-align:center;';
            
            const title = document.createElement('div');
            title.style.cssText = 'font-size:1.25rem;font-weight:bold;color:#333;margin-bottom:1rem;';
            title.textContent = '请输入您的姓名';
            
            const input = document.createElement('input');
            input.type = 'text';
            input.placeholder = '请输入姓名';
            input.style.cssText = 'width:100%;padding:0.75rem;border:2px solid #e5e7eb;border-radius:8px;font-size:1rem;margin-bottom:1.5rem;outline:none;transition:border-color 0.2s;';
            input.addEventListener('focus', function() {
                this.style.borderColor = '#3b82f6';
            });
            input.addEventListener('blur', function() {
                this.style.borderColor = '#e5e7eb';
            });
            
            const btn = document.createElement('button');
            btn.style.cssText = 'background:#3b82f6;color:white;border:none;padding:0.75rem 2rem;border-radius:8px;font-size:1rem;cursor:pointer;font-weight:600;width:100%;transition:background 0.2s;';
            btn.textContent = '确定';
            btn.addEventListener('mouseenter', function() {
                this.style.background = '#2563eb';
            });
            btn.addEventListener('mouseleave', function() {
                this.style.background = '#3b82f6';
            });
            
            const handleConfirm = () => {
                const name = input.value.trim();
                if (!name) {
                    input.style.borderColor = '#ef4444';
                    input.focus();
                    return;
                }
                setUserName(name);
                document.body.removeChild(modal);
            };
            
            btn.onclick = handleConfirm;
            input.onkeypress = function(e) {
                if (e.key === 'Enter') {
                    handleConfirm();
                }
            };
            
            dialog.appendChild(title);
            dialog.appendChild(input);
            dialog.appendChild(btn);
            modal.appendChild(dialog);
            document.body.appendChild(modal);
            
            // 聚焦输入框
            setTimeout(() => input.focus(), 100);
        }
        
        // 侧边栏折叠/展开功能
        function toggleSidebar() {
            const sidebar = document.getElementById('sidebar');
            if (sidebar) {
                sidebar.classList.toggle('collapsed');
                // 保存状态到localStorage
                const isCollapsed = sidebar.classList.contains('collapsed');
                localStorage.setItem('sidebarCollapsed', isCollapsed ? 'true' : 'false');
            }
        }
        
        // 恢复侧边栏状态
        function restoreSidebarState() {
            const sidebar = document.getElementById('sidebar');
            const savedState = localStorage.getItem('sidebarCollapsed');
            if (sidebar && savedState === 'true') {
                sidebar.classList.add('collapsed');
            }
        }
        
        // Tooltip位置计算和显示
        function setupTooltips() {
            const sidebar = document.getElementById('sidebar');
            if (!sidebar || !sidebar.classList.contains('collapsed')) return;
            
            const navItems = document.querySelectorAll('.sidebar.collapsed .nav-item, .sidebar.collapsed .nav-section form .flex');
            
            navItems.forEach(item => {
                const tooltip = item.querySelector('.nav-item-tooltip');
                if (!tooltip) return;
                
                item.addEventListener('mouseenter', function(e) {
                    const rect = item.getBoundingClientRect();
                    tooltip.style.left = (rect.right + 8) + 'px';
                    tooltip.style.top = (rect.top + rect.height / 2) + 'px';
                    tooltip.style.transform = 'translateY(-50%)';
                    tooltip.style.opacity = '1';
                    tooltip.style.visibility = 'visible';
                });
                
                item.addEventListener('mouseleave', function() {
                    tooltip.style.opacity = '0';
                    tooltip.style.visibility = 'hidden';
                });
            });
        }
        
        // 监听侧边栏折叠状态变化
        function observeSidebarCollapse() {
            const sidebar = document.getElementById('sidebar');
            if (!sidebar) return;
            
            const observer = new MutationObserver(function(mutations) {
                mutations.forEach(function(mutation) {
                    if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
                        setTimeout(setupTooltips, 100);
                    }
                });
            });
            
            observer.observe(sidebar, {
                attributes: true,
                attributeFilter: ['class']
            });
        }
        
        document.addEventListener("DOMContentLoaded", function() {
            // 恢复侧边栏状态
            restoreSidebarState();
            
            // 设置tooltip
            setTimeout(setupTooltips, 100);
            observeSidebarCollapse();
            
            // 检查是否需要显示姓名输入弹窗
            showNameInputModal();
            
            renderMathInElement(document.body, {
                delimiters: [
                    {left: "$$", right: "$$", display: true},
                    {left: "$", right: "$", display: false},
                    {left: "\\(", right: "\\)", display: false},
                    {left: "\\[", right: "\\]", display: true}
                ],
                throwOnError : false
            });
        });

        // 自定义弹窗函数（支持空格键确认）
        window.customAlert = function(message, callback) {
            const modal = document.createElement('div');
            modal.style.cssText = 'position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.4);z-index:9999;display:flex;align-items:center;justify-content:center;';
            
            const dialog = document.createElement('div');
            dialog.style.cssText = 'background:white;padding:2rem;border-radius:12px;box-shadow:0 10px 40px rgba(0,0,0,0.2);max-width:400px;text-align:center;';
            
            const msg = document.createElement('div');
            msg.style.cssText = 'margin-bottom:1.5rem;font-size:1rem;color:#333;';
            msg.textContent = message;
            
            const btn = document.createElement('button');
            btn.style.cssText = 'background:#007AFF;color:white;border:none;padding:0.75rem 2rem;border-radius:8px;font-size:1rem;cursor:pointer;font-weight:600;';
            btn.textContent = '确定';
            
            const handleConfirm = () => {
                document.body.removeChild(modal);
                if (callback) callback();
            };
            
            btn.onclick = handleConfirm;
            
            // 监听空格键
            const handleKeyPress = (e) => {
                if (e.code === 'Space' || e.key === ' ') {
                    e.preventDefault();
                    handleConfirm();
                }
            };
            
            document.addEventListener('keydown', handleKeyPress);
            btn.addEventListener('click', () => {
                document.removeEventListener('keydown', handleKeyPress);
            });
            
            dialog.appendChild(msg);
            dialog.appendChild(btn);
            modal.appendChild(dialog);
            document.body.appendChild(modal);
            
            // 点击背景关闭
            modal.onclick = (e) => {
                if (e.target === modal) {
                    document.removeEventListener('keydown', handleKeyPress);
                    handleConfirm();
                }
            };
            
            btn.focus();
        }

        async function postAudit(code, reason) {
            const res = await fetch('/audit', {
                method: 'POST',
                headers: {'Content-Type': 'application/json'},
                body: JSON.stringify({question_code: code, audit_reason: reason})
            });
            const result = await res.json();
            if(result.success) {
                // 自动跳转下一题
                const nextBtn = document.getElementById('next-btn');
                if(nextBtn) nextBtn.click();
                else window.location.reload();
            } else {
                customAlert('审核失败: ' + result.error);
            }
        }

        // 录入题目按钮处理函数
    </script>
</body>
</html>








