/* Anvil Web 入口樣式（add-web-portal D6；update-portal-visual-design D1–D5）。
   伺服器端渲染＋少量原生 JS，無外部資源：字型自帶於 static/fonts/。
   變數名稱是三張卡共用的契約（design D2）：student.css／console.css 只引用、不新增全域變數。
   主題（D3）：:root 是淺色；作業系統深色且未手動選淺色時用深色；data-theme="dark" 強制深色。
   兩組色值的文字對比由 tests/test_theme.py 檢查（INV-UI-3，≥ 4.5:1）。 */

@font-face {
  font-family: "Public Sans";
  src: url("fonts/public-sans-latin-wght.woff2") format("woff2");
  font-weight: 100 900; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("fonts/jetbrains-mono-latin-wght.woff2") format("woff2");
  font-weight: 100 800; font-style: normal; font-display: swap;
}

:root {
  color-scheme: light;
  --ground: #f9fafb;
  --surface: #ffffff;
  --raised: #f3f4f6;
  --border: #e8e8e8;
  --rule: #f0f0f0;
  --control: #d1d5db;
  --text: #111111;
  --muted: #5f6368;
  --accent: #1d5fbf;
  --primary-bg: #1d1f20;
  --primary-ink: #ffffff;
  --positive: #247b50;
  --negative: #c4242a;
  --warning: #92400e;
  --pill-positive-bg: #dcfae5; --pill-positive-ink: #04250e;
  --pill-negative-bg: #ffedea; --pill-negative-ink: #831c1e;
  --pill-warning-bg: #fffbeb;  --pill-warning-ink: #92400e;
  --pill-neutral-bg: #f3f4f6;  --pill-neutral-ink: #374151;
  --pill-info-bg: #e8f0fb;     --pill-info-ink: #1a4a8f;

  /* 字型、字級、圓角、間距（D2）：兩種主題相同 */
  --font: "Public Sans", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
  --fs-title: 24px; --fs-section: 16px; --fs-body: 14px; --fs-small: 12px; --fs-clock: 32px;
  --radius-card: 6px; --radius-control: 6px; --radius-chip: 4px;
  --gap: 16px; --card-pad: 20px; --pad: 32px;
  --content-max: 1152px; --bar-height: 48px; --control-height: 36px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --ground: #171719;
    --surface: #131217;
    --raised: #212023;
    --border: #2a292e;
    --rule: #1f1e23;
    --control: #3a3a3e;
    --text: #f2f2f3;
    --muted: #9a9ca2;
    --accent: #4a8ad6;
    --primary-bg: #f2f2f3;
    --primary-ink: #131217;
    --positive: #5fc39c;
    --negative: #e5566f;
    --warning: #d9a441;
    --pill-positive-bg: #1b2828; --pill-positive-ink: #5fc39c;
    --pill-negative-bg: #2c1a20; --pill-negative-ink: #e5566f;
    --pill-warning-bg: #2a2416;  --pill-warning-ink: #d9a441;
    --pill-neutral-bg: #212023;  --pill-neutral-ink: #bdbdc0;
    --pill-info-bg: #1a2433;     --pill-info-ink: #7fb0ea;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --ground: #171719;
  --surface: #131217;
  --raised: #212023;
  --border: #2a292e;
  --rule: #1f1e23;
  --control: #3a3a3e;
  --text: #f2f2f3;
  --muted: #9a9ca2;
  --accent: #4a8ad6;
  --primary-bg: #f2f2f3;
  --primary-ink: #131217;
  --positive: #5fc39c;
  --negative: #e5566f;
  --warning: #d9a441;
  --pill-positive-bg: #1b2828; --pill-positive-ink: #5fc39c;
  --pill-negative-bg: #2c1a20; --pill-negative-ink: #e5566f;
  --pill-warning-bg: #2a2416;  --pill-warning-ink: #d9a441;
  --pill-neutral-bg: #212023;  --pill-neutral-ink: #bdbdc0;
  --pill-info-bg: #1a2433;     --pill-info-ink: #7fb0ea;
}

/* ---- 基礎 ---- */
*, *::before, *::after { box-sizing: border-box; }
[hidden], .hidden { display: none !important; }   /* .badge 等 display 規則不得蓋掉 hidden（卡 B 倒數到期切換） */
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground); color: var(--text);
  font-family: var(--font); font-size: var(--fs-body); line-height: 20px;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1 { font-size: var(--fs-title); line-height: 32px; font-weight: 600; margin: 0 0 16px; letter-spacing: -0.01em; }
h2 { font-size: var(--fs-section); line-height: 24px; font-weight: 600; margin: 24px 0 8px; }
h3 { font-size: var(--fs-body); line-height: 20px; font-weight: 600; margin: 16px 0 8px; }
h1 small, h2 small { font-size: var(--fs-body); font-weight: 400; color: var(--muted); }
p { margin: 0 0 12px; }
ul, ol { margin: 0 0 12px; padding-left: 20px; }
code, pre, kbd, samp, .mono { font-family: var(--font-mono); font-size: 13px; }
code { overflow-wrap: normal; }
pre {
  background: var(--raised); color: var(--text); border-radius: var(--radius-control);
  padding: 12px 16px; margin: 8px 0; overflow-x: auto; white-space: pre; line-height: 20px;
}
pre code { font-size: inherit; }
::selection { background: var(--accent); color: var(--surface); }

/* ---- 外殼：48px 頂列＋置中欄（D5） ---- */
.topbar { background: var(--ground); border-bottom: 1px solid var(--border); position: relative; z-index: 2; }
.topbar-inner {
  max-width: calc(var(--content-max) + 2 * var(--pad)); margin: 0 auto; padding: 0 var(--pad);
  height: var(--bar-height); display: flex; align-items: center; gap: 32px;
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-weight: 600; font-size: 15px; white-space: nowrap; flex: none; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 24px; height: 24px; display: inline-grid; place-items: center; flex: none;
  border: 1px solid var(--accent); border-radius: var(--radius-chip); color: var(--accent);
  font-family: var(--font-mono); font-size: 13px; font-weight: 600; line-height: 1;
}
.nav { display: flex; align-items: stretch; gap: 24px; height: 100%; }
.nav a {
  position: relative; display: inline-flex; align-items: center; height: 100%;
  color: var(--muted); white-space: nowrap;
}
.nav a:hover { color: var(--text); text-decoration: none; }
/* 選取的一致做法（D1）：文字轉主要色＋與文字等寬、貼在頂列下緣的 1px 強調色線 */
.nav a[aria-current="page"] { color: var(--text); }
.nav a[aria-current="page"]::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px; background: var(--accent); }
.bar-tools { margin-left: auto; display: flex; align-items: center; gap: 16px; white-space: nowrap; min-width: 0; }
.who { color: var(--text); min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.who .role { color: var(--muted); }
.bar-tools form { margin: 0; }

/* 主題切換：停用 JS 時隱藏（<html class="js"> 由 head 裡的主題腳本加上） */
.theme-toggle { display: none; }
.js .theme-toggle { display: inline-flex; }
.theme-toggle { min-height: 32px; padding: 0 10px; font-weight: 400; }

/* 手機選單（<details>，不需 JS 也能開）：桌面隱藏 */
.menu { display: none; }
.menu > summary {
  list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 8px;
  height: var(--control-height); padding: 0 12px; border: 1px solid var(--control); border-radius: var(--radius-control);
  color: var(--text);
}
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary::after { content: ""; width: 6px; height: 6px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: translateY(-2px) rotate(45deg); }
.menu[open] > summary::after { transform: translateY(2px) rotate(-135deg); }
.menu-panel {
  position: absolute; left: 0; right: 0; top: var(--bar-height);
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 8px 16px 16px; box-shadow: 0 12px 28px rgba(0, 0, 0, .2);
}
.menu-panel .nav { flex-direction: column; align-items: stretch; gap: 0; height: auto; }
.menu-panel .nav a[aria-current="page"]::after { content: none; }
.menu-panel .nav a { display: flex; align-items: center; min-height: 44px; color: var(--muted); border-bottom: 1px solid var(--rule); }
.menu-panel .nav a[aria-current="page"] { color: var(--text); font-weight: 600; }
.menu-panel .nav a[aria-current="page"]::before { content: ""; width: 1px; align-self: stretch; margin: 10px 11px 10px 0; background: var(--accent); }
.menu-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; padding-top: 12px; }

.page {
  width: 100%; max-width: calc(var(--content-max) + 2 * var(--pad));
  margin: 0 auto; padding: 32px var(--pad) 48px;
}
.foot {
  width: 100%; max-width: calc(var(--content-max) + 2 * var(--pad)); margin: 0 auto;
  padding: 0 var(--pad) 32px; color: var(--muted); font-size: 13px;
}

/* ---- 共用類別（D4） ---- */
.muted, .meta { color: var(--muted); }
.meta { font-size: var(--fs-small); }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.stack { display: flex; flex-direction: column; gap: var(--gap); }
.stack > * { margin-top: 0; margin-bottom: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--gap); align-items: start; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr)); gap: var(--gap); }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card);
  padding: var(--card-pad); margin: 0 0 var(--gap); min-width: 0;
}
.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }
.card.narrow { max-width: 400px; margin: 48px auto; }
.cards { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); gap: var(--gap); }
.cards .card { margin: 0; }
.cards h2 { margin: 0 0 4px; }
.card.task.disabled { opacity: 0.7; }

.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 24px; margin: 8px 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; min-width: 0; }
.steps li { margin-bottom: 8px; }
.timeline { list-style: none; padding: 0; }
.timeline .card { margin-bottom: 12px; }
.list { columns: 2; column-gap: 32px; padding-left: 20px; }
details > summary { cursor: pointer; color: var(--accent); }
.countdown strong { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-weight: 500; }

/* ---- 表格：規則線與對齊，無斑馬紋、無表頭底色。不可把 thead／tbody／tr 設成 display: table
   （每列自己算欄寬，表頭對不齊；測試站 11/01 回報 B1） ---- */
.table, table.fixed { width: 100%; border-collapse: collapse; margin: 8px 0; }
table.fixed { table-layout: fixed; }
.table th, .table td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--rule); vertical-align: top; }
.table th { color: var(--muted); font-weight: 400; font-size: var(--fs-small); line-height: 16px; border-bottom-color: var(--border); }
.table th.num, .table td.num { text-align: right; }
.table td:first-child, .table th:first-child { padding-left: 0; }
.table td:last-child, .table th:last-child { padding-right: 0; }

/* ---- 表單與按鈕：唯一主要按鈕反白（.primary），其餘為外框按鈕 ---- */
.form { display: grid; gap: 16px; margin: 8px 0; max-width: 40rem; }
.form label { display: grid; gap: 8px; font-weight: 500; }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--surface);
  min-height: var(--control-height); padding: 7px 10px; width: 100%;
  border: 1px solid var(--control); border-radius: var(--radius-control);
}
textarea { min-height: 96px; line-height: 20px; }
input::placeholder, textarea::placeholder { color: var(--muted); }
button, .button {
  font: inherit; font-weight: 500; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--control-height); padding: 0 14px; cursor: pointer; white-space: nowrap;
  background: var(--surface); color: var(--text); border: 1px solid var(--control); border-radius: var(--radius-control);
  text-decoration: none;
}
button:hover, .button:hover { background: var(--raised); text-decoration: none; }
button.primary, .button.primary, button[type="submit"].primary { background: var(--primary-bg); color: var(--primary-ink); border-color: var(--primary-bg); }
button.primary:hover, .button.primary:hover { background: var(--primary-bg); opacity: 0.9; }
button.danger, .button.danger { color: var(--negative); border-color: var(--negative); background: transparent; }
button.link {
  background: none; border: 0; min-height: 0; padding: 0; color: var(--accent); font-weight: 400;
}
button.link:hover { background: none; text-decoration: underline; }
button:disabled, .button.disabled, button:disabled:hover { opacity: 0.55; cursor: not-allowed; background: var(--surface); }
.inline { display: inline; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 16px; }
form.danger { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }

/* ---- 狀態標記（INV-UI-2：一定有文字，顏色只是輔助） ---- */
.status, .badge {
  display: inline-flex; align-items: center; flex: none; white-space: nowrap; vertical-align: middle;
  height: 20px; padding: 0 6px; border-radius: var(--radius-chip);
  font-size: var(--fs-small); font-weight: 500; line-height: 1;
  background: var(--pill-neutral-bg); color: var(--pill-neutral-ink);
}
[data-status="positive"] { background: var(--pill-positive-bg); color: var(--pill-positive-ink); }
[data-status="negative"] { background: var(--pill-negative-bg); color: var(--pill-negative-ink); }
[data-status="warning"]  { background: var(--pill-warning-bg);  color: var(--pill-warning-ink); }
[data-status="info"]     { background: var(--pill-info-bg);     color: var(--pill-info-ink); }
[data-status="neutral"]  { background: var(--pill-neutral-bg);  color: var(--pill-neutral-ink); }

/* 標示（規劃目標／系統評估／已驗證／示意資料；add-web-portal D5） */
.claim {
  display: inline-block; max-width: 100%; vertical-align: middle; padding: 0 6px; line-height: 20px;
  border-radius: var(--radius-chip); font-size: var(--fs-small); background: var(--pill-neutral-bg); color: var(--pill-neutral-ink);
}
.claim-verified { background: var(--pill-positive-bg); color: var(--pill-positive-ink); }
.claim-planned { background: var(--pill-warning-bg); color: var(--pill-warning-ink); }
.claim-demo { background: var(--pill-info-bg); color: var(--pill-info-ink); }

/* ---- 提醒（notice 巨集）與舊的 .alert／.ok ---- */
.notice {
  background: var(--raised); border: 1px solid var(--border); border-radius: var(--radius-card);
  padding: 12px 16px; margin: 0 0 var(--gap);
}
.notice > :last-child { margin-bottom: 0; }
.notice h2 { font-size: var(--fs-body); margin: 0 0 8px; }
.notice-info { background: var(--pill-info-bg); border-color: transparent; color: var(--text); }
.notice-positive, .ok { background: var(--pill-positive-bg); border-color: transparent; color: var(--pill-positive-ink); }
.notice-warning { background: var(--pill-warning-bg); border-color: transparent; color: var(--pill-warning-ink); }
.notice-negative, .alert { background: var(--pill-negative-bg); border-color: transparent; color: var(--pill-negative-ink); }
.alert, .ok { border: 1px solid transparent; border-radius: var(--radius-control); padding: 10px 12px; margin: 0 0 12px; }
.notice-title { font-weight: 600; }
/* 提醒框內的連結：沿用提醒框的文字色（已過對比測試），以底線辨識；--accent 在淡色底上不保證 4.5:1 */
.notice a, .alert a, .ok a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }

/* ---- 空狀態：保留區塊，一句話 ---- */
.empty {
  color: var(--muted); border: 1px dashed var(--control); border-radius: var(--radius-card);
  padding: 9px 12px; margin: 8px 0;
}

/* ---- 可複製字串（指令、指紋、ID）：等寬、單行、區塊內橫向捲動、不在中間斷行 ---- */
.copyable {
  display: flex; align-items: stretch; min-width: 0; max-width: 100%; margin: 8px 0;
  border: 1px solid var(--border); border-radius: var(--radius-control); background: var(--raised);
}
.copyable-text {
  flex: 1 1 auto; min-width: 0; overflow-x: auto; white-space: pre; overflow-wrap: normal; word-break: normal;
  padding: 8px 12px; line-height: 20px; color: var(--text); background: none;
}
.copyable-button { display: none; flex: none; border: 0; border-left: 1px solid var(--border); border-radius: 0 var(--radius-control) var(--radius-control) 0; background: transparent; min-height: 36px; }
.js .copyable-button { display: inline-flex; }
.copyable-button[data-copied] { color: var(--positive); }

/* ---- 窄寬度：640px 以下導覽收進選單，頂列一行；左右留白 16px ---- */
@media (max-width: 960px) {
  .topbar-inner { gap: 20px; }
  .nav { gap: 16px; }
  .bar-tools { gap: 12px; }
}
@media (max-width: 720px) {
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  :root { --pad: 16px; --card-pad: 16px; }
  .topbar-inner { gap: 12px; }
  .topbar-inner > .nav, .topbar-inner > .bar-tools { display: none; }
  .no-menu .topbar-inner > .bar-tools { display: flex; }
  .menu { display: block; margin-left: auto; }
  .page { padding-top: 24px; }
  h1 { font-size: 22px; line-height: 28px; }
  button, .button, input, select { min-height: 44px; }
  button.link { min-height: 44px; }
  .facts { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .facts dt { margin-top: 8px; }
  .list { columns: 1; }
  .table { display: block; overflow-x: auto; }
}
