/* 設計系統 — 對應 docs/ui-design-spec.md（v2：ui-ux-pro-max 強化） */
:root {
  --bg: #FAFAFA;
  --surface: #FFFFFF;
  --surface-2: #F5F7FF;
  --border: #EAEAEA;
  --text: #1A1A1A;
  --text-muted: #6B7280;
  --primary: #1E40AF;       /* 加深以穩過 WCAG AA */
  --primary-soft: #E8F0FE;
  --accent: #D97706;        /* amber 強調：KPI、熱度條 */
  --up: #D92D20;   /* 台股紅漲 */
  --down: #039855; /* 台股綠跌 */
  --heat: #F97316;
  --radius: 12px;
  --radius-sm: 8px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #0B1120;
    --surface: #151C2C;
    --surface-2: #1B2336;
    --border: #26304A;
    --text: #E8ECF4;
    --text-muted: #94A3B8;
    --primary: #3B82F6;
    --primary-soft: #1E293B;
    --up: #FF5A4D;
    --down: #22C55E;
  }
}

/* 手動深色覆寫（「我的」可選 data-theme="dark"，不論系統皆深色）；
   data-theme="light" 時本區與系統 media-query 皆不命中 → 回基礎 :root 淺色 */
:root[data-theme="dark"] {
  --bg: #0B1120;
  --surface: #151C2C;
  --surface-2: #1B2336;
  --border: #26304A;
  --text: #E8ECF4;
  --text-muted: #94A3B8;
  --primary: #3B82F6;
  --primary-soft: #1E293B;
  --up: #FF5A4D;
  --down: #22C55E;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.container { max-width: 1200px; margin: 0 auto; padding: 24px 20px; }

/* 頂部導航列 */
.site-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.site-nav-home {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
}
.site-nav-auth {
  display: flex;
  align-items: center;
  gap: 12px;
}
.site-nav-auth a {
  color: var(--text-muted);
  text-decoration: none;
}
.site-nav-auth a:hover {
  color: var(--text);
}
.site-nav-auth form {
  display: inline;
}

/* 標題列 */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; gap: 16px;
}
.topbar h1 { font-size: 22px; font-weight: 700; margin: 0; }
/* 標題日期後綴（排行頁「· YYYY/MM/DD」）：淡、細、略小，與粗體標題區隔 */
.title-date { color: var(--text-muted); font-weight: 400; font-size: .7em; }
.topbar-controls { display: flex; align-items: center; gap: 12px; }
.topbar select,
.topbar input[type="date"] {
  font-size: 14px; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
  font-family: inherit; cursor: pointer;
}
.topbar input[type="date"]::-webkit-calendar-picker-indicator { cursor: pointer; opacity: 0.7; }
.topbar input[type="date"]:hover { border-color: var(--primary); }

/* 排行明細「個股」欄前的標記直欄：☆ 星號在上、live 小點在下 */
.row-mark { display: flex; flex-direction: column; align-items: center; gap: 3px; flex: 0 0 auto; }
/* 盤中 live 小點：盤中時段每列星號下顯示一顆小藍點（靜態），該檔成交價一變就「閃一下」 */
.live-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--primary);
  opacity: 0.5; flex: 0 0 auto;
}
.live-dot[hidden] { display: none; }
.live-dot.flash { animation: dotflash 0.8s ease-out; }
@keyframes dotflash {
  0% { opacity: 1; transform: scale(1.9); box-shadow: 0 0 0 0 rgba(30, 64, 175, 0.55); }
  100% { opacity: 0.5; transform: scale(1); box-shadow: 0 0 0 6px rgba(30, 64, 175, 0); }
}
@media (prefers-reduced-motion: reduce) { .live-dot.flash { animation: none; } }

/* 個股頁盤中即時列：標題下方一條，現價/漲跌/即時周轉率…每 5 秒更新（盤中才顯示） */
.live-strip {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px;
  margin: 0 0 16px; padding: 10px 14px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.live-strip[hidden] { display: none; }
.ls-live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; color: var(--primary); }
.ls-live .live-dot { opacity: 1; }
.ls-item { display: inline-flex; align-items: baseline; gap: 5px; }
.ls-label { font-size: 12px; color: var(--text-muted); }
.ls-val { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.ls-time { margin-left: auto; font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* 大盤/台指 KPI 現值盤中跳動時，淡淡閃一下（紅漲綠跌色由趨勢類別決定，不在此改色） */
.kpi-flash { animation: kpiflash 0.7s ease-out; }
@keyframes kpiflash {
  0% { background: var(--primary-soft); }
  100% { background: transparent; }
}
@media (prefers-reduced-motion: reduce) { .kpi-flash { animation: none; } }

/* 搜尋框 */
.search { position: relative; display: flex; align-items: center; }
.search-ico {
  position: absolute; left: 10px; width: 16px; height: 16px;
  color: var(--text-muted); pointer-events: none;   /* Lucide 用 currentColor */
}
.search input {
  font-size: 14px; padding: 8px 12px 8px 32px; width: 200px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
}
.search input:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary); }
/* 全市場搜尋建議下拉 */
.search-suggest {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 50;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .10); max-height: 320px; overflow-y: auto; padding: 4px;
}
.suggest-item {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  border: 0; background: transparent; padding: 7px 10px; border-radius: 6px;
  cursor: pointer; font-size: 13px; color: var(--text);
}
.suggest-item:hover { background: var(--surface-2); }
.suggest-item .sg-code { font-variant-numeric: tabular-nums; color: var(--text-muted); min-width: 46px; }
.suggest-item .sg-name { flex: 1; }
.suggest-empty { padding: 10px; font-size: 13px; color: var(--text-muted); }

/* KPI 摘要列 */
.kpi-row {
  /* 一排放完所有卡（4 或 5 張皆等寬同列）；手機才換行 */
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  gap: 16px; margin-bottom: 24px;
}
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px;
  min-width: 0;   /* 六格併一排後允許收縮，內容改為換行而非溢出卡片 */
}
.kpi-label { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.kpi-value {
  font-size: 26px; font-weight: 700; line-height: 1.1;
  font-variant-numeric: tabular-nums; color: var(--text);
}
.kpi-value.accent { color: var(--accent); }
.kpi-value .unit { font-size: 14px; font-weight: 500; color: var(--text-muted); }
.kpi-sub { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.kpi-delta { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi-delta.up { color: var(--up); }
.kpi-delta.down { color: var(--down); }
/* 資金流向預判 KPI tile（第 2 格）：流出在上（綠跌）、流入在下（紅漲） */
.fc-line { display: flex; align-items: center; gap: .25rem; font-size: .95rem; font-weight: 600; line-height: 1.5; }
.fc-line b, .fc-line i, .fc-line svg { flex: none; white-space: nowrap; }   /* 「流出/流入」標籤與箭頭不拆行 */
.fc-line .fc-ind { min-width: 0; overflow-wrap: anywhere; }                 /* 產業名過長時自行換行 */
.fc-line i { width: 14px; height: 14px; }
.fc-line.up { color: var(--up); }
.fc-line.down { color: var(--down); }
.fc-line b { font-weight: 700; }
.fc-ind.fc-mine { font-weight: 700; text-decoration: underline; }  /* 個股頁：本股所屬產業入榜時標亮 */
/* M20 列上移/下移：表格尾欄直式一組 ▲▼；手機卡片靠右下。清單類會保存順序 */
.row-mv-col { width: 26px; text-align: center; }
.row-mv-group { display: inline-flex; flex-direction: column; gap: 2px; }
.row-mv {
  border: 1px solid var(--border); background: var(--bg); color: var(--text-dim);
  border-radius: 4px; font-size: .6rem; line-height: 1; padding: 3px 5px; cursor: pointer;
}
.row-mv:hover { color: var(--text); border-color: var(--text-dim); }
.rank-card { position: relative; }
.rank-card .row-mv-group { position: absolute; right: 8px; bottom: 8px; flex-direction: row; }
.rank-card .row-mv { padding: 6px 10px; font-size: .7rem; }  /* 手機加大點擊面積 */
.rank-card .rc-sub { padding-right: 92px; }  /* 副資訊列避開右下 ▲▼，長字串不重疊 */
/* M21 線條樣式設定面板（個股頁 K 線：劃線/MA 的顏色、實虛、粗細） */
#lineStylePanel { position: absolute; z-index: 1200; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: 0 8px 24px rgba(0, 0, 0, .18); padding: 10px 12px; display: grid; gap: 6px; }
#lineStylePanel .ls-title { font-weight: 700; font-size: .85rem; color: var(--text); }
.ls-row { display: grid; grid-template-columns: 42px 34px 1fr 1fr; gap: 6px; align-items: center;
  font-size: .8rem; color: var(--text); }
.ls-row input[type="color"] { width: 30px; height: 22px; padding: 0; border: 1px solid var(--border);
  border-radius: 4px; background: none; cursor: pointer; }
.ls-row select { font-size: .78rem; padding: 2px 4px; border: 1px solid var(--border); border-radius: 4px;
  background: var(--surface); color: var(--text); }
#lineStylePanel .ls-reset { justify-self: end; margin-top: 2px; }
/* M22 下單 KPI 格＋下單 modal（玉山模擬） */
.trade-quick { display: flex; gap: 8px; margin: 6px 0 2px; }
.trade-quick button { flex: 1; padding: 8px 0; border-radius: var(--radius-sm); border: 1px solid var(--border);
  font-weight: 700; font-size: .95rem; cursor: pointer; }
.trade-buy { background: var(--up); color: #fff; border-color: var(--up); }
.trade-sell { background: var(--down); color: #fff; border-color: var(--down); }
.trade-quick button:hover { filter: brightness(1.05); }
.trade-dialog { border: none; border-radius: var(--radius); padding: 0; width: min(92vw, 360px);
  background: var(--surface); color: var(--text); box-shadow: 0 12px 40px rgba(0,0,0,.28); }
.trade-dialog::backdrop { background: rgba(0,0,0,.4); }
.td-form { padding: 16px; display: grid; gap: 12px; }
.td-head { display: flex; align-items: center; justify-content: space-between; }
.td-head h3 { margin: 0; font-size: 1.05rem; }
.badge.sim { background: var(--accent); color: #fff; padding: 2px 8px; border-radius: 999px; font-size: .72rem; font-weight: 700; }
/* M28 正式環境徽章：用台股紅（警示色）比模擬更醒目——正式牽涉真實金錢,理應一眼可辨、不比模擬平淡 */
.badge.live { background: var(--up); color: #fff; padding: 2px 8px; border-radius: 999px; font-size: .72rem; font-weight: 700; }
.td-side { display: flex; gap: 8px; }
.td-side button { flex: 1; padding: 8px 0; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-muted); font-weight: 700; cursor: pointer; }
.td-side .td-buy.active { background: var(--up); color: #fff; border-color: var(--up); }
.td-side .td-sell.active { background: var(--down); color: #fff; border-color: var(--down); }
.td-stock { font-weight: 700; }
.td-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: .9rem; }
.td-row > span:first-child { color: var(--text-muted); }
.td-pxwrap { display: flex; gap: 6px; align-items: center; }
.td-input { width: 96px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }
.td-mini { padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2);
  color: var(--text-muted); cursor: pointer; font-size: .82rem; }
.td-mini.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.td-step { display: inline-flex; align-items: center; gap: 0; }
.td-step button { width: 32px; height: 32px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); font-size: 1.1rem; cursor: pointer; }
.td-step button:first-child { border-radius: 6px 0 0 6px; }
.td-step button:last-child { border-radius: 0 6px 6px 0; }
.td-step .td-input { width: 64px; border-radius: 0; border-left: none; border-right: none; text-align: center; }
.td-est { font-weight: 700; }
.td-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 2px; }
.td-actions button { padding: 9px 16px; border-radius: var(--radius-sm); font-weight: 700; cursor: pointer; border: 1px solid var(--border); }
.td-actions .btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.td-actions .btn-confirm { background: var(--up); color: #fff; border-color: var(--up); }
.td-actions .btn-ghost { background: var(--surface); color: var(--text); }
.trade-dialog[data-side="sell"] .btn-confirm { background: var(--down); border-color: var(--down); }
.td-dl { margin: 0; display: grid; gap: 6px; }
.td-dlrow { display: flex; justify-content: space-between; gap: 12px; font-size: .92rem; }
.td-dlrow dt { color: var(--text-muted); margin: 0; }
.td-dlrow dd { margin: 0; font-weight: 700; }
.td-buy-txt { color: var(--up); } .td-sell-txt { color: var(--down); }
.td-warn { font-size: .8rem; color: var(--text-muted); background: var(--surface-2); padding: 8px 10px; border-radius: 6px; }
.td-status { font-size: .82rem; min-height: 1.1em; color: var(--text-muted); }
.td-status.bad { color: var(--up); font-weight: 700; }  /* 錯誤紅字（同漲色紅） */
.td-select { padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text); font-size: .88rem; }
.td-pxq > span:last-child { display: inline-flex; gap: 6px; }
/* M26 個股頁下單側欄：桌機兩欄（主內容＋300px sticky 側欄），<1024px 回單欄用 modal */
.stock-wrap { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; }
@media (min-width: 1024px) {
  /* 僅在側欄實際渲染（未 hidden）時才切兩欄，避免 trade off 時右側留白 */
  .stock-wrap:has(.trade-side:not([hidden])) { grid-template-columns: minmax(0, 1fr) 300px; }
  /* :not([hidden]) 讓 class 樣式不覆蓋 [hidden] 的 display:none —— trade off 時側欄真正不渲染（fail-closed） */
  .trade-side:not([hidden]) { position: sticky; top: 16px; align-self: start;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px; display: grid; gap: 12px; }
  .trade-side #tdCancel { display: none; }  /* 側欄常駐，無「取消」語意 */
  .trade-side #tdFill { display: grid; gap: 12px; }  /* 側欄內表單列間距（modal 由 .td-form 提供，此處補上） */
  .kpi.kpi-trade { display: none; }  /* 桌機：下單改由側欄承載，隱藏 KPI 下單格 */
}
@media (max-width: 1023.98px) { .trade-side { display: none; } }
/* 點價帶入：交易啟用時五檔/明細價格可點；下單格內「正向/反向」鈕（.td-pxwrap 內，M27 起
   由最佳五檔標頭移入）沿用 .td-mini／.td-mini.on 樣式，不再需要 .rt-cap 專屬覆寫 */
.rt-book2 td.rt-px, .rt-ticks td.rt-px { cursor: pointer; }
@keyframes td-flash { from { background: var(--primary-soft); } to { background: transparent; } }
#tdFill.flash { animation: td-flash .6s ease-out; }
/* 指數趨勢 KPI：sparkline + 趨勢徽章 */
.kpi-sub.idx-trend { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; row-gap: 2px; }   /* 空間不足時訊號標籤換行，不戳出卡片 */
.idx-spark { display: inline-block; width: 56px; height: 20px; position: relative; flex: none; }
/* KPI「今日多空」三大指數盤中 % 疊圖：中型畫布 + 識別色圖例（非紅漲綠跌） */
.idx3-box { position: relative; height: 52px; margin-top: 2px; }
.idx3-box .hint { font-size: 12px; }
.idx3-legend { display: flex; gap: 10px; align-items: center; }
.idx3-key { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.idx3-dot { display: inline-block; width: 10px; height: 3px; border-radius: 2px; }
.idx3-taiex { background: #12B76A; }
.idx3-tpex { background: #F04438; }
.idx3-txf { background: #3B82F6; }
/* 今日多空：點擊放大 modal（三線可勾選顯隱；idx3.js 動態建立） */
.idx3-clickable { cursor: pointer; }
.idx3-modal { position: fixed; inset: 0; z-index: 1000; background: rgba(0, 0, 0, .45);
  display: flex; align-items: center; justify-content: center; }
.idx3-modal[hidden] { display: none; }   /* display:flex 會蓋掉 hidden 預設樣式，需明確關閉 */
.idx3-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  width: min(860px, 94vw); padding: 16px 18px; box-shadow: 0 12px 40px rgba(0, 0, 0, .25); }
.idx3-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.idx3-head h3 { margin: 0; font-size: 1rem; }
.idx3-close { border: none; background: transparent; color: var(--text-muted);
  font-size: 1.1rem; cursor: pointer; padding: 4px 8px; }
.idx3-toggles { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.idx3-tg { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
  color: var(--text); cursor: pointer; font-size: .85rem; min-height: 30px; }
.idx3-tg.off { opacity: .38; }
.idx3-tg .idx3-dot { width: 12px; height: 3px; }
.idx3-big { position: relative; height: min(52vh, 420px); }
.kpi-sub.idx-trend .sr-sig { font-size: 11px; font-weight: 600; white-space: nowrap; }
.kpi-sub.idx-trend .sr-sig.up { color: var(--up); }
.kpi-sub.idx-trend .sr-sig.down { color: var(--down); }
.kpi-sub.idx-trend .sr-sig.flat { color: var(--text-muted); }
.skeleton-kpi { min-height: 92px; background: var(--surface-2); border-color: var(--border); }

/* 表 + 圖並排 grid */
.grid-2 {
  display: grid; grid-template-columns: 1.4fr 1fr; gap: 24px;
  align-items: start;   /* 右欄固定在自身內容高度，不被加長的左表（如產業篩選）拉長 */
}
/* grid 內以 gap 取代卡片 margin，避免左卡 margin-bottom 造成下沿差一個 gap */
.grid-2 .card { margin-bottom: 0; }
/* 右欄：Top5 + 產業資金流向直向堆疊，整欄撐到與排行明細同高 */
.side-col { display: flex; flex-direction: column; gap: 24px; min-height: 0; }
.sector-card { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.sector-card .card-head { flex-wrap: wrap; row-gap: 4px; }
.sector-card .card-head h2 { white-space: nowrap; }
/* 近10日 資金流入/流出 各前 5：兩組各 5 列填滿卡片高度（下沿對齊排行明細）；單欄避免橫向變形 */
.sector-flow { flex: 1; min-height: 600px; display: flex; flex-direction: column; gap: 14px; overflow: hidden; }
.sf-group { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.sf-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font-size: 13px; font-weight: 700; margin-bottom: 6px; }
.sf-head.up { color: var(--up); }
.sf-head.down { color: var(--down); }
.sf-head .sf-sub { font-size: 11px; font-weight: 400; color: var(--text-muted); }
.sf-rows { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 6px; }
.sf-empty { color: var(--text-muted); font-size: 12px; padding: 4px 0; }
.sector-row { flex: 1; min-height: 0; display: flex; align-items: center; gap: 10px; cursor: pointer; border-radius: 6px; padding: 0 6px; margin: 0 -6px; transition: background 0.12s; }
.sector-row:hover { background: var(--surface-2); }
.sector-row .sr-name { flex: 0 0 7.5em; font-size: 12px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sector-row .sr-share { flex: 0 0 3em; text-align: right; font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.sector-row .sr-spark { flex: 1; min-width: 0; align-self: stretch; position: relative; }
.sector-row .sr-delta { flex: 0 0 6.2em; display: flex; flex-direction: column; align-items: flex-end; gap: 1px; text-align: right; font-variant-numeric: tabular-nums; }
.sector-row .sr-pp { font-size: 12px; font-weight: 600; }
.sector-row .sr-delta.up .sr-pp { color: var(--up); }
.sector-row .sr-delta.down .sr-pp { color: var(--down); }
.sector-row .sr-sig { font-size: 10px; font-weight: 600; white-space: nowrap; }
.sector-row .sr-sig.up { color: var(--up); }
.sector-row .sr-sig.down { color: var(--down); }
.sector-row .sr-sig.flat { color: var(--text-muted); }

/* 排行明細上方的產業篩選提示列（點產業資金流向帶出個股時顯示） */
.filter-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; padding: 8px 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.filter-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); }
.filter-chip b { color: var(--primary); font-weight: 700; }
.filter-bar .btn-ghost { flex: 0 0 auto; }

/* 卡片 */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 24px; margin-bottom: 24px;
}
.card h2 { font-size: 16px; font-weight: 600; margin: 0 0 16px; }

/* 卡片標題列（標題 + 動作）。M15：檢視分頁增至 5 顆後表頭較寬 →
   空間不足時換行（比照 sector-card），避免動作區與分頁重疊擋住點擊 */
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; row-gap: 8px; }
.card-head h2 { margin: 0; }
/* 排行／自選 切換（segmented control） */
.head-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.view-toggle { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px; gap: 2px; }
.vt-btn { display: inline-flex; align-items: center; gap: 4px; border: 0; background: transparent; color: var(--text-muted); font: inherit; font-size: 13px; font-weight: 600; padding: 5px 14px; border-radius: 7px; cursor: pointer; white-space: nowrap; transition: color 0.12s, background 0.12s, transform 0.08s; }
.vt-btn:hover { color: var(--text); }
.vt-btn:active { transform: scale(0.97); }
.vt-btn.active { background: var(--surface); color: var(--primary); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06); }
.vt-count { min-width: 18px; padding: 0 5px; font-size: 11px; line-height: 16px; text-align: center; border-radius: 9px; background: var(--primary); color: #fff; font-weight: 700; font-variant-numeric: tabular-nums; }
.vt-btn.active .vt-count { background: var(--primary); }
.vt-btn:not(.active) .vt-count { background: var(--text-muted); }
.card-actions { display: flex; align-items: center; gap: 12px; }
.hint { font-size: 12px; color: var(--text-muted); }
.btn-ghost {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; padding: 6px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--text-muted);
  cursor: pointer;
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-muted); }

/* 表格 */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--border); }
th { font-size: 12px; color: var(--text-muted); font-weight: 600; position: sticky; top: 0; background: var(--surface); }
th.col-left, td.col-left { text-align: left; }
td.num { font-variant-numeric: tabular-nums; }
td.turnover { font-weight: 600; }
table tr[data-code] { cursor: pointer; transition: background .15s ease; }
table tr[data-code]:hover { background: var(--surface-2); }
table tr[data-code]:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }

/* F15：可拖曳的欄位表頭 + 點擊排序 */
th.drag-col { cursor: pointer; -webkit-user-select: none; user-select: none; transition: background .15s ease, color .15s ease; }
th.drag-col:hover { color: var(--text); background: var(--surface-2); }
th.drag-col.drag-over { background: var(--primary-soft); box-shadow: inset 2px 0 0 var(--primary); }
th.drag-col.sorted { color: var(--primary); }
.sort-ind { margin-left: 4px; font-size: 10px; }
th.fixed-col { color: var(--text-muted); }
/* 固定但可排序的欄（個股） */
th.sort-col { cursor: pointer; -webkit-user-select: none; user-select: none; transition: background .15s ease, color .15s ease; }
th.sort-col:hover { color: var(--text); background: var(--surface-2); }
th.sort-col.sorted { color: var(--primary); }

/* 排名徽章（前 3 名強調） */
.rank-cell { text-align: left; }
.rank-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 999px;
  font-size: 12px; font-weight: 700; color: #fff;
}
.rank-badge.r1 { background: #D97706; }       /* 金 */
.rank-badge.r2 { background: #94A3B8; }       /* 銀 */
.rank-badge.r3 { background: #B45309; }       /* 銅 */
.rank-plain { color: var(--text-muted); font-variant-numeric: tabular-nums; padding-left: 4px; }
.rank-over { font-weight: 600; }   /* 搜尋帶入、非前 20 名：顯示「20+」 */
/* 排名下方的迷你趨勢（紅多綠空灰中性）；尚未算出時隱藏 */
.rank-trend { display: block; margin-top: 3px; font-size: 10px; font-weight: 600; white-space: nowrap; }
.rank-trend:empty { display: none; }
.rank-trend.up { color: var(--up); }
.rank-trend.down { color: var(--down); }
.rank-trend.flat { color: var(--text-muted); }

/* 市場別標籤 */
.badge { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px; }
.badge.twse { background: var(--primary-soft); color: var(--primary); }
.badge.tpex { background: var(--surface-2); color: var(--text-muted); }

/* 漲跌色 */
.up { color: var(--up); }
.down { color: var(--down); }
td.num.up, td.num.down { font-weight: 600; }

/* M25 回測欄：樣本不足（<5）弱化顯示 */
.bt-low { opacity: .5; }
/* M25 策略追蹤摘要列：與下方表格保持間距 */
#potentialTrack { margin-bottom: 10px; }

/* 頁面導覽（每日排行 / 盤中即時） */
.title-wrap { display: flex; flex-direction: column; gap: 10px; }
/* 分段控制風格的頁面導覽（與 .seg 一致） */
.page-nav {
  display: inline-flex; gap: 2px; padding: 2px; align-self: flex-start;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.page-nav a {
  font-size: 13px; padding: 6px 16px; border-radius: 6px; font-weight: 500;
  color: var(--text-muted); text-decoration: none;
  transition: background .15s ease, color .15s ease;
}
.page-nav a:hover { color: var(--text); }
.page-nav a.active {
  background: var(--surface); color: var(--primary); font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .06);
}
@media (prefers-reduced-motion: reduce) { .page-nav a { transition: none; } }
.error-text { color: var(--up); }
/* K 線圖容器（maintainAspectRatio:false 需要固定高度的父層） */
.chart-box { position: relative; width: 100%; }
.chart-box.turnover-box { height: 90px; }
.chart-box.price-box { height: 300px; }
.chart-box.vol-box { height: 100px; }

/* 盤中更新頻率選單 */
.refresh-pick { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); white-space: nowrap; }
.refresh-pick select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 4px 8px; cursor: pointer;
}

/* 自訂圖例：勾選框 + 色塊（取代 Chart.js 內建點擊式圖例，切換顯示更明確） */
.chart-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 16px; margin: 4px 0 12px; }
.legend-item {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer; -webkit-user-select: none; user-select: none;
  font-size: 13px; color: var(--text); padding: 3px 9px; border-radius: var(--radius-sm);
  transition: opacity .15s ease, background .15s ease;
}
.legend-item:hover { background: var(--surface-2); }
.legend-item.off { opacity: .4; }
.legend-item input { width: 15px; height: 15px; margin: 0; cursor: pointer; accent-color: var(--primary); flex: 0 0 auto; }
.legend-swatch { width: 18px; height: 4px; border-radius: 2px; background: var(--sw, #888); flex: 0 0 auto; }
.legend-swatch.dashed { height: 0; background: none; border-top: 3px dashed var(--sw, #888); }
.legend-swatch.candle { width: 14px; height: 14px; border-radius: 3px; background: linear-gradient(90deg, var(--up) 50%, var(--down) 50%); }

/* 面板讀數列：放在各子圖「上方」（流式、不疊圖、不壓格線）。值接在小標題後面 */
/* padding-right ≈ y 軸寬(52px)+小間距 → 靠右的均線讀數收在最後格線往前一點，不貼到最右 */
.panel-head { display: flex; align-items: baseline; font-size: 11px; line-height: 1.2; color: var(--text-muted); white-space: nowrap; margin: 6px 0 1px; padding-right: 58px; overflow: hidden; }
.panel-head .ro-title { color: var(--text); font-weight: 600; margin-right: 6px; }
.panel-head b { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 600; }
.panel-head b.up { color: var(--up); }
.panel-head b.down { color: var(--down); }
.panel-head .ma-group { margin-left: auto; display: inline-flex; align-items: center; }   /* 均線靠右（靠後）*/
.panel-head .ro-item { display: inline-flex; align-items: center; gap: 3px; margin-left: 12px; cursor: pointer; -webkit-user-select: none; user-select: none; }
.panel-head .ro-item.off { opacity: .35; }
.panel-head .ro-line { display: inline-block; width: 12px; height: 3px; border-radius: 2px; }
/* 右側控制群：趨勢線工具（在前）+ 均線（在後），整群靠右 */
.panel-head .ro-ctrl { margin-left: auto; display: inline-flex; align-items: center; gap: 10px; }
.panel-head .ro-ctrl .ma-group { margin-left: 0; }   /* 靠右改交給 .ro-ctrl */
.panel-head .draw-tools { display: inline-flex; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px; }
.panel-head .draw-btn { font: inherit; font-size: 11px; line-height: 1.2; padding: 2px 8px; border: 0; background: transparent; color: var(--text-muted); cursor: pointer; border-radius: 5px; }
.panel-head .draw-btn:hover { color: var(--text); }
.panel-head .draw-btn.active { background: var(--surface); color: var(--primary); font-weight: 600; }
.panel-head .sr-tools { display: inline-flex; align-items: center; gap: 4px; }
.panel-head .sr-label { color: var(--text-muted); }
/* 圖表下方說明（條列） */
.chart-notes { margin: 8px 0 0; padding-left: 18px; line-height: 1.55; }
.chart-notes li { margin: 2px 0; }
.chart-notes b { color: var(--text); font-weight: 600; }
/* 趨勢徽章（K 線讀數列 / KPI / 排行）：漲紅跌綠、盤整中性 */
.trend-badge { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 999px; margin-left: 8px; vertical-align: middle; }
.trend-badge:empty { display: none; }
.trend-badge.up { color: var(--up); background: rgba(217, 45, 32, .10); }
.trend-badge.down { color: var(--down); background: rgba(3, 152, 85, .10); }
.trend-badge.flat { color: var(--text-muted); background: var(--surface-2); }
/* 個股頁標題旁：上一檔 / 下一檔 */
.stock-nav { display: inline-flex; gap: 6px; margin-left: 8px; vertical-align: middle; }
.stock-nav .nav-btn { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border); color: var(--text); background: var(--surface); text-decoration: none; cursor: pointer; }
.stock-nav .nav-btn:hover { background: var(--surface-2); }
.stock-nav .nav-btn.disabled { color: var(--text-muted); background: var(--surface-2); opacity: .5; cursor: default; }
.panel-head .ro-trend { margin-left: 10px; font-weight: 600; }
.panel-head .ro-trend:empty { display: none; }
.panel-head .ro-trend.up { color: var(--up); }
.panel-head .ro-trend.down { color: var(--down); }
.panel-head .ro-trend.flat { color: var(--text-muted); }
.kpi-value.kpi-trend-value { font-size: 20px; }   /* 趨勢文字較長，字級略小 */
.kpi-trend-value.up { color: var(--up); }
.kpi-trend-value.down { color: var(--down); }
.kpi-trend-value.flat { color: var(--text-muted); }

/* 「綜合資訊」後的日期 */
.hdr-date { font-size: 13px; color: var(--text-muted); font-weight: 500; margin-left: 6px; font-variant-numeric: tabular-nums; }

/* 身分欄（代號 + 名稱 + 市場 合併） */
td.ident-col { text-align: left; display: flex; align-items: center; gap: 6px; }
/* 自選星號（在「個股」欄最前）：lucide SVG，平時低調、滑到列才明顯，加入後實心金色 */
.watch-star { flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border: 0; background: transparent; cursor: pointer; border-radius: 6px; color: var(--text-muted); opacity: 0.3; transition: opacity 0.12s, color 0.12s, background 0.12s, transform 0.08s; }
.watch-star svg { width: 15px; height: 15px; fill: none; }
tr:hover .watch-star { opacity: 0.85; }
.watch-star:hover { opacity: 1; color: #F59E0B; background: var(--surface-2); }
.watch-star:active { transform: scale(0.88); }
.watch-star.on { opacity: 1; color: #F59E0B; }
.watch-star.on svg { fill: #F59E0B; }
/* 個股頁標題列的「加入自選」星號：較大、永遠可見（非表格列，無 hover 浮現） */
.watch-star.title-star { width: 34px; height: 34px; opacity: 1; }
.watch-star.title-star svg { width: 22px; height: 22px; }
.watch-star.title-star:hover { color: #F59E0B; background: var(--surface-2); }
.ident { display: flex; flex-direction: column; gap: 2px; line-height: 1.25; }
/* 名稱與產業別同一行；產業別字較小、置於名稱右側 */
.ident-name-row { display: inline-flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.ident-name { font-weight: 600; color: var(--text); }
.ident-meta { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.ident-code { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.ident-industry { font-size: 11px; color: var(--text-muted); }

/* 欄位選擇器面板 */
.col-picker-wrap { position: relative; display: inline-block; }
.col-picker {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
  min-width: 180px; padding: 8px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
}
.col-picker[hidden] { display: none; }
.col-picker-title { font-size: 12px; color: var(--text-muted); padding: 2px 6px 6px; }
.col-picker label {
  display: flex; align-items: center; gap: 8px; padding: 5px 6px;
  font-size: 13px; color: var(--text); border-radius: var(--radius-sm); cursor: pointer;
}
.col-picker label:hover { background: var(--surface-2); }
.col-picker input[type=checkbox] { accent-color: var(--primary); }

/* 狀態 */
.state { text-align: center; color: var(--text-muted); padding: 40px 0; }
.error { background: rgba(217,45,32,.08); color: var(--up); padding: 12px 16px; border-radius: var(--radius-sm); }

/* 空狀態 */
.empty { text-align: center; color: var(--text-muted); padding: 48px 16px; }
.empty svg, .empty i[data-lucide] {
  width: 40px; height: 40px; margin-bottom: 12px;
  color: var(--text-muted);   /* Lucide 用 currentColor */
}
.empty-title { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.empty-sub { font-size: 13px; }

/* 載入骨架 */
.skeleton-table { padding: 8px 0; }
.skeleton-line, .skeleton-kpi {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}
.skeleton-line { height: 36px; border-radius: var(--radius-sm); margin: 6px 0; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

@media (prefers-reduced-motion: reduce) {
  .skeleton-line, .skeleton-kpi { animation: none; }
  table tr[data-code], th.drag-col { transition: none; }
}

a.back { color: var(--text-muted); text-decoration: none; font-size: 14px; }
a.back:hover { color: var(--text); }

/* Lucide 行內圖標尺寸（占位 i 與替換後的 svg 一併設定，避免載入跳動） */
.btn-ghost i[data-lucide], .btn-ghost svg,
.kpi-delta i[data-lucide], .kpi-delta svg { width: 14px; height: 14px; }
a.back i[data-lucide], a.back svg { width: 18px; height: 18px; vertical-align: middle; }

/* 個股頁：標題列（返回 + 標題 + 市場標籤） */
.stock-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.stock-title h1 { font-size: 22px; font-weight: 700; margin: 0; }
.stock-title a.back { font-size: 20px; line-height: 1; }

/* 區間切換（segmented control） */
.seg {
  display: inline-flex; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px;
}
.seg-btn {
  font-size: 13px; padding: 6px 14px; border: 0; background: transparent;
  color: var(--text-muted); cursor: pointer; border-radius: 6px;
  transition: background .15s ease, color .15s ease;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--surface); color: var(--primary); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.seg-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }

@media (prefers-reduced-motion: reduce) { .seg-btn { transition: none; } }

/* 響應式 */
/* 平板：表/圖改上下堆疊，KPI 維持但可換 2 欄 */
@media (max-width: 1024px) {
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .kpi-row { grid-auto-flow: row; grid-template-columns: repeat(2, 1fr); }
}

/* 手機（≤640px）*/
@media (max-width: 640px) {
  .container { padding: 16px 12px; }
  .topbar { flex-direction: column; align-items: stretch; }
  .topbar h1 { font-size: 18px; }
  .topbar-controls { flex-direction: column; align-items: stretch; }
  .search input { width: 100%; }
  .kpi-value { font-size: 22px; }
  .card { padding: 16px 12px; }
  .card-head { flex-direction: column; align-items: stretch; gap: 8px; }
  .card-actions { justify-content: space-between; }
  /* 表格可橫向捲動，避免擠壓 */
  #tableWrap { overflow-x: auto; }
  #tableWrap table { min-width: 560px; }
  th, td { padding: 8px 10px; }
}

/* ---- 手機底部 4-Tab 導覽（P0 地基）---- */
/* 桌機/平板一律隱藏；僅手機顯示，固定底部、預留 iOS/Android 安全區。 */
.bottom-tabbar { display: none; }

@media (max-width: 640px) {
  .bottom-tabbar {
    display: flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 100;
    height: calc(56px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--surface);
    border-top: 1px solid var(--border);
  }
  .bottom-tabbar .tab {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 44px;            /* 觸控目標 ≥44px */
    text-decoration: none;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
  }
  .bottom-tabbar .tab.active { color: var(--primary); }
  .bottom-tabbar .tab i { width: 22px; height: 22px; }
  .bottom-tabbar .tab:active { background: var(--surface-2); }
  .bottom-tabbar .tab:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }

  /* 有 Tab Bar 的頁面，內容底部留白避免被固定列遮住（72px = 56px bar + .container 手機 16px 底部 padding）*/
  body:has(.bottom-tabbar) .container { padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)); }
}

/* ---- 特別關注 · 有戲（右欄頂端小卡）---- */
.special-watch { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.sw-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); cursor: pointer; transition: border-color 0.12s, transform 0.08s; }
.sw-row:hover { border-color: var(--primary); }
.sw-row:active { transform: scale(0.99); }
.sw-rank { font-size: 18px; font-weight: 800; color: var(--primary); min-width: 22px; text-align: center; }
.sw-ident { display: flex; flex-direction: column; line-height: 1.25; flex: 1; min-width: 0; }
.sw-name { font-weight: 700; color: var(--text); }
.sw-meta { font-size: 12px; color: var(--text-muted); }
.sw-count { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--up); white-space: nowrap; }

/* 潛力飆股：均線糾結旗標 */
.sq-flag { font-weight: 700; }
.sq-flag.hot { color: var(--up); }
.sq-flag.warm { color: #E8830C; }

/* 當日盤中區：左分時圖、右五檔+逐筆 */
.rt-panel { display: flex; gap: 16px; margin: 12px 0; align-items: stretch; }
.rt-chart-col { flex: 2 1 420px; min-width: 300px; display: flex; flex-direction: column; }
.rt-side-col { flex: 1 1 260px; min-width: 240px; display: flex; flex-direction: column; gap: 8px; }
.rt-chart-box { position: relative; flex: 3 1 0; min-height: 140px; }
.rt-chart-box.rt-vol-box { flex: 1 1 0; min-height: 56px; }
.rt-title { font-size: .9rem; margin: 0 0 6px; }
/* ① seg 切換器緊接「已收盤」狀態之後，不再貼最右 */
.rt-head { display: flex; align-items: center; justify-content: flex-start; gap: 8px; margin-bottom: 6px; }
.rt-head .rt-title { margin: 0; }
.seg-sm .seg-btn { padding: 2px 8px; font-size: .72rem; }
.rt-readout { font-size: .72rem; color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.rt-cap { font-size: .78rem; font-weight: 600; color: var(--text-muted); margin-bottom: 2px; }
.rt-book2 .rt-total-lbl { text-align: center; color: var(--text-muted); font-weight: 400; }
/* 五檔買賣並排 */
/* ④ 固定版面讓四欄等寬對齊，搭配 colgroup 的 width:25% */
.rt-book2 { width: 100%; table-layout: fixed; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.rt-book2 col { width: 25%; }
.rt-book2 td { padding: 3px 8px; text-align: right; font-size: .85rem; border-bottom: 1px solid var(--border); }
.rt-book2 .rt-px.bid { border-right: 2px solid var(--border); }
.rt-book2 .rt-px.up { color: var(--up); }
.rt-book2 .rt-px.down { color: var(--down); }
.rt-book2 .rt-px.best { font-weight: 700; }
.rt-book-total td { font-weight: 700; color: var(--text-muted); }
.rt-book2 thead .rt-book-head th { padding: 2px 8px; font-size: .78rem; font-weight: 700; text-align: center; border-bottom: 1px solid var(--border); }
.rt-book2 .rt-book-head th.bid { color: var(--up); }
.rt-book2 .rt-book-head th.ask { color: var(--down); }
.rt-strength { margin-top: 4px; }
.rt-strength-bar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--border); }
.rt-strength-bar .bid { background: var(--up); }
.rt-strength-bar .ask { background: var(--down); }
.rt-strength-lbl { display: flex; justify-content: space-between; font-size: .72rem; color: var(--text-muted); margin-top: 2px; }
/* 逐筆：固定高度、內部捲動，不撐長頁面 */
.rt-ticks-wrap { height: 200px; overflow-y: auto; border-top: 1px solid var(--border); }
.rt-ticks { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.rt-ticks th, .rt-ticks td { padding: 2px 8px; text-align: right; font-size: .82rem; }
.rt-ticks thead th { position: sticky; top: 0; background: var(--surface); }
.rt-ticks .rt-sz.up { color: var(--up); font-weight: 600; }
.rt-ticks .rt-sz.down { color: var(--down); font-weight: 600; }
/* 大單分級底色：單量 ≥ 近期中位數 × 12/20/30/50 → t1..t4 逐級加深；
   外盤（主動買）紅色系、內盤（主動賣）綠色系；無方向之中性大單維持琥珀。 */
.rt-ticks tr.big-buy.big-t1 { background: rgba(217, 45, 32, .10); }
.rt-ticks tr.big-buy.big-t2 { background: rgba(217, 45, 32, .20); }
.rt-ticks tr.big-buy.big-t3 { background: rgba(217, 45, 32, .32); }
.rt-ticks tr.big-buy.big-t4 { background: rgba(217, 45, 32, .46); }
.rt-ticks tr.big-sell.big-t1 { background: rgba(3, 152, 85, .12); }
.rt-ticks tr.big-sell.big-t2 { background: rgba(3, 152, 85, .22); }
.rt-ticks tr.big-sell.big-t3 { background: rgba(3, 152, 85, .34); }
.rt-ticks tr.big-sell.big-t4 { background: rgba(3, 152, 85, .48); }
.rt-ticks tr.big-flat { background: rgba(245, 158, 11, .18); }   /* 中性大單（無內外盤方向） */
/* 大量K高/低（分時圖水平參考線）表頭圖例：桃紅=高、綠=低（識別色，與紅漲綠跌區隔） */
.rt-bigk { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.rt-bigk b { font-weight: 700; font-variant-numeric: tabular-nums; }
.rt-bigk .hi { color: #E64980; }
.rt-bigk .lo { color: #12B76A; }
/* 價碰漲跌停：漲停紅底、跌停綠底（個股頁五檔/逐筆共用） */
.lim-up { background: var(--up); color: #fff; padding: 0 4px; border-radius: 3px; }
.lim-down { background: var(--down); color: #fff; padding: 0 4px; border-radius: 3px; }
@media (max-width: 720px) { .rt-panel { flex-direction: column; } }

/* 自訂交易日日曆 */
.date-picker { position: relative; display: inline-block; }
.date-btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); cursor: pointer; font-variant-numeric: tabular-nums; }
.date-pop { position: absolute; right: 0; top: calc(100% + 6px); z-index: 50; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.18); padding: 10px; width: 252px; }
.dp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.dp-title { font-weight: 600; }
.dp-nav { border: none; background: transparent; font-size: 1.1rem; cursor: pointer; color: var(--text); padding: 2px 8px; }
.dp-nav:disabled { color: var(--text-muted); cursor: not-allowed; }
.dp-wds, .dp-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.dp-wd { text-align: center; font-size: .75rem; color: var(--text-muted); padding: 2px 0; }
.dp-cell { text-align: center; padding: 6px 0; font-size: .85rem; border: none; background: transparent; border-radius: 6px; color: var(--text); cursor: pointer; }
.dp-cell.empty { visibility: hidden; }
.dp-cell.disabled { color: var(--border); cursor: not-allowed; }
.dp-cell[data-iso]:hover { background: var(--surface-2); }
.dp-cell.sel { background: var(--primary); color: #fff; }

/* Top5 長條圖容器：固定高度讓右欄底部與左欄排名表對齊 */
.bar-box { position: relative; height: 340px; }

/* 籌碼欄徽章：進貨紅/出貨綠/持平灰（台股紅漲綠跌）*/
.chips.up { color: var(--up); font-weight: 600; }
.chips.down { color: var(--down); font-weight: 600; }
.chips.flat { color: var(--text-muted); }
.major.up { color: var(--up); font-weight: 600; }
.major.down { color: var(--down); font-weight: 600; }
.major.flat { color: var(--text-muted); }

/* K 線頻率下拉 + 自訂分鐘輸入 */
.seg-select, .seg-min { font-size: .8rem; padding: 2px 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); }
.seg-min { width: 56px; }
#klineSeg.disabled { opacity: .4; pointer-events: none; }

/* ──────────────────────────────────────────────────────────────────────────
   認證頁（登入／註冊／忘記密碼／重設／狀態頁）— 極簡單欄置中卡片
   沿用設計系統 tokens，明暗模式自動適配；單一主要 CTA、清楚的表單回饋。
   ────────────────────────────────────────────────────────────────────────── */
.auth-wrap {
  max-width: 400px;
  margin: clamp(24px, 8vh, 72px) auto 48px;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .05);
}
@media (prefers-color-scheme: dark) {
  .auth-card { box-shadow: 0 6px 24px rgba(0, 0, 0, .35); }
}
.auth-card h1 {
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}
/* 狀態頁頂部圖示（Lucide，currentColor）*/
.auth-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
}
.auth-icon.ok { background: rgba(3, 152, 85, .12); color: var(--down); }
.auth-icon.warn { background: rgba(217, 45, 32, .10); color: var(--up); }
.auth-icon i[data-lucide], .auth-icon svg { width: 24px; height: 24px; }
.auth-sub {
  color: var(--text-muted);
  font-size: 14px;
  margin: 0 0 22px;
  line-height: 1.6;
}
.auth-sub strong { color: var(--text); font-weight: 600; }

/* 表單：垂直堆疊、欄位間距一致 */
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.field label .req { color: var(--up); margin-left: 2px; }
.field input {
  width: 100%;
  font: inherit;
  font-size: 16px;           /* ≥16px 避免 iOS 自動放大 */
  padding: 11px 13px;
  min-height: 44px;          /* 觸控目標 */
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.field input::placeholder { color: var(--text-muted); }
.field input:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.field-hint { font-size: 12px; color: var(--text-muted); }

/* 密碼欄：右側顯示/隱藏切換 */
.pw-wrap { position: relative; display: flex; align-items: center; }
.pw-wrap input { padding-right: 44px; }
.pw-toggle {
  position: absolute; right: 4px;
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  border: 0; background: transparent; color: var(--text-muted);
  cursor: pointer; border-radius: var(--radius-sm);
}
.pw-toggle:hover { color: var(--text); }
.pw-toggle:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.pw-toggle i[data-lucide], .pw-toggle svg { width: 18px; height: 18px; }

/* 主要 CTA 按鈕 */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%;
  font: inherit; font-size: 15px; font-weight: 600;
  min-height: 44px; padding: 11px 18px;
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  background: var(--primary); color: #fff;
  cursor: pointer;
  transition: background .15s, transform .08s, box-shadow .15s;
}
.btn-primary:hover { background: #1B3A9E; }
.btn-primary:active { transform: scale(.99); }
.btn-primary:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--primary-soft); }
@media (prefers-color-scheme: dark) {
  .btn-primary:hover { background: #5B96F8; }
}

/* 次要連結列（註冊／忘記密碼／回登入）*/
.auth-links {
  margin: 18px 0 0; padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 13px; color: var(--text-muted);
  text-align: center;
}
.auth-links a { color: var(--primary); text-decoration: none; font-weight: 500; }
.auth-links a:hover { text-decoration: underline; }
.auth-links .sep { margin: 0 8px; opacity: .5; }
/* 開發模式小提示 */
.auth-note {
  margin-top: 16px; padding: 10px 12px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px; color: var(--text-muted); line-height: 1.5;
}

/* 表單錯誤（沿用 .error 配色，補間距與圖示對齊）*/
.auth-form .error, .auth-card > .error {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 4px; font-size: 13px;
}
.auth-card > .error { margin-bottom: 18px; }

/* 帳號審核頁：狀態徽章 + 操作鈕 */
.admin-users .card { overflow-x: auto; }
.admin-users table { min-width: 560px; }
.admin-users th, .admin-users td { text-align: left; }
.admin-users td.actions { text-align: right; white-space: nowrap; }
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600;
  padding: 2px 9px; border-radius: 999px;
  line-height: 1.5;
}
.badge.yes { background: rgba(3, 152, 85, .12); color: var(--down); }
.badge.no { background: var(--surface-2); color: var(--text-muted); }
.badge.admin { background: var(--primary-soft); color: var(--primary); }
.badge i[data-lucide], .badge svg { width: 13px; height: 13px; }
.btn-sm { font-size: 13px; padding: 6px 14px; min-height: 34px; width: auto; }
.btn-danger {
  border-color: var(--border); background: var(--surface); color: var(--up);
}
.btn-danger:hover { background: rgba(217, 45, 32, .08); border-color: var(--up); }

@media (max-width: 640px) {
  .auth-card { padding: 24px 18px; }
}

/* ---- 手機排行卡片列（P1a；僅 ≤640px）---- */
@media (max-width: 640px) {
  /* 卡片模式下，桌機表格專屬提示/欄位工具隱藏（拖曳排序、欄位選擇在手機卡片不適用） */
  .card-actions .hint { display: none; }
  .col-picker-wrap { display: none; }

  .rank-card-list { display: flex; flex-direction: column; gap: 10px; }
  .rank-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    cursor: pointer;
  }
  .rank-card:active { transform: scale(0.995); }

  .rank-card .rc-top {
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .rank-card .rc-rank { flex: 0 0 auto; min-width: 26px; text-align: center; }
  .rank-card .rc-mark { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 4px; }
  .rank-card .ident { flex: 1 1 auto; min-width: 0; overflow: hidden; }
  .rank-card .rc-turn-label { flex: 0 0 auto; font-size: 12px; color: var(--text-muted); }

  .rank-card .rc-main {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
  }
  .rank-card .rc-turn {
    font-size: 22px;
    font-weight: 700;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
    display: inline-flex;
    align-items: baseline;
    gap: 4px;
  }
  .rank-card .rc-turn .unit { font-size: 13px; font-weight: 600; }
  .rank-card .rc-price {
    font-size: 14px;
    font-variant-numeric: tabular-nums;
    text-align: right;
    white-space: nowrap;
  }
  .rank-card .rc-sub { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

  /* ☆ 觸控目標 ≥44px（卡片內按鈕） */
  .rank-card .watch-star { min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
}

/* ---- 手機 KPI 橫滑卡（P1b；僅 ≤640px）---- */
@media (max-width: 640px) {
  /* 由 2 欄 grid 改為水平捲動 + snap；覆寫 760px 的 grid 規則 */
  .kpi-row {
    display: flex;
    grid-template-columns: none;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    gap: 10px;
  }
  .kpi-row::-webkit-scrollbar { display: none; }
  .kpi-row .kpi {
    flex: 0 0 80%;            /* 一次約一張半，露出下一張提示可捲 */
    scroll-snap-align: start;
  }
  /* 卡序對齊設計稿：榜首 / 加權 / 櫃買 / 台指近月 / 預判
     （DOM 為 榜首,台指(#kpiTxf),加權(#kpiTaiex),櫃買(#kpiTpex),預判(#kpiForecast)；把台指移到櫃買之後、預判維持最後）*/
  .kpi-row #kpiTxf { order: 1; }
  .kpi-row #kpiForecast { order: 2; }
}

/* ---- 共用底部 sheet（P1c；排序／更新頻率等複用）---- */
.sheet-overlay {
  position: fixed; inset: 0; z-index: 200;     /* 高於底部 Tab Bar(100) */
  background: rgba(0, 0, 0, .4);
  display: flex; align-items: flex-end;
  opacity: 0; transition: opacity .18s ease;
}
.sheet-overlay.open { opacity: 1; }
.bottom-sheet {
  width: 100%;
  background: var(--surface);
  border-top-left-radius: 16px; border-top-right-radius: 16px;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  transform: translateY(100%); transition: transform .22s ease;
  max-height: 80vh; overflow-y: auto;
}
.sheet-overlay.open .bottom-sheet { transform: translateY(0); }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 8px auto 12px; }
.sheet-title { font-weight: 700; font-size: 15px; margin-bottom: 8px; color: var(--text); }
.sheet-list { display: flex; flex-direction: column; }
.sheet-option {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 48px; padding: 0 8px;            /* 觸控目標 ≥44px */
  background: none; border: none; border-bottom: 1px solid var(--border);
  font-size: 15px; color: var(--text); text-align: left; cursor: pointer;
}
.sheet-option:last-child { border-bottom: none; }
.sheet-option.active { color: var(--primary); font-weight: 700; }
.sheet-option:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.sheet-hint { color: var(--text-muted); font-weight: 600; }
@media (prefers-reduced-motion: reduce) {
  .sheet-overlay, .bottom-sheet { transition: none; }
}

/* 排序鈕：僅手機顯示（桌機以表頭排序）；手機同時隱藏欄位「還原預設」鈕 */
.sort-btn { display: none; }
@media (max-width: 640px) {
  .sort-btn { display: inline-flex; align-items: center; gap: 4px; }
  #resetCols { display: none; }
}

/* ---- 市場洞察可收合（P1d）---- */
/* details 化的洞察卡：桌機維持原樣（展開、不可收合、無揭示三角）；手機點標題收合 */
.insight > summary {
  list-style: none;            /* 去掉預設揭示三角（Firefox/標準） */
  display: block;              /* summary 當一般區塊，內部 h2/card-head 維持原樣式 */
}
.insight > summary::-webkit-details-marker { display: none; }   /* Safari/Chrome 三角 */

/* 桌機（>640px）：summary 不可互動 → 不能收合、維持展開，外觀同現況（零回歸） */
@media (min-width: 641px) {
  .insight > summary { pointer-events: none; }
}

/* 手機（≤640px）：可點標題收合，右側 CSS 箭頭指示展開/收合 */
@media (max-width: 640px) {
  .insight > summary { cursor: pointer; position: relative; padding-right: 22px; }
  .insight > summary::after {
    content: ""; position: absolute; right: 6px; top: 50%; margin-top: -6px;
    width: 8px; height: 8px;
    border-right: 2px solid var(--text-muted); border-bottom: 2px solid var(--text-muted);
    transform: rotate(45deg); transition: transform .15s;   /* 收合：朝下 ▾ */
  }
  .insight[open] > summary::after { margin-top: -2px; transform: rotate(225deg); }  /* 展開：朝上 ▴ */
  /* filter-bar 觸控微調：窄機可換行，清除鈕好點 */
  .filter-bar { flex-wrap: wrap; row-gap: 6px; }
}
/* reduced-motion：頂層合併查詢（避免舊 Android WebView 不支援巢狀 @media） */
@media (max-width: 640px) and (prefers-reduced-motion: reduce) {
  .insight > summary::after { transition: none; }
}

/* ---- 盤中更新頻率：手機用按鈕開 sheet、桌機用原生 select（P2）---- */
.refresh-btn { display: none; }
@media (max-width: 640px) {
  .refresh-btn { display: inline-flex; align-items: center; gap: 4px; }
  .refresh-pick { display: none; }
}

/* ---- 個股詳情頁手機收尾（P3a；僅 ≤640px）---- */
@media (max-width: 640px) {
  /* 頂列：標題+badge+☆+上/下一檔 可換行、不橫向溢出 */
  .stock-title { flex-wrap: wrap; gap: 8px 10px; }
  .stock-title h1 { font-size: 20px; }
  .stock-nav { margin-left: 0; }

  /* 三層圖手機高度（縮短 K 線、整體更貼近一屏可讀） */
  .chart-box.turnover-box { height: 76px; }
  .chart-box.price-box { height: 240px; }
  .chart-box.vol-box { height: 84px; }

  /* 讀數列（OHLC/均線）與期間/頻率 seg：窄機可換行，不橫向溢出 */
  .panel-head { flex-wrap: wrap; row-gap: 4px; white-space: normal; overflow: visible; }
  /* 控制群（頻率/劃線/撐壓/均線）窄機換行靠左，不靠右推擠戳出右界（修 MA 溢出） */
  .panel-head .ro-ctrl { flex-wrap: wrap; margin-left: 0; gap: 6px 10px; }
  .panel-head .ma-group { flex-wrap: wrap; margin-left: 0; row-gap: 4px; }
  .seg { flex-wrap: wrap; }
  .seg-btn { padding: 6px 10px; }

  /* 盤中即時列：可換行，數值不擠壓 */
  .live-strip { flex-wrap: wrap; row-gap: 4px; }
}

/* ---- 個股手機子分頁（P3b；走勢K線/即時五檔；桌機隱藏 nav、僅 ≤640px gate 面板）---- */
.stock-subtabs { display: none; }   /* 桌機一律隱藏 nav；兩面板並陳（零回歸） */
@media (max-width: 640px) {
  /* 子分頁僅在可用（rtPanel 有資料、JS 取消 hidden）時顯示 */
  .stock-subtabs:not([hidden]) { display: flex; gap: 8px; margin: 4px 0 12px; }
  .stock-subtabs .subtab {
    flex: 1 1 0; min-height: 40px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text-muted);
    font-size: 14px; font-weight: 600; cursor: pointer;
  }
  .stock-subtabs .subtab.active { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }
  /* 依 active 分頁隱藏另一面板（僅手機；桌機不 gate→兩塊並陳） */
  body[data-stocktab="kline"] .pane-book { display: none; }
  body[data-stocktab="book"] .pane-kline { display: none; }
}

/* ---- K 線橫向全螢幕（P3c；⤢ 鈕僅手機；覆蓋層 iOS 相容、不旋轉）---- */
.kline-fs-btn { display: none; }   /* 桌機隱藏（已有完整圖） */
@media (max-width: 640px) {
  .kline-fs-btn { display: inline-flex; align-items: center; gap: 4px; min-height: 36px; }
}
.kline-fs {
  position: fixed; inset: 0; z-index: 300;
  background: var(--bg);
  display: flex; flex-direction: column;
}
.kline-fs[hidden] { display: none; }
.kline-fs-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; border-bottom: 1px solid var(--border);
}
.kline-fs-hint { font-size: 13px; color: var(--text-muted); }
.kline-fs-close {
  background: none; border: none; color: var(--text); cursor: pointer;
  min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center;
}
.kline-fs-body { flex: 1; min-height: 0; position: relative; }
.kline-fs-body .chart-box.price-box { height: 100%; }   /* 填滿（覆寫固定高度）*/
body.kline-fs-open { overflow: hidden; }                 /* 鎖背景捲動 */

/* ---- 自選股頁 / 通用 page-head 與空狀態（P4a）---- */
.page-head { margin-bottom: 12px; }
.page-head h1 { font-size: 22px; font-weight: 700; margin: 0; }
.muted { color: var(--text-muted); }
.wl-empty {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 48px 16px; text-align: center; color: var(--text-muted);
}
.wl-empty .wl-empty-ico { width: 40px; height: 40px; }
.wl-empty-title { font-size: 16px; font-weight: 600; color: var(--text); margin: 0; }

/* ---- 我的(/me) 設定清單（P4b）---- */
.me-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.me-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; min-height: 52px;
  border-bottom: 1px solid var(--border);
}
.me-row:last-child { border-bottom: none; }
.me-label { color: var(--text); font-weight: 600; }
.me-value { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.me-link { text-decoration: none; color: var(--text); }
.me-link:hover { background: var(--surface-2); }
.me-logout button { background: none; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 14px; color: var(--up); font-weight: 600; cursor: pointer; }
.me-setting .seg-select { font-size: 14px; }
.theme-seg { display: inline-flex; gap: 4px; }
.theme-seg .seg-btn { padding: 6px 10px; }

/* 手機：頂列 site-nav 簡化——帳號/登入/登出/審核改由底部「我的」Tab(/me) 進入（spec §4.1；稽核 R6）*/
@media (max-width: 640px) {
  .site-nav-auth { display: none; }
}
/* 庫藏股手機卡片：副標（期間/預定/已買回/均價）允許換行，避免撐寬卡片造成水平溢出 */
.bb-card .rc-sub { white-space: normal; overflow-wrap: anywhere; line-height: 1.5; }
.bb-card .rc-price { white-space: nowrap; }
/* M14：排行明細檢視分頁增至 5 顆（＋庫藏股/歷史股），≤640px 允許換行，
   避免 min-content 撐寬 .grid-2 造成整頁水平溢出 */
@media (max-width: 640px) {
  .view-toggle { flex-wrap: wrap; }
  .head-left { min-width: 0; }
}
/* ---- 帳務頁（/ledger；分頁式：總覽/庫存/委託成交/損益）---- */
.ledger-synced { margin: -4px 0 16px; }
.sub-tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.sub-tab {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text-muted);
  font: inherit; font-size: 14px; font-weight: 600; padding: 8px 16px; cursor: pointer;
}
.sub-tab:hover { color: var(--text); }
.sub-tab.active { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }
.ledger-table { overflow-x: auto; }

/* 帳務成交查詢列：桌機一列排開、手機換行堆疊 */
.fill-filter { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 12px; }
.fill-filter label { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--text-muted); }
.fill-filter input { padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 13px; }
.fill-filter .ff-code { width: 88px; text-align: left; }
.fill-filter .ff-dash { color: var(--text-muted); }
.fill-filter .seg-btn { padding: 5px 12px; }
/* 各股已實現小表標題 */
.ledger-subhead { font-weight: 700; font-size: 14px; margin: 4px 0 8px; color: var(--text); }
/* 庫存/成交手機卡片：損益率括號縮小 */
.ledger-card .rc-pct { font-size: 12px; font-weight: 600; }

/* 帳務手機卡片：沿用 .rank-card 底樣式，標題列左右對齊 */
.ledger-card .rc-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.ledger-card .rc-title { font-weight: 700; }
.ledger-card .rc-sub { margin-top: 4px; white-space: normal; overflow-wrap: anywhere; }

/* 星星清單選單（M15 多清單）：桌機浮動於星星旁、≤640px 固定為底部面板 */
.wl-menu { position: absolute; z-index: 1200; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: 0 8px 24px rgba(0, 0, 0, .18); padding: 4px; min-width: 136px; }
.wl-menu-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 12px;
  border: none; background: transparent; color: var(--text); cursor: pointer; border-radius: 6px;
  font-size: .9rem; text-align: left; }
.wl-menu-item:hover, .wl-menu-item:focus-visible { background: var(--surface-2); }
.wl-menu-item .wl-check { width: 16px; height: 16px; border: 1.5px solid var(--border); border-radius: 4px;
  display: inline-flex; align-items: center; justify-content: center; font-size: 12px; color: #fff; flex: none; }
.wl-menu-item.on .wl-check { background: var(--primary); border-color: var(--primary); }
.wl-menu-item.on .wl-check::before { content: '✓'; }
@media (max-width: 640px) {
  .wl-menu { position: fixed; left: 12px !important; right: 12px; top: auto !important;
    bottom: calc(64px + env(safe-area-inset-bottom)); }
  .wl-menu-item { min-height: 44px; }
}
