/* A1 新手說明書：全站共用樣式。元件是封閉集合，寫內容只能用這裡定義的 class（見 _build/spec.md） */

:root {
  color-scheme: light;
  --bg: #EEF2F3;
  --paper: #FFFFFF;
  --paper-2: #F5F8F9;
  --ink: #1C2A31;
  --muted: #56676F;
  --line: #CBD6DA;
  --accent: #D9472F;
  --link: #1F6F8B;
  /* 業務領域色：圖解與標籤共用 */
  --c-sales: #D9472F;     /* 銷售、客戶、應收 */
  --c-purchase: #5C62C2;  /* 採購、廠商、應付 */
  --c-stock: #D99A22;     /* 庫存、倉庫、商品 */
  --c-money: #3F8F45;     /* 現金、銀行、收付款 */
  --c-report: #23877B;    /* 報表、分析 */
  --tip: #3F8F45;
  --warn: #C2410C;
  --note: #1F6F8B;
  --font-display: "LXGW WenKai TC", "Kaiti TC", "DFKai-SB", "BiauKai", serif;
  --font-body: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  --radius: 14px;
  --side: 280px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #11181C; --paper: #1A242A; --paper-2: #202C33; --ink: #E6EDF0; --muted: #98A9B0; --line: #33444B;
    --accent: #F06A50; --link: #6CC3E0;
    --c-sales: #F06A50; --c-purchase: #8C91F0; --c-stock: #EDB040; --c-money: #5DBA63; --c-report: #3DB3A3;
    --tip: #5DBA63; --warn: #F08A4B; --note: #6CC3E0;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #11181C; --paper: #1A242A; --paper-2: #202C33; --ink: #E6EDF0; --muted: #98A9B0; --line: #33444B;
  --accent: #F06A50; --link: #6CC3E0;
  --c-sales: #F06A50; --c-purchase: #8C91F0; --c-stock: #EDB040; --c-money: #5DBA63; --c-report: #3DB3A3;
  --tip: #5DBA63; --warn: #F08A4B; --note: #6CC3E0;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-padding-top: 72px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.75;
}
img { max-width: 100%; height: auto; }
a { color: var(--link); text-underline-offset: 3px; }
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 700; line-height: 1.3; text-wrap: balance; margin: 0; }
h1 { font-size: clamp(2rem, 6vw, 3rem); }
h2 { font-size: clamp(1.5rem, 4.4vw, 2rem); }
h3 { font-size: 1.3rem; margin-top: 8px; }
h4 { font-size: 1.1rem; }
p, ul, ol { margin: 0; }
ul, ol { padding-left: 1.4em; }
li + li { margin-top: 4px; }
code { font-size: 0.92em; background: var(--paper-2); padding: 1px 6px; border-radius: 6px; }
b.ui, .ui { font-weight: 700; color: var(--ink); white-space: nowrap; }

/* ===== 外框（由 build.py 產生） ===== */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar .brand { font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; color: var(--ink); text-decoration: none; }
.topbar .brand small { font-family: var(--font-body); font-weight: 400; color: var(--muted); font-size: 0.8rem; margin-left: 6px; }
.layout {
  display: grid;
  grid-template-columns: var(--side) minmax(0, 1fr);
  gap: 32px;
  max-width: 1240px;
  margin-inline: auto;
  padding: 24px 16px 80px;
}
.side { position: sticky; top: 64px; align-self: start; max-height: calc(100vh - 80px); overflow: auto; font-size: 0.93rem; }
.side details { border: 0; }
.side summary { display: none; }
.side ol { list-style: none; padding: 0; display: grid; gap: 2px; }
.side a { display: block; padding: 4px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; line-height: 1.4; }
.side a:hover { background: var(--paper); }
.side a[aria-current="page"] { background: var(--paper); font-weight: 700; color: var(--accent); }
.side .sub { padding-left: 12px; margin: 2px 0 6px; border-left: 2px solid var(--line); margin-left: 10px; }
.side .sub a { font-size: 0.86rem; color: var(--muted); padding: 2px 8px; }
.side .group { font-size: 0.78rem; letter-spacing: 0.1em; color: var(--muted); padding: 10px 10px 2px; }
main { min-width: 0; display: grid; gap: 40px; align-content: start; }
.page-head { display: grid; gap: 10px; }
.page-head .kicker { color: var(--muted); font-size: 0.9rem; letter-spacing: 0.08em; }
.page-head .lead { font-size: 1.1rem; color: var(--muted); max-width: 40em; }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pager a { background: var(--paper); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: var(--ink); display: grid; }
.pager a small { color: var(--muted); }
.pager .next { text-align: right; grid-column: 2; }
.foot { color: var(--muted); font-size: 0.85rem; border-top: 1px solid var(--line); padding-top: 16px; }
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .side { position: static; max-height: none; }
  .side summary { display: block; cursor: pointer; background: var(--paper); border-radius: var(--radius); padding: 10px 14px; font-weight: 700; }
  .side details[open] summary { margin-bottom: 8px; }
}

/* ===== 內容區塊 ===== */
section.topic {
  background: var(--paper);
  border-radius: 20px;
  padding: 28px 24px;
  display: grid; gap: 16px;
}
section.topic > * { max-width: 46em; }
section.topic > figure, section.topic > table, section.topic > .table-wrap, section.topic > .cards { max-width: none; }
section.topic h2 { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
section.topic h2 .src { font-family: var(--font-body); font-weight: 400; font-size: 0.8rem; }
section.topic.chapter-intro { background: transparent; padding: 0; }
@media (max-width: 520px) { section.topic { padding: 22px 16px; border-radius: 16px; } }

/* 在哪裡打開 */
.where { font-size: 0.92rem; color: var(--muted); }
.where::before { content: "在哪裡："; font-weight: 700; color: var(--ink); }

/* 白話說 */
.plain {
  background: var(--paper-2);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-family: var(--font-display);
  font-size: 1.12rem;
  line-height: 1.7;
}
.plain::before { content: "白話說"; display: block; font-family: var(--font-body); font-size: 0.78rem; letter-spacing: 0.12em; color: var(--muted); margin-bottom: 2px; }

/* 提醒框 */
.callout { border-left: 5px solid var(--k); background: color-mix(in srgb, var(--k) 9%, var(--paper)); border-radius: 10px; padding: 12px 16px; }
.callout::before { display: block; font-weight: 700; color: var(--k); font-size: 0.9rem; margin-bottom: 2px; }
.callout.tip { --k: var(--tip); } .callout.tip::before { content: "小技巧"; }
.callout.warn { --k: var(--warn); } .callout.warn::before { content: "注意"; }
.callout.note { --k: var(--note); } .callout.note::before { content: "補充"; }

/* 存檔後會影響什麼 */
.affects { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.affects::before { content: "存檔後會影響："; flex-basis: 100%; font-weight: 700; font-size: 0.92rem; }
.affects li { margin: 0; border: 1.5px solid var(--k, var(--line)); color: var(--k, var(--ink)); border-radius: 999px; padding: 2px 12px; font-size: 0.92rem; font-weight: 700; background: var(--paper); }
.k-sales { --k: var(--c-sales); } .k-purchase { --k: var(--c-purchase); } .k-stock { --k: var(--c-stock); }
.k-money { --k: var(--c-money); } .k-report { --k: var(--c-report); }

/* 步驟 */
ol.steps { list-style: none; padding: 0; counter-reset: st; display: grid; gap: 10px; }
ol.steps > li { counter-increment: st; position: relative; padding-left: 44px; margin: 0; }
ol.steps > li::before {
  content: counter(st); position: absolute; left: 0; top: 1px;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--ink); color: var(--paper);
  display: grid; place-items: center; font-weight: 700; font-size: 0.9rem;
}

/* 欄位表 */
.table-wrap { overflow-x: auto; }
table.fields { border-collapse: collapse; width: 100%; font-size: 0.95rem; }
table.fields th, table.fields td { border-bottom: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
table.fields th { background: var(--paper-2); font-weight: 700; white-space: nowrap; }
table.fields td:first-child { font-weight: 700; white-space: nowrap; }
table.fields .req { color: var(--accent); font-size: 0.8rem; margin-left: 4px; }
@media (max-width: 600px) {
  table.fields, table.fields tbody, table.fields tr, table.fields td { display: block; width: 100%; }
  table.fields thead { display: none; }
  table.fields tr { border-bottom: 1px solid var(--line); padding: 8px 0; }
  table.fields td { border: 0; padding: 2px 0; white-space: normal; }
}

/* 截圖與圖解 */
figure { margin: 0; display: grid; gap: 8px; }
figure.shot img { border: 1px solid var(--line); border-radius: 10px; background: #fff; display: block; }
figure.shot { max-width: 820px; }
figcaption { font-size: 0.88rem; color: var(--muted); }
figure.diagram { background: var(--paper-2); border-radius: var(--radius); padding: 16px; }
figure.diagram svg { width: 100%; height: auto; display: block; max-height: 560px; }
/* 手機上圖解不縮到看不清：維持最小寬度，在框內左右滑動 */
@media (max-width: 700px) {
  figure.diagram { overflow-x: auto; }
  figure.diagram svg { min-width: 600px; max-height: none; }
  figure.diagram::after { content: "← 可左右滑動看完整圖解 →"; font-size: 0.78rem; color: var(--muted); }
  /* 說明文字固定在可視範圍，不跟著圖左右捲 */
  figure.diagram figcaption, figure.diagram::after { position: sticky; left: 0; max-width: calc(100vw - 80px); }
}
figure.diagram svg text { fill: var(--ink); font-family: var(--font-body); }
figure.diagram svg .t-muted { fill: var(--muted); }
figure.diagram svg .box { fill: var(--paper); stroke: var(--line); stroke-width: 1.5; }
figure.diagram svg .line { stroke: var(--muted); stroke-width: 2; fill: none; }
figure.diagram svg .sales { stroke: var(--c-sales); } figure.diagram svg .f-sales { fill: var(--c-sales); }
figure.diagram svg .purchase { stroke: var(--c-purchase); } figure.diagram svg .f-purchase { fill: var(--c-purchase); }
figure.diagram svg .stock { stroke: var(--c-stock); } figure.diagram svg .f-stock { fill: var(--c-stock); }
figure.diagram svg .money { stroke: var(--c-money); } figure.diagram svg .f-money { fill: var(--c-money); }
figure.diagram svg .report { stroke: var(--c-report); } figure.diagram svg .f-report { fill: var(--c-report); }

/* 小卡片格 */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.card { background: var(--paper-2); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 6px; align-content: start; border-top: 4px solid var(--k, var(--line)); }
.card h4 { font-size: 1.05rem; }
a.card { color: var(--ink); text-decoration: none; }
a.card:hover { outline: 2px solid var(--k, var(--line)); }

/* 標籤 */
.badge { display: inline-block; font-family: var(--font-body); font-size: 0.75rem; font-weight: 700; border-radius: 999px; padding: 1px 10px; vertical-align: middle; border: 1.5px solid currentColor; }
.badge.addon { color: var(--c-purchase); }
.badge.deprecated { color: var(--muted); }
.badge.paid { color: var(--c-stock); }

/* FAQ */
aside.faq { border: 1.5px dashed var(--line); border-radius: var(--radius); padding: 14px 18px; display: grid; gap: 8px; background: var(--paper); }
aside.faq h4 { font-family: var(--font-body); font-size: 1rem; }
aside.faq h4::before { content: "Q"; display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; background: var(--accent); color: var(--paper); font-size: 0.85rem; margin-right: 8px; }
aside.faq .faq-src { font-size: 0.8rem; }

/* 詳細內容收合 */
details.more { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 16px; }
details.more > summary { cursor: pointer; font-weight: 700; }
details.more[open] > summary { margin-bottom: 10px; }
details.more > :not(summary) + * { margin-top: 12px; }

/* 辭典 */
dl.terms { display: grid; grid-template-columns: 9em 1fr; gap: 10px 18px; margin: 0; }
dl.terms dt { font-weight: 700; }
dl.terms dd { margin: 0; }
@media (max-width: 560px) { dl.terms { grid-template-columns: 1fr; gap: 2px; } dl.terms dd { margin-bottom: 10px; } }
