/*
 * Design System — 擷取自環境部官網 www.moenv.gov.tw
 * 來源：其 index.css 定義的 CSS 變數（2026-07 擷取）
 *   主色 --c-pry1 #007A96（環境部青綠）、--c-pry2 #EDF7F3（薄荷淺底）、
 *   次藍 --c-pry3 #1264A3、警示 --c-red1 #E74C3C、
 *   灰階 #333/#999/#CBCBCB/#F4F6F7、字體 "Microsoft JhengHei"。
 * 下方沿用原本的變數命名，換值即全站換風。
 */
:root {
  /* 環境部青綠（主色系 · 鎖定不動） */
  --pri: #007a96;            /* 環境部主色 · 青綠（moenv --c-pry1） */
  --pri-hover: #005f75;      /* 深青綠（hover，由主色加深衍生） */
  --pri-soft: #aaced5;       /* 淺青綠（chip 邊框；moenv 陰影色 #AACED5） */
  --pri-bg: #edf7f3;         /* 薄荷淺底（moenv --c-pry2；chip/done 卡背景） */

  /* 文字 / 結構（冷調中性 —— 與青綠同溫，較 #333/#999 精緻） */
  --fg: #23313a;             /* 主要文字 · 冷墨 */
  --muted: #647079;          /* 次要文字 · 冷灰 */
  --line: #dbe2e4;           /* 控制項邊框（柔） */
  --hairline: #e9edef;       /* 內部分隔線（表格列 / 區塊） */

  /* 背景 */
  --bg: #eef2f3;             /* 頁面底（冷調淺灰） */
  --paper: #ffffff;          /* 卡片底 · 白 */
  --paper-soft: #f3f6f7;     /* 內嵌區塊（淺灰） */

  /* 狀態色 */
  --good: #128a6e;           /* 通過（青綠系綠，與主色協調） */
  --warn: #c77700;           /* 警告（琥珀） */
  --warn-bg: #fdf1e0;        /* 警告淺底 */
  --bad: #e74c3c;            /* 失敗（moenv --c-red1） */
  --bad-bg: #fdedeb;         /* 失敗淺底 */
  --uncertain: #647079;      /* 不確定（冷灰） */
  --skip: #aab4ba;           /* 略過（冷灰） */

  /* ---- 設計層 tokens：圓角 / 陰影 / 過場 ---- */
  --r-sm: 6px; --r: 10px; --r-lg: 14px; --r-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(24,43,50,.05), 0 1px 3px rgba(24,43,50,.045);
  --shadow-md: 0 6px 16px rgba(24,43,50,.08), 0 2px 6px rgba(24,43,50,.05);
  --shadow-pop: 0 16px 40px rgba(24,43,50,.16);
  --ring: 0 0 0 3px rgba(0,122,150,.18);
  --ease: 160ms cubic-bezier(.2,.6,.2,1);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  /* 台灣黑體優先（各平台取原生高品質字面）；保留 JhengHei 對齊環境部官網 */
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  font-size: 15px; line-height: 1.6;
  background: var(--bg); color: var(--fg);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-variant-numeric: tabular-nums;
}

/* 基礎排版 */
h1, h2, h3 { line-height: 1.25; letter-spacing: -0.01em; color: var(--fg); }
h1 { font-size: 1.75rem; font-weight: 700; margin: 0 0 4px; }
input, select, textarea, button { font-family: inherit; }
::selection { background: var(--pri-soft); color: var(--pri-hover); }
:focus-visible { outline: 2px solid var(--pri); outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none; border-color: var(--pri); box-shadow: var(--ring);
}
/* eyebrow：小型分類 / 欄位標籤（結構性微標題） */
.eyebrow {
  font-size: 11px; font-weight: 700; letter-spacing: .09em;
  text-transform: uppercase; color: var(--pri);
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* 版面：左側邊欄 + 右主內容 */
.layout { display: flex; min-height: 100vh; align-items: stretch; }

/* 左側邊欄 */
.sidebar {
  overflow: auto;
  width: 248px; flex-shrink: 0;
  display: flex; flex-direction: column;
  padding: 22px 16px 18px;
  background: var(--paper);
  border-right: 1px solid var(--line);
  position: sticky; top: 0; height: 100vh;
}
/* 品牌鎖定：青綠勾選章 + 兩行字標 */
.sidebar .brand {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; color: var(--fg);
  padding: 4px 6px; margin-bottom: 26px;
}
.brand-logo { flex-shrink: 0; width: 64px; height: 64px; display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text b { font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.brand-text span { font-size: 11px; color: var(--muted); letter-spacing: .04em; }

.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-select {
  font: inherit; width: 100%; margin-bottom: 12px;
  padding: 10px 12px; border: 1px solid var(--pri-soft); border-radius: var(--r-sm);
  background: var(--pri-bg); color: var(--pri-hover); font-weight: 600; cursor: pointer;
  transition: border-color var(--ease), box-shadow var(--ease);
}
.side-select:hover { border-color: var(--pri); }
.side-link {
  position: relative;
  padding: 9px 12px; border-radius: var(--r-sm);
  text-decoration: none; color: var(--fg); font-size: 14px;
  transition: background var(--ease), color var(--ease);
}
.side-link:hover { background: var(--paper-soft); color: var(--pri); }
.side-link[aria-current="page"] {
  background: var(--pri-bg); color: var(--pri-hover); font-weight: 600;
}
.side-link[aria-current="page"]::before {
  content: ""; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 3px; height: 18px; border-radius: 0 3px 3px 0; background: var(--pri);
}
.side-logout {
  margin-top: auto; padding: 10px 12px; border-radius: var(--r-sm);
  text-align: center; text-decoration: none; color: var(--muted); font-size: 14px;
  border: 1px solid var(--line);
  transition: color var(--ease), border-color var(--ease), background var(--ease);
}
.side-logout:hover { color: var(--bad); border-color: var(--bad); background: var(--bad-bg); }

/* 側欄「最近瀏覽」：分隔線 + 小標 + 列表（字級小於選單） */
.side-recent {
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--hairline);
}
.side-recent-label {
  font-size: 11px; font-weight: 700; letter-spacing: .06em;
  color: var(--muted); padding: 0 12px; margin-bottom: 6px;
}
.recent-views-list { display: flex; flex-direction: column; }
.recent-view-item {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 6px 12px; text-decoration: none; color: var(--fg);
  font-size: 12px; border-radius: var(--r-sm);
}
.recent-view-item:hover { background: var(--paper-soft); color: var(--pri); }
.rv-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rv-time { color: var(--muted); font-size: 11px; white-space: nowrap; }

.container { flex: 1; min-width: 0; max-width: 980px; margin: 32px auto; padding: 0 28px; }

.landing h1 { margin-bottom: 16px; }
.card-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.recent-section { margin-top: 32px; }
.recent-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.recent-head h2 { margin: 0; font-size: 18px; }
.link-btn {
  background: none; border: 0; color: var(--muted); cursor: pointer;
  font-size: 13px; padding: 4px 8px;
}
.link-btn:hover { color: var(--bad); text-decoration: underline; }
.recent-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; background: var(--paper); border: 1px solid var(--line);
  border-radius: 6px; margin: 6px 0; text-decoration: none; color: var(--fg);
  transition: border-color .15s;
}
.recent-row:hover { border-color: var(--pri); }
.recent-main strong { display: block; }
.recent-meta { color: var(--muted); font-size: 13px; }
.recent-aside { display: flex; gap: 8px; align-items: center; }
.recent-when {
  color: var(--muted); font-size: 12px;
  /* 固定寬度 + 右對齊 + 表格數字：日期成為穩定一欄，左側 badge 才能對齊 */
  font-variant-numeric: tabular-nums;
  min-width: 120px; text-align: right; white-space: nowrap;
}
.recent-controls select {
  font: inherit; padding: 4px 8px; border: 1px solid var(--line); border-radius: 4px;
  background: var(--paper); color: var(--fg);
}
.app-status {
  font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: var(--r-pill);
  background: var(--paper-soft); color: var(--muted); white-space: nowrap;
  border: 1px solid var(--line);
}
.app-status.pass { background: var(--pri-bg); color: var(--good); border-color: rgba(18,138,110,.4); }
.app-status.fail { background: var(--bad-bg); color: var(--bad); border-color: rgba(231,76,60,.42); }
.app-status.reviewing { background: #e3f2fd; color: #1565c0; border-color: rgba(21,101,192,.3); }
.app-status.timeout { background: #fff3e0; color: #e65100; border-color: rgba(230,81,0,.3); }
.btn-dl-report {
  background: none; border: 1px solid var(--line); border-radius: var(--r-sm);
  cursor: pointer; font-size: 14px; padding: 3px 7px; line-height: 1;
  color: var(--pri); transition: border-color var(--ease), background var(--ease);
}
.btn-dl-report:hover { border-color: var(--pri); background: var(--pri-bg); }
.btn-dl-report:disabled { opacity: .5; cursor: wait; }
.pagination {
  display: flex; justify-content: center; align-items: center; gap: 12px;
  margin: 16px 0; font-size: 13px; color: var(--muted);
}
.pagination button {
  padding: 6px 14px; background: var(--paper); border: 1px solid var(--line);
  border-radius: 4px; cursor: pointer; font: inherit; color: var(--fg);
}
.pagination button:hover:not(:disabled) { border-color: var(--pri); color: var(--pri); }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }
.card {
  display: block; padding: 22px 24px; background: var(--paper);
  border: 1px solid var(--line); border-radius: var(--r);
  text-decoration: none; color: var(--fg);
  box-shadow: var(--shadow-sm);
  transition: transform var(--ease), box-shadow var(--ease), border-color var(--ease);
}
.card:hover { transform: translateY(-2px); border-color: var(--pri-soft); box-shadow: var(--shadow-md); }
.card h2 { margin: 0 0 6px 0; font-size: 1.1rem; }
.card p { margin: 0; color: var(--muted); }

.login { max-width: 420px; margin: 56px auto; background: var(--paper); padding: 32px; border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-md); }
.login-logo { display: block; width: 72px; height: 72px; margin: 0 auto 18px; }
.login h1 { font-size: 1.4rem; }
.login form label { display: block; margin: 16px 0; font-size: 13px; font-weight: 600; color: var(--muted); }
.login input { display: block; width: 100%; padding: 11px 12px; margin-top: 6px; border: 1px solid var(--line); border-radius: var(--r-sm); font-size: 14px; color: var(--fg); transition: border-color var(--ease), box-shadow var(--ease); }
.login button { width: 100%; margin-top: 4px; padding: 12px 18px; background: var(--pri); color: #fff; border: 0; border-radius: var(--r-sm); cursor: pointer; font-size: 15px; font-weight: 600; box-shadow: var(--shadow-sm); transition: background var(--ease), box-shadow var(--ease); }
.login button:hover { background: var(--pri-hover); box-shadow: var(--shadow-md); }
.hint { color: var(--muted); font-size: 13px; }
.error { color: var(--bad); font-size: 13px; }

.application-form fieldset { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin-bottom: 16px; }
.application-form legend { font-weight: 700; padding: 0 8px; }
/* 只套用在「案件基本資料」欄位；勿外溢到 dropzone 的隱藏 file input、產品特性 checkbox 等 */
.base-info label { display: inline-block; width: 48%; margin: 8px 0; vertical-align: top; }
.base-info input { display: block; width: 96%; padding: 6px; margin-top: 4px; border: 1px solid var(--line); border-radius: 4px; }

.rule-group { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; margin: 12px 0; }
.rule-group > summary { padding: 12px 16px; font-weight: 700; cursor: pointer; user-select: none; color: var(--pri); }
.rule-group[open] > summary { border-bottom: 1px solid var(--line); }
.rule-card { padding: 12px 16px; border-top: 1px dashed var(--line); }
.rule-card:first-of-type { border-top: 0; }
/* 標頭改為由上而下堆疊：標題 → 涉及規則（避免長說明擠壓標題/badge 掉行） */
.rule-head { display: block; }
.rule-head strong { display: block; color: var(--pri); }
.rule-head .docs { display: block; margin-top: 6px; color: var(--muted); font-size: 13px; }

/* 驗證材料：項目內左右兩欄（左：標題 + 涉及規則；右：上傳區） */
.rule-card.two-col {
  display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 24px;
  align-items: start; padding: 16px;
}
.rule-card.two-col .rc-right { min-width: 0; }
/* 上傳區填滿右欄、靠右對齊 */
.rule-card.two-col .rc-right .dropzone { display: block; width: 100%; }
/* 左欄改為由上而下堆疊：標題 → 涉及規則 */
.two-col .rule-head { display: block; }
.two-col .rule-head strong { display: block; }
.two-col .rule-head .docs { display: block; margin-top: 8px; }
/* 規則的「選填 / 條件式」以括號文字呈現（不在 chip badge 內再套 badge） */
.rule-chip-note { color: var(--muted); font-size: 11px; margin-left: 3px; }
@media (max-width: 640px) {
  .rule-card.two-col { grid-template-columns: 1fr; gap: 14px; }
}

.rule-chip {
  display: inline-block;
  padding: 1px 8px;
  margin: 0 2px;
  background: var(--pri-bg);
  border: 1px solid var(--pri-soft);
  border-radius: 12px;
  color: var(--pri);
  font-family: ui-monospace, monospace;
  font-size: 12px;
  cursor: help;
  position: relative;
  outline: none;
}
.rule-chip:hover, .rule-chip:focus { background: var(--pri-soft); }
.rule-chip .rule-req {
  margin-left: 5px;
  font-family: var(--font, sans-serif);
  font-size: 10px;
  font-weight: 600;
  padding: 0 4px;
  border-radius: 8px;
}
.rule-chip .rule-req.optional { background: var(--paper-soft); color: var(--muted); }
.rule-chip .rule-req.conditional { background: var(--warn-bg); color: var(--warn); }
.rule-chip[data-tip]:hover::after,
.rule-chip[data-tip]:focus::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  transform: translateX(-50%);
  background: var(--fg);
  color: var(--paper);
  padding: 8px 12px;
  border-radius: 6px;
  font-family: system-ui, sans-serif;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  width: max-content;
  max-width: 420px;
  box-shadow: 0 4px 12px rgba(0,0,0,.18);
  z-index: 10;
  pointer-events: none;
}
.rule-chip[data-tip]:hover::before,
.rule-chip[data-tip]:focus::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 100%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--fg);
  z-index: 10;
  pointer-events: none;
}
.rule-desc { margin: 6px 0; color: var(--fg); font-size: 13px; }
.dropzone {
  display: block; padding: 16px; border: 2px dashed var(--line); border-radius: 6px;
  text-align: center; cursor: pointer; color: var(--muted); transition: all .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--pri); color: var(--pri); background: var(--pri-bg); }
.dz-files { list-style: none; padding: 0; margin: 8px 0 0 0; font-size: 13px; }
.dz-files li { padding: 4px 0; }
.dz-files em { color: var(--warn); font-style: normal; }

.submit-bar { margin: 24px 0; }
.submit-bar button {
  padding: 12px 26px; background: var(--pri); color: #fff; border: 0;
  border-radius: var(--r-sm); font-size: 16px; font-weight: 600; cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background var(--ease), box-shadow var(--ease), transform var(--ease);
}
.submit-bar button:hover:not(:disabled) { background: var(--pri-hover); box-shadow: var(--shadow-md); }
.submit-bar button:active:not(:disabled) { transform: translateY(1px); }
.submit-bar button:disabled { background: var(--skip); cursor: not-allowed; box-shadow: none; }
.submit-bar #submit-status { margin-left: 12px; color: var(--muted); }

.loading { padding: 16px; color: var(--muted); }

.summary-counts { list-style: none; padding: 0; display: flex; gap: 12px; flex-wrap: wrap; }
.summary-counts li { padding: 6px 12px; border-radius: 4px; background: var(--paper); border: 1px solid var(--line); }
.summary-counts li.pass { color: var(--good); border-color: var(--good); }
.summary-counts li.fail { color: var(--bad); border-color: var(--bad); }
.summary-counts li.uncertain { color: var(--uncertain); border-color: var(--uncertain); }
/* 可點擊篩選 */
.summary-counts li { cursor: pointer; user-select: none; transition: background .12s; }
.summary-counts li:hover { background: var(--paper-soft, #f0ece4); }
.summary-counts li.active { box-shadow: inset 0 0 0 2px currentColor; font-weight: 700; }
.summary-counts li.all { color: var(--fg); }
.filter-hint { font-size: 12px; color: var(--muted, #888); margin: 4px 0 0; }

/* 結果排序控制列 */
.result-controls { display: flex; align-items: center; gap: 14px; margin: 12px 0 4px; }
.result-controls .sort-ctrl { font-size: 13px; color: var(--muted, #555); }
.result-controls select {
  font: inherit; padding: 3px 8px; border: 1px solid var(--line); border-radius: 4px;
  background: var(--paper); color: var(--fg); margin-left: 4px;
}
.filter-indicator { font-size: 12px; color: var(--muted, #888); }

/* ---- 審查結果頁 ---- */
/* 標題右側狀態 badge */
.result-head { margin-bottom: 10px; }
.result-head .hint { margin: 6px 0 0; }
/* 標題內的案件編號（QT-…） */
.result-appno {
  margin-left: 10px; vertical-align: middle;
  font-family: ui-monospace, monospace; font-size: 1.05rem; font-weight: 700;
  color: var(--pri);
}
.result-appno:empty { display: none; }
.status-badge {
  display: inline-block; vertical-align: middle; margin-left: 12px;
  font-size: 13px; font-weight: 600; line-height: 1;
  padding: 6px 12px; border-radius: var(--r-pill);
  border: 1px solid var(--line); background: var(--paper-soft); color: var(--muted);
}
.status-badge.is-loading, .status-badge.reviewing {
  background: #e3f2fd; color: #1565c0; border-color: rgba(21,101,192,.3);
}
.status-badge.is-loading { animation: badgePulse 1.4s ease-in-out infinite; }
@keyframes badgePulse { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }
.status-badge.pass { background: var(--pri-bg); color: var(--good); border-color: rgba(18,138,110,.4); }
.status-badge.fail { background: var(--bad-bg); color: var(--bad); border-color: rgba(231,76,60,.42); }
.status-badge.timeout { background: #fff3e0; color: #e65100; border-color: rgba(230,81,0,.3); }

/* 審查總覽：卡片式儀表板 */
.overview-card {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm); padding: 20px 24px; margin: 8px 0 16px;
}
.overview-card h2 { margin: 0 0 16px; font-size: 1.15rem; }
.overview-stats { display: flex; align-items: center; gap: 28px; margin-bottom: 18px; }
.ov-stat { display: flex; flex-direction: column; gap: 2px; }
.ov-num { font-size: 2.2rem; font-weight: 700; line-height: 1; color: var(--pri); font-variant-numeric: tabular-nums; }
.ov-label { font-size: 13px; color: var(--muted); }
.ov-divider { align-self: stretch; width: 1px; background: var(--hairline); }
.ov-bar {
  display: flex; height: 10px; border-radius: var(--r-pill);
  overflow: hidden; background: var(--paper-soft); margin-bottom: 14px;
}
.ov-seg { flex-basis: 0; min-width: 0; }
.ov-seg.pass { background: var(--good); }
.ov-seg.fail { background: var(--bad); }
.ov-seg.uncertain { background: var(--uncertain); }
.ov-seg.skip { background: var(--skip); }
.ov-legend { display: flex; flex-wrap: wrap; gap: 18px; }
.ov-leg { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); }
.ov-leg .dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.ov-leg.pass .dot { background: var(--good); }
.ov-leg.fail .dot { background: var(--bad); }
.ov-leg.uncertain .dot { background: var(--uncertain); }
.ov-leg.skip .dot { background: var(--skip); }
.ov-leg b { font-size: 15px; font-weight: 700; color: var(--fg); font-variant-numeric: tabular-nums; }

.btn-download-report {
  margin-left: auto; padding: 6px 14px; background: var(--pri); color: #fff;
  border: 0; border-radius: var(--r-sm); cursor: pointer; font-size: 13px;
  font-weight: 600; white-space: nowrap;
  transition: background var(--ease), box-shadow var(--ease);
}
.btn-download-report:hover { background: var(--pri-hover); box-shadow: var(--shadow-sm); }
.btn-download-report:disabled { opacity: .5; cursor: wait; }

/* 結果頁 toolbar：下拉標籤 */
.ctrl-field { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
/* 篩選提示：獨立最後一行 */
#filter-indicator { display: block; margin: 8px 0 4px; }

.rule-result { margin: 16px 0; }

/* 規則明細卡：左欄識別軌 + 右欄內容 */
.detail-card {
  display: grid; grid-template-columns: 128px 1fr;
  background: var(--paper); border-left: 3px solid var(--line);
  padding: 16px 18px; margin: 10px 0; border-radius: var(--r-sm);
}
.detail-card.pass { border-left-color: var(--good); }
.detail-card.fail { border-left-color: var(--bad); background: rgba(231,76,60,.055); }
.detail-card.uncertain { border-left-color: var(--uncertain); background: rgba(100,112,121,.05); }
.detail-card.skip { border-left-color: var(--skip); opacity: .8; }

/* 左欄：判定 / 規則代碼 / 判讀類型（由上而下） */
.dc-rail {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  padding-right: 16px; border-right: 1px solid var(--hairline);
}
.dc-rail .verdict-badge { white-space: nowrap; }
.dc-rail .rule-code {
  font-family: ui-monospace, monospace; font-weight: 700; font-size: 13px; color: var(--pri-hover);
}
.dc-rail .rule-type { font-size: 12px; color: var(--muted); }

/* 右欄：主旨 + 來源 + 檢查 + 擷取值 + 說明/推論 */
.dc-body { min-width: 0; padding-left: 16px; }
.dc-title { font-size: 15px; font-weight: 600; color: var(--fg); line-height: 1.45; }
.dc-meta { margin-top: 4px; font-size: 12px; color: var(--muted); word-break: break-all; }

/* 窄螢幕：改為上下堆疊，左欄轉為橫向 */
@media (max-width: 560px) {
  .detail-card { grid-template-columns: 1fr; }
  .dc-rail {
    flex-direction: row; align-items: center; gap: 10px;
    padding: 0 0 10px; margin-bottom: 10px;
    border-right: 0; border-bottom: 1px solid var(--hairline);
  }
  .dc-body { padding-left: 0; }
}

/* 判定 badge（四狀態，沿用全站描邊膠囊語言） */
.verdict-badge {
  display: inline-block; font-size: 12px; font-weight: 700; line-height: 1;
  padding: 4px 10px; border-radius: var(--r-pill); border: 1px solid transparent; white-space: nowrap;
}
.verdict-badge.pass { background: var(--pri-bg); color: var(--good); border-color: rgba(18,138,110,.4); }
.verdict-badge.fail { background: var(--bad-bg); color: var(--bad); border-color: rgba(231,76,60,.42); }
.verdict-badge.uncertain { background: var(--paper-soft); color: var(--uncertain); border-color: var(--line); }
.verdict-badge.skip { background: var(--paper-soft); color: var(--skip); border-color: var(--line); }

/* 擷取值：資料才用等寬；有值才顯示 */
.dc-extracted {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  margin: 10px 0; padding: 8px 12px; background: var(--paper-soft);
  border: 1px solid var(--hairline); border-radius: var(--r-sm);
}
.dc-field-label { font-size: 11px; font-weight: 700; color: var(--muted); flex-shrink: 0; }
.dc-extracted code { font-family: ui-monospace, monospace; font-size: 13px; color: var(--fg); word-break: break-word; }

/* 規則說明 / AI 推論：可讀內文（非等寬） */
.dc-reason { margin: 8px 0 0; }
.dc-reason > summary {
  cursor: pointer; font-size: 13px; font-weight: 600; color: var(--pri);
  padding: 4px 0; user-select: none;
}
.dc-reason > summary:hover { color: var(--pri-hover); }
.dc-prose {
  margin-top: 6px; font-size: 14px; line-height: 1.7; color: var(--fg);
  white-space: pre-wrap; word-break: break-word;
  background: var(--paper-soft); border-radius: var(--r-sm); padding: 12px 14px;
  max-height: 320px; overflow-y: auto;
}
/* 子檢查的狀態小標（沿用） */
.status-tag { font-weight: 700; }

.files-progress { margin: 16px 0; padding: 12px; background: var(--paper); border: 1px solid var(--line); border-radius: 6px; }
.files-progress h2 { font-size: 14px; margin: 0 0 8px 0; color: var(--muted); font-weight: 600; }
/* 整體進度列：檔案審查 N/M → 彙整比對 X/Y（issue #5 進度可視化） */
.overall-progress { margin: 0 0 10px 0; }
.overall-progress .op-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.overall-progress .op-label { font-size: 13px; color: var(--fg); font-weight: 600; }
.overall-progress .op-count { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.overall-progress .op-track { margin-top: 6px; height: 8px; border-radius: 4px; background: var(--paper-soft); border: 1px solid var(--hairline); overflow: hidden; }
.overall-progress .op-fill { height: 100%; width: 0%; background: var(--pri); border-radius: 4px; transition: width .4s ease; }
.overall-progress .op-warn { margin: 6px 0 0 0; font-size: 12px; color: var(--warn); background: var(--warn-bg); border-radius: 4px; padding: 4px 8px; }
.files-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.file-card {
  padding: 8px 12px; background: var(--paper-soft); border: 1px solid var(--line); border-radius: 4px;
  font-size: 13px; transition: border-color .2s;
}
.file-card .file-name {
  font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.file-card .file-stage { color: var(--muted); font-size: 12px; margin-top: 2px; }
.file-card.ocr { border-color: var(--warn); }
.file-card.ocr .file-stage { color: var(--warn); }
.file-card.review { border-color: var(--pri); }
.file-card.review .file-stage { color: var(--pri); }
.file-card.done { border-color: var(--good); background: var(--pri-bg); }
.file-card.done .file-stage { color: var(--good); }

.rule-result.live {
  background: var(--paper); border: 1px solid var(--line); border-left: 3px solid var(--pri);
  border-radius: var(--r); padding: 14px 16px; box-shadow: var(--shadow-sm);
}
.rule-result.live h3 { margin: 0 0 8px; font-size: 15px; line-height: 1.4; }
.rule-result.live h3::after { content: " · 即時"; color: var(--pri); font-size: 12px; font-weight: normal; }

.dz-files .dz-row {
  display: flex; align-items: center; gap: 8px; padding: 4px 0;
}
.dz-files .dz-row .dz-meta { flex: 1; }
.dz-files .dz-row .dz-remove {
  background: transparent; border: 0; color: var(--bad); cursor: pointer;
  font-size: 14px; padding: 2px 6px; border-radius: 3px;
}
.dz-files .dz-row .dz-remove:hover { background: var(--bad-bg); }
.dz-files li.warn { color: var(--warn); }

/* 產品特性勾選區（影響條件式規則觸發） */
.product-attrs { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin-bottom: 16px; }
.product-attrs legend { font-weight: 700; padding: 0 8px; }
.attrs-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 8px; margin: 8px 0; }
.attr-checkbox {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px;
  border-radius: var(--r-sm); cursor: pointer;
  font-size: 14px; color: var(--fg); user-select: none;
}
.attr-checkbox:hover { background: var(--paper-soft); }
/* 與 toolbar 勾選框一致：青綠 accent */
.attr-checkbox input[type=checkbox] { accent-color: var(--pri); cursor: pointer; margin: 0; }
.product-attrs .hint { display: block; margin-top: 8px; color: var(--muted, #666); font-size: 12px; }

/* Result 頁規則 header：分代碼 + 數量 + 描述 */
.badge-optional {
  display: inline-block; white-space: nowrap;
  font-size: 11px; font-weight: 600; color: var(--muted, #888);
  border: 1px solid var(--line); border-radius: 3px; padding: 0 6px; margin-left: 6px;
}
.rule-result h3 .rule-code { font-family: ui-monospace, monospace; font-weight: 700; color: var(--pri-hover); }
.rule-result h3 .rule-field {
  font-weight: 600; color: var(--fg); margin-left: 8px;
}
.rule-result h3 .rule-type {
  font-weight: 400; font-size: 11px; color: var(--muted);
  border: 1px solid var(--line); border-radius: var(--r-pill); padding: 2px 8px; margin-left: 8px;
}
.rule-result h3 .rule-count { color: var(--muted); font-size: 0.9em; margin-left: 6px; }
.rule-result h3 .rule-desc { display: block; font-weight: 400; font-size: 13px; color: var(--muted); margin-top: 6px; line-height: 1.6; }
.detail-card details[open] pre { white-space: pre-wrap; word-break: break-word; max-height: 200px; overflow-y: auto; }

/* 逐子項拆解：① 是否填寫 / ② 是否與 EPEAT 一致 … 各自標狀態 */
.rule-checks { list-style: none; margin: 10px 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.check-row {
  display: grid; grid-template-columns: 1.5em auto 1fr; gap: 4px 10px;
  align-items: baseline; padding: 8px 12px; border-radius: var(--r-sm);
  border-left: 3px solid var(--line); background: var(--paper-soft);
  font-size: 13.5px;
}
.check-row.pass { border-left-color: var(--good); }
.check-row.fail { border-left-color: var(--bad); }
.check-row.uncertain { border-left-color: var(--uncertain); }
.check-row .status-tag { font-size: 12px; }
.check-row.pass .status-tag { color: var(--good); }
.check-row.fail .status-tag { color: var(--bad); }
.check-row.uncertain .status-tag { color: var(--uncertain); }
.check-row .check-no { color: var(--muted); font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.check-row .check-label { font-weight: 600; color: var(--fg); }
.check-row .check-reason {
  grid-column: 2 / -1; color: var(--muted); line-height: 1.65; margin-top: 2px;
}

/* ---- 結果頁：文件分組 ---- */
.doc-group {
  margin: 14px 0; background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--r); overflow: hidden; box-shadow: var(--shadow-sm);
}
.doc-group[open] { border-color: var(--pri-soft); }
.doc-group-header {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 14px 16px; cursor: pointer; user-select: none;
  font-size: 15px; transition: background .12s;
}
.doc-group-header:hover { background: var(--paper-soft); }
.doc-group-header .doc-code {
  font-weight: 700; color: var(--pri); font-family: ui-monospace, monospace;
  font-size: 16px; min-width: 3em;
}
.doc-group-header .doc-name { font-weight: 600; color: var(--fg); }
.doc-group-header .doc-stats { margin-left: auto; display: flex; gap: 8px; font-size: 13px; }
.doc-group-header .stat-pass { color: var(--good); font-weight: 600; }
.doc-group-header .stat-fail { color: var(--bad); font-weight: 700; }
.doc-group-header .stat-uncertain { color: var(--uncertain); font-weight: 600; }
.doc-group-header .stat-skip { color: var(--skip); }
.doc-group-header .doc-count { color: var(--muted); font-size: 12px; white-space: nowrap; }
.doc-group > .detail-card { margin: 0; border-radius: 0; border-top: 1px solid var(--hairline); }
.doc-group > .detail-card .detail-meta { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ---- 規則列表頁 ---- */
.rules-head {
  display: flex; justify-content: space-between; align-items: flex-end;
  flex-wrap: wrap; gap: 12px; margin-bottom: 16px;
}
.rules-head h1 { margin: 0; }
/* 規則頁：標題本身即產品類別下拉 —— 無框線，右側保留箭頭 */
.title-select {
  appearance: none; -webkit-appearance: none;
  margin: 0; padding: 0 36px 0 0;
  border: 0; background-color: transparent;
  font-family: inherit; font-size: 1.75rem; font-weight: 700; line-height: 1.25;
  letter-spacing: -.01em;
  color: var(--fg); cursor: pointer; max-width: 100%;
  vertical-align: baseline;
  /* 右側自訂箭頭（環境部青綠 chevron） */
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23007a96' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat; background-position: right center; background-size: 24px 24px;
}
.title-select:hover { color: var(--pri); }
.title-select:focus-visible { outline: 2px solid var(--pri-soft); outline-offset: 4px; border-radius: 4px; }
.cat-switch { font-size: 13px; color: var(--muted); }
.cat-switch select {
  display: block; margin-top: 4px; font: inherit; padding: 6px 10px;
  border: 1px solid var(--line); border-radius: 4px;
  background: var(--paper); color: var(--fg); min-width: 220px;
}
.rules-controls {
  display: flex; align-items: center; gap: 12px; margin: 14px 0 8px; flex-wrap: wrap;
}
.rules-controls input[type="search"] {
  flex: 1 1 280px; padding: 10px 14px; font: inherit;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--paper); color: var(--fg);
  transition: border-color var(--ease), box-shadow var(--ease);
}
/* toolbar 內的下拉（例：首頁狀態篩選）—— 與搜尋框同高、同框、同圓角 */
.rules-controls select {
  padding: 10px 14px; font: inherit; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--paper); color: var(--fg); min-width: 180px;
  transition: border-color var(--ease), box-shadow var(--ease);
}
/* 分類勾選列（toolbar 下一行） */
.rules-filters {
  display: flex; align-items: center; gap: 18px;
  margin: 10px 0 2px; flex-wrap: wrap;
}
/* toolbar 內的分類勾選框 */
.filter-check {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 14px; color: var(--fg); cursor: pointer;
  user-select: none; white-space: nowrap;
}
.filter-check input { accent-color: var(--pri); cursor: pointer; margin: 0; }
.filter-check strong { color: var(--muted); font-weight: 600; }
/* 搜尋按鈕 */
.btn-search {
  padding: 10px 20px; font: inherit; font-weight: 600; cursor: pointer;
  background: var(--pri); color: #fff; border: 0; border-radius: var(--r-sm);
  box-shadow: var(--shadow-sm);
  transition: background var(--ease), box-shadow var(--ease), transform var(--ease);
}
.btn-search:hover { background: var(--pri-hover); box-shadow: var(--shadow-md); }
.btn-search:active { transform: translateY(1px); }
/* 顯示筆數：獨立一行，位於 toolbar 下方 */
#rules-shown { display: block; margin: 6px 0 12px; }
.rules-table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--r); overflow: hidden; font-size: 14px;
  box-shadow: var(--shadow-sm);
}
.rules-table thead th {
  background: var(--pri-bg); color: var(--pri-hover); text-align: left;
  padding: 12px 14px; font-weight: 700; font-size: 12.5px;
  letter-spacing: .02em; white-space: nowrap;
  border-bottom: 2px solid var(--pri-soft);
}
.rules-table tbody td {
  padding: 12px 14px; border-top: 1px solid var(--hairline); vertical-align: top;
}
.rules-table tbody tr:first-child td { border-top: 0; }
.rules-table tbody tr { transition: background var(--ease); }
.rules-table tbody tr:hover { background: var(--pri-bg); }
.rules-table .code-cell strong { color: var(--pri-hover); white-space: nowrap; }
.rules-table .muted-cell { color: var(--muted); }
.rules-table .empty-cell { text-align: center; color: var(--muted); padding: 24px; }
.docs-cell { line-height: 1.9; }
.doc-chip {
  display: inline-block; padding: 2px 9px; border-radius: var(--r-pill); font-size: 12px;
  background: var(--pri-bg); border: 1px solid var(--pri-soft); color: var(--pri-hover);
  white-space: nowrap;
}
.vt-chip {
  display: inline-block; padding: 2px 9px; border-radius: var(--r-pill); font-size: 12px;
  background: var(--paper-soft); border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
/* required 標籤（沿用 upload 頁的語意配色）—— 統一皆帶邊框，框色隨語意 */
.rule-req {
  display: inline-block; padding: 2px 9px; border-radius: var(--r-pill);
  font-size: 12px; font-weight: 700; white-space: nowrap;
  border: 1px solid transparent;
}
.rule-req.required { background: var(--pri-bg); color: var(--pri-hover); border-color: var(--pri-soft); }
.rule-req.optional { background: var(--paper-soft); color: var(--muted); border-color: var(--line); }
.rule-req.conditional { background: var(--warn-bg); color: var(--warn); border-color: rgba(199,119,0,.38); }
/* 規則頁「必填」/ 文件頁「必附」欄：淡紅底 + 紅字 + 淡紅框（不影響 AI 審查欄的「是」） */
.req-cell .rule-req.required { background: var(--bad-bg); color: var(--bad); border-color: rgba(231,76,60,.42); }

/* ===== 保密文件填寫 event page（/doc-fill，獨立、無側欄） ===== */
.doc-fill-page { max-width: 720px; margin: 0 auto; }
.doc-fill-head { margin-bottom: 20px; }
.doc-fill-head .hint { margin: 6px 0 0; }
.field-rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.field-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr) 34px; gap: 8px; align-items: center; }
.field-row input { padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--r-sm); }
.remove-field-btn {
  height: 34px; border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--paper); color: var(--muted); cursor: pointer;
  transition: color var(--ease), border-color var(--ease);
}
.remove-field-btn:hover { color: var(--bad); border-color: var(--bad); }
.ghost-btn {
  padding: 7px 14px; border: 1px dashed var(--pri-soft); border-radius: var(--r-sm);
  background: var(--pri-bg); color: var(--pri); font-weight: 600; cursor: pointer;
  transition: border-color var(--ease), background var(--ease);
}
.ghost-btn:hover { border-color: var(--pri); }
.doc-fill-page fieldset > label { display: block; margin: 10px 0; font-weight: 600; }
.doc-fill-page fieldset > label input[type="text"],
.doc-fill-page fieldset > label input[type="file"] {
  display: block; width: 100%; margin-top: 5px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: var(--r-sm); font-weight: 400;
}
.doc-fill-options { display: flex; gap: 20px; margin-top: 10px; flex-wrap: wrap; }
.doc-fill-options .attr-checkbox { display: flex; align-items: center; gap: 6px; cursor: pointer; }
#fill-status.status-error { color: var(--bad); }
.doc-fill-result {
  background: var(--paper); border: 1px solid var(--line); border-radius: 8px;
  padding: 16px; margin-top: 4px;
}
.doc-fill-result h2 { margin: 0 0 8px; font-size: 1.05rem; }
.doc-fill-result ul { margin: 0; padding-left: 20px; color: var(--fg); }
.doc-fill-result li { margin: 3px 0; }

/* ====================================================================
   RWD — 行動裝置適應
   ==================================================================== */

/* 漢堡按鈕（桌面隱藏） */
.sidebar-toggle {
  display: none; position: fixed; top: 12px; left: 12px; z-index: 1100;
  width: 40px; height: 40px; border: 0; border-radius: var(--r-sm);
  background: var(--paper); color: var(--fg); cursor: pointer;
  box-shadow: var(--shadow-sm); align-items: center; justify-content: center;
}
.sidebar-toggle:hover { background: var(--paper-soft); }

/* 背景遮罩 */
.sidebar-backdrop {
  display: none; position: fixed; inset: 0; z-index: 999;
  background: rgba(0,0,0,.4); opacity: 0; transition: opacity .2s;
}
.sidebar-backdrop.open { display: block; opacity: 1; }

/* ---- 768px 以下：��欄變抽屜 ---- */
@media (max-width: 768px) {
  .sidebar-toggle { display: flex; }

  .sidebar {
    position: fixed; top: 0; left: 0; z-index: 1000;
    transform: translateX(-100%);
    transition: transform .25s cubic-bezier(.4,0,.2,1);
    width: 260px; height: 100vh; height: 100dvh;
    box-shadow: var(--shadow-pop);
  }
  .sidebar.open { transform: translateX(0); }

  .container { max-width: 100%; margin: 16px auto; padding: 0 14px; padding-top: 52px; }

  /* 審查總覽 */
  .overview-card { padding: 14px 12px; }
  .overview-stats { flex-wrap: wrap; gap: 14px 20px; }
  .ov-num { font-size: 1.7rem; }
  .ov-divider { display: none; }
  .ov-legend { gap: 10px; }

  /* 結果排序控制��� */
  .result-controls { flex-wrap: wrap; gap: 8px; }

  /* 文件分組標題 */
  .doc-group-header { padding: 12px 10px; gap: 6px; }
  .doc-group-header .doc-stats { margin-left: 0; flex-basis: 100%; justify-content: flex-start; gap: 12px; }
  .doc-group-header .doc-code { font-size: 14px; min-width: 2.5em; }

  /* 規則明細卡 */
  .detail-card { padding: 12px 10px; }
  .dc-body { padding-left: 12px; }

  /* 檔案進度 grid */
  .files-grid { grid-template-columns: 1fr; }

  /* 標題文字 */
  h1 { font-size: 1.35rem; }
  .result-appno { display: block; margin: 4px 0 0; font-size: .9rem; }
  .status-badge { margin-left: 0; margin-top: 8px; }

  /* 首頁卡片 */
  .card-grid { grid-template-columns: 1fr; }

  /* 產���特性 */
  .attrs-grid { grid-template-columns: 1fr; }

  /* 規則列表 toolbar */
  .rules-controls { flex-wrap: wrap; gap: 8px; }
  .rules-controls input[type="search"] { flex: 1 1 100%; }
  .rules-controls select { min-width: 0; flex: 1 1 calc(50% - 4px); }
  .btn-download-report { margin-left: 0; flex: 1 1 100%; text-align: center; }
}

/* ---- 480px 以下：極窄螢幕加強 ---- */
@media (max-width: 480px) {
  .container { padding: 0 10px; padding-top: 52px; }
  .overview-stats { gap: 10px 16px; }
  .ov-num { font-size: 1.4rem; }
  .detail-card { grid-template-columns: 1fr; padding: 10px 8px; }
  .dc-rail {
    flex-direction: row; align-items: center; gap: 8px;
    padding: 0 0 8px; margin-bottom: 8px;
    border-right: 0; border-bottom: 1px solid var(--hairline);
  }
  .dc-body { padding-left: 0; }
  .dc-extracted { padding: 6px 8px; gap: 6px; }
  .check-row { padding: 6px 8px; font-size: 13px; }
  .doc-group-header .doc-name { font-size: 14px; }
  .btn-download-report { width: 100%; text-align: center; margin-top: 10px; }
}
