/* 試卷還原工具 v2：light mode，單一 accent，無 emoji
   系統原則：中性介面、一套字級、一套掣、12% 墨色 hairline、hover micro-interactions */
:root {
  --ink: #191c1f;
  --muted: #5c636a;
  --hairline: rgba(25, 28, 31, 0.12);
  --hairline-soft: rgba(25, 28, 31, 0.07);
  --bg: #f6f5f2;          /* 微暖紙感灰 */
  --card: #ffffff;
  --accent: #1a56c4;      /* 墨藍，唯一 accent */
  --accent-hover: #14449e;
  --accent-soft: #eaf0fb;
  --danger: #b3261e;
  --ok: #146c36;
  --r-lg: 14px; --r-md: 10px; --r-btn: 8px;
  --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 24px; --s-6: 32px; --s-8: 48px;
  --t-h1: 22px; --t-h2: 17px; --t-body: 16px; --t-small: 14px; --t-label: 13px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: var(--t-body);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
h1 { font-size: var(--t-h1); font-weight: 600; letter-spacing: -0.01em; margin: 0; }
h2 { font-size: var(--t-h2); font-weight: 600; letter-spacing: -0.01em; margin: 0 0 var(--s-4); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

/* ---- 佈局骨架 ---- */
.view { max-width: 1080px; margin: 0 auto; padding: var(--s-5) var(--s-5) var(--s-8); }
[hidden] { display: none !important; }  /* 全域：任何 display rule 都唔准覆蓋 hidden */

/* ---- 頂欄：全寬 sticky，內容由 .view 自帶頂部空間 ---- */
header {
  position: sticky; top: 0; z-index: 10;
  background: var(--card); border-bottom: 1px solid var(--hairline);
}
.topbar-inner {
  max-width: 1080px; margin: 0 auto;
  display: flex; align-items: center; gap: var(--s-4);
  padding: 12px var(--s-5);
}
header h1 { display: flex; align-items: center; gap: 10px; flex: 1; font-size: 18px; }
header h1 svg { display: block; }
/* LOGO 可撳返工作區 */
header h1#brand-home { cursor: pointer; user-select: none; border-radius: 8px; transition: opacity 0.15s ease; }
header h1#brand-home:hover { opacity: 0.7; }
header h1#brand-home:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
#view-main { padding-top: var(--s-6); }
#me-name { color: var(--muted); font-size: var(--t-small); }
nav { display: flex; gap: var(--s-2); align-items: center; }

/* 用戶名 pop-up menu（登出收埋入去）*/
.user-menu { position: relative; display: flex; align-items: center; }
.user-menu-btn { display: inline-flex; align-items: center; gap: 6px; background: var(--card); color: var(--muted); border: 1px solid var(--hairline); border-radius: 10px; padding: 8px 12px; min-height: 0; font-size: var(--t-small); }
.topbar-inner button.user-menu-btn:hover:not(:disabled) { background: var(--hairline-soft); color: var(--ink); border-color: var(--hairline); }
.user-menu-btn .caret { color: var(--muted); }
.user-menu-pop { position: absolute; right: 0; top: calc(100% + 6px); min-width: 140px; background: var(--card); border: 1px solid var(--hairline); border-radius: 10px; box-shadow: 0 8px 24px rgba(25,28,31,.12); padding: 6px; z-index: 30; }
.user-menu-pop .menu-item { display: block; width: 100%; text-align: left; background: var(--card); color: var(--ink); border: none; border-radius: 6px; padding: 9px 12px; min-height: 0; font-size: var(--t-small); }
/* 選單項目嘅 icon：同文字 baseline 對齊，icon 顏色跟文字 */
.user-menu-pop .menu-item .menu-ic { display: inline-flex; width: 15px; height: 15px; flex: none; align-items: center; justify-content: center; margin-right: 8px; color: var(--muted); vertical-align: -3px; }
.user-menu-pop .menu-item .menu-ic svg { display: block; width: 15px; height: 15px; }
.user-menu-pop button.menu-item:hover:not(:disabled) { background: var(--hairline-soft); color: var(--ink); }
.user-menu-pop button.menu-item:hover:not(:disabled) .menu-ic { color: var(--ink); }

/* 頁 row「操作」menu */
.page-actions { position: relative; margin-left: auto; display: inline-flex; flex: none; }
.page-actions-btn { display: inline-flex; align-items: center; gap: 6px; background: var(--card); color: var(--muted); border: 1px solid var(--hairline); border-radius: 8px; padding: 5px 10px; min-height: 0; font-size: var(--t-small); }
.page-actions-btn .pa-dots { display: none; font-size: 15px; line-height: 1; }
.stat-cell { white-space: nowrap; font-variant-numeric: tabular-nums; }
td.stat-cell.muted { color: var(--muted); }
button.page-actions-btn:hover:not(:disabled) { background: var(--hairline-soft); color: var(--ink); border-color: var(--hairline); }
.page-actions-btn .caret { color: var(--muted); }
.page-menu-pop { position: fixed; min-width: 170px; background: var(--card); border: 1px solid var(--hairline); border-radius: 10px; box-shadow: 0 8px 24px rgba(25,28,31,.12); padding: 6px; z-index: 60; }
.page-menu-pop .menu-item { display: flex; gap: 8px; width: 100%; text-align: left; background: var(--card); color: var(--ink); border: none; border-radius: 6px; padding: 9px 12px; min-height: 0; font-size: var(--t-small); }
.page-menu-pop button.menu-item:hover:not(:disabled) { background: var(--hairline-soft); color: var(--ink); }
.page-menu-pop .menu-item.danger { color: var(--danger); }
/* danger 項目（移除此頁）連 icon 一齊轉紅 */
.page-menu-pop .menu-item.danger .menu-ic { color: var(--danger); }
.page-menu-pop button.menu-item.danger:hover:not(:disabled) { color: var(--danger); }
.page-menu-pop button.menu-item.danger:hover:not(:disabled) .menu-ic { color: var(--danger); }
/* 每頁 32×32 icon 掣（對比）*/
/* 對比預覽 toggle：預設要有「撳得」的觀感——用墨色圖示 + 明顯邊框；
   之前用 var(--muted) 淺灰，同 disabled 太似，用戶以為按唔到。 */
.icon-btn-32 { width: 32px; height: 32px; min-height: 0; padding: 0; display: inline-flex; align-items: center; justify-content: center; background: var(--card); color: var(--ink); border: 1px solid var(--hairline); border-radius: 8px; font-size: var(--t-small); flex: none; cursor: pointer; transition: background-color .15s ease, color .15s ease, border-color .15s ease; }
.icon-btn-32 svg { flex: none; }
button.icon-btn-32:hover:not(:disabled) { background: var(--hairline-soft); color: var(--ink); border-color: var(--muted); }
/* 已開啟（對比顯示中）：淺藍底 + 藍框 + 藍圖示，一眼睇出「開住」 */
.icon-btn-32[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
button.icon-btn-32[aria-pressed="true"]:hover:not(:disabled) { background: #dde8fb; color: var(--accent); border-color: var(--accent); }
button.icon-btn-32:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .icon-btn-32 { transition: none; } }
.page-menu-pop .menu-item { align-items: flex-start; }
.page-menu-pop .menu-ic { display: inline-flex; width: 14px; height: 14px; flex: none; margin-top: 2px; color: var(--muted); }
.page-menu-pop .menu-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.page-menu-pop .menu-main { display: block; white-space: nowrap; }
.page-menu-pop .menu-sub { display: block; color: var(--muted); font-size: 11px; }
.menu-sep { height: 1px; background: var(--hairline-soft); margin: 5px 4px; }
/* popover 內嘅選單項唔要框線（避免框中框） */
.user-menu-pop button#btn-logout { border: none; background: var(--card); color: var(--ink); }
.user-menu-pop button#btn-logout:hover:not(:disabled) { background: var(--hairline-soft); color: var(--ink); }
.menu-divider { height: 1px; background: var(--hairline-soft); margin: 6px 4px; }
.menu-version { padding: 4px 12px 6px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.tab {
  border: none; background: none; padding: 8px 12px; cursor: pointer;
  color: var(--muted); font-size: var(--t-body); border-radius: var(--r-btn);
  font-family: inherit; position: relative; transition: color .15s ease, background-color .15s ease;
}
.tab:hover { color: var(--ink); background: var(--hairline-soft); }
.tab.active { color: var(--accent); font-weight: 600; }
.tab.active::after {
  content: ""; position: absolute; left: 12px; right: 12px; bottom: 2px;
  height: 2px; background: var(--accent); border-radius: 1px;
}

/* ---- 掣：一對（filled primary / outline secondary）---- */
button {
  font-family: inherit; font-size: var(--t-body);
  background: var(--accent); color: #fff; border: 1px solid var(--accent);
  border-radius: var(--r-btn); padding: 9px 20px; min-height: 40px; cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, transform .1s ease, box-shadow .15s ease;
}
/* 用 :where() 令通用 hover 規則權重降到 (0,0,1)，任何 component 自訂 hover（.icon-btn-32、
   .page-actions-btn、.ba-seg-btn 等）都穩定贏，唔會一 hover 就變實心藍 */
button:where(:hover:not(:disabled):not(.tab)) { background: var(--accent-hover); border-color: var(--accent-hover); }
button:active:not(:disabled) { transform: translateY(1px); }
button:focus-visible, .tab:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
button:disabled { background: #c3cbdc; border-color: #c3cbdc; cursor: default; }
button.secondary, #btn-cancel-draft, #btn-logout {
  background: var(--card); color: var(--ink); border: 1px solid var(--hairline);
}
button.secondary:hover:not(:disabled), #btn-cancel-draft:hover:not(:disabled), #btn-logout:hover:not(:disabled) {
  background: var(--hairline-soft); border-color: var(--hairline);
}
button.secondary:disabled { background: var(--card); color: #b6bcc3; border-color: var(--hairline-soft); }
/* 框線動作掣（藍色 outline）：藍邊＋藍字＋白底 */
button.btn-outline { background: var(--card); color: var(--accent); border: 1px solid var(--accent); }
button.btn-outline:hover:not(:disabled) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
button.btn-outline:disabled { background: var(--card); color: #b6bcc3; border-color: var(--hairline-soft); }
#btn-delete-job { background: var(--card); color: var(--danger); border: 1px solid var(--hairline); }
#btn-delete-job:hover:not(:disabled) { background: #fbeeed; border-color: rgba(179, 38, 30, 0.35); }
#btn-back { font-size: var(--t-body); }

/* ---- 工作區：左「我的任務」寬欄；右欄上「儲存空間」、下「上傳卡」 ---- */
#workspace { display: grid; grid-template-columns: 1fr 400px; gap: var(--s-5); align-items: start; }
#workspace .card { margin: 0; }
#workspace .jobs-card { grid-column: 1; grid-row: 1; }   /* 左：最近任務（高） */
#workspace .side-col {                                    /* 右欄：儲存空間＋上傳卡疊埋，唔受列高影響 */
  grid-column: 2; grid-row: 1;
  display: flex; flex-direction: column; gap: var(--s-5);
}
/* ---- 卡片 ---- */
.card {
  background: var(--card); border: 1px solid var(--hairline);
  border-radius: var(--r-lg); padding: var(--s-5); margin: var(--s-5) 0;
}

/* ---- 登入 ---- */
#view-login {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: var(--s-5); max-width: none;
}
.login-card {
  width: 420px; max-width: 100%; background: var(--card);
  border: 1px solid var(--hairline); border-radius: var(--r-lg); padding: var(--s-6);
}
.login-card h1 { display: flex; align-items: center; gap: 10px; margin-bottom: var(--s-5); font-size: 20px; }
#view-login .row { margin-top: var(--s-3); }
#dev-buttons { margin-top: var(--s-4); }
#dev-buttons button { flex: 1; font-size: var(--t-small); white-space: nowrap; padding-inline: 8px; }

/* ---- 表單 ---- */
label { display: block; margin: var(--s-3) 0; font-size: var(--t-label); color: var(--muted); }
label.inline { display: inline-flex; gap: 8px; align-items: center; color: var(--ink); font-size: var(--t-body); margin: var(--s-4) 0; }
#pane-user .card label.inline { margin: var(--s-4) 0; }
#thumb-list:empty { margin: 0; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
input[type="text"], input[type="password"] {
  display: block; width: 100%; margin-top: 6px; padding: 11px 12px;
  border: 1px solid var(--hairline); border-radius: var(--r-btn);
  font-size: var(--t-body); font-family: inherit; color: var(--ink); background: #fff;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input[type="text"]:focus, input[type="password"]:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
/* ---- 上載 dropzone ---- */
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  border: 1.5px dashed rgba(25, 28, 31, 0.22); border-radius: var(--r-lg);
  background: #fbfaf8; padding: var(--s-6) var(--s-4);
  cursor: pointer; text-align: center;
  transition: border-color .15s ease, background-color .15s ease;
}
.dropzone:hover, .dropzone:focus-visible {
  border-color: var(--accent); background: var(--accent-soft);
  outline: none;
}
.dropzone.drag-over {
  border-color: var(--accent); background: var(--accent-soft);
  border-style: solid;
}
.dropzone svg { color: var(--accent); margin-bottom: 4px; }
.dz-title { font-size: var(--t-body); font-weight: 500; color: var(--ink); }
.dz-sub { font-size: var(--t-small); color: var(--muted); }
.dropzone input[type="file"] {
  position: absolute; width: 1px; height: 1px;
  clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}
.hint { color: var(--muted); font-size: var(--t-small); line-height: 1.6; margin: var(--s-3) 0 0; }
.error { color: var(--danger); font-size: var(--t-small); }
.page-warning { color: #8a5a00; font-size: var(--t-small); }

/* ---- 表格 ---- */
table { width: 100%; border-collapse: collapse; font-size: var(--t-body); }
/* 表格欄多時：卡片內橫向捲動，避免欄位逐字斷行 */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll > table { min-width: 620px; }
.table-scroll > table th, .table-scroll > table td { white-space: nowrap; }
.table-scroll > table th:first-child, .table-scroll > table td:first-child { white-space: nowrap; }
/* 表格內按鈕唔准逐字斷行，表格本身靠橫向捲動 */
.table-scroll > table button { white-space: nowrap; flex: none; }
#admin-job-table { min-width: 840px; }
#all-jobs-table { min-width: 660px; }
th {
  text-align: left; padding: 10px 8px; font-size: var(--t-label); font-weight: 500;
  color: var(--muted); border-bottom: 1px solid var(--hairline);
}
td { padding: 12px 8px; border-bottom: 1px solid var(--hairline-soft); }
tbody tr { transition: background-color .15s ease; }
tbody tr:hover { background: #fafaf8; }
tbody tr:last-child td { border-bottom: none; }

/* ---- 狀態 badge：圓點 + 文字 ---- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 99px; font-size: var(--t-label); font-weight: 500;
  background: #eef0f2; color: var(--muted); white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.done { background: #e3f2e8; color: var(--ok); }
.badge.running, .badge.generating, .badge.postprocess, .badge.queued {
  background: var(--accent-soft); color: var(--accent);
}
.badge.failed { background: #fbe6e4; color: var(--danger); }
/* partial：部分完成（介乎 done 綠同 failed 紅之間，用現有 #b26a00 warn 橙） */
.badge.partial { background: #fdf1e0; color: #b26a00; }
/* 「重新生成剛完成」提示：badge 旁邊的小 pill + 列表頂部橫幅（20 秒後自動消失） */
.page-updated {
  display: inline-flex; align-items: center; margin-left: 6px;
  padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent); white-space: nowrap;
  border: 1px solid rgba(26, 86, 196, 0.25);
}
.page-updated-banner {
  margin: 10px 0 4px; padding: 8px 12px; border-radius: 8px;
  background: var(--accent-soft); color: var(--accent);
  font-size: var(--t-small); font-weight: 500;
}

/* ---- 進度條 ---- */
.pbar {
  display: inline-flex; align-items: center; gap: 8px; vertical-align: middle;
}
.pbar-track {
  display: inline-block; width: 160px; height: 6px; background: var(--hairline-soft);
  border-radius: 3px; overflow: hidden;
}
.pbar-pct {
  font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 34px;
}
.pbar-label {
  font-size: 12px; color: var(--muted);
}
.pbar-track > span {
  display: block; height: 100%; background: var(--accent); border-radius: 3px;
  transition: width .6s ease;
  animation: pbar-stripes 1s linear infinite;
  background-image: linear-gradient(45deg, rgba(255,255,255,0.25) 25%, transparent 25%, transparent 50%, rgba(255,255,255,0.25) 50%, rgba(255,255,255,0.25) 75%, transparent 75%, transparent);
  background-size: 16px 16px;
}
@keyframes pbar-stripes { from { background-position: 0 0; } to { background-position: 16px 0; } }
@media (prefers-reduced-motion: reduce) { .pbar-track > span { animation: none; } .spinner { animation: none; } .upload-progress-fill { animation: none !important; } .thumb-spinner::after { animation: none; } .thumb-img { transition: none; } }

/* ---- 上傳進度（兩段式：上傳 % → 伺服器處理中）---- */
.upload-progress { display: flex; align-items: center; gap: 10px; margin: 12px 0; }
.upload-progress[hidden] { display: none; }
.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--hairline-soft); border-top-color: var(--accent);
  animation: spin .8s linear infinite; flex: 0 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
/* 「開始處理」loading 態：主按鈕係藍底白字，spinner 要用白色先睇得見 */
#btn-start.is-loading {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  cursor: progress;
}
/* 保持主色藍（唔好被 button:disabled 的灰底蓋過），令人睇得出「正在工作」 */
#btn-start.is-loading:disabled {
  background: var(--accent); border-color: var(--accent); color: #fff; opacity: 1;
}
#btn-start.is-loading .spinner { border-color: rgba(255, 255, 255, 0.4); border-top-color: #fff; }
/* modal 內容載入中：spinner + 文字橫排 */
.hint-loading { display: inline-flex; align-items: center; gap: 8px; }
/* 無障礙：prefers-reduced-motion 要停轉動。注意必須寫喺 .spinner 定義之後，
   否則同權重下會被上面 .spinner { animation: spin } 蓋過（第 272 行嗰條舊規則就係咁失效） */
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
  /* PM 拍板（2026-11-10）：reduce-motion 下嚴格零動畫（脈動都唔要，前庭敏感用戶唔友好；
     「正在開始…」文字已表達工作中）。圓環四邊淺白＋頂部白，讀成完整圓環唔似壞掉。 */
  #btn-start.is-loading .spinner {
    border-color: rgba(255, 255, 255, 0.55); border-top-color: #fff; animation: none;
  }
}
.upload-progress-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.upload-progress-label { color: var(--muted); font-size: var(--t-label); font-variant-numeric: tabular-nums; }
.upload-progress-track { height: 4px; background: var(--hairline-soft); border-radius: 999px; overflow: hidden; }
.upload-progress-fill { height: 100%; width: 0%; background: var(--accent); border-radius: 999px; transition: width .2s ease; }
.upload-progress.indeterminate .upload-progress-fill { width: 35% !important; animation: indet 1.1s ease-in-out infinite; }
@keyframes indet { 0% { margin-left: -35%; } 100% { margin-left: 100%; } }

/* ---- 縮圖清單（draft）---- */
#thumb-list { display: flex; flex-direction: column; margin: var(--s-4) 0; }
/* draft 列表式：一行一頁（序號 + 縮圖 + 檔名 + 移除） */
.draft-row {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 4px; border-bottom: 1px solid var(--hairline-soft);
  cursor: grab; background: #fff;
}
.draft-row:last-child { border-bottom: none; }
.draft-row.drag-over { outline: 2px dashed var(--accent); outline-offset: -2px; }
.draft-idx {
  flex: none; width: 22px; height: 22px; border-radius: 50%;
  background: rgba(25, 28, 31, 0.78); color: #fff;
  font-size: 12px; line-height: 22px; text-align: center;
}
.draft-thumb {
  flex: none; width: 36px; height: 48px; object-fit: cover; display: block;
  border: 1px solid var(--hairline); border-radius: 4px; background: #f0efec;
}
.draft-name {
  flex: 1; min-width: 0; font-size: var(--t-small); font-weight: 500; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.draft-row button { flex: none; min-height: 32px; padding: 5px 14px; font-size: var(--t-small); }
.img-wrap { position: relative; display: inline-block; line-height: 0; }
.img-wrap .ext-tag { z-index: 2; line-height: 1.4; }
.ext-tag {
  position: absolute; left: 6px; bottom: 6px;
  background: rgba(25, 28, 31, 0.72); color: #fff;
  font-size: 11px; padding: 2px 6px; border-radius: 4px; letter-spacing: 0.3px;
}
.thumb {
  width: calc((100% - 24px) / 3); min-width: 0; position: relative; border: 1px solid var(--hairline);
  border-radius: var(--r-md); background: #fff; padding: 5px; cursor: grab;
  transition: box-shadow .15s ease, border-color .15s ease, transform .15s ease;
}
.thumb:hover { border-color: rgba(26, 86, 196, 0.45); box-shadow: 0 2px 8px rgba(25, 28, 31, 0.08); }
.thumb img {
  width: 100%; height: 138px; object-fit: cover; display: block;
  border-radius: 6px; background: #f0efec;
}
.thumb-name {
  display: block; margin-top: 5px; font-size: 11px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.4;
}
.thumb .idx {
  position: absolute; top: 9px; left: 9px;
  background: rgba(25, 28, 31, 0.78); color: #fff; border-radius: 9px;
  padding: 0 7px; font-size: 12px; line-height: 18px;
}
.thumb .remove {
  position: absolute; top: 8px; right: 8px;
  background: rgba(25, 28, 31, 0.55); color: #fff; border: none; border-radius: 50%;
  width: 22px; height: 22px; min-height: 0; padding: 0; font-size: 13px; line-height: 1;
  opacity: 0; transition: opacity .15s ease, background-color .15s ease;
}
.thumb:hover .remove, .thumb .remove:focus-visible { opacity: 1; }
.thumb .remove:hover { background: var(--danger); transform: none; }
.thumb.drag-over { outline: 2px dashed var(--accent); outline-offset: 2px; }

/* ---- 任務詳情：逐頁對比 ---- */
.crumb {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: var(--s-4); padding-bottom: var(--s-4);
  border-bottom: 1px solid var(--hairline-soft);
}
.crumb a { font-size: var(--t-small); }
.crumb-sep { color: var(--muted); }
.crumb-here { font-size: var(--t-h2); font-weight: 600; letter-spacing: -0.01em; }
.detail-meta { margin-left: auto; color: var(--muted); font-size: var(--t-label); font-variant-numeric: tabular-nums; white-space: nowrap; }
.job-actions {
  margin-top: var(--s-4); padding-top: var(--s-4);
  border-top: 1px solid var(--hairline-soft);
  justify-content: flex-end;
}
#btn-detail-add { margin-right: auto; }
.page-idx { color: var(--muted); font-size: var(--t-label); font-variant-numeric: tabular-nums; min-width: 1.2em; text-align: right; flex: none; }
.job-actions a { margin-left: auto; }
.page-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-4);
  border-top: 1px solid var(--hairline); padding: var(--s-4) 0;
}
.page-row img {
  width: 100%; height: auto; display: block;
  border: 1px solid var(--hairline); border-radius: 8px; background: #fff;
}
.page-head { display: flex; align-items: center; gap: 12px; margin-top: var(--s-5); flex-wrap: wrap; }
.page-head strong { font-size: var(--t-body); font-weight: 600; }
.page-thumb {
  width: 36px; height: 48px; object-fit: cover; display: block;
  border: 1px solid var(--hairline); border-radius: 4px; background: #fff; flex: none;
}
/* 縮圖 loading spinner（page-thumb / draft-thumb / ba 大圖）*/
.thumb-box { position: relative; display: inline-block; overflow: hidden; border-radius: 4px; flex: none; }
.thumb-box img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-spinner { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 2; pointer-events: none; }
.thumb-spinner::after { content: ""; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--hairline-soft); border-top-color: var(--accent); animation: spin .8s linear infinite; }
.thumb-img { display: block; opacity: 0; transition: opacity .15s ease; }
.page-name {
  font-size: var(--t-small); font-weight: 500; max-width: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.page-head button { min-height: 32px; padding: 5px 14px; font-size: var(--t-small); }
.row { display: flex; gap: 10px; align-items: center; margin-top: var(--s-4); flex-wrap: wrap; }

/* ---- 響應式 ---- */
@media (max-width: 1040px) {
  /* 平板／窄桌面：兩欄放唔落任務表（~900-1040 會逼爆表頭），改單欄 */
  #workspace { grid-template-columns: 1fr; }
  #workspace .jobs-card { grid-column: 1; grid-row: auto; }
  #workspace .side-col { grid-column: 1; grid-row: auto; }  /* 單欄：任務 → 儲存 → 上傳（DOM 順序：side-col 先出） */
  .page-actions-btn { width: 32px; padding: 0; justify-content: center; }
  .page-actions-btn .pa-label, .page-actions-btn .caret { display: none; }
  .page-actions-btn .pa-dots { display: inline; }
}
@media (max-width: 640px) {
  /* 窄版任務表欄多，改成卡內橫向捲動，避免日期／狀態逐字斷行 */
  #workspace .jobs-card { overflow-x: auto; }
  #job-table { min-width: 640px; }
  /* 窄版（draft）任務詳情頁面：整行保持一行，檔名最多 2 行摺行，移除掣留喺右邊 */
  .page-head-draggable { flex-wrap: nowrap; }
  .page-head-draggable .page-meta .page-name {
    white-space: normal; display: -webkit-box;
    -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden; text-overflow: clip;
  }
  .page-head-draggable > button { flex: 0 0 auto; }
  /* 窄版詳情底部三粒掣改直向全寬，避免屈字 */
  .job-actions { flex-direction: column; align-items: stretch; }
  .job-actions button { width: 100%; }
}
@media (max-width: 720px) {
  .view { padding: var(--s-4) var(--s-4) var(--s-6); }
  .topbar-inner { padding: 10px var(--s-4); flex-wrap: wrap; gap: var(--s-2); }
  #me-name { display: none; }
  .page-row { grid-template-columns: 1fr; }
  button { width: auto; }
  .row button { flex: 1; }
  .login-card { padding: var(--s-5); }
}

/* ---- Lightbox 原圖預覽 ---- */
.lightbox {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(25, 28, 31, 0.72);
  display: none; align-items: center; justify-content: center;
  flex-direction: column; gap: var(--s-3); padding: var(--s-5);
  cursor: zoom-out;
}
.lightbox.open { display: flex; }
.lightbox-img {
  max-width: min(920px, 92vw); max-height: 80vh; object-fit: contain;
  background: #fff; border-radius: var(--r-md);
  box-shadow: 0 12px 40px rgba(25, 28, 31, 0.35);
}
.lightbox-name {
  color: #fff; font-size: var(--t-small);
  max-width: 92vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#thumb-list .draft-thumb, #pages .page-thumb, #pages .page-row img { cursor: zoom-in; }

/* ---- Before/After slider ---- */
.ba-wrap {
  position: relative; width: 100%; max-width: 640px; margin: var(--s-4) 0 var(--s-2);
  border: 1px solid var(--hairline); border-radius: 8px; overflow: hidden;
  background: #fff; touch-action: none; user-select: none; cursor: ew-resize;
}
.ba-img { display: block; width: 100%; height: auto; pointer-events: none; }
/* 上層（原圖）唔可以用 fill 拉伸：原圖同成品長寬比唔同（原圖有書桌背景／成品裁緊）時
   會被拉歪，令滑桿兩邊對唔上。用 contain 保持真實比例，多出嚟的位置留白。 */
.ba-top { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #fff; }
.ba-chip {
  position: absolute; top: 10px; left: 10px; z-index: 2;
  background: rgba(25, 28, 31, 0.72); color: #fff;
  font-size: 12px; padding: 3px 10px; border-radius: 99px; pointer-events: none;
}
.ba-chip-r { left: auto; right: 10px; }
.ba-load-error {
  padding: 24px; text-align: center; color: var(--danger);
  font-size: var(--t-small); background: #fff;
}
.ba-seg {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 4;
  display: flex; background: var(--card); border: 1px solid var(--hairline);
  border-radius: 99px; overflow: hidden;
}
/* specificity (0,4,1)：要壓過通用 button:hover:not(:disabled):not(.tab) 嘅 (0,3,1) */
.ba-seg button.ba-seg-btn {
  border: none; border-radius: 0; min-height: 26px; padding: 3px 14px;
  font-size: var(--t-label); background: var(--card); color: var(--muted);
}
.ba-seg button.ba-seg-btn + .ba-seg-btn { border-left: 1px solid var(--hairline); }
.ba-seg button.ba-seg-btn:hover { background: var(--accent-soft); color: var(--accent); }
.ba-seg button.ba-seg-btn.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.ba-handle {
  position: absolute; top: 0; bottom: 0; left: 50%; width: 2px;
  background: #fff; box-shadow: 0 0 0 1px rgba(25, 28, 31, 0.25);
  transform: translateX(-1px); pointer-events: none;
}
.ba-grip {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 36px; height: 36px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 8px rgba(25, 28, 31, 0.3);
  cursor: ew-resize; pointer-events: auto;
}
.ba-grip::before, .ba-grip::after {
  content: ""; position: absolute; top: 50%;
  width: 8px; height: 2px; background: var(--ink); border-radius: 1px;
}
.ba-grip::before { left: 6px; box-shadow: -2px -3px 0 0 var(--ink), -2px 3px 0 0 var(--ink); }
/* 重生成中：舊成品仍顯示但鎖住唔畀拖 */
.ba-wrap.regen { pointer-events: none; cursor: default; }
.ba-wrap.regen::after {
  content: "生成中——以下係舊成品"; position: absolute; inset: 0; z-index: 3;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, 0.55);
  color: var(--ink); font-size: 14px; font-weight: 600;
}
.ba-grip::after { right: 6px; box-shadow: 2px -3px 0 0 var(--ink), 2px 3px 0 0 var(--ink); }

.empty-hint { color: var(--muted); font-size: var(--t-small); padding: var(--s-5) 8px !important; text-align: center; }

/* ---- 任務詳情 modal ---- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(25, 28, 31, 0.45);
  display: flex; align-items: center; justify-content: center;
  padding: var(--s-5);
}
.modal-card {
  width: 100%; max-width: 920px; max-height: calc(100vh - 48px);
  display: flex; flex-direction: column; overflow: hidden;
  margin: 0 auto;
  box-shadow: 0 12px 40px rgba(25, 28, 31, 0.28);
}
.modal-card .crumb { flex: none; }
/* 詳情 header 的「預覽」icon 切換掣 */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; min-height: 0; padding: 0; flex: none;
  background: var(--card); color: var(--muted);
  border: 1px solid var(--hairline); border-radius: 8px;
}
button.icon-btn:hover:not(:disabled) { background: var(--hairline-soft); color: var(--ink); border-color: var(--hairline); transform: none; }
.icon-btn[hidden] { display: none; }
.icon-btn .ic-eye-off { display: none; }
button.icon-btn[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
button.icon-btn[aria-pressed="true"]:hover:not(:disabled) { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
button.icon-btn:disabled { background: var(--card); color: #b6bcc3; border-color: var(--hairline-soft); opacity: .5; cursor: default; }
button.icon-btn[aria-pressed="true"]:disabled { background: var(--hairline-soft); color: #b6bcc3; border-color: var(--hairline-soft); opacity: .5; }
.icon-btn[aria-pressed="true"] .ic-eye { display: none; }
.icon-btn[aria-pressed="true"] .ic-eye-off { display: inline; }
.modal-card #pages { flex: 1; min-height: 0; overflow-y: auto; padding-right: 4px; }
.modal-card .job-actions { flex: none; margin-top: var(--s-4); }
body.modal-open { overflow: hidden; }
.modal-close {
  margin-left: auto; align-self: flex-start;
  background: var(--card); color: var(--muted);
  border: 1px solid var(--hairline); border-radius: 50%;
  width: 32px; height: 32px; min-height: 0; padding: 0; font-size: 14px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
button.modal-close:hover:not(:disabled) { background: var(--hairline-soft); border-color: var(--hairline); color: var(--ink); transform: none; }

/* ---- 儲存用量 chart（純 CSS，light mode，accent 墨藍）---- */
:root { --chart-2: #2f8f83; }
/* 頂部左右：左 = 各用戶佔比 doughnut + legend，右 = 容量 summary + meter */
.usage-split {
  display: grid; grid-template-columns: auto minmax(0, 380px);
  justify-content: start; column-gap: 40px;
  align-items: center; margin: 0 0 var(--s-5);
}
/* 管理頁頂部兩張卡（儲存用量／生成統計）左右並排，窄窗疊排 */
.admin-cards {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, 360px);
  gap: 16px; align-items: stretch;
}
@media (max-width: 1040px) {
  .admin-cards { grid-template-columns: 1fr; }
  /* 疊排（手機）下唔好再撐高到貼卡底：內容自然由頂排落，卡 padding 自留上下內距。
     用 .admin-cards 前綴（0,2,0）壓過後面嘅 .usage-gen { height:100% }（0,1,0） */
  .admin-cards .usage-gen { height: auto; flex: none; justify-content: flex-start; }
  .admin-cards .usage-gen-chart { flex: none; justify-content: flex-start; }
}
/* 生成統計獨立成卡後：唔再要 split grid 第三欄，卡內垂直置中 */
.usage-gen { height: 100%; }
.usage-gen-chart { flex: 1; justify-content: center; }
.usage-share { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.usage-donut { position: relative; width: 130px; height: 130px; }
.usage-donut svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.usage-donut-track { fill: none; stroke: var(--hairline-soft); stroke-width: 14; }
.usage-donut-seg { fill: none; stroke-width: 14; stroke-linecap: butt; transition: stroke-dasharray 0.4s ease; }
.usage-donut-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.usage-donut-total { color: var(--ink); font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1; }
.usage-donut-cap { color: var(--muted); font-size: var(--t-label); }
.usage-legend { display: flex; flex-direction: column; gap: 4px; }
.usage-legend-row { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: var(--t-label); white-space: nowrap; }
.usage-legend-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }

.usage-side {
  display: flex; flex-direction: column; justify-content: center; gap: 8px;
}
.usage-side-summary { color: var(--ink); font-size: var(--t-small); font-variant-numeric: tabular-nums; }
.usage-side-sub { color: var(--muted); font-size: var(--t-label); font-variant-numeric: tabular-nums; }
.usage-meter {
  height: 6px; background: var(--hairline-soft); border-radius: 999px; overflow: hidden;
}
.usage-meter-fill {
  height: 100%; width: 0%; background: var(--accent); border-radius: 999px;
  transition: width 0.4s ease;
}
.usage-meter-fill.warn { background: #b26a00; }
.usage-meter-fill.bad { background: var(--danger); }

/* 生成統計小圖：普通／加強兩條水平 bar（純 HTML/CSS，配色用現有變數） */
.usage-gen { display: flex; flex-direction: column; gap: 8px; justify-content: center; flex: 1; }
.usage-gen-title { color: var(--muted); font-size: var(--t-label); }
.usage-gen-chart { display: flex; flex-direction: column; gap: 8px; }
.usage-gen-row { display: grid; grid-template-columns: 64px 1fr auto; align-items: center; gap: 10px; }
.usage-gen-label { color: var(--muted); font-size: var(--t-label); white-space: nowrap; }
.usage-gen-bar {
  height: 10px; background: var(--hairline-soft); border-radius: 999px; overflow: hidden;
}
.usage-gen-fill { height: 100%; border-radius: 999px; transition: width 0.4s ease; }
.usage-gen-fill.normal { background: var(--accent); }
.usage-gen-fill.deep { background: var(--chart-2); }
.usage-gen-count { color: var(--ink); font-size: var(--t-label); font-variant-numeric: tabular-nums; }
.usage-gen-empty { color: var(--muted); font-size: var(--t-label); }

@media (max-width: 900px) {
  .usage-gen { min-width: 0; }
}

/* 分頁條：表下方，上一頁／下一頁＋頁碼 */
.pager { display: flex; align-items: center; gap: 10px; margin-top: var(--s-3); min-height: 32px; justify-content: center; }
@media (max-width: 640px) { .pager { justify-content: flex-start; } }
.pager:empty { display: none; }
.pager-label { color: var(--muted); font-size: var(--t-small); font-variant-numeric: tabular-nums; }

/* 表格「用量」欄：上文字 + 下細 bar */
.usage-cell { min-width: 150px; }
.usage-cell-line { color: var(--ink); font-size: var(--t-small); font-variant-numeric: tabular-nums; margin-bottom: 5px; white-space: nowrap; }
.usage-cell-track { height: 5px; background: var(--hairline-soft); border-radius: 999px; overflow: hidden; max-width: 340px; }
.usage-cell-fill { height: 100%; border-radius: 999px; }

@media (max-width: 640px) {
  .usage-split { grid-template-columns: 1fr; gap: 20px; }
  .usage-side { align-items: center; text-align: center; }
  .usage-side .usage-meter { width: 100%; }
  /* 表格窄版防爆版 */
  .usage-cell { min-width: 0; }
  th { white-space: nowrap; }
  #usage-table button.secondary { white-space: nowrap; padding-inline: 10px; }
  th, td { padding-left: 6px; padding-right: 6px; }
  .usage-cell-line { font-size: var(--t-label); }
  .usage-cell-track { min-width: 90px; }
}

/* ---- 用戶工作區：共享容量 meter ＋ 自己用量 ---- */
.storage-card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: var(--s-3, 12px); }
.storage-card-head h2 { margin: 0; }
.storage-val { color: var(--ink); font-size: var(--t-small); font-variant-numeric: tabular-nums; }
.storage-meter { height: 6px; background: var(--hairline-soft); border-radius: 999px; overflow: hidden; }
.storage-meter-fill { height: 100%; width: 0%; background: var(--accent); border-radius: 999px; transition: width .4s ease; }
.storage-meter-fill.warn { background: #b26a00; }
.storage-meter-fill.bad { background: var(--danger); }
.storage-caption-row { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: var(--t-label); }
.storage-caption.bad { color: var(--danger); }
.storage-mine { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---- 任務詳情 modal：draft 頁面拖動排序 ---- */
.page-head[draggable="true"], .page-head-draggable { cursor: grab; }
.page-head.dragging { opacity: .5; }
.page-head.drag-over { outline: 2px dashed var(--accent); outline-offset: -2px; border-radius: 6px; }
.drag-grip { color: var(--muted); cursor: grab; display: inline-flex; align-items: center; flex: 0 0 auto; }

/* 頁面檔名＋大小（draft-row / page-head 共用） */
.page-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 auto; }
.page-size { color: var(--muted); font-size: var(--t-label); font-variant-numeric: tabular-nums; }
.page-meta .page-name, .page-meta .draft-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-sub { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.page-sub .badge { padding: 2px 8px; font-size: 12px; gap: 5px; }
.page-sub .badge::before { width: 6px; height: 6px; }
.badge.cancelled { background: #eef0f2; color: var(--muted); }
.page-item { padding: var(--s-4) 0; border-bottom: 1px solid var(--hairline-soft); }
.page-item:last-child { border-bottom: none; }
.page-item .page-head { margin-top: 0; }

/* ---- 任務頁狀態 filter ---- */
.status-filter { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 var(--s-4); }
.filter-chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--hairline); background: var(--card); color: var(--muted); font-size: var(--t-small); cursor: pointer; }
/* 注意：全域 button:hover:not(:disabled):not(.tab) 權重 (0,3,1)，自訂 chip 的 hover 要用 button.<class>:hover:not(:disabled)（(0,4,1)）先蓋得過，否則會變實心藍 */
button.filter-chip:hover:not(.active):not(:disabled) { background: var(--hairline-soft); color: var(--ink); }
button.filter-chip.active:hover:not(:disabled) { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.filter-chip .chip-count { font-variant-numeric: tabular-nums; color: inherit; opacity: .8; }
.filter-chip.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); font-weight: 600; }
