/* 帳戶報告 v3 —— 參考 Mercury / Wealthsimple / Robinhood 這類得獎金融產品的做法:
   單色 (墨黑) 介面 + 一個靛藍點綴、大量留白、大字數字、平滑面積圖; 桌機左側選單, 手機底部分頁列。
   顏色照台股習慣: 上漲 / 賺錢紅色 (--up), 下跌 / 賠錢綠色 (--down), 只用在漲跌上。 */
:root {
  --bg: #F5F6F8;
  --surface: #FFFFFF;
  --surface2: #F2F3F6;
  --ink: #0B0D12;
  --ink2: #2B2F3A;
  --muted: #6B7280;
  --faint: #9CA3AF;
  --line: #E8EAEE;
  --line-strong: #D9DCE2;
  --accent: #4353D9;
  --accent-soft: rgba(67, 83, 217, 0.10);
  --acct: #4353D9;
  --bench: #A3A9B5;
  --up: #D9372B;
  --up-soft: rgba(217, 55, 43, 0.09);
  --down: #0E8A55;
  --down-soft: rgba(14, 138, 85, 0.10);
  --short: #C2701E;
  --dd: #0B0D12;
  --side: #FFFFFF;
  --note-bg: #F2F3F6;
  --note-ink: #4B5161;
  --shadow: 0 1px 2px rgba(11, 13, 18, 0.04), 0 1px 1px rgba(11, 13, 18, 0.02);
  --shadow-lg: 0 12px 32px rgba(11, 13, 18, 0.08);
  --radius: 20px;
  --nav-w: 168px;
  --font: "Geist", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  --brass: var(--accent);
  --brass-soft: var(--accent-soft);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #09090C; --surface: #121318; --surface2: #1A1C23; --ink: #F3F4F6; --ink2: #D1D5DB; --muted: #9CA3AF;
    --faint: #6B7280; --line: #22252E; --line-strong: #2E323D; --accent: #8B97FF; --accent-soft: rgba(139, 151, 255, 0.14);
    --acct: #8B97FF; --bench: #6B7280; --up: #FF6B5E; --up-soft: rgba(255, 107, 94, 0.13); --down: #34D399;
    --down-soft: rgba(52, 211, 153, 0.12); --short: #F0A35A; --dd: #F3F4F6; --side: #0E0F13;
    --note-bg: #1A1C23; --note-ink: #C7CBD4; --shadow: none; --shadow-lg: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #09090C; --surface: #121318; --surface2: #1A1C23; --ink: #F3F4F6; --ink2: #D1D5DB; --muted: #9CA3AF;
  --faint: #6B7280; --line: #22252E; --line-strong: #2E323D; --accent: #8B97FF; --accent-soft: rgba(139, 151, 255, 0.14);
  --acct: #8B97FF; --bench: #6B7280; --up: #FF6B5E; --up-soft: rgba(255, 107, 94, 0.13); --down: #34D399;
  --down-soft: rgba(52, 211, 153, 0.12); --short: #F0A35A; --dd: #F3F4F6; --side: #0E0F13;
  --note-bg: #1A1C23; --note-ink: #C7CBD4; --shadow: none; --shadow-lg: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.55;
  -webkit-text-size-adjust: 100%; -webkit-font-smoothing: antialiased; overflow-x: hidden;
  font-feature-settings: "tnum" 1;
}
.num, td, .kpi .v, .h-num { font-variant-numeric: tabular-nums; }
button { font: inherit; color: inherit; }
a { color: var(--accent); text-underline-offset: 3px; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.up { color: var(--up); }
.down { color: var(--down); }
.muted { color: var(--muted); }

/* ───────── 登入 ───────── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--bg); }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border-radius: 24px; padding: 40px 32px 32px;
  display: flex; flex-direction: column; gap: 18px; box-shadow: var(--shadow-lg); border: 1px solid var(--line);
}
.login-card::before {
  content: ""; width: 44px; height: 44px; background: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20viewBox%3D%220%200%2032%2032%22%3E%3Cdefs%3E%3ClinearGradient%20id%3D%22lgmark%22%20x1%3D%220%22%20y1%3D%220%22%20x2%3D%221%22%20y2%3D%221%22%3E%3Cstop%20offset%3D%220%22%20stop-color%3D%22%235D6DFF%22/%3E%3Cstop%20offset%3D%221%22%20stop-color%3D%22%232A36B0%22/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect%20width%3D%2232%22%20height%3D%2232%22%20rx%3D%229%22%20fill%3D%22url%28%23lgmark%29%22/%3E%3Cpath%20d%3D%22M8%2022c3.5%200%204.5-6.5%208-6.5S20%209%2024%209%22%20fill%3D%22none%22%20stroke%3D%22%23fff%22%20stroke-width%3D%222.4%22%20stroke-linecap%3D%22round%22/%3E%3Cpath%20d%3D%22M8%2024.5h16%22%20stroke%3D%22%23fff%22%20stroke-opacity%3D%22.35%22%20stroke-width%3D%221.6%22%20stroke-linecap%3D%22round%22/%3E%3C/svg%3E") center / contain no-repeat;
}
.login-card h1 { font-size: 24px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.login-card p { margin: 0; color: var(--muted); font-size: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 500; }
.field input {
  font: inherit; font-size: 16px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink);
}
.field input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 4px var(--accent-soft); }
.btn-primary {
  border: 0; border-radius: 12px; padding: 13px; background: var(--ink); color: var(--surface); font-weight: 600;
  font-size: 15px; cursor: pointer; margin-top: 4px;
}
.btn-primary:hover { opacity: 0.88; }
.err { color: var(--up); font-size: 14px; min-height: 1.2em; }

/* ───────── 側邊選單 (桌機) ───────── */
.top {
  position: fixed; left: 0; top: 0; bottom: 0; width: var(--nav-w); z-index: 30; background: var(--side);
  transition: width 0.18s ease;
  border-right: 1px solid var(--line);
}
.top-row { height: 100%; display: flex; flex-direction: column; padding: 18px 10px 14px; gap: 4px; }
.brand { display: flex; align-items: center; gap: 8px; padding: 0 0 14px 6px; }
.nav-tog {
  margin-left: auto; width: 26px; height: 28px; border: 0; border-radius: 8px; background: none; color: var(--muted);
  cursor: pointer; display: grid; place-items: center; flex: none;
}
.nav-tog:hover { background: var(--surface2); color: var(--ink); }
.nav-tog svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; }
/* 收合: 只剩 64px 圖示列; 滑鼠移上去就浮出完整選單 (蓋在內容上, 不推擠版面) */
body.nav-min { --nav-w: 64px; }
.brand .mark { width: 28px; height: 28px; flex: none; display: block; }
.brand-t { font-weight: 600; font-size: 14.5px; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.who { padding: 10px 10px; margin: 0 0 8px; border-radius: 12px; background: var(--surface2); min-width: 0; }
.who .name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who .sub { font-size: 11.5px; color: var(--muted); line-height: 1.45; margin-top: 2px; }
.acct-sel {
  font: inherit; font-size: 13.5px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); margin-bottom: 10px;
}
.tabs { display: flex; flex-direction: column; gap: 2px; }
.tab {
  display: flex; align-items: center; gap: 10px; border: 0; background: none; padding: 9px 10px; border-radius: 10px;
  font-size: 14px; color: var(--muted); cursor: pointer; text-align: left; font-weight: 500; transition: background 0.12s, color 0.12s;
}
.tab .ic { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.tab:hover { background: var(--surface2); color: var(--ink); }
.tab[aria-selected="true"] { background: var(--ink); color: var(--surface); }
.tools { margin-top: auto; display: flex; gap: 6px; flex-wrap: wrap; padding: 0 4px; }
.icon-btn {
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink2); border-radius: 999px;
  padding: 5px 10px; font-size: 12px; cursor: pointer; white-space: nowrap; font-weight: 500;
}
.icon-btn:hover { border-color: var(--ink2); color: var(--ink); }
.preview-bar {
  margin-left: var(--nav-w); background: var(--accent-soft); color: var(--accent); font-size: 12.5px; text-align: center;
  padding: 7px 16px; font-weight: 500;
}

/* ───────── 版面 ───────── */
main { margin-left: var(--nav-w); max-width: 1380px; padding: 32px 40px 56px; display: flex; flex-direction: column; gap: 24px; min-width: 0; }
.foot { margin-left: var(--nav-w); max-width: 1380px; padding: 8px 40px 40px; font-size: 12px; color: var(--faint); line-height: 1.7; }
.panel > * { min-width: 0; max-width: 100%; }
.panel { display: flex; flex-direction: column; gap: 24px; }
.card { background: var(--surface); border-radius: var(--radius); padding: 24px 26px; box-shadow: var(--shadow); min-width: 0; border: 1px solid var(--line); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.card-head h2 { font-size: 16px; font-weight: 600; margin: 0; letter-spacing: -0.01em; color: var(--ink); display: flex; align-items: center; gap: 8px; }
.card-head .hint { font-size: 12.5px; color: var(--muted); }
details.fold > summary { cursor: pointer; list-style: none; margin-bottom: 0; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold[open] > summary { margin-bottom: 18px; }
.fold-ic { display: inline-block; color: var(--muted); transition: transform 0.15s; font-size: 11px; }
details.fold[open] .fold-ic { transform: rotate(90deg); }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; }

/* ───────── 總覽: 大數字 ───────── */
.hero2 { padding: 4px 2px 6px; }
.h-label { font-size: 13.5px; color: var(--muted); font-weight: 500; }
.h-num { font-size: 60px; font-weight: 600; letter-spacing: -0.035em; line-height: 1.08; margin: 6px 0 16px; }
.h-num .cur { font-size: 22px; font-weight: 500; color: var(--faint); letter-spacing: 0; margin-right: 10px; vertical-align: 0.55em; }
.h-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 10px; }
.dchip {
  display: inline-flex; align-items: baseline; gap: 8px; padding: 7px 14px; border-radius: 999px; font-weight: 600;
  font-size: 14px; background: var(--surface2); color: var(--ink);
}
.dchip.up { background: var(--up-soft); color: var(--up); }
.dchip.down { background: var(--down-soft); color: var(--down); }
.dchip .dk { font-weight: 500; font-size: 12.5px; opacity: 0.8; }
.dchip .dp { font-weight: 500; opacity: 0.85; }
.dnote { font-size: 13px; color: var(--muted); margin-left: 4px; }
.dnote b { font-weight: 600; }

/* KPI: 白色一整塊、細分隔線 */
.kpis {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; background: var(--line);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
.card .kpis { box-shadow: none; border-radius: 14px; }
.kpis.kpis-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpi { background: var(--surface); padding: 20px 22px; min-width: 0; }
.kpi .k { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.kpi .v { font-size: 27px; font-weight: 600; line-height: 1.25; white-space: nowrap; margin: 6px 0 4px; letter-spacing: -0.025em; }
.kpi .s { font-size: 12.5px; color: var(--faint); line-height: 1.45; }
.kpi .s .ln { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .s b { font-weight: 500; }
html[lang="en"] .bar-row { grid-template-columns: 168px 1fr 92px; }

/* 控制列 (iOS 式分段按鈕) */
.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.pills { display: flex; gap: 2px; background: var(--surface2); padding: 3px; border-radius: 12px; overflow-x: auto; max-width: 100%; }
.pill {
  border: 0; background: none; padding: 6px 13px; border-radius: 9px; font-size: 13px; color: var(--muted);
  cursor: pointer; white-space: nowrap; font-weight: 500;
}
.pill:hover { color: var(--ink); }
.pill[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(11, 13, 18, 0.12); }
.chart { width: 100%; height: 320px; position: relative; }
.chart.small { height: 170px; }
/* 總覽四張圖: 控制列 + 2×2 一起塞進一個畫面 (圖高跟著視窗高度算) */
.quad-board { display: flex; flex-direction: column; gap: 14px; }
.quad-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
.card.qc { padding: 14px 18px 12px; }
.card.qc .card-head { margin-bottom: 4px; }
.card.qc .card-head h2 { font-size: 14.5px; }
.card.qc .legend { margin-top: 6px; font-size: 12px; gap: 2px 14px; }
.chart.quad { height: clamp(150px, calc((100vh - 300px) / 2), 300px); }
.chart-bar { padding: 14px 18px; }
.chart-bar .controls { justify-content: space-between; }
.ctl-r { display: flex; gap: 8px; flex-wrap: wrap; }
.ctl-l { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ctl-hint { font-size: 12px; color: var(--faint); margin-left: auto; margin-right: 4px; }
.yr-sel {
  font: inherit; font-size: 13px; font-weight: 500; color: var(--muted); background-color: var(--surface2); border: 0;
  border-radius: 12px; padding: 8px 30px 8px 13px; cursor: pointer; -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m7 10 5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center; background-size: 15px;
}
.yr-sel:hover { color: var(--ink); }
.yr-sel.on { background-color: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 0 0 3px var(--surface2), 0 1px 3px rgba(11, 13, 18, 0.14); }
@media (max-width: 1440px) { .ctl-hint { display: none; } }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 12.5px; color: var(--muted); margin-top: 12px; }
.legend b { color: var(--ink); font-weight: 600; }
.sw { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.notes { background: var(--note-bg); color: var(--note-ink); border-radius: 14px; padding: 14px 18px; font-size: 13.5px; }
.notes p { margin: 4px 0; }

/* ───────── 表格 ───────── */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; padding: 0 4px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 12px 12px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
th { font-weight: 500; color: var(--muted); font-size: 12px; background: var(--surface); }
th:first-child, td:first-child { text-align: left; }
tbody tr:last-child td { border-bottom: 0; }
td.l, th.l { text-align: left; }
.sticky-col th:first-child, .sticky-col td:first-child { position: sticky; left: 0; background: var(--surface); z-index: 1; }
.metric-label { white-space: normal; min-width: 160px; }
.metric-label small { display: block; color: var(--faint); font-size: 12px; line-height: 1.4; }
.group-row td { background: var(--surface2); font-weight: 600; color: var(--ink); font-size: 13px; padding-top: 9px; padding-bottom: 9px; }
.heat td { text-align: center; min-width: 60px; }
.heat td:first-child { text-align: left; }
.heat tr.yr-first td { border-top: 1px solid var(--line-strong); }
.heat .sub-row td { font-size: 12px; color: var(--muted); padding-top: 4px; padding-bottom: 4px; border-bottom: 0; }
.heat .sub-row td.up { color: var(--up); }
.heat .sub-row td.down { color: var(--down); }
.stock-cell { display: flex; flex-direction: column; line-height: 1.3; }
.stock-cell .c { font-weight: 600; }
.stock-cell .n { font-size: 12px; color: var(--muted); }
.side { display: inline-block; font-size: 11.5px; padding: 2px 9px; border-radius: 999px; font-weight: 600; }
.side.long { color: var(--accent); background: var(--accent-soft); }
.side.short { color: var(--short); background: rgba(194, 112, 30, 0.12); }
.more {
  margin-top: 14px; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 999px;
  padding: 8px 18px; cursor: pointer; font-size: 13.5px; color: var(--ink2); font-weight: 500;
}
.more:hover { border-color: var(--ink2); }
table.compact td, table.compact th { padding: 9px 10px; }
.grid2.fee-2 { grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); }
table.compact td { font-size: 13.5px; }
tr.clickable:hover td { background: var(--surface2); }

/* 手機卡片 (持股 / 交易) */
.cards-m { display: none; flex-direction: column; gap: 10px; }
.mcard { border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; background: var(--surface); }
.mcard .t { font-weight: 600; }
.mcard .r { text-align: right; font-weight: 600; font-size: 16px; }
.mcard .d { font-size: 12.5px; color: var(--muted); }
.mcard .dr { font-size: 13px; text-align: right; }
.mcard.clickable, tr.clickable { cursor: pointer; }
.mcard.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* 長條 */
.bars { display: flex; flex-direction: column; gap: 11px; }
.bar-row { display: grid; grid-template-columns: 120px 1fr 92px; gap: 12px; align-items: center; font-size: 13.5px; }
.bar-track { height: 8px; background: var(--surface2); border-radius: 999px; position: relative; overflow: hidden; }
.bar-fill { position: absolute; top: 0; bottom: 0; border-radius: 999px; }
.bar-row .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .val { text-align: right; font-weight: 500; }

/* 交易 */
.stock-pick { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stock-pick select, .stock-pick input {
  font: inherit; font-size: 14px; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); max-width: 100%;
}
.trade-nav { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.nav-btn {
  flex: none; width: 38px; height: 38px; border-radius: 999px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); font-size: 13px; cursor: pointer;
}
.nav-btn:hover:not(:disabled) { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.nav-btn:disabled { opacity: 0.3; cursor: default; }
.nav-info { flex: 1; min-width: 0; font-size: 14px; line-height: 1.5; text-align: center; }
.tv-split { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 22px; align-items: stretch; }
.tv-main { min-width: 0; }
.chart.candle { height: 440px; }
.tr-detail { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; color: var(--muted); margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.tr-detail b { font-weight: 600; }
.tlist { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); display: flex; flex-direction: column; min-width: 0; overflow: hidden; contain: size; }
.tl-tools { display: flex; flex-direction: column; gap: 8px; padding: 12px 12px 6px; }
.tl-q { font: inherit; font-size: 13.5px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--surface2); color: var(--ink); width: 100%; }
.tl-q:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.tl-count { font-size: 12px; color: var(--muted); padding: 0 14px 8px; }
.tl-box { flex: 1 1 auto; min-height: 0; overflow-y: auto; position: relative; border-top: 1px solid var(--line); }
.tl-row {
  display: grid; grid-template-columns: 60px minmax(0, 1fr) auto 64px; gap: 8px; align-items: center; width: 100%;
  border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; padding: 9px 14px;
  font-size: 13px; cursor: pointer; color: var(--ink);
}
.tl-row:hover { background: var(--surface2); }
.tl-row.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.tl-row .tl-d { color: var(--faint); font-size: 12px; }
.tl-row .tl-s { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tl-row .tl-s b { font-weight: 600; }
.tl-row .tl-r { text-align: right; font-weight: 600; }
.tl-held { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); margin-right: 5px; vertical-align: middle; }
.fee-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.chip { display: inline-block; font-size: 12px; padding: 2px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ───────── 平板 / 手機: 頂端一列 + 底部分頁列 ───────── */
@media (max-width: 1080px) {
  .kpis, .kpis.kpis-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid2, .grid2.fee-2 { grid-template-columns: minmax(0, 1fr); }
  .quad-grid { grid-template-columns: minmax(0, 1fr); }
  .chart.quad { height: 240px; }
  .fee-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tv-split { grid-template-columns: minmax(0, 1fr); }
  .tlist { contain: none; }
  .tl-box { flex: none; height: 320px; }
}
@media (max-width: 900px) {
  .top { position: sticky; top: 0; bottom: auto; width: auto; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .top-row { flex-direction: row; align-items: center; padding: 10px 16px; gap: 10px; height: auto; }
  .brand { padding: 0; }
  .brand-t, .nav-tog { display: none; }
  body.nav-min { --nav-w: 0px; }
  .who { background: none; padding: 0; margin: 0; flex: 1 1 auto; }
  .who .sub { display: none; }
  .acct-sel { margin: 0; max-width: 40vw; }
  .tools { margin: 0; padding: 0; flex-wrap: nowrap; }
  .icon-btn { padding: 5px 10px; }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; flex-direction: row; justify-content: space-around;
    background: var(--side); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .tab { flex-direction: column; gap: 3px; padding: 6px 2px; font-size: 10.5px; flex: 1 1 0; min-width: 0; text-align: center; border-radius: 10px; white-space: nowrap; }
  .tab .ic { width: 21px; height: 21px; }
  .tab[aria-selected="true"] { background: none; color: var(--ink); }
  .tab[aria-selected="true"] .ic { stroke-width: 2.2; }
  .tab:not([aria-selected="true"]) { color: var(--faint); }
  .preview-bar, main, .foot { margin-left: 0; }
  main { padding: 20px 16px 28px; gap: 16px; }
  .panel { gap: 16px; }
  .foot { padding: 0 16px 96px; }
  .h-num { font-size: 42px; }
  .h-num .cur { font-size: 16px; margin-right: 6px; }
}
@media (max-width: 640px) {
  .card { padding: 18px 16px; border-radius: 18px; }
  .kpi { padding: 15px 15px; }
  .kpi .v { font-size: 21px; }
  .kpi .s .ln { white-space: normal; }
  .kpi .s { font-size: 11.5px; }
  .kpi .s .nw { white-space: nowrap; }
  .card .kpi { padding: 14px 12px; }
  html[lang="en"] .bar-row { grid-template-columns: 112px 1fr 70px; }
  .dchip { font-size: 13px; padding: 6px 12px; }
  .dnote { flex-basis: 100%; margin-left: 2px; }
  .chart { height: 250px; }
  .chart.small { height: 140px; }
  .chart.quad { height: 220px; }
  .card.qc .legend { flex-wrap: wrap; white-space: normal; }
  .chart.candle { height: 320px; }
  .chart-bar { padding: 12px 14px; }
  .bar-row { grid-template-columns: 86px 1fr 78px; font-size: 13px; }
  table { font-size: 13px; }
  th, td { padding: 9px 8px; }
  .hide-m { display: none; }
  .cards-m { display: flex; }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}

/* 交易: 標題列 (股票 + 報酬) | 原始/還原 + 上一筆/下一筆 */
.tv-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px 16px; flex-wrap: wrap; margin-bottom: 6px; }
.tv-title { min-width: 0; }
.tv-title .tt { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tv-title .code { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.tv-title .nm { font-size: 18px; font-weight: 500; color: var(--ink2); }
.tv-title .ret { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.tv-title .ts { font-size: 13px; color: var(--muted); margin-top: 3px; }
.tv-ctrl { display: flex; align-items: center; gap: 10px; }
.pager { display: flex; align-items: center; gap: 2px; background: var(--surface2); border-radius: 12px; padding: 3px; }
.pg-btn {
  width: 32px; height: 30px; border: 0; border-radius: 9px; background: none; cursor: pointer;
  display: grid; place-items: center; color: var(--ink);
}
.pg-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.pg-btn:hover:not(:disabled) { background: var(--surface); box-shadow: 0 1px 3px rgba(11, 13, 18, 0.12); }
.pg-btn:disabled { opacity: 0.28; cursor: default; }
.pg-n { font-size: 12.5px; color: var(--muted); min-width: 92px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 500; }
.adj-hint { margin: 0 0 6px; font-size: 12.5px; color: var(--muted); min-height: 0; }
.adj-hint:empty { display: none; }

/* 自動縮放按鈕 */
.fit-btn {
  display: inline-flex; align-items: center; gap: 6px; border: 0; background: var(--surface2); color: var(--muted);
  border-radius: 12px; padding: 7px 12px; font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.fit-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.fit-btn:hover { color: var(--ink); background: var(--surface); box-shadow: 0 0 0 1px var(--line-strong); }
.fit-btn.icon-only { padding: 7px 9px; }

td:has(> .stock-cell) { text-align: left; }

/* 長表格: 卡片內捲動, 表頭固定在上面 */
.tbl-wrap.vscroll { max-height: min(620px, 72vh); overflow: auto; }
.tbl-wrap.vscroll thead th { position: sticky; top: 0; z-index: 2; background: var(--surface); box-shadow: inset 0 -1px 0 var(--line-strong); }
.tbl-wrap.vscroll.sticky-col thead th:first-child { z-index: 3; }
td.due, th.due { background: var(--accent-soft); }
.tbl-wrap.vscroll thead th.due { background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.tbl-wrap.vscroll table.compact th, .tbl-wrap.vscroll table.compact td { padding-left: 6px; padding-right: 6px; }
.tbl-wrap.vscroll table.compact td { font-size: 12.5px; }
.tbl-wrap.vscroll table.compact th { font-size: 11.5px; }
.tbl-wrap.vscroll.vs-sm { max-height: 360px; }
.ctl-l { min-width: 0; max-width: 100%; }
.ctl-l .pills { min-width: 0; max-width: 100%; flex: 0 1 auto; }
@media (max-width: 640px) { #range-pills .pill { padding: 6px 7px; font-size: 12.5px; } }
.who .sub .range { display: inline-flex; flex-direction: column; align-items: center; font-variant-numeric: tabular-nums; line-height: 1.35; }
.who .sub .range i { display: block; width: 1px; height: 9px; background: var(--line-strong); margin: 2px 0; }

/* 側欄 (電腦版) — 放在最後, 才蓋得過上面的基本樣式 */
@media (min-width: 901px) {
  /* 收合 / 展開 / 滑鼠移上去: 排版完全一樣, 只有寬度在變 (文字被裁切), 圖示不會上下左右跳。
     圖示中心固定在 x = 32px (= 收合寬度 64 的正中間): logo 10+8+14, 頁籤 10+12.5+9.5 */
  .top { overflow: hidden; }
  .top-row { padding: 18px 10px 14px; }
  .brand { order: 1; padding: 0 0 14px 8px; gap: 10px; flex-wrap: nowrap; }
  .tabs { order: 2; margin-bottom: auto; }
  .who { order: 3; margin: 8px 0 8px; }
  .acct-sel { order: 4; }
  .tools { order: 5; margin-top: 0; flex-direction: column; flex-wrap: nowrap; align-items: flex-start; padding: 0; gap: 6px; }
  .tools .icon-btn { width: 44px; padding: 5px 0; font-size: 11px; text-align: center; white-space: nowrap; }
  .tab { padding: 9px 10px 9px 12.5px; white-space: nowrap; overflow: hidden; }
  .tab-l, .brand-t, .who .name { white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: clip; }
  body.nav-min .top:hover { width: 168px; box-shadow: var(--shadow-lg), 1px 0 0 var(--line); transition: width 0.18s ease 0.06s; }
  body.nav-min .top:not(:hover) .who, body.nav-min .top:not(:hover) .acct-sel { display: none; }
}
