/* ============================================================
   台股主動式 ETF 持倉研究網站｜設計系統
   風格基準：Apple 人機介面（大量留白、圓角材質、細分隔線、
   系統字體、克制的單一強調色、緩速 ease-out 動態）
   漲跌配色依臺灣慣例：紅為獲利／增加，綠為虧損／減少。
   ============================================================ */

:root {
  color-scheme: light dark;

  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Segoe UI Variable Text", "Segoe UI", "PingFang TC", "Microsoft JhengHei",
    "Noto Sans TC", system-ui, sans-serif;
  --font-num: "SF Mono", ui-monospace, "Cascadia Mono", "Segoe UI Mono", Menlo, Consolas, monospace;

  --bg: #f5f5f7;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-soft: #fbfbfd;
  --surface-hover: #f2f2f5;
  --surface-sunken: #eeeef1;
  --thead-bg: #eceef1;

  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #a1a1a6;

  --separator: rgba(0, 0, 0, 0.09);
  --separator-strong: rgba(0, 0, 0, 0.16);

  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-soft: rgba(0, 113, 227, 0.1);
  --accent-text: #0071e3;

  --gain: #d4001f;
  --gain-soft: rgba(212, 0, 31, 0.09);
  --loss: #00875a;
  --loss-soft: rgba(0, 135, 90, 0.09);
  --neutral: #86868b;

  --warn: #b25000;
  --warn-soft: rgba(178, 80, 0, 0.1);

  --nav-bg: rgba(251, 251, 253, 0.82);

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --radius-pill: 980px;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 4px 12px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.06), 0 12px 28px rgba(0, 0, 0, 0.07);
  --shadow-pop: 0 8px 20px rgba(0, 0, 0, 0.1), 0 24px 48px rgba(0, 0, 0, 0.12);

  --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur: 0.24s;

  --max-width: 1180px;
  --nav-height: 56px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --bg-elevated: #1c1c1e;
    --surface: #1c1c1e;
    --surface-soft: #161618;
    --surface-hover: #2c2c2e;
    --surface-sunken: #131315;
    --thead-bg: #2a2a2d;

    --text: #f5f5f7;
    --text-secondary: #98989d;
    --text-tertiary: #6e6e73;

    --separator: rgba(255, 255, 255, 0.1);
    --separator-strong: rgba(255, 255, 255, 0.2);

    --accent: #0a84ff;
    --accent-hover: #409cff;
    --accent-soft: rgba(10, 132, 255, 0.16);
    --accent-text: #4aa8ff;

    --gain: #ff453a;
    --gain-soft: rgba(255, 69, 58, 0.16);
    --loss: #30d158;
    --loss-soft: rgba(48, 209, 88, 0.15);
    --neutral: #98989d;

    --warn: #ff9f0a;
    --warn-soft: rgba(255, 159, 10, 0.16);

    --nav-bg: rgba(22, 22, 24, 0.78);

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5), 0 4px 14px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.5), 0 14px 32px rgba(0, 0, 0, 0.45);
    --shadow-pop: 0 10px 24px rgba(0, 0, 0, 0.55), 0 28px 56px rgba(0, 0, 0, 0.5);
  }
}

:root[data-theme="dark"] {
  --bg: #000000;
  --bg-elevated: #1c1c1e;
  --surface: #1c1c1e;
  --surface-soft: #161618;
  --surface-hover: #2c2c2e;
  --surface-sunken: #131315;
  --text: #f5f5f7;
  --text-secondary: #98989d;
  --text-tertiary: #6e6e73;
  --separator: rgba(255, 255, 255, 0.1);
  --separator-strong: rgba(255, 255, 255, 0.2);
  --accent: #0a84ff;
  --accent-hover: #409cff;
  --accent-soft: rgba(10, 132, 255, 0.16);
  --accent-text: #4aa8ff;
  --gain: #ff453a;
  --gain-soft: rgba(255, 69, 58, 0.16);
  --loss: #30d158;
  --loss-soft: rgba(48, 209, 88, 0.15);
  --neutral: #98989d;
  --warn: #ff9f0a;
  --warn-soft: rgba(255, 159, 10, 0.16);
  --nav-bg: rgba(22, 22, 24, 0.78);
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5), 0 4px 14px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.5), 0 14px 32px rgba(0, 0, 0, 0.45);
  --shadow-pop: 0 10px 24px rgba(0, 0, 0, 0.55), 0 28px 56px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: -0.003em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font-family: inherit; font-size: inherit; color: inherit; }

::selection { background: var(--accent-soft); }

/* ---------- 導覽列 ---------- */

.nav {
  position: sticky;
  top: 0;
  z-index: 60;
  height: var(--nav-height);
  background: var(--nav-bg);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--separator);
}

.nav-inner {
  max-width: var(--max-width);
  height: 100%;
  margin: 0 auto;
  padding: 0 22px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 10px;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.015em;
  color: var(--text);
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
/* 品牌全名「宇津台股ETF研究所」橫排比舊名「持倉研究」寬 68px，導覽列上限 1180px
   放不下。疊成兩行：小字「宇津台股」在上，寬度與舊名相當（多約 8px，由 margin 吸收）。 */
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-pre { font-size: 11px; font-weight: 500; color: var(--text-secondary); letter-spacing: 0.04em; }
.brand-mark {
  width: 22px; height: 22px;
  border-radius: 7px;
  background: linear-gradient(150deg, var(--accent) 0%, #5e5ce6 100%);
  display: grid; place-items: center;
  color: #fff; font-size: 11px; font-weight: 700; letter-spacing: 0;
}

.nav-links { display: flex; align-items: center; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.nav-links::-webkit-scrollbar { display: none; }

.nav-link {
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  color: var(--text-secondary);
  font-size: 13.5px;
  white-space: nowrap;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav-link:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.nav-link.is-active { background: var(--text); color: var(--bg-elevated); font-weight: 500; }

.nav-tools { display: flex; align-items: center; gap: 8px; margin-left: 12px; }

.icon-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border: 1px solid var(--separator);
  border-radius: var(--radius-pill);
  background: transparent;
  cursor: pointer;
  color: var(--text-secondary);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), transform 0.1s var(--ease);
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.icon-btn:active { transform: scale(0.94); }

.data-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--surface-hover);
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--loss); flex: none; }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--gain); }

/* ---------- 版面 ---------- */

main { max-width: var(--max-width); margin: 0 auto; padding: 30px 22px 90px; }

.page-head { margin-bottom: 26px; }
.page-title {
  margin: 0 0 6px;
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -0.021em;
  line-height: 1.13;
}
.page-sub { margin: 0; color: var(--text-secondary); font-size: 14px; max-width: 68ch; }

.section { margin-top: 34px; }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 14px; margin-bottom: 13px; flex-wrap: wrap;
}
.section-title { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -0.017em; }
.section-note { margin: 0; color: var(--text-tertiary); font-size: 12.5px; }

.card {
  background: var(--surface);
  border: 1px solid var(--separator);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}
.card-pad { padding: 20px 22px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
/* 全市場 KPI：固定五格，與 ETF 檔數無關，加到二十幾檔也不會變成一片卡海。 */
.grid-kpi { grid-template-columns: repeat(5, minmax(0, 1fr)); }

/* ---------- 基金總覽卡 ---------- */

.fund-card {
  background: var(--surface);
  border: 1px solid var(--separator);
  border-radius: var(--radius-xl);
  padding: 24px 26px 20px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--dur) var(--ease-out), transform var(--dur) var(--ease-out);
}
.fund-card:hover { box-shadow: var(--shadow-md); }

.fund-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.fund-code { font-size: 12px; font-weight: 600; letter-spacing: 0.06em; color: var(--accent-text); }
.fund-name { margin: 2px 0 0; font-size: 21px; font-weight: 600; letter-spacing: -0.018em; }
.fund-meta { margin: 5px 0 0; font-size: 12.5px; color: var(--text-tertiary); }

.hero-value { margin-top: 18px; }
.hero-label { font-size: 12.5px; color: var(--text-secondary); }
.hero-number {
  font-size: 40px; font-weight: 600; letter-spacing: -0.028em; line-height: 1.05;
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
}
.hero-number .unit { font-size: 16px; font-weight: 500; letter-spacing: -0.01em; color: var(--text-secondary); }
.hero-pct { font-size: 17px; font-weight: 600; letter-spacing: -0.015em; }

.stat-row {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 2px; margin-top: 20px;
  border-top: 1px solid var(--separator); padding-top: 16px;
}
.stat { min-width: 0; }
.stat-label { font-size: 11.5px; color: var(--text-tertiary); white-space: nowrap; }
.stat-value { font-size: 16px; font-weight: 600; letter-spacing: -0.014em; margin-top: 2px; }
.stat-value.sm { font-size: 14px; }

.pill-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 16px; }
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 11px; border-radius: var(--radius-pill);
  font-size: 12.5px; font-weight: 500;
  background: var(--surface-sunken); color: var(--text-secondary);
}
.pill b { font-weight: 600; color: var(--text); }
.pill.buy { background: var(--gain-soft); color: var(--gain); }
.pill.buy b { color: var(--gain); }
.pill.sell { background: var(--loss-soft); color: var(--loss); }
.pill.sell b { color: var(--loss); }
.pill.quiet { opacity: 0.62; }

/* ---------- 數值語意 ---------- */

.gain { color: var(--gain); }
.loss { color: var(--loss); }
.flat { color: var(--text-secondary); }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-num); font-size: 0.94em; }

/* ---------- 控制元件 ---------- */

.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--separator);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  margin-bottom: 16px;
}

/* ---- ETF 選擇器（全站共用） ---- */
.picker { position: relative; display: inline-block; }
.picker-btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 34px; padding: 0 11px 0 13px;
  background: var(--surface-sunken);
  border: 1px solid transparent; border-radius: 10px;
  font-family: inherit; font-size: 13px; color: var(--text);
  cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.picker-btn:hover { background: var(--surface-hover); }
.picker-btn[aria-expanded="true"] { border-color: var(--accent); background: var(--surface); }
.picker-label { font-variant-numeric: tabular-nums; }
.picker-caret { display: inline-flex; color: var(--text-tertiary); }
.picker-btn[aria-expanded="true"] .picker-caret { transform: rotate(180deg); }

.picker-panel {
  position: absolute; z-index: 40; top: calc(100% + 6px); left: 0;
  /* 20 檔 + 15 個投信群組標題 = 35 列、內容高約 1,090px。
     原本固定 400px 只看得到三分之一，改成跟著視窗高度走。 */
  width: 306px; max-height: min(72vh, 620px); overflow: hidden;
  display: flex; flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--separator);
  border-radius: 12px;
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.16);
}
.picker-panel[hidden] { display: none; }
.picker-search {
  flex: none; margin: 8px; padding: 0 11px; height: 32px;
  background: var(--surface-sunken);
  border: 1px solid transparent; border-radius: 8px;
  font-family: inherit; font-size: 13px; color: var(--text);
}
.picker-search:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.picker-list { overflow-y: auto; padding: 0 6px 8px; }
.picker-group {
  /* 捲動時投信名稱釘在頂端，否則滑到一半不知道現在看的是哪一家 */
  position: sticky; top: 0; z-index: 1;
  padding: 9px 8px 4px;
  background: var(--bg-elevated);
  font-size: 11px; font-weight: 600; letter-spacing: 0.04em;
  color: var(--text-tertiary);
}
.picker-empty { padding: 18px 8px; text-align: center; font-size: 12.5px; color: var(--text-tertiary); }

.picker-item { display: flex; align-items: center; gap: 2px; border-radius: 8px; }
.picker-item:hover { background: var(--surface-hover); }
.picker-item.is-on { background: var(--accent-soft); }
.picker-item.is-full { opacity: 0.4; }
.picker-pick {
  flex: 1; min-width: 0;
  display: flex; align-items: baseline; gap: 7px;
  padding: 7px 8px; border: 0; background: transparent;
  font-family: inherit; font-size: 13px; color: var(--text);
  text-align: left; cursor: pointer;
}
.picker-pick:disabled { cursor: not-allowed; }
.picker-item.is-on .picker-pick { color: var(--accent-text); font-weight: 600; }
.picker-code { flex: none; font-family: var(--font-num); font-size: 12px; letter-spacing: 0.02em; }
.picker-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-tags { flex: none; font-size: 10.5px; color: var(--text-tertiary); }
.picker-item.is-on .picker-tags { color: var(--accent-text); opacity: 0.75; }
.picker-pin {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; margin-right: 4px;
  border: 0; border-radius: 7px; background: transparent;
  color: var(--text-tertiary); cursor: pointer; opacity: 0;
  transition: opacity var(--dur) var(--ease), color var(--dur) var(--ease);
}
.picker-item:hover .picker-pin, .picker-pin.is-on { opacity: 1; }
.picker-pin:hover { color: var(--text-secondary); background: var(--surface-sunken); }
.picker-pin.is-on { color: var(--accent-text); }
.picker-pin.is-on svg { fill: currentColor; }

/* 多選時顯示已選 ETF 的可移除標籤 */
.picker-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.picker-chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 6px 0 10px;
  background: var(--accent-soft); color: var(--accent-text);
  border-radius: 8px; font-size: 12.5px; font-weight: 600;
  font-family: var(--font-num); letter-spacing: 0.02em;
}
.picker-chip button {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; padding: 0;
  border: 0; border-radius: 5px; background: transparent;
  color: inherit; cursor: pointer; opacity: 0.6;
}
.picker-chip button:hover { opacity: 1; background: var(--surface); }

/* ---------- 全站 ETF 快搜 ----------
   導覽列已經被 10 個分頁塞滿，1060px 就得靠縮字距才不溢出，
   所以觸發鍵只佔一顆 32px 圖示，面板改成蓋在畫面中央，不跟導覽列爭寬度。 */
.finder-backdrop {
  position: fixed; inset: 0; z-index: 90;
  display: flex; justify-content: center; align-items: flex-start;
  padding: 12vh 16px 16px;
  background: rgba(0, 0, 0, 0.34);
}
.finder-backdrop[hidden] { display: none; }
.finder {
  width: 100%; max-width: 460px; max-height: min(70vh, 560px);
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg-elevated);
  border: 1px solid var(--separator);
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}
.finder-head {
  flex: none; display: flex; align-items: center; gap: 9px;
  padding: 12px 12px 11px;
  border-bottom: 1px solid var(--separator);
}
.finder-icon { display: inline-flex; color: var(--text-tertiary); }
.finder-input {
  flex: 1; min-width: 0; height: 26px;
  border: 0; background: transparent;
  font-family: inherit; font-size: 15px; color: var(--text);
}
.finder-input:focus { outline: none; }
.finder-esc {
  flex: none; padding: 3px 7px;
  border: 1px solid var(--separator); border-radius: 6px;
  background: transparent; cursor: pointer;
  font-family: var(--font-num); font-size: 11px; color: var(--text-tertiary);
}
.finder-esc:hover { background: var(--surface-hover); color: var(--text); }
.finder-list { overflow-y: auto; padding: 6px; }
.finder-item {
  display: flex; align-items: baseline; gap: 9px; width: 100%;
  padding: 8px 10px; border: 0; border-radius: 8px;
  background: transparent; cursor: pointer; text-align: left;
  font-family: inherit; font-size: 13.5px; color: var(--text);
}
.finder-item.is-cursor { background: var(--accent-soft); color: var(--accent-text); }
.finder-code { flex: none; font-family: var(--font-num); font-size: 12.5px; letter-spacing: 0.02em; }
.finder-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.finder-tags { flex: none; font-size: 10.5px; color: var(--text-tertiary); }
.finder-item.is-cursor .finder-tags { color: var(--accent-text); opacity: 0.75; }
.finder-hint {
  flex: none; padding: 8px 12px;
  border-top: 1px solid var(--separator);
  font-size: 11.5px; color: var(--text-tertiary);
}
/* 面板開著時鎖住背景捲動，否則手機上滑清單會連整頁一起帶走 */
body.modal-open { overflow: hidden; }

.segmented {
  display: inline-flex; padding: 2px; gap: 2px;
  background: var(--surface-sunken);
  border-radius: 10px;
}
.segmented button {
  border: 0; background: transparent; cursor: pointer;
  padding: 5px 13px; border-radius: 8px;
  font-size: 13px; color: var(--text-secondary);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  white-space: nowrap;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"] {
  background: var(--surface); color: var(--text); font-weight: 600;
  box-shadow: var(--shadow-xs);
}

.segmented a {
  display: inline-flex; align-items: center;
  padding: 5px 13px; border-radius: 8px;
  font-size: 13px; color: var(--text-secondary); text-decoration: none;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  white-space: nowrap;
}
.segmented a:hover { color: var(--text); text-decoration: none; }
.segmented a[aria-current="page"] {
  background: var(--surface); color: var(--text); font-weight: 600;
  box-shadow: var(--shadow-xs);
}

/* ---------- 期貨與選擇權 ---------- */

.derivative-etf-grid { align-items: stretch; }
.derivative-etf-card {
  display: flex; flex-direction: column; min-width: 0;
  padding: 20px; color: inherit; text-decoration: none;
  background: var(--surface); border: 1px solid var(--separator);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-sm);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease-out);
}
.derivative-etf-card:hover {
  color: inherit; text-decoration: none; border-color: var(--accent);
  box-shadow: var(--shadow-md); transform: translateY(-1px);
}
.derivative-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.derivative-code { font-family: var(--font-num); font-size: 17px; font-weight: 700; letter-spacing: 0.025em; }
.tag.current { background: var(--accent-soft); color: var(--accent-text); }
.derivative-fund-name {
  margin-top: 3px; min-height: 18px; color: var(--text-secondary);
  font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.derivative-card-meta {
  margin-top: 13px; padding-top: 11px; border-top: 1px solid var(--separator);
  color: var(--text-tertiary); font-size: 11.5px;
}
.derivative-card-legs { display: grid; gap: 8px; margin-top: 10px; }
.derivative-leg-summary {
  display: grid; grid-template-columns: minmax(64px, .75fr) repeat(3, minmax(68px, 1fr));
  gap: 7px; align-items: end; padding: 10px 11px;
  background: var(--surface-sunken); border-radius: var(--radius-sm);
}
.derivative-leg-summary > div { min-width: 0; }
.derivative-leg-summary span { display: block; color: var(--text-tertiary); font-size: 10.5px; }
.derivative-leg-summary b { display: block; margin-top: 2px; font-size: 13px; white-space: nowrap; }
.derivative-leg-name b { font-size: 14px; }
.derivative-leg-summary small {
  grid-column: 2 / -1; color: var(--text-secondary); font-size: 10.5px; text-align: right;
}
.derivative-card-link { margin-top: auto; padding-top: 13px; color: var(--accent-text); font-size: 12.5px; font-weight: 600; }
.derivative-history-card {
  display: grid; gap: 7px; padding: 16px 18px; color: inherit; text-decoration: none;
}
.derivative-history-card:hover { text-decoration: none; border-color: var(--accent); }
.derivative-history-card > strong { font-size: 13.5px; }
.derivative-history-card > span { color: var(--text-tertiary); font-size: 12px; }
.derivative-disclosure { margin-top: 12px; overflow: hidden; }
.derivative-disclosure > summary { cursor: pointer; list-style: none; user-select: none; }
.derivative-disclosure > summary::-webkit-details-marker { display: none; }
.derivative-disclosure > summary {
  padding: 13px 16px; color: var(--text-secondary); font-size: 12.5px; font-weight: 600;
}
.derivative-disclosure > summary::before { content: '＋'; display: inline-block; width: 20px; color: var(--accent-text); }
.derivative-disclosure[open] > summary::before { content: '－'; }
.derivative-disclosure-body { padding: 0 12px 12px; }
.derivative-tabs { margin: -8px 0 4px; overflow-x: auto; max-width: 100%; }
.derivative-detail-section { margin-top: 22px; }
.settlement-disclosure { margin-bottom: 9px; overflow: hidden; }
.settlement-disclosure > summary {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 13px 17px; cursor: pointer; list-style: none; user-select: none;
}
.settlement-disclosure > summary::-webkit-details-marker { display: none; }
.settlement-disclosure > summary::before { content: '＋'; color: var(--accent-text); font-weight: 700; }
.settlement-disclosure[open] > summary::before { content: '－'; }
.settlement-disclosure > summary > span:first-of-type { flex: 1; }
.settlement-result { text-align: right; font-size: 15px; font-weight: 700; white-space: nowrap; }
.settlement-result small { display: block; margin-top: 2px; font-size: 11px; font-weight: 500; color: var(--text-secondary); }
.settlement-flow { display: block; margin-top: 3px; font-size: 12px; color: var(--text-secondary); }
.settlement-flow b { color: var(--text); font-weight: 600; }
.settlement-story { margin: 12px 0 0; font-size: 13px; line-height: 1.6; color: var(--text-secondary); }
.settlement-body { padding: 0 18px 16px 42px; border-top: 1px solid var(--separator); }

.field {
  display: flex; align-items: center; gap: 7px;
  padding: 0 12px; height: 34px;
  background: var(--surface-sunken);
  border: 1px solid transparent;
  border-radius: 10px;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.field:focus-within { border-color: var(--accent); background: var(--surface); }
.field svg { flex: none; color: var(--text-tertiary); }
.field input, .field select {
  border: 0; background: transparent; outline: none;
  font-size: 13.5px; color: var(--text); min-width: 0; width: 100%;
  font-family: inherit;
}
.field.w-search { width: 236px; }
.field.w-sm { width: auto; }
.field select { cursor: pointer; }

.btn {
  height: 34px; padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--separator);
  background: var(--surface); cursor: pointer;
  font-size: 13.5px; color: var(--text);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), transform 0.1s var(--ease);
}
.btn:hover { background: var(--surface-hover); }
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-secondary); }
.btn.ghost:hover { background: var(--surface-hover); color: var(--text); }

.spacer { flex: 1; }
.count-note { font-size: 12.5px; color: var(--text-tertiary); white-space: nowrap; }

/* ---------- 分頁列 ---------- */
.pager {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-top: 12px;
}
.pager-nav { display: flex; gap: 6px; flex-wrap: wrap; }
.pager-nav .btn[disabled] { opacity: 0.4; cursor: default; pointer-events: none; }

/* ---------- 表格 ---------- */

/* ---- 比較頁：重疊矩陣與雙行儲存格 ---- */
.matrix-wrap { padding: 6px; overflow-x: auto; }
.matrix { border-collapse: collapse; width: 100%; font-size: 13px; }
.matrix th, .matrix td {
  padding: 9px 12px; text-align: right;
  border-bottom: 1px solid var(--separator);
  font-variant-numeric: tabular-nums;
}
.matrix tr:last-child th, .matrix tr:last-child td { border-bottom: 0; }
.matrix th {
  background: var(--thead-bg);
  border-bottom: 1px solid var(--separator-strong);
  font-weight: 600; color: var(--text); font-family: var(--font-num); font-size: 14px;
}
.matrix tr:first-child th:first-child { border-top-left-radius: 8px; }
.matrix tr:first-child th:last-child { border-top-right-radius: 8px; }
.matrix th.left { text-align: left; color: var(--text); background: transparent; border-bottom-color: var(--separator); }
.matrix td { color: var(--text); }
.matrix td.self { color: var(--text-tertiary); background: var(--surface-sunken); }
.matrix td.unique { color: var(--text-secondary); font-style: normal; }

.cell-two { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; line-height: 1.3; }
.cell-two span { font-variant-numeric: tabular-nums; }
.cell-two b { font-size: 12px; }
/* 跨檔比較時標出成本最低與最高的那一檔，只加細微標記，不搶走漲跌色 */
.cell-two.is-low > span { color: var(--accent-text); font-weight: 600; }
.cell-two.is-high > span { color: var(--warn); font-weight: 600; }
.dim { color: var(--text-tertiary); }
.warn-text { color: var(--warn); font-weight: 600; }

/* 推估成本的就地口徑註記：資訊要看得到，但不搶走表格的視線 */
/* 建倉脈絡圖的控制列：ETF 開關與區間切換 */
.chart-controls {
  display: flex; flex-wrap: wrap; align-items: center;
  justify-content: space-between; gap: 12px;
  margin-bottom: 4px;
}
.legend-toggle {
  border: 0; background: transparent; padding: 3px 7px;
  border-radius: 7px; cursor: pointer; font-family: inherit;
  transition: background var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.legend-toggle:hover { background: var(--surface-hover); }
.legend-toggle.is-off { opacity: 0.45; }
.legend-toggle.is-off:hover { opacity: 0.75; }

.lineage-verdict {
  margin: 12px 2px 0;
  padding: 11px 14px;
  background: var(--accent-soft);
  border-radius: 10px;
  font-size: 13px; line-height: 1.7; color: var(--text-secondary);
}
.lineage-verdict b { color: var(--text); font-weight: 600; }

.cost-note {
  margin: 14px 2px 0;
  padding: 11px 14px;
  background: var(--surface-sunken);
  border-radius: 10px;
  font-size: 12.5px; line-height: 1.65;
  color: var(--text-secondary);
}
.cost-note b { color: var(--text); font-weight: 600; }
.cost-note a { color: var(--accent-text); }

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--separator);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}
/* 表格自帶捲動區：橫向永遠可捲，縱向設高度上限讓表頭可以固定。 */
.table-scroll {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  max-height: calc(100vh - 210px);
  min-height: 180px;
  overscroll-behavior: contain;
}
.table-scroll.short { max-height: none; min-height: 0; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  position: sticky; top: 0; z-index: 2;
  /* 標題列要能一眼認出來：專用底色（與資料列差一階）、主文字色、
     14px，並用較強的分隔線收邊。捲動時這條會固定在上面，對比不夠會整條糊掉。 */
  background: var(--thead-bg);
  border-bottom: 1px solid var(--separator-strong);
  padding: 13px 12px;
  font-size: 14px; font-weight: 600; color: var(--text);
  text-align: right; white-space: nowrap;
  letter-spacing: 0;
}
thead th:first-child, thead th.left { text-align: left; }
thead th.sortable { cursor: pointer; user-select: none; transition: color var(--dur) var(--ease); }
thead th.sortable:hover { color: var(--accent-text); }
thead th .arrow { opacity: 0.3; margin-left: 4px; font-size: 10px; font-weight: 400; }
thead th.sortable:hover .arrow { opacity: 0.6; }
thead th.sorted { color: var(--accent-text); }
thead th.sorted .arrow { opacity: 1; }

tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--separator);
  text-align: right; white-space: nowrap;
}
tbody td:first-child, tbody td.left { text-align: left; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; transition: background 0.14s var(--ease); }
tbody tr.clickable:hover { background: var(--surface-hover); }

/* 一檔一欄的寬表：第一欄（股票）釘在左側。
   20 檔會長到 25 欄、約 2,276px，橫捲後沒有這個就認不出在看哪一列。 */
table.sticky-first thead th:first-child {
  position: sticky; left: 0; z-index: 3;
  background: var(--thead-bg);
}
table.sticky-first tbody td:first-child {
  position: sticky; left: 0; z-index: 1;
  background: var(--surface);
  border-right: 1px solid var(--separator);
}
table.sticky-first tbody tr.clickable:hover td:first-child { background: var(--surface-hover); }

.cell-stock { display: flex; align-items: center; gap: 9px; min-width: 0; }
.code-badge {
  font-family: var(--font-num); font-size: 11.5px; font-weight: 600;
  padding: 2px 7px; border-radius: 6px;
  background: var(--surface-sunken); color: var(--text-secondary);
  flex: none;
}
.stock-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; max-width: 15ch; }

/* ---------- 可展開的表格列（總覽頁的每檔 ETF） ----------
   一列一檔、點列就地展開，取代原本每檔一張大卡的排法：
   卡片排法在五檔就要捲一段，往二十幾檔走會變成無止境捲動。 */

.row-expand { display: inline-flex; margin-right: 7px; color: var(--text-tertiary); vertical-align: -1px; }
.row-expand svg { transform: rotate(-90deg); transition: transform var(--dur) var(--ease); }
tr.is-open .row-expand { color: var(--accent-text); }
tr.is-open .row-expand svg { transform: rotate(0); }
tr.is-open > td { background: var(--surface-hover); border-bottom-color: transparent; }

.row-detail > td { padding: 0; background: var(--surface-sunken); }
.fund-panel {
  display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 24px; padding: 18px 22px 22px;
  /* 表格儲存格預設不換行、靠右；面板要回到一般排版 */
  white-space: normal; text-align: left;
}
.panel-main { min-width: 0; }
.panel-main .fund-meta { margin: 0 0 2px; }
.panel-boards { display: grid; gap: 12px; align-content: start; min-width: 0; }
.panel-board {
  background: var(--surface); border: 1px solid var(--separator);
  border-radius: var(--radius); padding: 11px 14px 9px;
}
.panel-row {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 3px 0; font-size: 13px; color: inherit;
}
.panel-row:hover { text-decoration: none; color: var(--accent-text); }
.panel-row-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel-row b { white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------- 色弱友善模式 ----------
   紅綠是紅綠色盲最難分辨的一組。切到此模式後，漲跌改用金黃／靛藍，
   保留「暖色＝上漲」的直覺，只覆寫 --gain／--loss 系列代幣。

   換色理由：原本用橙／藍，色盲安全但**兩色亮度幾乎相同**
   （深色底亮度比 1.03、淺色底 1.15），一般色覺讀起來反而比紅綠更吃力
   （CIEDE2000 由紅綠的 77 掉到 48）。金黃／靛藍同時拉開色相與亮度，
   四項指標全面優於舊值：

     深色底 #1c1c1e   亮度比 1.03 -> 2.11   一般 48.5 -> 67.8
                      protan 45.4 -> 63.2   deutan 50.5 -> 66.5
     淺色底 #ffffff   亮度比 1.15 -> 2.02   一般 47.7 -> 62.2
                      protan 46.7 -> 58.5   deutan 52.7 -> 61.6

   代價：三色覺缺陷（tritan，盛行率遠低於紅綠型）由 54~58 降到 42~49，
   仍在可辨範圍。本模式的目標本來就是紅綠型。 */
:root[data-cvd="safe"] {
  --gain: #8a6d00;
  --gain-soft: rgba(138, 109, 0, 0.11);
  --loss: #3730a3;
  --loss-soft: rgba(55, 48, 163, 0.11);
}
@media (prefers-color-scheme: dark) {
  :root[data-cvd="safe"]:not([data-theme="light"]) {
    --gain: #ffd60a;
    --gain-soft: rgba(255, 214, 10, 0.18);
    --loss: #7c8cff;
    --loss-soft: rgba(124, 140, 255, 0.18);
  }
}
:root[data-cvd="safe"][data-theme="dark"] {
  --gain: #ffd60a;
  --gain-soft: rgba(255, 214, 10, 0.18);
  --loss: #7c8cff;
  --loss-soft: rgba(124, 140, 255, 0.18);
}

/* 只描邊、不填色：填色留給 .tag（狀態），描邊代表身分。
   內距少 1px 補回外框佔掉的寬度，整體尺寸與填色版一致。 */
.etf-tag {
  display: inline-block; padding: 1px 7px; border-radius: var(--radius-pill);
  font-size: 11.5px; font-weight: 600; letter-spacing: 0.02em;
  background: transparent; border: 1px solid currentColor;
  text-decoration: none; cursor: pointer;
}
/* 標籤是通往該檔專頁的連結；hover 才淡淡填色，平時維持描邊代表身分 */
.etf-tag:hover { background: color-mix(in srgb, currentColor 14%, transparent); }
/* 資料較短時的成本標記。掛在 ETF 代號旁與成本數字後，
   要不要畫完全由後端的旗標決定，前端不判斷條件。 */
.uncal-badge {
  display: inline-grid; place-items: center;
  width: 15px; height: 15px; margin-left: 3px;
  border-radius: 50%; font-size: 9.5px; font-weight: 700; line-height: 1;
  white-space: nowrap; vertical-align: 2px;
  background: var(--warn-soft); color: var(--warn);
  border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  cursor: help;
}
.uncal-mark {
  margin-left: 2px; color: var(--warn); font-weight: 700; cursor: help;
}

/* 同一格裡並排數個 ETF 標籤（當日個股動向的「誰在買／誰在賣」） */
.tag-list { display: flex; flex-wrap: wrap; gap: 4px; }

/* ---------- 今日焦點的金額排行 ---------- */

.rank-row {
  display: block; padding: 7px 0 9px; color: inherit;
  border-bottom: 1px solid var(--separator);
}
.rank-row:last-child { border-bottom: 0; padding-bottom: 2px; }
.rank-row:hover { text-decoration: none; }
.rank-row:hover .rank-name { color: var(--accent-text); }
.rank-line { display: flex; align-items: center; gap: 9px; font-size: 13.5px; }
.rank-no {
  flex: none; width: 17px; text-align: center;
  font-size: 11.5px; font-weight: 600; color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}
.rank-name {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 7px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rank-amt { flex: none; font-variant-numeric: tabular-nums; }
.rank-foot { display: flex; align-items: center; gap: 9px; margin: 5px 0 0 26px; }
.rank-foot .bar-track { flex: 1; min-width: 0; }
/* 原本 flex:none 讓標籤永不收縮，一檔股票 9 家一起動就會撐出卡片外
   （市場共識頁實測溢出 72px）。改成可收縮並換行，長名單往下疊。 */
.rank-foot .tag-list { flex: 0 1 auto; min-width: 0; justify-content: flex-end; }

/* 近 N 日成績單的「最好／最差」欄 */
.pick-cell { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-width: 168px; }
/* 顏色由 app.js 的 ETF_PALETTE 依基金清單順序指派並以 inline style 套用；
   這裡不再每檔寫死一條規則，否則每加一檔 ETF 就要改 CSS。 */

/* 色彩模式按鈕：開啟時以強調色填色，讓目前狀態一眼可辨 */
.icon-btn[aria-pressed="true"] { color: var(--accent-text); background: var(--accent-soft); }

.tag-row { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.tag {
  display: inline-block; padding: 2px 9px; border-radius: var(--radius-pill);
  font-size: 11.5px; font-weight: 500; white-space: nowrap;
  background: var(--surface-sunken); color: var(--text-secondary);
}
.tag.buy { background: var(--gain-soft); color: var(--gain); }
.tag.sell { background: var(--loss-soft); color: var(--loss); }
.tag.exit { background: var(--warn-soft); color: var(--warn); }
.tag.rebuy { background: var(--accent-soft); color: var(--accent-text); }

/* ---------- 族群淨額條（市場共識頁） ----------
   以中線為零，向右為淨買超、向左為淨賣超；長度只在同一張表內相對比較。 */
.ind-row { display: flex; align-items: center; gap: 10px; padding: 5px 0; }
.ind-name { width: 116px; flex: none; font-size: 12.5px; color: var(--text-secondary); }
.ind-track { position: relative; flex: 1; height: 14px; border-radius: 4px; background: var(--surface-sunken); }
.ind-zero { position: absolute; left: 50%; top: -1px; bottom: -1px; width: 1px; background: var(--separator-strong); }
.ind-fill { position: absolute; top: 2px; bottom: 2px; border-radius: 3px; }
.ind-fill.up { background: var(--gain); }
.ind-fill.down { background: var(--loss); }
.ind-amt { width: 92px; flex: none; text-align: right; font-size: 12.5px; font-variant-numeric: tabular-nums; }

/* ---------- 績效對比：對照基準置頂列 ---------- */
.bench-bar {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 20px; flex-wrap: wrap;
  border: 1px solid color-mix(in srgb, var(--accent) 32%, transparent);
}
.bench-name { margin-top: 5px; font-size: 17px; font-weight: 600; }
.bench-right { text-align: right; min-width: 260px; }

/* ---------- 走勢條 ---------- */

.bar-track {
  position: relative; height: 5px; width: 62px; border-radius: 3px;
  background: var(--surface-sunken); overflow: hidden; display: inline-block; vertical-align: middle;
}
.bar-fill { position: absolute; top: 0; bottom: 0; border-radius: 3px; }
/* 漲跌色寫在樣式表裡，切換色彩模式時才會跟著代幣重算；
   放進 inline style 的 var() 是在插入當下就定色的，換模式不會變。 */
.bar-fill.up { background: var(--gain); }
.bar-fill.down { background: var(--loss); }

/* ---------- 空狀態／訊息 ---------- */

.empty {
  padding: 54px 24px; text-align: center; color: var(--text-tertiary);
}
.empty-title { font-size: 16px; font-weight: 600; color: var(--text-secondary); margin-bottom: 5px; }
.empty-body { font-size: 13.5px; }

.notice {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 15px 18px; border-radius: var(--radius);
  background: var(--warn-soft); color: var(--warn);
  font-size: 13.5px; margin-bottom: 18px;
  border: 1px solid color-mix(in srgb, var(--warn) 24%, transparent);
}
.notice.error { background: var(--gain-soft); color: var(--gain); border-color: color-mix(in srgb, var(--gain) 24%, transparent); }
.notice strong { display: block; margin-bottom: 3px; }
.notice code {
  font-family: var(--font-num); font-size: 12.5px;
  background: rgba(0, 0, 0, 0.06); padding: 1px 6px; border-radius: 5px;
}

.skeleton {
  background: linear-gradient(90deg, var(--surface-sunken) 25%, var(--surface-hover) 50%, var(--surface-sunken) 75%);
  background-size: 300% 100%;
  animation: shimmer 1.3s var(--ease) infinite;
  border-radius: var(--radius);
}
@keyframes shimmer { 0% { background-position: 150% 0; } 100% { background-position: -150% 0; } }

/* 給搜尋引擎的文字摘要：資料載入前會短暫露出，載入後由 app.js 移除 */
.seo-summary {
  max-width: var(--max-width); margin: 0 auto; padding: 0 22px 60px;
  color: var(--text-muted, inherit); font-size: 14px; line-height: 1.7;
}
.seo-summary h2 { font-size: 17px; margin: 0 0 8px; }
.seo-summary h3 { font-size: 15px; margin: 16px 0 6px; }

/* 期權位階圖與檔位走勢：手機上縮到 900 寬的四成字會看不清，改成可左右滑 */
@media (max-width: 640px) {
  .chart-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .chart-scroll > svg { min-width: 680px; }
}

/* ---------- 單檔 ETF 專頁 ---------- */

/* 標題列左右兩欄：左為身分（代號、全名、投信與策略），右為損益。
   窄視窗時 wrap 成上下排列，不另寫斷點。 */
.fund-hero {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 20px; flex-wrap: wrap; margin: 6px 0 18px;
}
.fund-hero-name { margin: 8px 0 0; font-size: 26px; font-weight: 600; letter-spacing: -0.02em; }
.fund-hero-tags { margin: 6px 0 0; color: var(--text-tertiary); font-size: 13px; }
.fund-hero-pnl { text-align: right; min-width: 240px; }
.fund-hero-meta { margin: 5px 0 0; color: var(--text-tertiary); font-size: 12px; }
.back-link { display: inline-block; font-size: 13px; margin-bottom: 4px; }
/* 區塊內的次級標題，與 h2 拉出層次 */
.section-title.sm { font-size: 15px; }

/* ---------- 個股詳細 ---------- */

.detail-hero {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 20px; flex-wrap: wrap; margin-bottom: 22px;
}
.detail-title { display: flex; align-items: center; gap: 13px; flex-wrap: wrap; }
.detail-code {
  font-family: var(--font-num); font-size: 15px; font-weight: 600;
  padding: 4px 11px; border-radius: 9px;
  background: var(--surface-sunken); color: var(--text-secondary);
}

.chart-card { padding: 20px 8px 12px 4px; }
.chart-legend {
  display: flex; flex-wrap: wrap; gap: 16px;
  padding: 0 20px 12px; font-size: 12.5px; color: var(--text-secondary);
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 14px; height: 3px; border-radius: 2px; }
.legend-swatch.dash { background: none; border-top: 2px dashed currentColor; height: 0; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; }

svg.chart { display: block; width: 100%; height: auto; overflow: visible; }
svg.chart text { font-family: var(--font-sans); font-size: 10.5px; fill: var(--text-tertiary); }
svg.chart .grid-line { stroke: var(--separator); stroke-width: 1; }
svg.chart .axis-line { stroke: var(--separator-strong); stroke-width: 1; }
.chart-hover-line { stroke: var(--text-tertiary); stroke-width: 1; stroke-dasharray: 3 3; }

.chart-tip {
  position: absolute; pointer-events: none; z-index: 40;
  background: var(--surface); border: 1px solid var(--separator);
  border-radius: var(--radius); box-shadow: var(--shadow-pop);
  padding: 10px 13px; font-size: 12.5px; min-width: 168px;
  transition: opacity 0.12s var(--ease);
}
.chart-tip .tip-date { font-weight: 600; margin-bottom: 6px; font-size: 12px; color: var(--text-secondary); }
.chart-tip .tip-row { display: flex; justify-content: space-between; gap: 16px; }
.chart-tip .tip-row span:first-child { color: var(--text-secondary); }

.chart-holder { position: relative; }

/* ---------- 說明頁 ---------- */

.prose { max-width: 74ch; font-size: 14.5px; line-height: 1.68; }
.prose h3 { font-size: 17px; font-weight: 600; letter-spacing: -0.014em; margin: 28px 0 8px; }
.prose h3:first-child { margin-top: 0; }
.prose p { margin: 0 0 12px; color: var(--text-secondary); }
.prose ul { margin: 0 0 14px; padding-left: 20px; color: var(--text-secondary); }
.prose li { margin-bottom: 5px; }
.prose strong { color: var(--text); font-weight: 600; }
.prose code {
  font-family: var(--font-num); font-size: 13px;
  background: var(--surface-sunken); padding: 1.5px 6px; border-radius: 5px; color: var(--text);
}

.kv { display: grid; grid-template-columns: minmax(0, 150px) minmax(0, 1fr); gap: 6px 18px; font-size: 13.5px; }
.kv dt { color: var(--text-secondary); }
.kv dd { margin: 0; }

/* ---------- 頁尾 ---------- */

.foot {
  max-width: var(--max-width); margin: 0 auto; padding: 26px 22px 40px;
  border-top: 1px solid var(--separator);
  color: var(--text-tertiary); font-size: 12.5px;
}
/* 所有權聲明另起一行，與資料日、口徑說明分開，才不會被讀成同一句附註 */
.foot-rights { margin-top: 8px; font-size: 12px; opacity: 0.85; }

/* ---------- 進場動畫 ---------- */

.view { animation: rise 0.34s var(--ease-out) both; }
@keyframes rise { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------- 手機 ---------- */

/* 導覽 9 項在 1120px 以下會把最後一項（研究口徑）擠出可視範圍。
   縮的是字距不是字：標籤全部維持看得懂，只讓膠囊貼緊文字。 */
@media (max-width: 1120px) {
  .nav-link { padding: 6px 8px; }
  .brand { margin-right: 10px; }
  .nav-tools { margin-left: 8px; }
}
/* 導覽第 10 項（績效對比）讓 1024px 又溢出 30px。再收一段字距與品牌區，
   下限落在約 960px；更窄就退回既有的橫捲行為。 */
@media (max-width: 1060px) {
  .nav-link { padding: 6px 6px; font-size: 13px; }
  .brand { margin-right: 6px; }
  .brand-text { display: none; }
  .nav-tools { margin-left: 6px; }
}

@media (max-width: 1080px) {
  .grid-kpi { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .fund-panel { grid-template-columns: minmax(0, 1fr); gap: 18px; }
}

@media (max-width: 900px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .derivative-etf-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 760px) {
  main { padding: 22px 15px 70px; }
  .finder-backdrop { padding: 7vh 12px 12px; }
  .finder { max-height: min(78vh, 560px); }
  .nav-inner { padding: 0 14px; }
  .brand span.brand-text { display: none; }
  .page-title { font-size: 25px; }
  .hero-number { font-size: 32px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .grid-kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* 表格在窄螢幕會比視窗寬並橫向捲動；展開的面板跟著左緣黏住，
     才不必為了看一段文字先把表格往右捲。 */
  .fund-panel {
    position: sticky; left: 0;
    width: calc(100vw - 30px); padding: 16px 14px 18px;
  }
  .fund-card { padding: 20px 18px 16px; border-radius: var(--radius-lg); }
  .toolbar { padding: 12px; gap: 8px; }
  .field.w-search { width: 100%; }
  .toolbar .spacer { display: none; }
  .count-note { width: 100%; }
  table { font-size: 12.5px; }
  thead th, tbody td { padding: 8px 9px; }
  /* 手機不做巢狀縱向捲動，整頁捲即可 */
  .table-scroll { max-height: none; min-height: 0; overflow-y: visible; }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 2px 0; }
  .kv dd { margin-bottom: 10px; }
  .derivative-leg-summary { grid-template-columns: minmax(58px, .75fr) repeat(3, minmax(62px, 1fr)); }
  .settlement-disclosure > summary { align-items: flex-start; }
  .settlement-body { padding-left: 16px; }
}

/* ============================================================
   手機版（2026-11-03 重排）
   三件事：底部分頁列取代頂部導覽、表格變卡片、圖例收合。
   只在 760px 以下生效，桌機完全不變。
   ============================================================ */

.tabbar { display: none; }
.more-sheet { display: none; }
.table-sortbar { display: none; }
.legend-more { display: none; }

@media (max-width: 760px) {
  :root { --tabbar-height: 58px; }

  /* 頂部只留品牌與工具列；頁面連結改由底部分頁列負責 */
  .nav-links { display: none; }
  .nav-tools { margin-left: auto; }
  main { padding-bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom, 0px) + 28px); }
  .foot { padding-bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom, 0px) + 12px); }

  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
    height: calc(var(--tabbar-height) + env(safe-area-inset-bottom, 0px));
    padding: 0 4px env(safe-area-inset-bottom, 0px);
    background: var(--nav-bg);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-top: 1px solid var(--separator);
  }
  .tabbar .tab {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    min-height: 44px; margin: 6px 2px;
    border: 0; border-radius: var(--radius);
    background: transparent; color: var(--text-tertiary);
    font: inherit; font-size: 11px; letter-spacing: 0.01em; text-decoration: none; cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
  }
  .tabbar .tab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
  .tabbar .tab.is-active { color: var(--text); font-weight: 600; }
  .tabbar .tab.is-active svg { stroke-width: 2.1; }
  .tabbar .tab[aria-expanded="true"] { color: var(--text); background: var(--surface-hover); }

  /* 「更多」底部抽屜 */
  .more-sheet { display: block; position: fixed; inset: 0; z-index: 69; }
  .more-sheet[hidden] { display: none; }
  .more-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.35); }
  .more-panel {
    position: absolute; left: 0; right: 0;
    bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom, 0px));
    background: var(--bg-elevated);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding: 8px 10px 12px;
    box-shadow: var(--shadow-pop);
    animation: sheet-up 0.22s var(--ease-out);
  }
  .more-grip { width: 36px; height: 4px; margin: 2px auto 10px; border-radius: 2px; background: var(--separator-strong); }
  .more-link {
    display: flex; flex-direction: column; gap: 1px;
    padding: 11px 12px; border-radius: var(--radius);
    color: var(--text); font-size: 15px; font-weight: 500; text-decoration: none;
  }
  .more-link small { font-size: 12px; font-weight: 400; color: var(--text-tertiary); }
  .more-link:active, .more-link.is-active { background: var(--surface-hover); }
  @keyframes sheet-up { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }

  /* 表格變卡片：每一列一張，欄名寫在值的左邊。
     寬表（一檔一欄、第一欄釘住的那種）保留表格橫捲，靠 .keep-table 跳過。 */
  .table-wrap:not(.keep-table) .table-scroll { overflow: visible; }
  .table-wrap:not(.keep-table) thead { display: none; }
  .table-wrap:not(.keep-table) table,
  .table-wrap:not(.keep-table) tbody,
  .table-wrap:not(.keep-table) tr,
  .table-wrap:not(.keep-table) td { display: block; width: auto; }
  .table-wrap:not(.keep-table) tbody tr { padding: 11px 14px 9px; border-bottom: 1px solid var(--separator); }
  .table-wrap:not(.keep-table) tbody tr:last-child { border-bottom: 0; }
  .table-wrap:not(.keep-table) tbody td {
    display: flex; align-items: baseline; justify-content: space-between; gap: 14px;
    padding: 3px 0; border: 0; white-space: normal; text-align: right; font-size: 13.5px;
  }
  .table-wrap:not(.keep-table) tbody td::before {
    content: attr(data-label);
    flex: none; max-width: 42%;
    color: var(--text-tertiary); font-size: 12px; font-weight: 400; text-align: left;
  }
  .table-wrap:not(.keep-table) tbody td:not([data-label])::before,
  .table-wrap:not(.keep-table) tbody td[data-label=""]::before { display: none; }
  /* 第一欄當卡片標題：靠左、加粗、不帶欄名 */
  .table-wrap:not(.keep-table) tbody td.is-title {
    display: inline-flex; align-items: center; gap: 8px; margin: 0 10px 5px 0;
    text-align: left; font-size: 14.5px; font-weight: 600;
  }
  .table-wrap:not(.keep-table) tbody td.is-title::before { display: none; }
  .table-wrap:not(.keep-table) tbody td.is-title + td:not(.is-title) { clear: both; }
  .table-wrap:not(.keep-table) tbody td .tag-list { justify-content: flex-end; }
  .table-wrap:not(.keep-table) tbody tr.row-detail { padding: 0 0 12px; }
  .table-wrap:not(.keep-table) tbody tr.row-detail > td { display: block; text-align: left; padding: 0; }
  .table-wrap:not(.keep-table) .fund-panel { position: static; width: auto; }

  /* 表頭藏起來後，排序改由這一條小工具列負責 */
  .table-wrap:not(.keep-table) .table-sortbar {
    display: flex; align-items: center; gap: 8px;
    padding: 9px 12px; border-bottom: 1px solid var(--separator);
    background: var(--thead-bg); font-size: 12.5px; color: var(--text-secondary);
  }
  .table-sortbar select {
    flex: 1; min-width: 0; padding: 6px 8px;
    border: 1px solid var(--separator); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text); font: inherit; font-size: 13px;
  }
  .table-sortbar button {
    padding: 6px 10px; border: 1px solid var(--separator); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text); font: inherit; font-size: 13px; cursor: pointer;
  }

  /* 建倉脈絡圖的圖例：22 檔會占掉一整屏，先只列有畫線的，其餘收進「更多」 */
  .chart-legend .legend-toggle.legend-extra { display: none; }
  .chart-legend.show-all .legend-toggle.legend-extra { display: inline-flex; }
  .chart-legend .legend-more {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 9px; border: 1px dashed var(--separator-strong); border-radius: var(--radius-pill);
    background: transparent; color: var(--text-secondary); font: inherit; font-size: 12px; cursor: pointer;
  }
  .chart-legend.show-all .legend-more { border-style: solid; }

  /* 數字磚：手機一行一張時，長說明改成單行省略 */
  .grid-kpi { grid-template-columns: minmax(0, 1fr); }
  .grid-kpi .card-pad { padding: 16px 18px; }
}

/* ---------- 今天一句話（總覽第一屏） ---------- */
.brief { margin-bottom: 6px; }
.brief-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.brief-kicker {
  font-size: 12px; font-weight: 700; letter-spacing: 0.08em; color: var(--accent-text);
  padding: 3px 9px; border-radius: var(--radius-pill); background: var(--accent-soft);
}
.brief-date { font-size: 12.5px; color: var(--text-tertiary); }
.brief-list {
  background: var(--surface); border: 1px solid var(--separator);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); overflow: hidden;
}
.brief-line {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 13px 18px; color: var(--text); font-size: 15.5px; line-height: 1.55;
  border-bottom: 1px solid var(--separator); text-decoration: none;
  animation: brief-in 0.5s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 70ms);
  transition: background var(--dur) var(--ease);
}
.brief-line:last-child { border-bottom: 0; }
.brief-line:hover { background: var(--surface-hover); text-decoration: none; color: var(--text); }
.brief-line b { font-weight: 600; font-variant-numeric: tabular-nums; }
.brief-text { min-width: 0; }
.brief-text .etf-tag { vertical-align: 1px; }
.brief-arrow { flex: none; color: var(--text-tertiary); transform: rotate(-90deg); transition: transform var(--dur) var(--ease); }
.brief-line:hover .brief-arrow { transform: rotate(-90deg) translateY(2px); color: var(--accent-text); }
@keyframes brief-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
/* 捲到某一節時，標題不要貼到黏在上面的導覽列底下 */
.section[id] { scroll-margin-top: calc(var(--nav-height) + 16px); }
@media (max-width: 760px) {
  .brief-line { font-size: 14.5px; padding: 12px 14px; }
}

/* ============================================================
   換臉（2026-11-03）：從「深色儀表板」改成「研究報表」
   原本的色票是 Apple 介面的通用色：亮藍強調、黑底、膠囊、大圓角，跟任何 AI 產的
   儀表板長一樣。這裡只覆寫變數與幾個字型規則，版型與元件不動：
   - 淺色是報表紙：暖灰白底、墨色字、靛藍強調（不用紅綠，那兩色留給漲跌）
   - 深色是墨色：暖黑而不是純黑，強調色同一組靛藍調亮
   - 圓角收小、膠囊改方角、陰影變淡：像印出來的表，不像 App 的卡片
   - 標題加字距與雙線底框，數字一律等寬對齊
   覆寫放在檔案最後，靠 cascade 蓋過上面的定義；要回到舊臉刪掉這一段即可。
   ============================================================ */

:root {
  --bg: #f3f0e8;
  --bg-elevated: #fffdf8;
  --surface: #fffdf8;
  --surface-soft: #faf7f0;
  --surface-hover: #f1ede3;
  --surface-sunken: #ebe6da;
  --thead-bg: #ece7da;

  --text: #1b1a17;
  --text-secondary: #5f5b53;
  --text-tertiary: #928d82;

  --separator: rgba(40, 32, 16, 0.12);
  --separator-strong: rgba(40, 32, 16, 0.26);

  --accent: #30499c;
  --accent-hover: #26408f;
  --accent-soft: rgba(48, 73, 156, 0.1);
  --accent-text: #2b4290;

  --gain: #c21f2a;
  --gain-soft: rgba(194, 31, 42, 0.09);
  --loss: #1e7f4f;
  --loss-soft: rgba(30, 127, 79, 0.1);
  --neutral: #7d786d;

  --warn: #a2560c;
  --warn-soft: rgba(162, 86, 12, 0.11);

  --nav-bg: rgba(243, 240, 232, 0.86);

  --radius-sm: 4px;
  --radius: 7px;
  --radius-lg: 9px;
  --radius-xl: 11px;
  --radius-pill: 5px;

  --shadow-xs: 0 1px 0 rgba(40, 32, 16, 0.05);
  --shadow-sm: 0 1px 2px rgba(40, 32, 16, 0.07);
  --shadow-md: 0 2px 6px rgba(40, 32, 16, 0.09);
  --shadow-pop: 0 10px 28px rgba(40, 32, 16, 0.18);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141311;
    --bg-elevated: #1d1b18;
    --surface: #1d1b18;
    --surface-soft: #191714;
    --surface-hover: #27241f;
    --surface-sunken: #110f0d;
    --thead-bg: #262320;

    --text: #f1ede4;
    --text-secondary: #a39e92;
    --text-tertiary: #716c62;

    --separator: rgba(255, 245, 225, 0.1);
    --separator-strong: rgba(255, 245, 225, 0.22);

    --accent: #7f94e6;
    --accent-hover: #94a7f0;
    --accent-soft: rgba(127, 148, 230, 0.16);
    --accent-text: #9fb0f2;

    --gain: #ff5a5a;
    --gain-soft: rgba(255, 90, 90, 0.15);
    --loss: #3fcf7f;
    --loss-soft: rgba(63, 207, 127, 0.14);
    --neutral: #a39e92;

    --warn: #f0a640;
    --warn-soft: rgba(240, 166, 64, 0.15);

    --nav-bg: rgba(20, 19, 17, 0.84);

    --shadow-xs: 0 1px 0 rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.45);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.5);
    --shadow-pop: 0 12px 32px rgba(0, 0, 0, 0.6);
  }
}

:root[data-theme="dark"] {
  --bg: #141311;
  --bg-elevated: #1d1b18;
  --surface: #1d1b18;
  --surface-soft: #191714;
  --surface-hover: #27241f;
  --surface-sunken: #110f0d;
  --thead-bg: #262320;
  --text: #f1ede4;
  --text-secondary: #a39e92;
  --text-tertiary: #716c62;
  --separator: rgba(255, 245, 225, 0.1);
  --separator-strong: rgba(255, 245, 225, 0.22);
  --accent: #7f94e6;
  --accent-hover: #94a7f0;
  --accent-soft: rgba(127, 148, 230, 0.16);
  --accent-text: #9fb0f2;
  --gain: #ff5a5a;
  --gain-soft: rgba(255, 90, 90, 0.15);
  --loss: #3fcf7f;
  --loss-soft: rgba(63, 207, 127, 0.14);
  --neutral: #a39e92;
  --warn: #f0a640;
  --warn-soft: rgba(240, 166, 64, 0.15);
  --nav-bg: rgba(20, 19, 17, 0.84);
  --shadow-xs: 0 1px 0 rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.45);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.5);
  --shadow-pop: 0 12px 32px rgba(0, 0, 0, 0.6);
}

/* 字：標題拉開字距、加粗；數字一律等寬對齊，報表的欄才會對得齊 */
.page-title { font-weight: 700; letter-spacing: 0.01em; }
.page-head { padding-bottom: 14px; border-bottom: 3px double var(--separator-strong); }
.section-title { font-weight: 700; letter-spacing: 0.01em; }
.section-title::before {
  content: ''; display: inline-block; width: 4px; height: 0.85em;
  margin-right: 9px; vertical-align: -1px; background: var(--accent);
}
.section-title.sm::before { width: 3px; }
.stat-value, .hero-number, .hero-pct, tbody td, .rank-amt, .panel-row b, .brief-line b {
  font-variant-numeric: tabular-nums;
}
.stat-label, .brief-kicker, .fund-code { letter-spacing: 0.06em; }

/* 品牌：單色方章，不用漸層 */
.brand-mark { background: var(--accent); border-radius: 4px; }

/* ETF 標籤與動作標籤：方角、細框，像報表上的章 */
.etf-tag { border-radius: 3px; padding: 1px 6px; letter-spacing: 0.04em; }
.tag { border-radius: 3px; }
.code-badge { border-radius: 3px; }
.uncal-badge { border-radius: 3px; }

/* 表格：表頭用細雙線收邊，列之間只留髮絲線 */
thead th { border-bottom: 2px solid var(--separator-strong); letter-spacing: 0.02em; }
tbody tr:last-child td { border-bottom: 1px solid var(--separator-strong); }
.table-wrap:not(.keep-table) tbody tr:last-child td { border-bottom: 0; }

/* 導覽：目前頁用底線而不是反白膠囊 */
.nav-link { border-radius: 0; padding-bottom: 7px; border-bottom: 2px solid transparent; }
.nav-link.is-active { background: transparent; color: var(--text); border-bottom-color: var(--accent); }
.nav-link:hover { background: transparent; }
.data-chip { border: 1px solid var(--separator); background: transparent; }

/* 手機底部分頁列：目前頁在上緣劃一道線 */
.tabbar .tab { border-radius: 4px; }
.tabbar .tab.is-active { box-shadow: inset 0 2px 0 var(--accent); }

/* 建倉脈絡圖的播放鈕：播放中變成實色，一眼看出正在動 */
.play-btn { white-space: nowrap; }
.play-btn.is-playing { background: var(--accent); color: #fff; border-color: var(--accent); }

/* 推定履約價的小標：和「短」同一套，但寫字不寫圓點，因為它會消失（清單到了就換真值） */
.uncal-badge.est-badge { width: auto; height: auto; padding: 1px 5px; font-size: 10px; border-radius: 3px; margin-left: 5px; }

/* 現貨法人買賣超：近 20 日長條圖 */
.inst-legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.inst-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.inst-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.inst-scroll svg { display: block; }
