/* 版面概念：工程圖紙般的冷調底色＋深墨字，強調色取自「機台運轉中」的青綠；
   內文一律系統字體（中文 web font 會造成首屏跳動），只有題號與數字用等寬字。 */
:root {
  --bg: #f3f5f6;
  --surface: #ffffff;
  --surface-2: #f8fafa;
  --ink: #15202b;
  --muted: #5a6773;
  --faint: #8a96a0;
  --line: #d7dde2;
  --line-strong: #b9c2c9;
  --accent: #0b6b67;
  --accent-ink: #ffffff;
  --accent-soft: #e2f0ee;
  --ok: #1d7a4c;
  --ok-soft: #e3f3ea;
  --warn: #9a6200;
  --warn-soft: #fbf1dc;
  --danger: #b42318;
  --danger-soft: #fbe9e7;
  --info: #2c5d9c;
  --info-soft: #e6eef8;
  --neutral-soft: #eceff1;
  --focus: #1f7fd6;
  --scroll-thumb: #c3cdd3;
  --scroll-thumb-hover: #9fb0b8;
  --shadow: 0 1px 2px rgba(21, 32, 43, .06), 0 4px 16px rgba(21, 32, 43, .06);

  --font-body: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Heiti TC", sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --fs-xs: .78rem;
  --fs-sm: .875rem;
  --fs-md: 1rem;
  --fs-lg: 1.15rem;
  --fs-xl: 1.45rem;
  --fs-2xl: 1.9rem;

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;

  --radius: 8px;
  --radius-sm: 6px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11171c;
    --surface: #182128;
    --surface-2: #1d272f;
    --ink: #e6ecef;
    --muted: #a3b0ba;
    --faint: #73818c;
    --line: #2c3740;
    --line-strong: #3d4a54;
    --accent: #4fc0b4;
    --accent-ink: #0b1a19;
    --accent-soft: #173733;
    --ok: #5ccf92;
    --ok-soft: #173326;
    --warn: #e7b558;
    --warn-soft: #3a2e15;
    --danger: #f08a7e;
    --danger-soft: #3d1f1b;
    --info: #8bb6ec;
    --info-soft: #1b2b40;
    --neutral-soft: #242e36;
    --focus: #6cb6ff;
    --scroll-thumb: #34424c;
    --scroll-thumb-hover: #4a5b66;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11171c;
  --surface: #182128;
  --surface-2: #1d272f;
  --ink: #e6ecef;
  --muted: #a3b0ba;
  --faint: #73818c;
  --line: #2c3740;
  --line-strong: #3d4a54;
  --accent: #4fc0b4;
  --accent-ink: #0b1a19;
  --accent-soft: #173733;
  --ok: #5ccf92;
  --ok-soft: #173326;
  --warn: #e7b558;
  --warn-soft: #3a2e15;
  --danger: #f08a7e;
  --danger-soft: #3d1f1b;
  --info: #8bb6ec;
  --info-soft: #1b2b40;
  --neutral-soft: #242e36;
  --focus: #6cb6ff;
  --scroll-thumb: #34424c;
  --scroll-thumb-hover: #4a5b66;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--fs-md);
  line-height: 1.65;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.3; text-wrap: balance; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
/* 捲軸跟著頁面色系：細、圓角、軌道透明 */
* { scrollbar-width: thin; scrollbar-color: var(--scroll-thumb) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 999px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: var(--scroll-thumb-hover); }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* 按鈕 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 40px; padding: 0 var(--sp-4);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
  font-size: var(--fs-sm); font-weight: 600; cursor: pointer; white-space: nowrap;
  text-decoration: none;
}
.btn:hover { border-color: var(--ink); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.btn-primary:hover { filter: brightness(1.08); }
.btn.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.btn-ghost:hover { color: var(--ink); background: var(--neutral-soft); }
.btn.btn-danger { color: var(--danger); border-color: var(--danger); background: var(--surface); }
.btn svg { width: 16px; height: 16px; flex: none; }

/* 狀態膠囊 */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 999px;
  font-size: var(--fs-xs); font-weight: 600; white-space: nowrap; line-height: 1.6;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.danger { background: var(--danger-soft); color: var(--danger); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.neutral { background: var(--neutral-soft); color: var(--muted); }

/* 提示訊息（toast） */
.toast-zone {
  position: fixed; z-index: 50;
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--sp-5) + env(safe-area-inset-bottom, 0px));
  display: grid; gap: var(--sp-2); width: min(560px, calc(100% - 32px));
}
.toast {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4); border-radius: var(--radius);
  background: var(--ink); color: var(--bg); box-shadow: var(--shadow);
  font-size: var(--fs-sm);
}
.toast .toast-msg { flex: 1; min-width: 0; }
.toast button {
  border: 0; background: transparent; color: inherit; font-weight: 700;
  text-decoration: underline; cursor: pointer; padding: 4px;
}
.toast.error { background: var(--danger); color: #fff; }

/* 動態效果一律寫在 no-preference 內，減少動態偏好的使用者就完全沒有過場 */
@media (prefers-reduced-motion: no-preference) {
  .btn, .opt, .nav-item { transition: background-color .15s ease, border-color .15s ease, color .15s ease; }
}


body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--surface); }
.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line);
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.topbar-inner { max-width: 1280px; margin: 0 auto; min-height: 60px; display: flex; align-items: center; gap: var(--sp-4); flex-wrap: wrap; padding-block: var(--sp-2); }
.brand { display: flex; flex-direction: column; flex: 1 1 260px; min-width: 0; }
.brand-title { font-weight: 700; }
.brand-sub { font-size: var(--fs-xs); color: var(--muted); }
.mode-note { font-size: var(--fs-xs); color: var(--warn); font-weight: 600; }
.wrap { max-width: 1280px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-5); padding-block: var(--sp-5) var(--sp-7);
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--sp-5); display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-4); min-width: 0; }
.card h2 { font-size: var(--fs-xl); }
.card h3 { font-size: var(--fs-lg); }
.field { width: 100%; min-height: 40px; padding: 8px var(--sp-3); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); }
.field[aria-invalid="true"] { border-color: var(--danger); }
.create-form { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr) auto; gap: var(--sp-3); align-items: start; }
.fld { display: grid; gap: 4px; font-size: var(--fs-sm); font-weight: 600; }
.req { color: var(--danger); }
.form-error { color: var(--danger); font-size: var(--fs-xs); font-weight: 600; }
.create-form .btn { margin-top: 26px; }
/* position: relative：讓表頭裡絕對定位的 visually-hidden 文字被捲動區裁切，否則會撐寬整頁 */
.table-wrap { position: relative; overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table.grid { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); min-width: 860px; }
.grid th, .grid td { padding: 10px var(--sp-4); border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.grid thead th { font-size: var(--fs-xs); color: var(--muted); font-weight: 600; background: var(--surface-2); }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid tr.group th { background: var(--neutral-soft); font-size: var(--fs-xs); color: var(--ink); }
.grid .num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.grid tfoot th, .grid tfoot td { font-weight: 700; font-size: var(--fs-md); border-bottom: 0; }
table.grid.answers { min-width: 0; }
.grid.answers tr.subject td { border-bottom: 0; padding-bottom: 2px; font-weight: 650; }
.grid.answers tr.rule-row td { padding-top: 0; }
.rule summary { cursor: pointer; font-size: var(--fs-xs); font-weight: 600; color: var(--accent); padding-block: 4px; }
.rule-body { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: var(--sp-3); margin-top: var(--sp-1); }
/* 注意事項沿用前台的米黃色；必備憑證用藍色區分 */
.rule-col { padding: var(--sp-3) var(--sp-4); border-left: 3px solid; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.rule-notes { background: var(--warn-soft); border-left-color: var(--warn); }
.rule-notes h4 { color: var(--warn); }
.rule-docs { background: var(--info-soft); border-left-color: var(--info); }
.rule-docs h4 { color: var(--info); }
.rule-body h4 { font-size: var(--fs-xs); margin-bottom: var(--sp-1); }
.rule-body ul, .rule-body ol { margin: 0; padding-left: 1.3em; display: grid; gap: 3px; font-size: var(--fs-sm); }
.rule-source { font-size: var(--fs-xs); color: var(--muted); }
/* 表單型問卷的答案頁：初篩結論與逐題判定 */
.verdict-banner { border-left: 4px solid var(--warn); background: var(--warn-soft); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; padding: var(--sp-4) var(--sp-5); display: grid; gap: var(--sp-2); }
.verdict-banner.ok { border-left-color: var(--ok); background: var(--ok-soft); }
.verdict-banner.bad { border-left-color: var(--danger); background: var(--danger-soft); }
.verdict-banner h3 { font-size: var(--fs-lg); }
.verdict-banner ul { margin: 0; padding-left: 1.2em; display: grid; gap: 2px; font-size: var(--fs-sm); }
.verdict-note { font-size: var(--fs-xs); color: var(--muted); }
.grid.judge td, .grid.judge th { vertical-align: top; }
.grid.judge thead th:first-child { white-space: nowrap; }
.grid.judge .no { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--muted); white-space: nowrap; width: 1%; }
.grid.judge .vd { white-space: nowrap; width: 1%; font-weight: 700; }
.vd.ok { color: var(--ok); }
.vd.bad { color: var(--danger); }
.vd.warn { color: var(--warn); }
.vd.none { color: var(--faint); font-weight: 400; }
.judge-q { font-weight: 650; }
/* 某一題底下的細項（3-1～3-5、10-1、11-1）：縮排、題目不加粗，和 14＋3 項主題區分 */
.grid.judge tr.sub .judge-cell { padding-left: var(--sp-4); border-left: 2px solid var(--line-strong); }
.grid.judge tr.sub .judge-q { font-weight: 500; }
.grid.judge tr.sub .vd { font-weight: 600; white-space: normal; min-width: 9em; }
.judge-a { white-space: pre-line; overflow-wrap: anywhere; }
.judge-n { font-size: var(--fs-xs); color: var(--muted); overflow-wrap: anywhere; }
.judge-cell { display: grid; gap: 4px; min-width: 0; }
/* 申請者上傳的檔案：每個檔一列，旁邊是內部的確認結果（尚未確認／可用／不可用）與備註，改了立刻存 */
.file-list { list-style: none; margin: var(--sp-1) 0 0; padding: 0; display: grid; gap: var(--sp-2); }
.file-row { display: grid; grid-template-columns: minmax(0, 1fr) 8.5em minmax(0, 1.2fr); gap: var(--sp-1) var(--sp-3); align-items: center; padding: var(--sp-2) var(--sp-3); border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); }
.file-main { display: grid; gap: 2px; min-width: 0; }
.file-open { border: 0; background: none; padding: 0; font: inherit; cursor: pointer; text-align: left; }
.file-state { grid-column: 1 / -1; font-size: var(--fs-xs); color: var(--muted); display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }
.file-state:empty { display: none; }
.file-state.bad { color: var(--danger); font-weight: 600; }
.file-miss { color: var(--danger); font-weight: 600; font-size: var(--fs-sm); }
.file-zone { font-weight: 650; color: var(--ink); margin-top: var(--sp-1); }
button.link { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; font: inherit; font-weight: 600; }
.none { color: var(--muted); font-family: var(--font-body); }
.todo { color: var(--warn); font-weight: 600; font-family: var(--font-body); }
.name-link { color: var(--accent); font-weight: 700; text-decoration: none; overflow-wrap: anywhere; }
.name-link:hover { text-decoration: underline; }
.sub { font-size: var(--fs-xs); color: var(--muted); overflow-wrap: anywhere; }
.link-cell { display: flex; gap: var(--sp-2); align-items: center; min-width: 260px; }
.link-cell input { flex: 1; min-width: 0; font-family: var(--font-mono); font-size: var(--fs-xs); }
.row-actions { display: flex; gap: var(--sp-2); justify-content: flex-end; flex-wrap: wrap; }
.status-list { display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center; }
/* 申請者列表的「已開放問卷」欄：一份問卷一行（名稱、狀態、檢視答案同一行），問卷多了也不會擠成一排 */
.survey-stack { display: grid; gap: var(--sp-2); }
.survey-stack .status-list { flex-wrap: nowrap; white-space: nowrap; }
/* 優先支持項目：不是資格條件，放在初篩結論下方給業務跟進 */
.priority-box { border: 1px solid var(--line); border-left: 4px solid var(--info); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; padding: var(--sp-4) var(--sp-5); display: grid; gap: var(--sp-2); }
.priority-box h3 { font-size: var(--fs-md); }
.priority-box ul { margin: 0; padding-left: 1.2em; display: grid; gap: 2px; font-size: var(--fs-sm); }
.priority-head { display: flex; gap: var(--sp-2) var(--sp-3); flex-wrap: wrap; align-items: center; }
.empty { padding: var(--sp-6); text-align: center; color: var(--muted); }
.state { padding: var(--sp-6); text-align: center; color: var(--muted); display: grid; gap: var(--sp-3); justify-items: center; }
.crumbs { font-size: var(--fs-sm); display: flex; gap: var(--sp-2); flex-wrap: wrap; color: var(--muted); }
.crumbs a { color: var(--accent); font-weight: 600; text-decoration: none; }
.page-nav { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.page-nav .crumbs { min-width: 0; flex: 1 1 200px; overflow-wrap: anywhere; }
.head-row { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--sp-4); flex-wrap: wrap; }
.head-row > div { min-width: 0; }
.kv { display: grid; grid-template-columns: 7.5em minmax(0, 1fr); gap: 6px var(--sp-3); font-size: var(--fs-sm); margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.survey-row { border: 1px solid var(--line); border-radius: var(--radius); padding: var(--sp-4); display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--sp-3) var(--sp-4); align-items: center; }
.survey-row.planned { background: var(--surface-2); }
.survey-row.planned h3 { color: var(--muted); }
.survey-row h3 { font-size: var(--fs-md); }
.survey-info { display: grid; gap: 6px; min-width: 0; }
.survey-acts { display: flex; gap: var(--sp-2); flex-wrap: wrap; justify-content: flex-end; }
.btn:disabled { cursor: progress; }

dialog { border: 0; border-radius: var(--radius); padding: 0; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); width: min(460px, calc(100% - 32px)); }
dialog::backdrop { background: rgba(10, 16, 22, .45); }
.dlg { padding: var(--sp-5); display: grid; gap: var(--sp-4); }
.dlg h3 { font-size: var(--fs-lg); }
.dlg-actions { display: flex; justify-content: flex-end; gap: var(--sp-2); flex-wrap: wrap; }

/* 管理員帳號操作（修改密碼、登出）與 SweetAlert2 表單 */
.topbar-actions { display: flex; gap: var(--sp-2); margin-left: auto; flex-wrap: wrap; }
.swal2-actions.swal-actions { gap: var(--sp-2); }
.swal2-popup { font-family: var(--font-body); }
.pw-form { display: grid; gap: var(--sp-3); text-align: left; }
.pw-field { display: grid; gap: 4px; font-size: var(--fs-sm); font-weight: 600; }
@media (max-width: 900px) {
  .create-form { grid-template-columns: minmax(0, 1fr); }
  .create-form .btn { margin-top: 0; justify-self: start; }
}
@media (max-width: 640px) {
  .file-row { grid-template-columns: minmax(0, 1fr); }
  .rule-body { grid-template-columns: minmax(0, 1fr); gap: var(--sp-3); }
  .survey-row { grid-template-columns: minmax(0, 1fr); }
  .survey-acts { justify-content: flex-start; }
  .card { padding: var(--sp-4); }
}
[hidden] { display: none; }
