/* Bookeep 使用手冊共用樣式。色值取自後台 jade 主題（web/lib/theme.ts、web/app/globals.css）。
   手機優先：預設排版是 390 寬，820 起加寬、1024 起目錄放左側。 */

:root {
  --bk-primary: #3AA192;
  --bk-link: #2F8377;
  --bk-solid: #2F8377;
  --bk-solid-hover: #286F65;
  --bk-sider: #22577A;
  --bk-sider-text: #E6F4F1;
  --bk-header-bg: #F0F5F5;
  --bk-bg: #F5F5F7;
  --bk-card: #FFFFFF;
  --bk-text: #1D1D1F;
  --bk-text-2: #6E6E73;
  --bk-sep: rgba(60, 60, 67, 0.14);
  --bk-tint: #E8F4F2;
  --bk-warn-bg: #FFF6E5;
  --bk-warn-text: #7A4B00;
  --bk-shot-bg: #ECECEE;
  --bk-font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bk-link: #63A299;
    --bk-solid: #2F8377;
    --bk-sider: #17384F;
    --bk-header-bg: #242426;
    --bk-bg: #1C1C1E;
    --bk-card: #2C2C2E;
    --bk-text: #F5F5F7;
    --bk-text-2: #A1A1A6;
    --bk-sep: rgba(235, 235, 245, 0.16);
    --bk-tint: #23403C;
    --bk-warn-bg: #3A2E14;
    --bk-warn-text: #FFD58A;
    --bk-shot-bg: #242426;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bk-bg);
  color: var(--bk-text);
  font-family: var(--bk-font);
  font-size: 16px;
  line-height: 1.75;
}

a { color: var(--bk-link); text-underline-offset: 2px; }
img { max-width: 100%; height: auto; }

/* 頂部 */
.topbar {
  background: var(--bk-sider);
  color: var(--bk-sider-text);
  padding: 12px 16px;
}
.topbar .brand {
  color: #fff;
  font-weight: 600;
  font-size: 17px;
  text-decoration: none;
}
.topbar .edition { margin-left: 8px; font-size: 13px; opacity: 0.85; }
/* 只有後台 /help 那份有（sync-help.mjs 加的）：回後台首頁 */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.topbar .back { color: #fff; font-size: 15px; text-decoration: underline; white-space: nowrap; min-height: 44px; display: inline-flex; align-items: center; }

/* 目錄：手機是一列可橫向滑動的按鈕，桌面放左側 */
.toc {
  background: var(--bk-card);
  border-bottom: 1px solid var(--bk-sep);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.toc ul {
  display: flex;
  gap: 4px;
  margin: 0;
  padding: 8px 12px;
  list-style: none;
  white-space: nowrap;
}
.toc a {
  display: block;
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--bk-text);
  text-decoration: none;
  font-size: 15px;
}
.toc a[aria-current="page"] { background: var(--bk-tint); color: var(--bk-link); font-weight: 600; }

.layout { max-width: 1180px; margin: 0 auto; }

main {
  padding: 20px 16px 48px;
  min-width: 0;
}

/* 內文 */
h1 { font-size: 26px; line-height: 1.35; margin: 8px 0 12px; }
h2 {
  font-size: 21px;
  line-height: 1.4;
  margin: 40px 0 12px;
  padding-top: 8px;
  border-top: 1px solid var(--bk-sep);
  scroll-margin-top: 16px;
}
h3 { font-size: 18px; margin: 28px 0 8px; scroll-margin-top: 16px; }
section:first-of-type > h2 { border-top: 0; margin-top: 16px; }
p, ul, ol { margin: 0 0 12px; }
ul, ol { padding-left: 1.4em; }
li { margin: 4px 0; }

.lead { font-size: 17px; color: var(--bk-text); }
.note, figcaption, .muted { color: var(--bk-text-2); font-size: 14px; }

/* 誰能做 */
.role {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--bk-text-2);
}
.role b {
  display: inline-block;
  padding: 1px 10px;
  border-radius: 999px;
  background: var(--bk-tint);
  color: var(--bk-link);
  font-weight: 600;
}

/* 步驟 */
ol.step { counter-reset: step; list-style: none; padding-left: 0; }
ol.step > li {
  counter-increment: step;
  position: relative;
  padding-left: 40px;
  margin: 10px 0;
}
ol.step > li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 2px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bk-solid);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  line-height: 28px;
  text-align: center;
}

/* 截圖 */
figure.shot { margin: 16px 0 20px; }
figure.shot img {
  display: block;
  border: 1px solid var(--bk-sep);
  border-radius: 10px;
  background: var(--bk-shot-bg);
}
figure.shot.phone img { max-width: 340px; margin: 0 auto; }
figure.shot figcaption { margin-top: 6px; text-align: center; }

figure.diagram { margin: 16px 0 20px; }
figure.diagram img { display: block; width: 100%; max-width: 420px; margin: 0 auto; }

/* 卡住時 */
.stuck {
  margin: 16px 0 24px;
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--bk-warn-bg);
  color: var(--bk-text);
}
.stuck > p:first-child { margin: 0 0 6px; font-weight: 600; color: var(--bk-warn-text); }
.stuck dl { margin: 0; }
.stuck dt { font-weight: 600; margin-top: 8px; }
.stuck dd { margin: 2px 0 0; }
dl.terms { margin: 12px 0 0; }
dl.terms dt { font-weight: 600; margin-top: 14px; }
dl.terms dd { margin: 2px 0 0; }

/* 提示框 */
.tip {
  margin: 16px 0;
  padding: 12px 16px;
  border-left: 4px solid var(--bk-primary);
  background: var(--bk-card);
  border-radius: 0 10px 10px 0;
}

/* 卡片列 */
.cards { display: grid; gap: 12px; grid-template-columns: 1fr; margin: 16px 0; }
.card {
  background: var(--bk-card);
  border: 1px solid var(--bk-sep);
  border-radius: 12px;
  padding: 14px 16px;
}
.card h3 { margin: 0 0 6px; font-size: 17px; }
.card p { margin: 0; font-size: 15px; }
.card a { text-decoration: none; }

/* 大表格：容器可以橫向捲，頁面本身不捲 */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 16px 0;
  border: 1px solid var(--bk-sep);
  border-radius: 10px;
  background: var(--bk-card);
}
.table-wrap table { border-collapse: collapse; min-width: 100%; font-size: 15px; }
.table-wrap th, .table-wrap td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--bk-sep);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}
.table-wrap td.wrap { white-space: normal; min-width: 12em; }
.table-wrap thead th { background: var(--bk-header-bg); font-weight: 600; position: sticky; top: 0; }
.table-wrap tbody tr:last-child td { border-bottom: 0; }
/* 權限總表：四欄都能折行，390 寬不用橫向捲就看得到業務那一欄 */
.table-wrap table.roles { font-size: 14px; }
.table-wrap table.roles th, .table-wrap table.roles td { white-space: normal; padding: 8px; }
.table-wrap table.roles td:first-child { min-width: 7em; }
.table-wrap table.roles td:not(:first-child) { min-width: 4.4em; }
.table-wrap table.roles th { white-space: nowrap; }
ol.footnotes { list-style: none; padding-left: 0; font-size: 14px; color: var(--bk-text-2); }

kbd, .ui {
  font-family: inherit;
  font-weight: 600;
}

/* 上一頁、下一頁 */
.pager {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  list-style: none;
  margin: 40px 0 0;
  padding: 16px 0 0;
  border-top: 1px solid var(--bk-sep);
}
.pager li { margin: 0; }
.pager a { display: inline-block; padding: 8px 0; text-decoration: none; font-weight: 600; }
.pager .next { margin-left: auto; text-align: right; }

/* 公開版的 CTA 與頁尾 */
.cta {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 16px;
  background: var(--bk-tint);
  text-align: center;
}
.cta-title { font-size: 19px; font-weight: 600; margin: 0 0 6px; }
.cta-button {
  display: inline-block;
  margin-top: 4px;
  padding: 10px 24px;
  border-radius: 8px;
  background: var(--bk-solid);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
}
.cta-button:hover { background: var(--bk-solid-hover); }
.site-footer { text-align: center; padding: 16px; color: var(--bk-text-2); font-size: 14px; }
.site-footer p { margin: 0; }

/* 平板 */
@media (min-width: 768px) {
  main { padding: 28px 32px 56px; }
  h1 { font-size: 30px; }
  .cards { grid-template-columns: 1fr 1fr; }
  .cards.three { grid-template-columns: 1fr 1fr 1fr; }
}

/* 桌面：目錄放左邊 */
@media (min-width: 1024px) {
  .layout {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 24px;
    padding: 0 24px;
  }
  .toc {
    border: 0;
    background: transparent;
    overflow: visible;
  }
  .toc ul {
    position: sticky;
    top: 16px;
    flex-direction: column;
    padding: 24px 0;
    white-space: normal;
  }
  .toc a { border-radius: 8px; }
  main { padding: 28px 0 64px; max-width: 820px; }
}

/* 列印：拿掉目錄與翻頁，截圖不要斷在中間 */
@media print {
  :root { color-scheme: light; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .topbar { background: none; color: #000; padding: 0 0 8pt; border-bottom: 1pt solid #999; }
  .topbar .brand { color: #000; }
  .toc, .pager, .cta, .topbar .back { display: none; }
  .layout { display: block; padding: 0; }
  main { padding: 0; max-width: none; }
  h2 { break-after: avoid; }
  figure, .stuck, .tip, .card, table { break-inside: avoid; }
  figure.shot.phone img { max-width: 60mm; }
  .table-wrap { overflow: visible; border: 0; }
  .table-wrap th, .table-wrap td { white-space: normal; }
  a { color: inherit; text-decoration: none; }
}
