/* 共用：色彩、字體、內文排版、表格、連動元件、計算機（前台與後台預覽共用） */
:root {
  --bg: #fbf4ea;
  --bg-deep: #f5e8d8;
  --surface: #fffcf7;
  --surface-2: #fdf6ee;
  --ink: #3b2a20;
  --ink-soft: #5c4636;
  --muted: #8d7463;
  --line: #ecdcc8;
  --line-strong: #dcc5ab;
  --accent: #c9662c;
  --accent-ink: #ffffff;
  --accent-soft: #fbe3cf;
  --accent-softer: #fdf0e4;
  --leaf: #5d8a54;
  --leaf-soft: #e5f0df;
  --warn: #b7791f;
  --warn-soft: #fff1d6;
  --danger: #b4483b;
  --danger-soft: #fbe4e0;
  --seg-cat: #c9662c;
  --seg-eq: #e7a46a;
  --seg-opt: #8fb27f;
  --shadow: 0 1px 2px rgba(91, 58, 30, 0.06), 0 6px 18px rgba(91, 58, 30, 0.07);
  --radius: 16px;
  --radius-sm: 10px;
  --font-body: 'Noto Sans TC', 'PingFang TC', 'Microsoft JhengHei', system-ui, sans-serif;
  --font-display: 'LXGW WenKai TC', 'Noto Sans TC', 'PingFang TC', 'Microsoft JhengHei', serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #1c1612;
    --bg-deep: #241c17;
    --surface: #2a211b;
    --surface-2: #30261f;
    --ink: #f4e8dc;
    --ink-soft: #e0cfbf;
    --muted: #b59d8a;
    --line: #3f3229;
    --line-strong: #55443a;
    --accent: #f0955a;
    --accent-ink: #2a1a10;
    --accent-soft: #4a2f1f;
    --accent-softer: #382619;
    --leaf: #9cc78f;
    --leaf-soft: #263522;
    --warn: #f0be6a;
    --warn-soft: #3d2f17;
    --danger: #f08c7e;
    --danger-soft: #42231f;
    --seg-cat: #f0955a;
    --seg-eq: #c98a54;
    --seg-opt: #8fb27f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 18px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #1c1612;
  --bg-deep: #241c17;
  --surface: #2a211b;
  --surface-2: #30261f;
  --ink: #f4e8dc;
  --ink-soft: #e0cfbf;
  --muted: #b59d8a;
  --line: #3f3229;
  --line-strong: #55443a;
  --accent: #f0955a;
  --accent-ink: #2a1a10;
  --accent-soft: #4a2f1f;
  --accent-softer: #382619;
  --leaf: #9cc78f;
  --leaf-soft: #263522;
  --warn: #f0be6a;
  --warn-soft: #3d2f17;
  --danger: #f08c7e;
  --danger-soft: #42231f;
  --seg-cat: #f0955a;
  --seg-eq: #c98a54;
  --seg-opt: #8fb27f;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 18px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}

* { 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: 16px;
  line-height: 1.75;
}
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }

/* ───── 內文 ───── */
.prose { overflow-wrap: anywhere; }
.prose > :first-child { margin-top: 0; }
.prose p, .prose ul, .prose ol { margin: 0.7em 0; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li { margin: 0.25em 0; }
.prose li > ul, .prose li > ol { margin: 0.2em 0; }
.prose strong { color: var(--ink); font-weight: 700; }
.prose del { color: var(--muted); }
.prose code { background: var(--accent-softer); border-radius: 6px; padding: 0.1em 0.4em; font-size: 0.9em; }
.prose hr { border: 0; border-top: 2px dashed var(--line); margin: 1.5em 0; }
.prose blockquote {
  margin: 1em 0;
  padding: 0.75em 1em;
  background: var(--accent-softer);
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--ink-soft);
}
.prose blockquote > :first-child { margin-top: 0; }
.prose blockquote > :last-child { margin-bottom: 0; }
.prose blockquote.warn, .prose p.warn {
  background: var(--warn-soft);
  border-left: 4px solid var(--warn);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.prose p.warn { padding: 0.6em 0.9em; }
.prose p.ok { background: var(--leaf-soft); border-left: 4px solid var(--leaf); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; padding: 0.6em 0.9em; }
.prose details {
  margin: 1em 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.5em 1em;
  background: var(--surface-2);
}
.prose summary { cursor: pointer; font-weight: 500; color: var(--ink-soft); }
.prose a.xref {
  text-decoration: none;
  border-bottom: 1px dashed currentColor;
  white-space: nowrap;
}
.prose mark { background: #ffe08a; color: #3b2a20; border-radius: 3px; padding: 0 2px; }

/* ───── 表格 ───── */
.table-wrap {
  margin: 1em 0;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  -webkit-overflow-scrolling: touch;
}
.table-wrap table { border-collapse: collapse; width: 100%; font-size: 0.93em; line-height: 1.6; }
.table-wrap th, .table-wrap td { padding: 0.55em 0.8em; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.table-wrap th { background: var(--accent-softer); color: var(--ink-soft); font-weight: 700; white-space: nowrap; }
.table-wrap tr:last-child td { border-bottom: 0; }
.table-wrap td:first-child { min-width: 7em; }
.table-wrap tbody tr:hover td { background: var(--surface-2); }
.table-wrap tr.total td { background: var(--accent-soft); border-top: 2px solid var(--line-strong); }
.table-wrap tr.subtotal td { background: var(--surface-2); border-top: 1px solid var(--line-strong); }
.table-wrap tr.is-off td { color: var(--muted); }
.cell-note { display: block; font-size: 0.82em; color: var(--muted); line-height: 1.4; margin-top: 0.15em; }
.chip {
  display: inline-block;
  margin-left: 0.4em;
  padding: 0 0.55em;
  border-radius: 999px;
  background: var(--leaf-soft);
  color: var(--leaf);
  font-size: 0.8em;
  font-weight: 500;
  white-space: nowrap;
}

/* ───── 連動元件 ───── */
.widget { margin: 1em 0; }
.widget .table-wrap { margin: 0; border-color: var(--line-strong); }
.widget-note { margin: 0.35em 0 0 !important; font-size: 0.8em; color: var(--muted); }
.widget-error { color: var(--danger); background: var(--danger-soft); padding: 0.5em 0.8em; border-radius: var(--radius-sm); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat-icon { font-size: 1.4em; line-height: 1; }
.stat-label { margin-top: 8px; color: var(--muted); font-size: 0.88em; }
.stat-value { font-family: var(--font-display); font-size: 1.55em; font-weight: 700; color: var(--accent); line-height: 1.3; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 0.8em; color: var(--muted); line-height: 1.45; margin-top: 2px; }

/* ───── 預算計算機 ───── */
.calc {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.calc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.calc-title { font-family: var(--font-display); font-size: 1.3em; font-weight: 700; }
.calc-sub { color: var(--muted); font-size: 0.86em; }
.calc-tiers { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.pill {
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 0.3em 1em;
  cursor: pointer;
}
.pill.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.calc-result { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.calc-num { background: var(--accent-softer); border-radius: var(--radius-sm); padding: 12px 14px; display: flex; flex-direction: column; }
.calc-num span { color: var(--muted); font-size: 0.86em; }
.calc-num strong { font-family: var(--font-display); font-size: 1.7em; color: var(--accent); line-height: 1.25; font-variant-numeric: tabular-nums; }
.calc-num em { font-style: normal; font-size: 0.8em; color: var(--muted); line-height: 1.45; }
.calc-bar { margin: 14px 0 6px; }
.bar { display: flex; height: 12px; border-radius: 999px; overflow: hidden; background: var(--line); gap: 2px; }
.bar span { min-width: 4px; }
.seg-cat { background: var(--seg-cat); }
.seg-eq { background: var(--seg-eq); }
.seg-opt { background: var(--seg-opt); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 0.8em; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.calc-lists details { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 8px; }
.calc-lists summary { cursor: pointer; font-weight: 700; color: var(--ink-soft); }
.calc-lists summary span { font-weight: 400; color: var(--muted); font-size: 0.86em; margin-left: 4px; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 2px 16px; margin-top: 6px; }
.check { display: flex; align-items: baseline; gap: 8px; padding: 4px 0; cursor: pointer; font-size: 0.92em; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; flex: none; transform: translateY(2px); }
.check span { flex: 1; }
.check small { color: var(--leaf); margin-left: 6px; }
.check em { font-style: normal; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.btn-ghost {
  white-space: nowrap;
  flex: none;
  border: 1px solid var(--line-strong);
  background: transparent;
  border-radius: 999px;
  padding: 0.25em 0.9em;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.86em;
}
.btn-ghost:hover { color: var(--accent); border-color: var(--accent); }
@media (max-width: 560px) {
  .calc { padding: 14px; margin: 0 -4px; }
  .stat { padding: 14px; }
}
