<!DOCTYPE html>
<html lang="zh-Hant">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  <title>1zTeSt 教師入口</title>
  <link rel="icon" href="https://i.imgur.com/9fl3wsq.png" type="image/png" />
  <link
    rel="stylesheet"
    href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"
    integrity="sha512-p6H9eH3j3z2mXbxqGIdl0u4i3s3G4B6cXX8tK6Xj6xJ8bF4lK2o5j4Q5m9B6j6h6d5k5j6j7k7l8m9n0p1q=="
    crossorigin="anonymous"
    referrerpolicy="no-referrer"
  />
  <link
    rel="stylesheet"
    href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"
  />
  <link href="https://cdnjs.cloudflare.com/ajax/libs/aos/2.3.4/aos.css" rel="stylesheet" />
  <link
    href="https://fonts.googleapis.com/css2?family=Pacifico&family=Noto+Sans+TC:wght@400;700&family=Exo+2:wght@500;700&display=swap"
    rel="stylesheet"
  />
  <link
    href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css"
    rel="stylesheet"
  />
  <link
    href="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.css"
    rel="stylesheet"
  />
  <script src="https://cdnjs.cloudflare.com/ajax/libs/aos/2.3.4/aos.js"></script>
  <script async src="https://www.googletagmanager.com/gtag/js?id=G-286HZQTWFH"></script>
  <script>
    /* Google 分析 */
    window.dataLayer = window.dataLayer || [];
    function gtag(){ dataLayer.push(arguments); }
    gtag('js', new Date());
    gtag('config', 'G-286HZQTWFH');
  </script>
  <script src="https://www.gstatic.com/firebasejs/9.22.1/firebase-app-compat.js"></script>
  <script src="https://www.gstatic.com/firebasejs/9.22.1/firebase-database-compat.js"></script>
  <script src="dont.js"></script>
  <style>
    *, *::before, *::after {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    :root {
      --primary-color: #333;
      --secondary-color: #555;
      --accent-color: #ae7d2f;
      --background-color: #f9f9f9;
      --header-height: 70px;
      --transition-speed: 0.3s;
      --font-family-primary: 'Noto Sans TC', sans-serif;
      --font-family-secondary: 'Exo 2', sans-serif;
      --font-family-title: 'Pacifico', cursive;
      --modal-overlay-bg: rgba(0, 0, 0, 0.5);
      --button-hover-bg: #ffba4c;
      --button-bg: var(--accent-color);
      --input-bg: #f0f0f0;
      --nav-bg: rgba(255, 255, 255, 0.95);
      --nav-active-bg: #fff;
    }

    body {
      font-family: var(--font-family-primary);
      color: var(--primary-color);
      background-color: #fff;
      line-height: 1.6;
      overflow-x: hidden;
    }

    a {
      color: var(--primary-color);
      text-decoration: none;
      transition: color var(--transition-speed) ease;
    }

    a:hover {
      color: var(--secondary-color);
    }

    img {
      max-width: 100%;
      height: auto;
      display: block;
    }

    header {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      background: var(--nav-bg);
      padding: 15px 0;
      z-index: 1000;
      transition: background var(--transition-speed) ease, box-shadow var(--transition-speed) ease;
      box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
    header.scrolled {
      background: #fff;
      box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    }

    .container {
      width: 90%;
      max-width: 1200px;
      margin: 0 auto;
      display: flex;
      align-items: center;
      justify-content: space-between;
      flex-wrap: wrap;
    }

    header h1 {
      font-family: var(--font-family-title);
      font-size: 2em;
      color: var(--primary-color);
      transition: color var(--transition-speed) ease;
    }

    nav ul {
      list-style: none;
      display: flex;
      gap: 20px;
      align-items: center;
    }
    nav ul li a {
      font-size: 1em;
      font-weight: 600;
      position: relative;
      padding: 5px 0;
      color: var(--primary-color);
      display: flex;
      align-items: center;
      gap: 8px;
    }
    nav ul li a::after {
      content: '';
      position: absolute;
      width: 0%;
      height: 2px;
      background: var(--primary-color);
      left: 0;
      bottom: -2px;
      transition: width var(--transition-speed) ease;
    }
    nav ul li a:hover::after {
      width: 100%;
    }
    .menu-toggle {
      display: none;
      flex-direction: column;
      justify-content: space-between;
      width: 25px;
      height: 20px;
      cursor: pointer;
    }
    .menu-toggle div {
      width: 100%;
      height: 3px;
      background: var(--primary-color);
      border-radius: 1.5px;
      transition: all var(--transition-speed) ease;
    }
    .menu-toggle.active div:nth-child(1) {
      transform: rotate(45deg) translate(5px, 5px);
    }
    .menu-toggle.active div:nth-child(2) {
      opacity: 0;
    }
    .menu-toggle.active div:nth-child(3) {
      transform: rotate(-45deg) translate(5px, -5px);
    }

    section#home {
      min-height: 100vh;
      background: url('https://i.meee.com.tw/iWc5Aso.gif') no-repeat center center/cover;
      display: flex;
      align-items: center;
      justify-content: flex-end;
      position: relative;
      text-align: right;
      padding: 60px 60px 60px 40px;
    }

    section#home::before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: rgba(255, 255, 255, 0.6);
      z-index: 1;
    }

    section#home .content {
      z-index: 2;
      animation: fadeInUp 1s ease-out;
      max-width: 700px;
      text-align: right;
      background: transparent;
      box-shadow: none;
    }

    @keyframes fadeInUp {
      0% { opacity: 0; transform: translateY(50px); }
      100% { opacity: 1; transform: translateY(0); }
    }

    section#home h1 {
      font-family: var(--font-family-title);
      font-size: 3em;
      margin-bottom: 20px;
      color: var(--primary-color);
      text-shadow: 0 3px 6px rgba(0,0,0,0.2);
    }

    section#home p {
      font-size: 1.3em;
      margin: 20px 0 30px;
      color: #555;
      text-shadow: 0 1px 3px rgba(0,0,0,0.1);
    }

    .btn-enter {
      display: inline-block;
      padding: 12px 25px;
      background: linear-gradient(135deg, #ae7d2f, #ffda7b);
      color: #fff;
      border: none;
      border-radius: 50px;
      cursor: pointer;
      font-size: 1.1em;
      font-weight: 600;
      transition: background var(--transition-speed) ease, transform var(--transition-speed) ease, box-shadow var(--transition-speed) ease;
      box-shadow: 0 6px 15px rgba(0,0,0,0.15);
      margin-top: 20px;
      position: relative;
      overflow: hidden;
    }
    .btn-enter::before {
      content: '';
      position: absolute;
      top: -50%;
      left: -50%;
      width: 200%;
      height: 200%;
      background: rgba(255, 255, 255, 0.2);
      transform: rotate(45deg);
      transition: all 0.3s ease;
    }
    .btn-enter:hover::before {
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
    }
    .btn-enter:hover {
      background: linear-gradient(135deg, #ffba4c, #ffd27f);
      transform: translateY(-5px);
      box-shadow: 0 8px 20px rgba(0,0,0,0.2);
    }

    .admin-btn {
      display: inline-flex;
      align-items: center;
      gap: 8px;
      padding: 10px 20px;
      border: none;
      border-radius: 8px;
      cursor: pointer;
      font-size: 0.95em;
      font-weight: 600;
      transition: all 0.3s ease;
      color: #fff;
      position: relative;
      overflow: hidden;
    }
    .admin-btn.search {
      background: linear-gradient(135deg, #f1c40f, #f39c12);
    }
    .admin-btn.search:hover {
      background: linear-gradient(135deg, #f39c12, #f1c40f);
      transform: translateY(-2px);
      box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    }
    .btn-toggle {
      background: linear-gradient(135deg, #27ae60, #2ecc71);
    }
    .btn-toggle:hover {
      transform: translateY(-2px);
      box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    }
    .btn-toggle.closed {
      background: linear-gradient(135deg, #e74c3c, #c0392b);
    }

    .btn-edit {
      background: linear-gradient(135deg, #2980b9, #3498db);
    }
    .btn-edit:hover {
      background: linear-gradient(135deg, #3498db, #2980b9);
      transform: translateY(-2px);
      box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    }
    .btn-delete {
      background: linear-gradient(135deg, #e74c3c, #c0392b);
    }
    .btn-delete:hover {
      background: linear-gradient(135deg, #c0392b, #e74c3c);
      transform: translateY(-2px);
      box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    }
    .btn-gold {
      background: linear-gradient(135deg, #f1c40f, #f39c12);
    }
    .btn-gold:hover {
      background: linear-gradient(135deg, #f39c12, #f1c40f);
      transform: translateY(-2px);
      box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    }
    .btn-purple {
      background: linear-gradient(135deg, #8e44ad, #9b59b6);
    }
    .btn-purple:hover {
      background: linear-gradient(135deg, #9b59b6, #8e44ad);
      transform: translateY(-2px);
      box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    }
    .modal-content input {
      width: 100%;
      max-width: 400px;
      padding: 14px 20px;
      border: 2px solid #ccc;
      border-radius: 12px;
      font-size: 1.1em;
      transition: border var(--transition-speed) ease, background var(--transition-speed) ease, box-shadow var(--transition-speed) ease;
    }
    .modal-content input:focus {
      border-color: var(--primary-color);
      outline: none;
      background: var(--input-bg);
      box-shadow: 0 0 8px rgba(174, 125, 47, 0.5);
    }
    .modal {
      display: none;
      position: fixed;
      z-index: 2000;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
      overflow: auto;
      background-color: var(--modal-overlay-bg);
      align-items: center;
      justify-content: center;
      padding: 20px;
    }
    .modal-content {
      background-color: #fff;
      padding: 40px 50px;
      border-radius: 16px;
      width: 100%;
      max-width: 500px;
      position: relative;
      box-shadow: 0 15px 40px rgba(0,0,0,0.2);
      animation: fadeInScale 0.6s ease-out;
      text-align: center;
    }
    @keyframes fadeInScale {
      from {
        opacity: 0;
        transform: scale(0.8);
      }
      to {
        opacity: 1;
        transform: scale(1);
      }
    }
    .close-modal {
      position: absolute;
      top: 15px;
      right: 20px;
      font-size: 1.5em;
      color: #333;
      cursor: pointer;
      transition: color var(--transition-speed) ease, transform var(--transition-speed) ease;
    }
    .close-modal:hover {
      color: var(--accent-color);
      transform: rotate(90deg);
    }
    #auth-title {
      font-size: 1.8em;
      font-weight: bold;
      text-transform: uppercase;
      letter-spacing: 1.5px;
      color: var(--primary-color);
      margin-bottom: 25px;
    }
    #error-message {
      color: #e74c3c;
      font-size: 0.95em;
      margin-bottom: 15px;
      font-weight: bold;
    }
    .toggle-auth {
      text-align: center;
      margin-top: 20px;
    }
    .toggle-auth a {
      color: var(--accent-color);
      cursor: pointer;
      font-weight: 600;
      text-decoration: underline;
    }

    footer {
      background: var(--primary-color);
      padding: 40px 20px;
      text-align: center;
      color: #fff;
    }
    footer p {
      margin-bottom: 10px;
      font-size: 0.9em;
    }
    footer a {
      color: #fff;
      margin: 0 10px;
      font-size: 0.9em;
      transition: color var(--transition-speed) ease;
      display: inline-flex;
      align-items: center;
      gap: 5px;
    }
    footer a:hover {
      color: #ddd;
    }
    footer .container {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 10px;
    }

    @media (max-width: 1024px) {
      .menu-toggle {
        display: flex;
      }
      nav ul {
        flex-direction: column;
        align-items: center;
        background: var(--nav-bg);
        position: absolute;
        top: var(--header-height);
        right: 0;
        width: 220px;
        display: none;
        padding: 20px 0;
        border-radius: 0 0 8px 8px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
      }
      nav ul.active {
        display: flex;
      }
      nav ul li {
        margin: 15px 0;
      }
    }
    @media (max-width: 768px) {
      section#home h1 {
        font-size: 2.5em;
      }
      section#home p {
        font-size: 1.1em;
      }
    }
    #adminContent {
      display: none;
      padding-top: 110px;
      width: 90%;
      max-width: 1200px;
      margin: 0 auto;
    }
    .section-title {
      margin-bottom: 20px;
    }
    .section-title h2, .section-title h3 {
      font-size: 1.5em;
      margin-bottom: 10px;
    }
    .section-title p {
      font-size: 1em;
      color: var(--secondary-color);
    }
    .table-responsive {
      margin-bottom: 30px;
    }
    .admin-table {
      width: 100%;
      margin-bottom: 0;
    }
    .admin-table thead th {
      background: #f0f0f0;
      font-weight: 600;
      position: sticky;
      top: 0;
      z-index: 2;
      user-select: none;
      white-space: nowrap;
      cursor: pointer;
    }
    .admin-table th, .admin-table td {
      vertical-align: middle;
      text-align: left;
      padding: 12px 15px;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .admin-table tbody tr:hover {
      background-color: #f1f1f1;
    }
    .admin-table td.actions {
      display: flex;
      gap: 4px;
      min-width: 80px;
      white-space: nowrap;
    }
    .modal-backdrop.show {
      opacity: 0.5;
    }
    .modal-body img {
      max-width: 100%;
      height: auto;
    }
    .view-content {
      white-space: pre-wrap;
      word-wrap: break-word;
    }
    .sort-indicator {
      margin-left: 4px;
      font-size: 0.8em;
      opacity: 0.8;
    }
    #viewContentModal .view-content img {
      max-width: 100%;
      height: auto;
      margin-bottom: 1rem;
    }

  </style>
</head>
<body>

  <header>
    <div class="container">
      <h1>1zTeSt</h1>
      <nav>
        <ul id="nav-links">
          <li>
            <a href="../index.html" target="_blank" rel="noopener noreferrer">
              <i class="fas fa-user"></i> 1zTeSt
            </a>
          </li>
          <li>
            <a href="https://www.instagram.com/hayashiiii__" target="_blank" rel="noopener noreferrer">
              <i class="fas fa-user"></i> 問題回報
            </a>
          </li>
          <li id="auth-links" style="display: none;">
            <a href="#" id="question-bank"><i class="fas fa-book"></i> 題庫管理</a>
            <a href="#" id="vocab-management"><i class="fas fa-book"></i> 單字題庫管理</a>
            <a href="#" id="score-management"><i class="fas fa-chart-bar"></i> 成績管理</a>
            <a href="#" id="logout"><i class="fas fa-sign-out-alt"></i> 登出</a>
          </li>
        </ul>
      </nav>
      <div
        class="menu-toggle"
        id="mobile-menu"
        aria-label="導航選單切換"
        aria-expanded="false"
        role="button"
        tabindex="0"
      >
        <div></div>
        <div></div>
        <div></div>
      </div>
    </div>
  </header>

  <section id="home" aria-labelledby="home-title">
    <div class="content animate__animated animate__fadeInUp" data-aos="fade-up">
      <h1 id="home-title" class="animate__animated animate__bounceIn" data-aos="bounce-in">
        1zTeSt 教師登入口
      </h1>
      <p
        class="animate__animated animate__fadeInUp"
        data-aos="fade-up"
        data-aos-delay="500"
      >
        教師專用登入口，管理學生測驗和成績。立即登入ㄅㄚ！
      </p>
      <button class="btn-enter" id="open-login">點我前往進入</button>
    </div>
  </section>

  <div id="adminContent">
    <div id="chapter-management-section">
      <div class="section-title">
        <h2>章節管理</h2>
        <p>新增、編輯或刪除章節</p>
      </div>
      <div class="mb-3">
        <button class="admin-btn btn-toggle" onclick="openAddChapterModal()">新增章節</button>
      </div>
      <div class="table-responsive">
        <table class="admin-table table table-striped table-hover">
          <thead>
            <tr>
              <th>章節名稱</th>
              <th>限制測驗題數</th>
              <th>是否開放</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody id="chaptersTableBody"></tbody>
        </table>
      </div>
    </div>
    <div id="question-bank-section">
      <div class="section-title">
        <h2>題庫管理</h2>
        <p>在選擇的章節內新增、編輯或刪除題目</p>
      </div>
      <div class="mb-3 d-flex align-items-center flex-wrap">
        <label for="chapterSelect" class="me-2 mb-2">選擇章節:</label>
        <select
          id="chapterSelect"
          class="form-select w-auto mb-2"
          onchange="loadQuestions()"
        >
          <option value="">--選擇章節--</option>
        </select>
      </div>
      <div class="button-group mb-3">
        <button class="admin-btn btn-gold" onclick="openAddQuestionModal()">新增題目</button>
        <button class="admin-btn btn-gold" onclick="exportToCSV()">匯出題目 CSV</button>
        <a
          class="admin-btn btn-gold"
          href="https://imgur.com/upload"
          target="_blank"
          rel="noopener noreferrer"
        >
          圖片上傳
        </a>
        <button class="admin-btn btn-purple" onclick="downloadTemplate()">
          批次匯入題目範本
        </button>
        <button class="admin-btn btn-purple" onclick="openBatchImportModal()">
          批次匯入題目
        </button>
      </div>

      <div class="table-responsive">
        <table class="admin-table table table-striped table-hover">
          <thead>
            <tr>
              <th style="min-width: 120px;">題目</th>
              <th>A</th>
              <th>B</th>
              <th>C</th>
              <th>D</th>
              <th>答案</th>
              <th>詳解</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody id="questionsTableBody"></tbody>
        </table>
      </div>
    </div>
    <div id="score-management-section" style="display: none;">
      <div class="section-title">
        <h2>成績管理</h2>
        <p>查看和管理學生的測驗成績 (可依章節篩選、搜尋及欄位排序)</p>
      </div>
      <div class="mb-3 d-flex align-items-center flex-wrap">
        <label for="scoreChapterFilter" class="me-2 mb-2">篩選章節:</label>
        <select
          id="scoreChapterFilter"
          class="form-select w-auto mb-2"
          onchange="filterAndSearchScores()"
        >
          <option value="">--所有章節--</option>
        </select>
      </div>
      <div class="mb-3">
        <input
          type="text"
          id="scoreSearchInput"
          class="form-control"
          placeholder="搜尋成績 (姓名、信箱、學號等)"
          onkeyup="filterAndSearchScores()"
        />
      </div>
      <div class="mb-3">
        <button class="admin-btn btn-gold" onclick="exportScoresToCSV()">匯出成績 CSV</button>
      </div>
      <div class="table-responsive">
        <table class="admin-table table table-striped table-hover" id="scoresTable">
          <thead>
            <tr>
              <th onclick="sortScores(0, false)">測驗日期<span class="sort-indicator" id="scores-sort-0"></span></th>
              <th onclick="sortScores(1, false)">測驗章節<span class="sort-indicator" id="scores-sort-1"></span></th>
              <th onclick="sortScores(2, true)">測驗時長<span class="sort-indicator" id="scores-sort-2"></span></th>
              <th onclick="sortScores(3, false)">測驗者姓名<span class="sort-indicator" id="scores-sort-3"></span></th>
              <th onclick="sortScores(4, false)">測驗者信箱<span class="sort-indicator" id="scores-sort-4"></span></th>
              <th onclick="sortScores(5, false)">測驗者學號<span class="sort-indicator" id="scores-sort-5"></span></th>
              <th onclick="sortScores(6, true)">分數<span class="sort-indicator" id="scores-sort-6"></span></th>
            </tr>
          </thead>
          <tbody id="scoresTableBody"></tbody>
        </table>
      </div>
    </div>
    <div id="vocab-management-section" style="display: none;">
      <div class="section-title">
        <h2>單字題庫管理</h2>
        <p>在選擇的章節內新增、編輯或刪除英文單字與中文解釋</p>
      </div>
      <div id="vocab-chapter-management-section">
        <div class="section-title">
          <h3>單字章節管理</h3>
        </div>
        <div class="mb-3">
          <button class="admin-btn btn-toggle" onclick="openAddVocabChapterModal()">新增單字章節</button>
        </div>
        <div class="table-responsive">
          <table class="admin-table table table-striped table-hover">
            <thead>
              <tr>
                <th>章節名稱</th>
                <th>是否開放</th>
                <th>操作</th>
              </tr>
            </thead>
            <tbody id="vocabChaptersTableBody"></tbody>
          </table>
        </div>
      </div>
      <div id="vocab-items-management-section">
        <div class="section-title">
          <h3>單字管理</h3>
        </div>
        <div class="mb-3 d-flex align-items-center flex-wrap">
          <label for="vocabChapterSelect" class="me-2 mb-2">選擇單字章節:</label>
          <select
            id="vocabChapterSelect"
            class="form-select w-auto mb-2"
            onchange="loadVocabItems()"
          >
            <option value="">--選擇章節--</option>
          </select>
        </div>
        <div class="button-group mb-3">
          <button class="admin-btn btn-gold" onclick="openAddVocabModal()">新增單字</button>
          <button class="admin-btn btn-gold" onclick="exportVocabToCSV()">匯出單字 CSV</button>
          <a
            class="admin-btn btn-gold"
            href="https://imgur.com/upload"
            target="_blank"
            rel="noopener noreferrer"
          >
            圖片上傳
          </a>
          <button class="admin-btn btn-purple" onclick="downloadVocabTemplate()">
            批次匯入範本
          </button>
          <button class="admin-btn btn-purple" onclick="openBatchVocabImportModal()">
            批次匯入
          </button>
        </div>
        <div class="table-responsive">
          <table class="admin-table table table-striped table-hover">
            <thead>
              <tr>
                <th>英文單字</th>
                <th>中文解釋</th>
                <th>操作</th>
              </tr>
            </thead>
            <tbody id="vocabItemsTableBody"></tbody>
          </table>
        </div>
      </div>
    </div>
  </div>
  <footer>
    <div class="container">
      <p>&copy; Copyright 2025 NasifyTech 納啟科技</p>
      <p>
        <a
          href="https://www.instagram.com/hayashiiii__"
          target="_blank"
          aria-label="Instagram"
        >
          <i class="fab fa-instagram"></i> Instagram
        </a>
        |
        <a href="#" target="_blank" aria-label="LINE">
          <i class="fab fa-line"></i> LINE
        </a>
      </p>
    </div>
  </footer>
  <div id="authModal" class="modal" aria-hidden="true" role="dialog" aria-labelledby="auth-title">
    <div class="modal-content">
      <span class="close-modal" id="close-auth" aria-label="關閉視窗">&times;</span>
      <h2 id="auth-title">登入 1zTeSt 教師</h2>
      <div id="error-message"></div>
      <form id="authForm">
        <input type="text" name="login-email" id="login-email" placeholder="信箱" required />
        <input type="password" name="login-password" id="login-password" placeholder="密碼" required />
        <button type="submit" id="auth-button" class="btn admin-btn btn-gold">登入</button>
      </form>
      <div class="toggle-auth">
        <span id="toggle-text">還沒有帳號？</span>
        <a href="#" id="toggle-auth">註冊</a>
      </div>
    </div>
  </div>
  <div class="modal fade" id="addChapterModal" tabindex="-1" aria-labelledby="addChapterModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <form id="addChapterForm">
          <div class="modal-header">
            <h5 class="modal-title" id="addChapterModalLabel">新增章節</h5>
            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
          </div>
          <div class="modal-body">
            <div class="mb-3">
              <label for="chapterName" class="form-label">章節名稱</label>
              <input type="text" class="form-control" id="chapterName" required />
            </div>
            <div class="mb-3">
              <label for="chapterLimit" class="form-label">限制測驗題數 (0 或空白 = 不限制)</label>
              <input type="number" class="form-control" id="chapterLimit" placeholder="0" min="0" />
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="admin-btn btn-delete" data-bs-dismiss="modal">取消</button>
            <button type="submit" class="admin-btn btn-toggle">新增</button>
          </div>
        </form>
      </div>
    </div>
  </div>

  <div class="modal fade" id="editChapterModal" tabindex="-1" aria-labelledby="editChapterModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <form id="editChapterForm">
          <div class="modal-header">
            <h5 class="modal-title" id="editChapterModalLabel">編輯章節</h5>
            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
          </div>
          <div class="modal-body">
            <input type="hidden" id="editChapterId" />
            <div class="mb-3">
              <label for="editChapterName" class="form-label">章節名稱</label>
              <input type="text" class="form-control" id="editChapterName" required />
            </div>
            <div class="mb-3">
              <label for="editChapterLimit" class="form-label">限制測驗題數 (0 = 不限制)</label>
              <input type="number" class="form-control" id="editChapterLimit" placeholder="0" min="0" />
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="admin-btn btn-delete" data-bs-dismiss="modal">取消</button>
            <button type="submit" class="admin-btn btn-toggle">更新</button>
          </div>
        </form>
      </div>
    </div>
  </div>
  <div class="modal fade" id="addModal" tabindex="-1" aria-labelledby="addModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <form id="addQuestionForm">
          <div class="modal-header">
            <h5 class="modal-title" id="addModalLabel">新增題目</h5>
            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
          </div>
          <div class="modal-body">
            <div class="mb-3">
              <label for="addQuestion" class="form-label">題目</label>
              <textarea class="form-control" id="addQuestion" required></textarea>
            </div>
            <div class="mb-3">
              <label for="addOptionA" class="form-label">選項 A</label>
              <input type="text" class="form-control" id="addOptionA" required />
            </div>
            <div class="mb-3">
              <label for="addOptionB" class="form-label">選項 B</label>
              <input type="text" class="form-control" id="addOptionB" required />
            </div>
            <div class="mb-3">
              <label for="addOptionC" class="form-label">選項 C</label>
              <input type="text" class="form-control" id="addOptionC" required />
            </div>
            <div class="mb-3">
              <label for="addOptionD" class="form-label">選項 D</label>
              <input type="text" class="form-control" id="addOptionD" required />
            </div>
            <div class="form-check form-switch mb-3">
              <input class="form-check-input" type="checkbox" id="isMultipleChoice">
              <label class="form-check-label" for="isMultipleChoice">是否為複選題</label>
            </div>
            <div class="mb-3" id="addSingleAnswerDiv">
              <label for="addSingleAnswerSelect" class="form-label">答案 (單選)</label>
              <select class="form-select" id="addSingleAnswerSelect">
                <option value="A">A</option>
                <option value="B">B</option>
                <option value="C">C</option>
                <option value="D">D</option>
              </select>
            </div>
            <div class="mb-3" id="addMultipleAnswerDiv" style="display: none;">
              <label class="form-label d-block">答案 (複選)</label>
              <div class="form-check">
                <input class="form-check-input" type="checkbox" value="A" id="addMultiA">
                <label class="form-check-label" for="addMultiA">A</label>
              </div>
              <div class="form-check">
                <input class="form-check-input" type="checkbox" value="B" id="addMultiB">
                <label class="form-check-label" for="addMultiB">B</label>
              </div>
              <div class="form-check">
                <input class="form-check-input" type="checkbox" value="C" id="addMultiC">
                <label class="form-check-label" for="addMultiC">C</label>
              </div>
              <div class="form-check">
                <input class="form-check-input" type="checkbox" value="D" id="addMultiD">
                <label class="form-check-label" for="addMultiD">D</label>
              </div>
            </div>
            <div class="mb-3">
              <label for="addExplanation" class="form-label">詳解</label>
              <textarea class="form-control" id="addExplanation"></textarea>
            </div>

          </div>
          <div class="modal-footer">
            <button type="button" class="admin-btn btn-delete" data-bs-dismiss="modal">取消</button>
            <button type="submit" class="admin-btn btn-gold">新增</button>
          </div>
        </form>
      </div>
    </div>
  </div>
  <div class="modal fade" id="editModal" tabindex="-1" aria-labelledby="editModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <form id="editQuestionForm">
          <div class="modal-header">
            <h5 class="modal-title" id="editModalLabel">編輯題目</h5>
            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
          </div>
          <div class="modal-body">
            <input type="hidden" id="editChapterId" />
            <input type="hidden" id="editQuestionId" />
            <div class="mb-3">
              <label for="editQuestion" class="form-label">題目</label>
              <textarea class="form-control" id="editQuestion" required></textarea>
            </div>
            <div class="mb-3">
              <label for="editOptionA" class="form-label">選項 A</label>
              <input type="text" class="form-control" id="editOptionA" required />
            </div>
            <div class="mb-3">
              <label for="editOptionB" class="form-label">選項 B</label>
              <input type="text" class="form-control" id="editOptionB" required />
            </div>
            <div class="mb-3">
              <label for="editOptionC" class="form-label">選項 C</label>
              <input type="text" class="form-control" id="editOptionC" required />
            </div>
            <div class="mb-3">
              <label for="editOptionD" class="form-label">選項 D</label>
              <input type="text" class="form-control" id="editOptionD" required />
            </div>
            <div class="form-check form-switch mb-3">
              <input class="form-check-input" type="checkbox" id="editIsMultipleChoice">
              <label class="form-check-label" for="editIsMultipleChoice">是否為複選題</label>
            </div>
            <div class="mb-3" id="editSingleAnswerDiv">
              <label for="editSingleAnswerSelect" class="form-label">答案 (單選)</label>
              <select class="form-select" id="editSingleAnswerSelect">
                <option value="A">A</option>
                <option value="B">B</option>
                <option value="C">C</option>
                <option value="D">D</option>
              </select>
            </div>
            <div class="mb-3" id="editMultipleAnswerDiv" style="display: none;">
              <label class="form-label d-block">答案 (複選)</label>
              <div class="form-check">
                <input class="form-check-input" type="checkbox" value="A" id="editMultiA">
                <label class="form-check-label" for="editMultiA">A</label>
              </div>
              <div class="form-check">
                <input class="form-check-input" type="checkbox" value="B" id="editMultiB">
                <label class="form-check-label" for="editMultiB">B</label>
              </div>
              <div class="form-check">
                <input class="form-check-input" type="checkbox" value="C" id="editMultiC">
                <label class="form-check-label" for="editMultiC">C</label>
              </div>
              <div class="form-check">
                <input class="form-check-input" type="checkbox" value="D" id="editMultiD">
                <label class="form-check-label" for="editMultiD">D</label>
              </div>
            </div>
            <div class="mb-3">
              <label for="editExplanation" class="form-label">詳解</label>
              <textarea class="form-control" id="editExplanation"></textarea>
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="admin-btn btn-delete" data-bs-dismiss="modal">取消</button>
            <button type="submit" class="admin-btn btn-gold">更新</button>
          </div>
        </form>
      </div>
    </div>
  </div>
  <div class="modal fade" id="viewContentModal" tabindex="-1" aria-labelledby="viewContentModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="viewContentModalLabel">內容詳情</h5>
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
        <div class="modal-body view-content" id="viewContentBody">
        </div>
        <div class="modal-footer">
          <button type="button" class="admin-btn btn-delete" data-bs-dismiss="modal">關閉</button>
        </div>
      </div>
    </div>
  </div>
  <div class="modal fade" id="batchImportModal" tabindex="-1" aria-labelledby="batchImportModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <form id="batchImportForm">
          <div class="modal-header">
            <h5 class="modal-title" id="batchImportModalLabel">批次匯入題目</h5>
            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
          </div>
          <div class="modal-body">
            <p>請選擇 CSV 檔案，需包含欄位：<br>
               <strong>題目,A,B,C,D,複選,答案,詳解</strong><br>
               <small>「複選」欄位：1(或Y)=複選，其餘視為單選。<br>
               若為複選題，答案請以「/」分隔，例如：A/C</small>
            </p>
            <div class="mb-3">
              <input type="file" id="csvFileInput" accept=".csv" required />
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="admin-btn btn-delete" data-bs-dismiss="modal">取消</button>
            <button type="submit" class="admin-btn btn-purple">開始匯入</button>
          </div>
        </form>
      </div>
    </div>
  </div>
  <div class="modal fade" id="addVocabChapterModal" tabindex="-1" aria-labelledby="addVocabChapterModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <form id="addVocabChapterForm">
          <div class="modal-header">
            <h5 class="modal-title" id="addVocabChapterModalLabel">新增單字章節</h5>
            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
          </div>
          <div class="modal-body">
            <div class="mb-3">
              <label for="vocabChapterName" class="form-label">章節名稱</label>
              <input type="text" class="form-control" id="vocabChapterName" required />
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="admin-btn btn-delete" data-bs-dismiss="modal">取消</button>
            <button type="submit" class="admin-btn btn-toggle">新增</button>
          </div>
        </form>
      </div>
    </div>
  </div>
  <div class="modal fade" id="editVocabChapterModal" tabindex="-1" aria-labelledby="editVocabChapterModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <form id="editVocabChapterForm">
          <div class="modal-header">
            <h5 class="modal-title" id="editVocabChapterModalLabel">編輯單字章節</h5>
            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
          </div>
          <div class="modal-body">
            <input type="hidden" id="editVocabChapterId" />
            <div class="mb-3">
              <label for="editVocabChapterName" class="form-label">章節名稱</label>
              <input type="text" class="form-control" id="editVocabChapterName" required />
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="admin-btn btn-delete" data-bs-dismiss="modal">取消</button>
            <button type="submit" class="admin-btn btn-toggle">更新</button>
          </div>
        </form>
      </div>
    </div>
  </div>
  <div class="modal fade" id="addVocabModal" tabindex="-1" aria-labelledby="addVocabModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <form id="addVocabForm">
          <div class="modal-header">
            <h5 class="modal-title" id="addVocabModalLabel">新增單字</h5>
            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
          </div>
          <div class="modal-body">
            <div class="mb-3">
              <label for="addVocEng" class="form-label">英文單字</label>
              <input type="text" class="form-control" id="addVocEng" required />
            </div>
            <div class="mb-3">
              <label for="addVocChinese" class="form-label">中文解釋</label>
              <input type="text" class="form-control" id="addVocChinese" required />
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="admin-btn btn-delete" data-bs-dismiss="modal">取消</button>
            <button type="submit" class="admin-btn btn-gold">新增</button>
          </div>
        </form>
      </div>
    </div>
  </div>
  <div class="modal fade" id="editVocabModal" tabindex="-1" aria-labelledby="editVocabModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <form id="editVocabForm">
          <div class="modal-header">
            <h5 class="modal-title" id="editVocabModalLabel">編輯單字</h5>
            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
          </div>
          <div class="modal-body">
            <input type="hidden" id="editVocabChapterKey" />
            <input type="hidden" id="editVocabId" />
            <div class="mb-3">
              <label for="editVocEng" class="form-label">英文單字</label>
              <input type="text" class="form-control" id="editVocEng" required />
            </div>
            <div class="mb-3">
              <label for="editVocChinese" class="form-label">中文解釋</label>
              <input type="text" class="form-control" id="editVocChinese" required />
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="admin-btn btn-delete" data-bs-dismiss="modal">取消</button>
            <button type="submit" class="admin-btn btn-gold">更新</button>
          </div>
        </form>
      </div>
    </div>
  </div>
  <div
    class="modal fade"
    id="batchVocabImportModal"
    tabindex="-1"
    aria-labelledby="batchVocabImportModalLabel"
    aria-hidden="true"
  >
    <div class="modal-dialog">
      <div class="modal-content">
        <form id="batchVocabImportForm">
          <div class="modal-header">
            <h5 class="modal-title" id="batchVocabImportModalLabel">批次匯入單字</h5>
            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
          </div>
          <div class="modal-body">
            <p>請選擇 CSV 檔案，欄位順序建議為：<br>
               <strong>英文單字,中文解釋</strong>
            </p>
            <div class="mb-3">
              <input type="file" id="vocabCsvFileInput" accept=".csv" required />
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="admin-btn btn-delete" data-bs-dismiss="modal">取消</button>
            <button type="submit" class="admin-btn btn-purple">開始匯入</button>
          </div>
        </form>
      </div>
    </div>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

  <script>
    const encodedSrc = "dGVhYWFjaGVyLmpz"; 
    const scriptSrc = atob(encodedSrc);
    const script = document.createElement("script");
    script.src = scriptSrc;
    document.body.appendChild(script);
</script>
</body>
</html>
