/* 版面：頂部列 (站名 + 麵包屑) → 置中 1200px 欄；每頁 = 標題摘要 → 篩選 → 指標列 → 圖表面板 → 各區比較／排行 */
:root {
  color-scheme: light;
  --bg: #f2f4f4;
  --surface: #fcfcfb;
  --ink: #102022;
  --ink-2: #4a5a5d;
  --ink-3: #788689;
  --line: #dde3e4;
  --line-faint: #eaeeee;
  --accent: #2a78d6;
  --brand: #f25500;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --muted-mark: #a7b1b3;
  --missing: #e6eaea;
  --font-body: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  --font-data: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 15px; line-height: 1.6; }
.wrap { max-width: 1200px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* header */
/* 頂部列用 brand color 底、白字；#f25500 配白字對比 3.46，只夠粗體大字，所以文字都加粗加大 */
header.top { background: var(--brand); color: #fff; }
header.top .wrap { display: flex; align-items: center; gap: 8px 24px; flex-wrap: wrap; padding-block: 12px; }
.brand { font-weight: 700; font-size: 18px; color: #fff; text-decoration: none; }
.crumbs { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 15px; font-weight: 500; color: rgba(255, 255, 255, .75); }
.crumbs a { color: #fff; text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }
.crumbs a[aria-current="page"] { font-weight: 700; }
header.top :focus-visible { outline-color: #fff; }

main { padding-block: 24px 48px; }
h1 { font-size: 26px; line-height: 1.3; margin: 0 0 6px; text-wrap: balance; }
.h1-type { font-size: 16px; font-weight: 500; color: var(--ink-2); margin-left: 10px; padding: 2px 10px; border: 1px solid var(--line); border-radius: 999px; vertical-align: 4px; }
h2 { font-size: 15px; margin: 0 0 4px; text-wrap: balance; }
.sec-head h2 { font-size: 19px; }
p { margin: 0 0 12px; }
.lede { color: var(--ink-2); max-width: 72ch; }

/* 篩選 */
.filters { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: end; margin: 16px 0 20px; }
.filters.inline { margin: 0; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 12px; color: var(--ink-3); letter-spacing: .04em; }
select, input[type="search"] { font: inherit; font-size: 14px; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; min-width: 0; max-width: 100%; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 13px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); border-radius: 999px; padding: 4px 12px; text-decoration: none; }
.chip:hover { border-color: var(--ink-3); }
.chip[aria-current="page"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
label.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-2); cursor: pointer; padding-block: 6px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { font: inherit; font-size: 13px; border: 0; background: var(--surface); color: var(--ink-2); padding: 6px 12px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }

/* 指標列 */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-bottom: 24px; }
.kpi { background: var(--surface); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.kpi .k { font-size: 12px; color: var(--ink-3); letter-spacing: .03em; }
.kpi .v { font-family: var(--font-data); font-size: 24px; font-weight: 500; line-height: 1.25; font-variant-numeric: tabular-nums; }
.kpi .v small { font-size: 13px; color: var(--ink-2); font-weight: 400; margin-left: 2px; }
.kpi .s { font-size: 12px; color: var(--ink-3); }

/* 面板 */
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
@media (max-width: 860px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; min-width: 0; }
.panel.full { grid-column: 1 / -1; }
.panel header { display: flex; justify-content: space-between; align-items: start; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.panel header p { margin: 0; font-size: 13px; color: var(--ink-3); max-width: 64ch; }
.chart { width: 100%; height: 340px; }
.chart.sm { height: 220px; }
.chart.tall { height: 520px; }
@media (max-width: 600px) { .chart { height: 280px; } .chart.tall { height: 420px; } }
/* 手機：縮減圖表上方的內容 (指標列、類型 chips 改成橫向捲動單列)，面板內距縮小把寬度留給圖表 */
@media (max-width: 600px) {
  main { padding-top: 16px; }
  h1 { font-size: 22px; }
  .lede { font-size: 14px; }
  .filters { margin: 12px 0 16px; }
  .field { max-width: 100%; }
  .filters .chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .chip { flex: none; }
  .kpis { grid-auto-flow: column; grid-template-columns: none; grid-auto-columns: minmax(136px, 42%); overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; margin-bottom: 16px; }
  .kpi { padding: 10px 12px; scroll-snap-align: start; }
  .kpi .v { font-size: 20px; }
  .kpi .s { font-size: 11px; }
  /* 圖表卡片貼齊螢幕左右邊緣；文字對齊頁面邊距，圖表再往外延伸 */
  .panel { margin-inline: calc(-1 * max(16px, env(safe-area-inset-left, 0px))) calc(-1 * max(16px, env(safe-area-inset-right, 0px))); padding: 12px 16px; border-radius: 0; border-inline: 0; }
  .panel .chart { width: auto; margin-inline: -12px; }
  .panel header { margin-bottom: 4px; }
}
.note { font-size: 12px; color: var(--ink-3); margin: 8px 0 0; }

/* 各區小圖 */
.sec-head { display: flex; justify-content: space-between; align-items: end; gap: 12px; flex-wrap: wrap; margin: 32px 0 12px; }
.sec-head p { margin: 0; }
.multiples { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.mcard { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px 8px; color: inherit; text-decoration: none; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.mcard:hover { border-color: var(--ink-3); }
.mcard[aria-current="page"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.mcard .row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.mcard .nm { font-weight: 500; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mcard .g { font-family: var(--font-data); font-size: 13px; font-variant-numeric: tabular-nums; }
.mcard svg { width: 100%; height: 40px; display: block; }
.mcard .meta { font-size: 11px; color: var(--ink-3); font-family: var(--font-data); }

/* 表格 */
.tablebox { overflow: auto; max-height: 520px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 7px 10px; text-align: right; border-bottom: 1px solid var(--line-faint); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
td:first-child a { color: var(--ink); text-decoration: none; }
td:first-child a:hover { color: var(--accent); text-decoration: underline; }
thead th { position: sticky; top: 0; background: var(--surface); color: var(--ink-3); font-weight: 500; font-size: 12px; border-bottom: 1px solid var(--line); }
thead th[data-k] { cursor: pointer; user-select: none; }
thead th[aria-sort="descending"]::after { content: " ↓"; }
thead th[aria-sort="ascending"]::after { content: " ↑"; }
td.num { font-family: var(--font-data); font-variant-numeric: tabular-nums; }
td.heat span { display: inline-block; min-width: 64px; padding: 1px 6px; border-radius: 4px; }
tbody tr:hover { background: var(--line-faint); }
button.add { font: inherit; font-size: 12px; border: 1px solid var(--line); background: transparent; color: var(--accent); border-radius: 6px; padding: 2px 8px; cursor: pointer; }
button.add:disabled { color: var(--ink-3); cursor: default; }
details.dt { margin-top: 10px; }
details.dt summary { cursor: pointer; font-size: 13px; color: var(--ink-2); }
details.dt .tablebox { margin-top: 8px; max-height: 360px; }

.cmp-chips { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.cmp-chip { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; border: 1px solid var(--line); border-radius: 999px; padding: 3px 6px 3px 10px; background: var(--surface); }
.cmp-chip a { color: var(--ink); text-decoration: none; }
.cmp-chip i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.cmp-chip button { border: 0; background: transparent; color: var(--ink-3); cursor: pointer; font-size: 14px; line-height: 1; padding: 2px 4px; }

/* footer */
footer { border-top: 1px solid var(--line); background: var(--surface); padding-block: 20px 28px; font-size: 13px; color: var(--ink-2); }
footer .method summary { cursor: pointer; font-weight: 500; color: var(--ink); }
footer .method ul { padding-left: 1.2em; margin: 8px 0 0; max-width: 80ch; }
footer .method li { margin-bottom: 4px; }
footer .links { display: flex; gap: 12px; margin: 16px 0 0; }
footer .links img { width: 24px; height: 24px; border-radius: 4px; display: block; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
