:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --mt: #2a78d6;
  --tb: #eb6834;
  --s3: #1baf7a;
  --neutral: #b9b8b1;
  --good: #006300;
  --bad: #d03b3b;
  --accent-soft: #e8f0fb;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", "PingFang TC", "Noto Sans TC", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --mt: #3987e5;
    --tb: #d95926;
    --s3: #199e70;
    --neutral: #5d5c57;
    --good: #0ca30c;
    --bad: #e66767;
    --accent-soft: #1c2a3d;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --mt: #3987e5;
  --tb: #d95926;
  --s3: #199e70;
  --neutral: #5d5c57;
  --good: #0ca30c;
  --bad: #e66767;
  --accent-soft: #1c2a3d;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--mt); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-size: 0.9em; background: var(--surface-2); padding: 0 4px; border-radius: 4px; }

/* ---- 頂部導覽 ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1240px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; gap: 18px; min-height: 54px; flex-wrap: wrap;
}
.brand { font-weight: 700; color: var(--text); white-space: nowrap; font-size: 16px; }
.brand span { color: var(--muted); font-weight: 500; margin-left: 6px; font-size: 13px; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav a {
  color: var(--text-2); padding: 6px 10px; border-radius: 8px; font-size: 14px; white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { color: var(--text); background: var(--surface-2); font-weight: 600; }
.theme-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  border-radius: 8px; padding: 4px 10px; font: inherit; font-size: 13px; cursor: pointer;
}

main { max-width: 1240px; margin: 0 auto; padding: 20px 16px 60px; }
.page-head { margin: 8px 0 20px; }
.page-head h1 { font-size: 26px; margin: 0 0 6px; letter-spacing: 0.01em; }
.page-head p { margin: 0; color: var(--text-2); max-width: 860px; }
.stamp { color: var(--muted); font-size: 13px; margin-top: 6px; }

h2.section { font-size: 19px; margin: 34px 0 6px; }
p.section-lede { margin: 0 0 14px; color: var(--text-2); font-size: 14px; max-width: 900px; }

/* ---- 卡片與格線 ---- */
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 960px) { .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 680px) { .g2, .g3 { grid-template-columns: minmax(0, 1fr); } }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; min-width: 0;
}
.card h3 { font-size: 15px; margin: 0 0 2px; }
.card .sub { color: var(--muted); font-size: 12.5px; margin: 0 0 8px; }
.chart { width: 100%; height: 340px; }
.chart.tall { height: 520px; }
.chart.xtall { height: 760px; }
.chart.short { height: 260px; }

/* ---- 數字卡 ---- */
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px;
}
.kpi .label { color: var(--text-2); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 26px; font-weight: 650; margin-top: 2px; line-height: 1.2; }
.kpi .note { color: var(--muted); font-size: 12px; margin-top: 4px; }
.kpi .split { display: flex; gap: 14px; align-items: baseline; margin-top: 2px; flex-wrap: wrap; }
.kpi .split div { font-size: 20px; font-weight: 650; }
.kpi .split small { display: block; font-size: 12px; color: var(--muted); font-weight: 500; }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: none; }
.dot.mt { background: var(--mt); }
.dot.tb { background: var(--tb); }
.dot.s3 { background: var(--s3); }
.dot.neutral { background: var(--neutral); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-2);
  background: var(--surface-2); border-radius: 999px; padding: 1px 9px; white-space: nowrap;
}
.legend-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 2px 0 6px; }

/* ---- 重點清單 ---- */
.insights { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.insights li {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px 10px 36px; position: relative; font-size: 14.5px;
}
.insights li::before {
  content: ""; position: absolute; left: 15px; top: 18px; width: 7px; height: 7px; border-radius: 50%; background: var(--mt);
}
.note-body h2, .note-body h3 { margin: 20px 0 6px; font-size: 17px; }
.note-body h4, .note-body h5 { margin: 16px 0 4px; font-size: 15px; }
.note-body p { margin: 6px 0; }
.note-body ul { margin: 4px 0 10px; padding-left: 20px; }
.note-body li { margin: 3px 0; }

.callout {
  border-left: 3px solid var(--mt); background: var(--accent-soft); padding: 10px 14px; border-radius: 6px;
  font-size: 14px; color: var(--text); margin: 10px 0;
}
.callout.warn { border-left-color: var(--tb); background: color-mix(in srgb, var(--tb) 10%, var(--surface)); }

/* ---- 表格 ---- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.data, table.md { border-collapse: collapse; width: 100%; font-size: 13.5px; }
table.data th, table.data td, table.md th, table.md td {
  padding: 7px 10px; border-bottom: 1px solid var(--grid); text-align: left; vertical-align: top; white-space: nowrap;
}
table.data td.wrap { white-space: normal; min-width: 180px; }
table.data th, table.md th {
  position: sticky; top: 0; background: var(--surface-2); color: var(--text-2); font-weight: 600; font-size: 12.5px;
  cursor: default; user-select: none;
}
table.data th.sortable { cursor: pointer; }
table.data th.sortable:hover { color: var(--text); }
table.data th .arrow { color: var(--muted); font-size: 11px; margin-left: 3px; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tr:last-child td { border-bottom: none; }
.scroll-y { max-height: 560px; overflow-y: auto; }
.muted { color: var(--muted); }
.up { color: var(--good); }
.down { color: var(--bad); }
.tag {
  display: inline-block; font-size: 11.5px; padding: 0 6px; border-radius: 4px; background: var(--surface-2); color: var(--text-2);
  margin-right: 3px;
}
.tag.mt { background: color-mix(in srgb, var(--mt) 16%, var(--surface)); color: var(--text); }
.tag.tb { background: color-mix(in srgb, var(--tb) 16%, var(--surface)); color: var(--text); }

.bar-cell { position: relative; min-width: 110px; }
.bar-cell .b { position: absolute; left: 0; top: 50%; height: 8px; transform: translateY(-50%); border-radius: 0 4px 4px 0; opacity: .85; }
.bar-cell span { position: relative; }

/* ---- 篩選列 ---- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 12px; }
.filters label { font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.filters select, .filters input[type="search"], .filters input[type="text"] {
  font: inherit; font-size: 14px; padding: 5px 9px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); min-height: 34px;
}
.filters input[type="search"] { min-width: 200px; }
.btn {
  font: inherit; font-size: 13.5px; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; min-height: 34px;
}
.btn:hover { background: var(--surface-2); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { font: inherit; font-size: 13px; border: 0; background: var(--surface); color: var(--text-2); padding: 6px 12px; cursor: pointer; }
.seg button.on { background: var(--surface-2); color: var(--text); font-weight: 600; }

.region-cards .card h3 { font-size: 17px; }
.region-cards .card .go { font-size: 14px; }
.empty {
  border: 1px dashed var(--axis); border-radius: var(--radius); padding: 22px; color: var(--text-2); background: var(--surface);
}
footer { color: var(--muted); font-size: 12.5px; text-align: center; padding: 20px 16px 40px; }
details > summary { cursor: pointer; color: var(--text-2); font-size: 13px; margin-top: 8px; }

@media (max-width: 680px) {
  .topbar-inner { flex-wrap: nowrap; gap: 10px; }
  .brand span { display: none; }
  .nav { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .nav::-webkit-scrollbar { display: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi .value { font-size: 22px; }
  .kpi .split div { font-size: 17px; }
  .page-head h1 { font-size: 22px; }
  .chart.xtall { height: 680px; }
}
