/* 投資儀表板：手機優先、深淺色。色票已用 dataviz 驗證腳本檢查（漲跌紅綠、均線四色）。 */
:root {
  color-scheme: light;
  --page: #f9f9f9;
  --surface: #ffffff;
  --text: #191919;
  --text-2: #666666;
  --grid: #e7e7e7;
  --axis: #c2c2c2;
  --border: rgba(11, 11, 11, 0.10);
  --wash: rgba(11, 11, 11, 0.05);
  --up: #ec4647;          /* 漲：紅（台股慣例） */
  --down: #008a17;        /* 跌：綠 */
  --s1: #257de0;          /* 週線 */
  --s2: #f47230;          /* 月線 */
  --s3: #00b894;          /* 季線 */
  --s4: #f2a600;          /* 年線 */
  --warn: #fbb315;
  --critical: #dc3c3d;
  --accent: #257de0;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0b0b0b;
    --surface: #191919;
    --text: #efefef;
    --text-2: #9c9c9c;
    --grid: #303030;
    --axis: #474747;
    --border: rgba(255, 255, 255, 0.10);
    --wash: rgba(255, 255, 255, 0.06);
    --up: #f07070;
    --down: #0b821e;
    --s1: #338ced;
    --s2: #e76624;
    --s3: #00a888;
    --s4: #d28e05;
    --accent: #338ced;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0b0b0b;
  --surface: #191919;
  --text: #efefef;
  --text-2: #9c9c9c;
  --grid: #303030;
  --axis: #474747;
  --border: rgba(255, 255, 255, 0.10);
  --wash: rgba(255, 255, 255, 0.06);
  --up: #f07070;
  --down: #0b821e;
  --s1: #338ced;
  --s2: #e76624;
  --s3: #00a888;
  --s4: #d28e05;
  --accent: #338ced;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 6px;
}
.brand { font-weight: 700; font-size: 17px; }
.theme {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; width: 36px; height: 36px; cursor: pointer; display: grid; place-items: center; padding: 0;
}
.tabs {
  display: flex; gap: 4px; overflow-x: auto; padding: 4px 16px 8px; position: sticky; top: 0; z-index: 5;
  background: var(--page); scrollbar-width: none; border-bottom: 1px solid var(--border);
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  flex: none; padding: 6px 12px; border-radius: 999px; color: var(--text-2); text-decoration: none; font-size: 14px;
}
.tabs a[aria-current="page"] { background: var(--text); color: var(--page); font-weight: 600; }
main { max-width: 1100px; margin: 0 auto; padding: 12px 16px 24px; }
section { margin: 0 0 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.hidden { display: none; }
.h { font-size: 16px; margin: 4px 0 8px; }
.h3 { font-size: 15px; margin: 0 0 8px; }
.h4 { font-size: 13px; margin: 10px 0 4px; color: var(--text-2); font-weight: 500; }
.sub { font-weight: 400; color: var(--text-2); font-size: 12px; }
.hint { color: var(--text-2); font-size: 12px; margin: 6px 0 0; }
.foot { display: flex; flex-direction: column; gap: 2px; color: var(--text-2); font-size: 12px; padding: 0 16px 24px; max-width: 1100px; margin: 0 auto; }

/* 數字卡 */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 720px) { .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px; min-width: 0; }
.tile .k { color: var(--text-2); font-size: 12px; }
.tile .v { font-size: 22px; font-weight: 650; margin: 2px 0; overflow-wrap: anywhere; }
.tile .d { font-size: 13px; }
.tile .m { color: var(--text-2); font-size: 12px; margin-top: 4px; }

/* 漲跌：文字維持一般字色，旁邊的三角形帶顏色 */
.up::before, .down::before, .flat::before { display: inline-block; margin-right: 2px; font-size: 0.8em; }
.up::before { content: "▲"; color: var(--up); }
.down::before { content: "▼"; color: var(--down); }
.flat::before { content: "–"; color: var(--text-2); }

/* 篩選列（每頁一列，放在所有圖表上方） */
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 12px; }
.filters button {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; min-height: 32px;
}
.filters button[aria-pressed="true"] { background: var(--text); color: var(--page); border-color: var(--text); }

/* 圖表 */
.chart { height: 340px; width: 100%; }
.chart.short { height: 220px; }
.chart.vol { height: 120px; }
.chart.mini { height: 170px; }
@media (min-width: 720px) { .chart { height: 420px; } }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--text-2); min-height: 20px; margin-bottom: 4px; font-variant-numeric: tabular-nums; }
.legend .sw { display: inline-block; width: 10px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 4px; }
.legend b { color: var(--text); font-weight: 600; }
.multiples { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 720px) { .multiples { grid-template-columns: repeat(3, minmax(0, 1fr)); } .multiples.wide { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.mult h4 { margin: 0 0 2px; font-size: 13px; font-weight: 600; }
.mult .legend { min-height: 18px; }

/* 表格 */
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 7px 8px; border-bottom: 1px solid var(--grid); text-align: right; white-space: nowrap; }
table.data th:first-child, table.data td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); }
table.data th { color: var(--text-2); font-weight: 500; cursor: pointer; user-select: none; }
table.data th[aria-sort="ascending"]::after { content: " ↑"; }
table.data th[aria-sort="descending"]::after { content: " ↓"; }
table.data tr.grp td { background: var(--wash); font-weight: 600; text-align: left; }
table.data tbody tr.row { cursor: pointer; }
table.data tbody tr.row:hover td, table.data tbody tr.row:focus-within td { background: var(--wash); }
table.data tr.sel td { background: var(--wash); }
details.tv { margin-top: 8px; }
details.tv summary { color: var(--text-2); font-size: 12px; cursor: pointer; }
details.tv .scroll-x { max-height: 320px; overflow: auto; }

/* 清單 */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 8px 0; border-bottom: 1px solid var(--grid); display: flex; gap: 8px; align-items: baseline; }
.list li:last-child { border-bottom: 0; }
.list .when { color: var(--text-2); font-size: 12px; flex: none; width: 96px; font-variant-numeric: tabular-nums; }
.list .what { flex: 1; min-width: 0; }
.badge { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-2); margin-left: 4px; }
.alert-list { margin: 0; padding-left: 18px; }
.alert-title { font-weight: 650; margin: 0 0 6px; }
.alert-title::before { content: "⚠ "; color: var(--critical); }
.day { font-weight: 650; margin: 12px 0 2px; font-size: 14px; }
.day:first-child { margin-top: 0; }

/* 族群橫條 */
.bars { display: grid; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 64px 1fr 64px; align-items: center; gap: 8px; font-size: 13px; }
.bar-track { position: relative; height: 10px; }
.bar-track::before { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--axis); }
.bar-fill { position: absolute; top: 0; height: 10px; border-radius: 4px; }
.bar-val { text-align: right; font-variant-numeric: tabular-nums; }

@media (forced-colors: active) {
  .up::before, .down::before { forced-color-adjust: none; }
}
