/* 視覺整理:放在 style.css 與各頁 <style> 之後載入,只覆蓋外觀,不影響 JS 行為。
   三個頁面共用;各頁特有的樣式(強調色、燈號等)留在自己的 <style>。 */
:root {
  color-scheme: dark; /* 原生捲軸、下拉選單跟著深色 */
  --panel-2: #202833;
  --radius: 10px;
  --radius-sm: 6px;
  --tint: color-mix(in srgb, var(--accent) 16%, transparent);
  --tint-line: color-mix(in srgb, var(--accent) 50%, transparent);
  --on-accent: #14100b;
  --warn-bg: #2a2614;
  --warn-line: #4d4216;
  --warn-text: #f3d36b;
}
/* 淺色主題:theme.js 依使用者選擇或系統設定加上 data-theme */
/* 預設強調色(藍)在淺色底上調深;故意只用屬性選擇器,讓出貨頁 :root[data-theme] 的橘色優先 */
[data-theme="light"] { --accent: #1f6fd1; }
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6f9;
  --panel: #ffffff;
  --panel-2: #f0f2f6;
  --line: #dde2e8;
  --text: #1d232b;
  --muted: #5e6a79;
  --pos: #d42a2a;
  --neg: #12854a;
  --on-accent: #ffffff;
  --warn-bg: #fff6dc;
  --warn-line: #ecd08a;
  --warn-text: #845c00;
}

.theme-toggle {
  margin: 0 0 6px auto; flex: 0 0 auto; align-self: center;
  display: grid; place-items: center; width: 32px; height: 32px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel); color: var(--muted); cursor: pointer;
}
.theme-toggle:hover { color: var(--text); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-toggle svg { width: 16px; height: 16px; }
/* 顯示「切過去」的圖示:深色時給太陽、淺色時給月亮 */
:root[data-theme="light"] .theme-toggle .sun,
:root:not([data-theme="light"]) .theme-toggle .moon { display: none; }

/* 頁籤式導覽:取代原本右上角浮動連結,手機可橫向滑動 */
.topnav {
  display: flex; gap: 4px; flex: 0 0 auto;
  padding: 6px 12px 0; border-bottom: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: none;
}
.topnav::-webkit-scrollbar { display: none; }
.topnav a {
  padding: 8px 10px; margin-bottom: -1px; white-space: nowrap;
  color: var(--muted); text-decoration: none; font-size: .88rem;
  border-bottom: 2px solid transparent;
}
.topnav a:hover { color: var(--text); }
.topnav a[aria-current] { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }

header { padding: 16px 16px 8px; }
h1 { font-size: 1.35rem; letter-spacing: .02em; }
.sub { display: flex; flex-wrap: wrap; gap: 2px 14px; }
.sub > span { white-space: nowrap; }
.sub > .days { white-space: normal; } /* 交易日清單很長,允許換行 */
.sub strong { color: var(--text); font-weight: 600; }

.warn {
  position: relative; margin: 8px 16px 0; padding: 8px 12px 8px 34px;
  border-radius: var(--radius-sm); background: var(--warn-bg); border: 1px solid var(--warn-line);
  color: var(--warn-text); font-size: .82rem; line-height: 1.5;
}
.warn::before {
  content: "!"; position: absolute; left: 10px; top: 10px;
  width: 16px; height: 16px; border-radius: 50%; display: grid; place-items: center;
  background: var(--warn-text); color: var(--warn-bg); font-size: .7rem; font-weight: 700;
}

/* 篩選列:去掉色帶,改成浮在頁面上的元件 */
.controls { background: none; border: 0; padding: 12px 16px 4px; gap: 10px 14px; }

/* 分段切換 */
.tabs {
  display: inline-flex; gap: 2px; padding: 3px; max-width: 100%; overflow-x: auto; scrollbar-width: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  background: none; border: 0; border-radius: 7px; padding: 6px 12px;
  color: var(--muted); font: inherit; font-size: .88rem; cursor: pointer;
}
.tabs button:hover { color: var(--text); }
.tabs button.on { background: var(--tint); color: var(--text); box-shadow: inset 0 0 0 1px var(--tint-line); }
.tabs .n {
  min-width: 1.7em; padding: 0 6px; border-radius: 999px; text-align: center;
  background: var(--line); color: var(--text); font-size: .72rem; font-variant-numeric: tabular-nums;
}
.tabs button.on .n { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.tabs .sep { width: 1px; margin: 5px 3px; background: var(--line); }

/* 勾選框改成膠囊開關;input 保留(JS 讀 checked),只是視覺隱藏 */
.market-group { gap: 6px; }
.controls .chk {
  position: relative; gap: 4px; padding: 4px 12px; cursor: pointer; user-select: none;
  border: 1px solid var(--line); border-radius: 999px; color: var(--muted) !important;
}
.chk input { position: absolute; opacity: 0; pointer-events: none; }
.chk::before { content: "+"; width: .8em; text-align: center; opacity: .6; }
.chk:has(input:checked) { color: var(--text) !important; background: var(--tint); border-color: var(--tint-line); }
.chk:has(input:checked)::before { content: "✓"; opacity: 1; color: var(--accent); }
.chk:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

.controls select {
  appearance: none; -webkit-appearance: none; cursor: pointer;
  padding: 5px 28px 5px 10px; border-radius: var(--radius-sm); background-color: var(--panel);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5l3 3 3-3' fill='none' stroke='%238b95a3' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center; background-size: 12px;
}
.controls select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.count {
  padding: 3px 10px; border-radius: 999px; background: var(--tint);
  font-size: .85rem; font-variant-numeric: tabular-nums;
}
.note { margin: 6px 16px 8px; font-size: .78rem; }

/* 表格包成圓角卡片 */
main { padding: 0 16px 12px; }
/* 高度跟著內容,列數少時卡片不會拉滿整頁留白;列數多時仍在卡片內捲動 */
.table-wrap { flex: 0 1 auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table { font-variant-numeric: tabular-nums; }
th, td { padding: 10px; border-bottom-color: color-mix(in srgb, var(--line) 65%, transparent); }
thead th {
  background: var(--panel-2); border-bottom: 1px solid var(--line);
  font-size: .76rem; font-weight: 500; letter-spacing: .03em;
}
tbody tr:last-child > td { border-bottom: 0; }
tbody tr:hover { background: var(--panel-2); }
a.code { text-decoration: none; }
a.code:hover { text-decoration: underline; }
.tag { padding: 1px 8px; border-radius: 999px; background: var(--bg); }
/* 法人同步買超的每日明細欄很長;靠右時標題會被擠出畫面,改成和內容一起靠左 */
th.daily, td.daily { text-align: left; }

/* 掃描頁(吸籌、出貨)共用:分數色塊、訊號標籤、展開明細 */
.score { font-weight: 700; }
.lvl { display: inline-block; min-width: 2.4em; padding: 1px 6px; border-radius: var(--radius-sm); text-align: center; }
.lvl.hi { background: color-mix(in srgb, var(--accent) 30%, transparent); color: var(--text); }
.lvl.mid { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.sig { display: inline-block; font-size: .72rem; padding: 1px 8px; margin: 1px 2px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
td.sigs { text-align: left; white-space: normal; min-width: 180px; }
th[data-key="signals"] { text-align: left; } /* 標題跟內容一樣靠左 */
tr.detail { cursor: default; background: var(--bg); }
tr.detail:hover { background: var(--bg); }
tr.detail td { text-align: left; white-space: normal; padding: 14px 16px; }
.bars { display: grid; grid-template-columns: 5.5em 1fr 4em; gap: 6px 12px; align-items: center; max-width: 460px; font-size: .8rem; }
.bar { height: 6px; background: var(--line); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: var(--accent); }
.muted { color: var(--muted); font-size: .78rem; margin-top: 8px; line-height: 1.6; }
/* 四維燈號(吸籌、出貨頁) */
td.lights { white-space: nowrap; }
.dot { display: inline-block; width: 9px; height: 9px; margin: 0 1px; border-radius: 50%; background: var(--line); vertical-align: middle; }
.dot.red { background: var(--pos); }
.dot.green { background: var(--neg); }
.red-n { margin-left: 4px; font-size: .78rem; color: var(--muted); }

footer { padding: 10px 16px; }

@media (max-width: 560px) {
  .topnav { padding: 4px 6px 0; }
  header { padding: 12px 12px 6px; }
  h1 { font-size: 1.2rem; }
  .warn { margin: 6px 12px 0; }
  .controls { padding: 10px 12px 2px; gap: 8px 10px; }
  .tabs button { padding: 5px 9px; }
  .count { width: auto; margin: 0 0 0 auto; }
  .note { margin: 4px 12px 6px; }
  main { padding: 0 8px 8px; }
  th, td { padding: 9px 8px; }
  td.sigs { white-space: nowrap; min-width: 0; } /* 不換行,避免一列被訊號撐高 */
  /* 明細列橫跨整張寬表;內容釘在可視範圍內,不用橫滑才看得到 */
  tr.detail td > div { position: sticky; left: 16px; max-width: calc(100vw - 64px); }
  /* 凍結欄底色跟著卡片走 */
  tbody tr:not(.detail) > :nth-child(-n+2) { background: var(--panel); }
  tbody tr:not(.detail):hover > :nth-child(-n+2) { background: var(--panel-2); }
}
