:root {
  --bg: #F4F5F2;
  --surface: #FFFFFF;
  --ink: #16181C;
  --ink-2: #3F444C;
  --muted: #5B616B;
  --line: #DCDFE3;
  --line-2: #ECEEF0;
  --chip: #F1F2F4;
  --accent: #1D4ED8;
  --accent-bg: #EEF2FF;
  --accent-ink: #1E3A8A;
  --warn-bg: #FCEFD9;
  --warn-ink: #8A4B08;
  --heat: #B45309;
  --red: #C62828;
  --green: #137A3F;
  --up: var(--red);
  --down: var(--green);
  --up-bg: #FDECEC;
  --down-bg: #E6F4EA;
  --font: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}
body[data-conv="us"] { --up: var(--green); --down: var(--red); --up-bg: #E6F4EA; --down-bg: #FDECEC; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.6 var(--font); padding-bottom: env(safe-area-inset-bottom); }
a { color: var(--accent); }
a:hover { color: var(--accent-ink); }
button, input, select { font: inherit; }
.wrap { max-width: 1360px; margin: 0 auto; padding: 0 16px; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--ink-2); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* 頂部 */
.top { background: var(--ink); color: #F4F5F2; position: sticky; top: 0; z-index: 10; }
.top-in { display: flex; align-items: center; gap: 8px 24px; min-height: 56px; flex-wrap: wrap; }
.brand { color: #F4F5F2; text-decoration: none; font-weight: 900; font-size: 18px; display: flex; gap: 8px; align-items: center; min-height: 44px; }
.brand:hover { color: #fff; }
.nav { display: flex; gap: 2px; }
.nav a { color: #D5D8DD; text-decoration: none; padding: 8px 12px; border-radius: 6px; }
.nav a.on { background: #F4F5F2; color: var(--ink); font-weight: 700; }
.live { margin-left: auto; font-size: 12px; color: #B9BEC6; display: flex; align-items: center; gap: 6px; }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: #6B7280; }
.live.on .dot { background: #22C55E; }
.live.err { color: #FCA5A5; }

.tabbar { display: none; }
@media (max-width: 760px) {
  .nav { display: none; }
  .tabbar { display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); z-index: 10; padding-bottom: env(safe-area-inset-bottom); }
  .tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 58px; font-size: 11px; color: var(--muted); text-decoration: none; }
  .tabbar a.on { color: var(--ink); font-weight: 700; }
  body { padding-bottom: 72px; }
}

main { padding-top: 16px; padding-bottom: 48px; display: flex; flex-direction: column; gap: 18px; }
main:focus { outline: none; }
h1 { font-size: 24px; margin: 0; font-weight: 900; }
h2 { font-size: 18px; margin: 0; font-weight: 900; }
h3 { font-size: 16px; margin: 0; font-weight: 700; }
.row { display: flex; flex-wrap: wrap; gap: 18px; align-items: flex-start; }
.grow { flex: 999 1 560px; min-width: 0; }
.side { flex: 1 1 340px; min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.note { font-size: 13px; color: var(--warn-ink); background: var(--warn-bg); border: 1px solid #F2D3A2; padding: 8px 12px; border-radius: 6px; margin: 0; }
.empty { color: var(--muted); font-size: 14px; padding: 8px 0; }

/* 指數 */
.idx { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.idx .it { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.idx .lb { font-size: 12px; color: var(--muted); }
.idx .pv { font-family: var(--mono); font-size: 19px; font-weight: 600; }
.idx .ch { font-family: var(--mono); font-size: 13px; font-weight: 600; }

/* 表格 */
.tbl-box { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); padding: 8px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 6px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
th.r, td.r { text-align: right; }
td.nm { font-weight: 700; }
td.nm .sym { font-family: var(--mono); font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 6px; }
tr.flash-up td { background: var(--up-bg); }
tr.flash-down td { background: var(--down-bg); }
td, tr { transition: background-color .8s ease; }

/* 元件 */
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 2px 8px; border-radius: 4px; background: var(--chip); color: var(--ink-2); white-space: nowrap; }
.chip.acc { background: var(--accent-bg); color: var(--accent-ink); font-weight: 500; }
.chip.up { background: var(--up-bg); color: var(--up); font-weight: 700; }
.chip.down { background: var(--down-bg); color: var(--down); font-weight: 700; }
.chip.warn { background: var(--warn-bg); color: var(--warn-ink); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.btn { min-height: 40px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--ink); background: var(--ink); color: #fff; font-weight: 700; cursor: pointer; }
.btn.ghost { background: var(--surface); color: var(--ink); border-color: #C9CDD3; font-weight: 500; }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.seg { display: inline-flex; gap: 4px; background: var(--chip); padding: 4px; border-radius: 8px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; min-height: 36px; padding: 0 12px; border-radius: 6px; cursor: pointer; color: var(--ink-2); }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; font-weight: 700; }
input[type="search"], input[type="password"], select { height: 42px; border: 1px solid #C9CDD3; border-radius: 8px; padding: 0 12px; background: var(--surface); color: var(--ink); min-width: 0; }
.x { border: 0; background: transparent; color: var(--muted); cursor: pointer; width: 32px; height: 32px; border-radius: 6px; font-size: 18px; line-height: 1; }
.x:hover { background: var(--chip); color: var(--ink); }

/* 搜尋 */
.search { position: relative; display: flex; gap: 8px; flex-wrap: wrap; }
.search input { flex: 1 1 240px; }
.results { position: absolute; top: 46px; left: 0; right: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.08); z-index: 5; max-height: 320px; overflow-y: auto; }
.results button { display: flex; width: 100%; justify-content: space-between; gap: 8px; border: 0; background: transparent; padding: 10px 12px; text-align: left; cursor: pointer; border-bottom: 1px solid var(--line-2); }
.results button:hover, .results button:focus { background: var(--chip); }

/* 事件卡片 */
.ev-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.ev { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; text-decoration: none; color: var(--ink); }
.ev:hover { border-color: var(--ink-2); color: var(--ink); }
.ev .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }
.ev .stage { font-size: 14px; color: var(--ink-2); }
.sev { display: inline-flex; gap: 2px; }
.sev i { width: 8px; height: 8px; border-radius: 2px; background: var(--line); display: inline-block; }
.sev i.on { background: var(--heat); }

/* 影響鏈 */
.chain { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.chain .col { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.chain .col h3 { font-size: 14px; color: var(--muted); }
.chain .li { display: flex; flex-direction: column; gap: 2px; padding: 8px 0; border-top: 1px solid var(--line-2); }
.chain .li:first-of-type { border-top: 0; }
.chain .li .t { display: flex; justify-content: space-between; gap: 8px; font-weight: 700; }
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0; }
.timeline li { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 12px; padding: 10px 0; border-top: 1px solid var(--line-2); }
.timeline li.cur { background: var(--accent-bg); border-radius: 8px; padding: 10px; border-top-color: transparent; }
.timeline .w { font-family: var(--mono); font-size: 13px; color: var(--muted); }
.reason { font-size: 13px; color: var(--ink-2); line-height: 1.55; min-width: 220px; }

/* 新聞 */
.news-list { display: flex; flex-direction: column; }
.news-item { display: flex; flex-direction: column; gap: 4px; padding: 12px 0; border-top: 1px solid var(--line-2); }
.news-item:first-child { border-top: 0; }
.news-item a.t { color: var(--ink); text-decoration: none; font-weight: 500; }
.news-item a.t:hover { text-decoration: underline; }
.imp { display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px; border-radius: 4px; font-family: var(--mono); font-size: 12px; font-weight: 700; background: var(--chip); color: var(--ink-2); }
.imp.i4 { background: #FDE7C8; color: #7A3E06; }
.imp.i5 { background: #7A3E06; color: #fff; }

/* 狀態 */
.kv { display: grid; grid-template-columns: minmax(120px, 200px) minmax(0, 1fr); gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.bad { color: var(--red); font-weight: 700; }
.good { color: var(--green); font-weight: 700; }

/* 登入 */
.login { max-width: 380px; margin: 10vh auto; }
.login label { font-weight: 700; }
.login input { width: 100%; }
