/* ═══════════════════════════════════════════════════════════════
   選股工作台 · Stock Screener — 設計系統
   ═══════════════════════════════════════════════════════════════ */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600&family=Noto+Sans+TC:wght@300;400;500;600&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  /* surfaces — 白底灰階，oklch 冷調 */
  --bg:          oklch(99%   0.005 240);
  --bg-2:        oklch(100%  0.003 240);
  --surface:     oklch(97%   0.006 240);
  --surface-2:   oklch(94%   0.008 240);
  --surface-hi:  oklch(91%   0.010 240);
  --border:      oklch(91%   0.008 240);
  --border-2:    oklch(86%   0.010 240);

  /* text */
  --text:        oklch(18%   0.010 240);
  --text-dim:    oklch(35%   0.010 240);
  --text-mute:   oklch(52%   0.010 240);
  --text-faint:  oklch(68%   0.008 240);

  /* accents — 青藍主色 */
  --accent:      oklch(52%   0.18  240);
  --accent-dim:  oklch(65%   0.14  240);
  --accent-bg:   oklch(95%   0.04  240);
  --info:        oklch(55%   0.16  260);   /* 略偏紫藍，次要資訊 */
  --info-bg:     oklch(95%   0.03  260);

  /* 台股漲跌色（紅漲綠跌） */
  --up:          oklch(54%   0.18  25);
  --up-bg:       oklch(97%   0.04  25);
  --down:        oklch(50%   0.16  155);
  --down-bg:     oklch(96%   0.04  155);
  --warn:        oklch(62%   0.14  75);
  --flat:        oklch(62%   0.006 240);

  /* radii */
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 10px;

  /* fonts */
  --font-sans: "Noto Sans TC", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "Menlo", monospace;
  --font-display: "Outfit", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  letter-spacing: 0.005em;
}

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, select { font: inherit; color: inherit; outline: none; }
.mono { font-family: var(--font-mono); font-feature-settings: "tnum"; }
.up   { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--flat); }

/* scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-2); border-radius: 99px; border: 2px solid var(--bg-2); }
::-webkit-scrollbar-thumb:hover { background: var(--surface-hi); }

/* ═══════════════════════════════════════════════════════════════
   LAYOUT
   ═══════════════════════════════════════════════════════════════ */
.app { display: flex; flex-direction: column; height: 100vh; }

/* ── Topbar ── */
.topbar {
  display: flex; align-items: center;
  height: 52px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  flex-shrink: 0;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 240px; }
.brand-mark {
  width: 26px; height: 26px;
  border-radius: 6px;
  background: var(--accent);
  display: grid; place-items: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 12px;
  color: white;
  letter-spacing: -0.04em;
}
.brand-text { line-height: 1.15; }
.brand-name { font-size: 15px; font-weight: 600; letter-spacing: 0.02em; color: var(--text); font-family: var(--font-display); }
.brand-sub  { font-size: 11px; color: var(--text-mute); font-family: var(--font-mono); letter-spacing: 0.08em; margin-top: 1px; }

.status-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 99px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-faint); }
.status-dot.live {
  background: var(--down);
  box-shadow: 0 0 0 3px oklch(50% 0.16 155 / 0.2);
  animation: pulse 2s ease-in-out infinite;
}
.status-dot.err { background: var(--up); box-shadow: 0 0 0 3px oklch(54% 0.18 25 / 0.2); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

.topbar-meta { margin-left: auto; display: flex; align-items: center; gap: 14px; font-family: var(--font-mono); font-size: 11px; color: var(--text-mute); }
.topbar-meta b { color: var(--text-dim); font-weight: 500; }
.topbar-meta .sep { color: var(--border-2); }

/* ── Layout ── */
.layout { display: flex; flex: 1; overflow: hidden; }

/* ═══════════════════════════════════════════════════════════════
   SIDEBAR
   ═══════════════════════════════════════════════════════════════ */
.sidebar {
  width: 282px;
  flex-shrink: 0;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}

/* Strategy tabs */
.strat-tabs {
  display: flex;
  padding: 12px 12px 0;
  gap: 2px;
}
.stab {
  flex: 1;
  padding: 9px 6px 10px;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-mute);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.02em;
  user-select: none;
}
.stab:hover { color: var(--text-dim); }
.stab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}
.stab.active[data-mode="aggressive"] { border-bottom-color: var(--info); }
.stab.active[data-mode="custom"]     { border-bottom-color: var(--warn); }
.strat-tabs-divider { height: 1px; background: var(--border); margin: 0 -1px; }

/* Table selector row (custom mode) */
.table-select-row {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
.table-select-row.show { display: flex; }
.table-select-label {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-mute);
  letter-spacing: 0.06em;
}
.table-select {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 5px 8px;
  cursor: pointer;
}
.table-select:hover { border-color: var(--border-2); }

.db-switch {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 10px;
  border-right: 1px solid var(--border);
}
.db-variant-select {
  height: 30px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 12px;
  padding: 0 10px;
  outline: none;
}
.db-variant-select:hover { border-color: var(--border-2); }
.db-variant-select option[disabled] { color: var(--text-faint); }

/* Section label */
.section-label {
  padding: 14px 16px 8px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--text-faint);
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.section-label .enabled-count {
  background: var(--accent-bg);
  color: var(--accent);
  padding: 1px 6px;
  border-radius: 99px;
  font-size: 9.5px;
}

/* Filters scroll */
.filters-scroll { flex: 1; overflow-y: auto; }
.filters-scroll::-webkit-scrollbar { width: 6px; }

/* Filter group (collapsible) */
.fgroup { border-bottom: 1px solid var(--border); }
.fgroup-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 16px;
  cursor: pointer;
  user-select: none;
  transition: background 0.1s;
}
.fgroup-header:hover { background: var(--surface); }
.fgroup-title { font-size: 13px; font-weight: 500; color: var(--text-dim); letter-spacing: 0.02em; }
.fgroup-title .icon { display: inline-block; margin-right: 6px; opacity: 0.85; }
.fgroup-meta { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-faint); }
.fgroup-arrow { font-size: 10px; color: var(--text-mute); transition: transform 0.2s; margin-left: 8px; }
.fgroup.open .fgroup-arrow { transform: rotate(180deg); }
.fgroup-body { padding: 4px 16px 10px; display: none; }
.fgroup.open .fgroup-body { display: block; }

/* Filter item */
.fitem { padding: 7px 0 5px; }
.fitem + .fitem { border-top: 1px dashed var(--border); }
.fitem-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  margin-bottom: 5px;
}
.fitem-name { font-size: 13px; color: var(--text); line-height: 1.3; }
.fitem-code { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-faint); letter-spacing: 0.02em; }

/* Toggle */
.toggle {
  width: 26px; height: 14px;
  border-radius: 99px;
  background: var(--surface-2);
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}
.toggle::after {
  content: '';
  position: absolute;
  width: 10px; height: 10px;
  background: var(--text-mute);
  border-radius: 50%;
  top: 2px; left: 2px;
  transition: all 0.15s;
}
.toggle.on { background: var(--accent-dim); }
.toggle.on::after { left: 14px; background: var(--text); }

/* Range inputs */
.range-row {
  display: flex; align-items: center; gap: 5px;
  margin-top: 2px;
}
.num-input {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 4px 7px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text);
  transition: all 0.1s;
}
.num-input:focus { border-color: var(--accent-dim); background: var(--surface-2); }
.num-input:disabled { opacity: 0.35; cursor: not-allowed; }
.num-input::placeholder { color: var(--text-faint); }
.range-sep { color: var(--text-faint); font-size: 10px; flex-shrink: 0; }

/* Bool radio */
.bool-row { display: flex; gap: 4px; margin-top: 4px; }
.brad {
  flex: 1;
  text-align: center;
  padding: 4px 0;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 10.5px;
  color: var(--text-mute);
  background: var(--surface);
  cursor: pointer;
  user-select: none;
  transition: all 0.12s;
}
.brad:hover { border-color: var(--border-2); color: var(--text-dim); }
.brad.sel-all   { background: var(--surface-2); color: var(--text); border-color: var(--border-2); }
.brad.sel-true  { background: var(--up-bg);     color: var(--up);   border-color: oklch(75% 0.12 25); }
.brad.sel-false { background: var(--down-bg);   color: var(--down); border-color: oklch(78% 0.10 155); }

/* Sidebar footer (buttons) */
.sidebar-footer {
  padding: 12px 16px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-2);
  display: flex; flex-direction: column;
  gap: 7px;
  flex-shrink: 0;
}
.btn-secondary, .btn-primary, .btn {
  height: 34px;
  border-radius: var(--r-md);
  font-size: 12px;
  font-weight: 500;
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  letter-spacing: 0.04em;
  transition: all 0.12s;
  font-family: var(--font-mono);
  cursor: pointer;
  white-space: nowrap;
  padding: 0 14px;
}
.btn {
  background: white;
  color: var(--text-dim);
  border: 1px solid var(--border-2);
}
.btn:hover { background: var(--surface); color: var(--text); }
.btn-secondary {
  background: var(--surface);
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.btn-secondary:hover { color: var(--text); background: var(--surface-2); border-color: var(--border-2); }
.btn-primary {
  background: var(--accent);
  color: white;
  font-weight: 600;
  border: 0;
}
.btn-primary:hover { background: var(--accent-dim); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

/* ═══════════════════════════════════════════════════════════════
   MAIN AREA
   ═══════════════════════════════════════════════════════════════ */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

/* KPI strip */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1px;
  background: var(--border);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.kpi-card {
  padding: 14px 18px;
  background: var(--bg-2);
}
.kpi-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  text-transform: uppercase;
  margin-bottom: 6px;
}
.kpi-value {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  letter-spacing: -0.01em;
}
.kpi-value.accent { color: var(--accent); }
.kpi-value.info   { color: var(--info); }
.kpi-value.up     { color: var(--up); }
.kpi-value.down   { color: var(--down); }
.kpi-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-mute);
  margin-top: 5px;
  letter-spacing: 0.02em;
}

/* Tabs bar */
.tabs-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.ctabs { display: flex; }
.ctab {
  padding: 11px 18px;
  font-size: 13.5px;
  color: var(--text-mute);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  display: flex; align-items: center; gap: 7px;
  margin-bottom: -1px;
  user-select: none;
}
.ctab:hover { color: var(--text-dim); }
.ctab.active { color: var(--text); border-bottom-color: var(--info); font-weight: 500; }
.ctab-badge {
  background: var(--surface-2);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  padding: 1px 7px;
  border-radius: 99px;
}
.ctab.active .ctab-badge { background: var(--info-bg); color: var(--info); }

.tabs-actions { display: flex; gap: 6px; }
.tool-btn {
  height: 28px;
  padding: 0 12px;
  border-radius: var(--r-sm);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 10.5px;
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid transparent;
  transition: all 0.1s;
  letter-spacing: 0.04em;
}
.tool-btn:hover { background: var(--surface); color: var(--text); }
.tool-btn.outlined { border-color: var(--border); background: var(--surface); }
.tool-btn.outlined:hover { border-color: var(--border-2); }

/* Options bar */
.opts-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.opts-label {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-faint);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.opts-select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 11.5px;
  padding: 5px 9px;
  cursor: pointer;
  min-width: 180px;
}
.opts-select:hover { border-color: var(--border-2); }
.realtime-badge {
  display: none;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--warn);
  background: var(--accent-bg);
  padding: 3px 9px;
  border-radius: 99px;
  border: 1px solid var(--border-2);
  letter-spacing: 0.04em;
}
.realtime-badge.show { display: inline-flex; align-items: center; gap: 5px; }
.result-info {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-mute);
  margin-left: auto;
}
.result-info b { color: var(--accent); font-weight: 600; }

/* ═══════════════════════════════════════════════════════════════
   TABLE
   ═══════════════════════════════════════════════════════════════ */
.table-tab { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.table-wrap { flex: 1; overflow: auto; position: relative; }
table.stocks {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.stocks thead { background: var(--bg-2); position: sticky; top: 0; z-index: 5; }
table.stocks thead th {
  text-align: right;
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-mute);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: color 0.1s;
}
table.stocks thead th:hover { color: var(--text-dim); }
table.stocks thead th.left { text-align: left; }
table.stocks thead th.sorted { color: var(--accent); }
table.stocks thead th .arr {
  display: inline-block;
  margin-left: 4px;
  opacity: 0;
}
table.stocks thead th.sorted .arr { opacity: 1; }

table.stocks tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.08s;
}
table.stocks tbody tr:hover { background: var(--surface); }
table.stocks tbody tr.selected {
  background: var(--info-bg);
  outline: 1px solid var(--info);
  outline-offset: -1px;
}
table.stocks tbody td {
  padding: 10px 14px;
  text-align: right;
  color: var(--text-dim);
  white-space: nowrap;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
table.stocks tbody td.left { text-align: left; font-family: var(--font-sans); color: var(--text); }
td.rank { color: var(--text-faint); font-size: 12px; }
td.sid { font-family: var(--font-mono); font-weight: 600; color: var(--info); font-size: 13.5px; }
td.sname { color: var(--text); font-weight: 500; }
td.score { color: var(--accent); font-weight: 600; }
.industry-tag {
  display: inline-block;
  font-size: 10.5px;
  color: var(--text-mute);
  background: var(--surface);
  padding: 2px 7px;
  border-radius: var(--r-sm);
  font-family: var(--font-sans);
  border: 1px solid var(--border);
}
.peak-check { color: var(--accent); }
.muted-dash { color: var(--text-faint); }

/* ═══════════════════════════════════════════════════════════════
   EMPTY / LOADING STATES
   ═══════════════════════════════════════════════════════════════ */
.state-box {
  flex: 1;
  min-height: 240px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px;
  color: var(--text-mute);
}
.state-icon { font-size: 32px; opacity: 0.5; }
.state-text { font-size: 13px; }
.state-hint { font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); letter-spacing: 0.04em; }
.spinner {
  width: 22px; height: 22px;
  border: 2px solid var(--surface-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══════════════════════════════════════════════════════════════
   DISTRIBUTION
   ═══════════════════════════════════════════════════════════════ */
.dist-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px;
  display: none;
  gap: 14px;
  flex-wrap: wrap;
  align-content: flex-start;
}
.dist-wrap.show { display: flex; }
.dist-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 14px 16px 12px;
  width: calc(33.33% - 10px);
  min-width: 240px;
}
.dist-title {
  font-size: 12px;
  color: var(--text);
  font-weight: 500;
  margin-bottom: 4px;
}
.dist-stats {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-mute);
  margin-bottom: 12px;
  letter-spacing: 0.04em;
}
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 70px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1px;
}
.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  height: 100%;
  position: relative;
}
.bar-fill {
  width: 100%;
  background: linear-gradient(to top, var(--info), oklch(55% 0.10 260 / 0.4));
  border-radius: 2px 2px 0 0;
  min-height: 2px;
  transition: height 0.3s;
}
.bar-col:hover .bar-fill { background: linear-gradient(to top, var(--accent), oklch(65% 0.14 240 / 0.5)); }
.bar-cnt {
  position: absolute;
  top: -14px;
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-mute);
}

/* ═══════════════════════════════════════════════════════════════
   CHART PANEL (right slide-in)
   ═══════════════════════════════════════════════════════════════ */
.chart-panel {
  width: 0;
  flex-shrink: 0;
  background: var(--bg-2);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.chart-panel.open { width: 640px; }

.chart-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 12px;
}
.chart-title {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chart-title .stock-num { color: var(--info); margin-right: 8px; }
.chart-close {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: var(--r-sm);
  color: var(--text-mute);
  font-size: 14px;
  transition: all 0.1s;
}
.chart-close:hover { background: var(--surface); color: var(--text); }

.chart-badges {
  display: flex; flex-wrap: wrap; gap: 5px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 40px;
}
.cbadge {
  display: inline-flex;
  padding: 2px 9px;
  border-radius: var(--r-sm);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  background: var(--surface);
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.cbadge.up   { background: var(--up-bg);   color: var(--up);   border-color: oklch(75% 0.12 25); }
.cbadge.down { background: var(--down-bg); color: var(--down); border-color: oklch(78% 0.10 155); }
.cbadge.info { background: var(--info-bg); color: var(--info); border-color: oklch(80% 0.10 260); }
.cbadge.warn { background: var(--accent-bg); color: var(--warn); border-color: oklch(85% 0.10 75); }
.cbadge.peak { background: var(--accent-bg); color: var(--accent); border-color: var(--accent-dim); }

.chart-subtabs { display: flex; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.cstab {
  flex: 1;
  text-align: center;
  padding: 9px;
  font-size: 11.5px;
  color: var(--text-mute);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  user-select: none;
  transition: all 0.1s;
  margin-bottom: -1px;
}
.cstab:hover { color: var(--text-dim); }
.cstab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 500; }

.chart-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px 24px;
  display: flex; flex-direction: column;
  gap: 18px;
}
.chart-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 14px;
}

.sub-chart-title {
  margin: 14px 4px 4px;
  font-size: 11px;
  color: var(--text-mute);
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.price-trend-badge {
  display: inline-flex;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  border: 1px solid var(--border);
}
.price-trend-badge.up {
  color: var(--up);
  background: var(--up-bg);
  border-color: oklch(75% 0.12 25);
}
.price-trend-badge.down {
  color: var(--down);
  background: var(--down-bg);
  border-color: oklch(78% 0.10 155);
}
.price-trend-badge.flat {
  color: var(--text-mute);
  background: var(--surface);
}
.price-trend-note {
  color: var(--text-faint);
  font-size: 10px;
}
.sub-price-chart {
  margin-top: 0;
  border-top: 1px dashed var(--border);
  padding-top: 4px;
}
.price-chart-block {
  margin-top: 14px;
}
.standalone-price-title {
  margin: 0 4px 8px;
}
.standalone-price-chart {
  border-top: 0;
  padding-top: 0;
}
.price-chart-legend {
  margin-top: 8px;
}
.legend-swatch.price-wick {
  width: 3px;
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(var(--up), var(--down));
}
.rev-hit:hover,
.price-hit:hover {
  fill: oklch(0.72 0.12 80 / 0.10);
}
.rev-hit.active,
.price-hit.active {
  fill: oklch(0.72 0.12 80 / 0.18);
  stroke: var(--accent);
  stroke-width: 1;
}
.sub-chart-empty {
  margin: 12px 4px 0;
  padding: 10px 12px;
  border: 1px dashed var(--border);
  border-radius: var(--r-sm);
  color: var(--text-mute);
  font-size: 12px;
  line-height: 1.5;
}
.chart-value-table {
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.month-detail-card {
  margin-top: 12px;
  padding: 12px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: color-mix(in oklab, var(--surface) 75%, black);
}
.month-detail-card.compact {
  margin: 8px 0 10px;
  padding: 10px;
}
.month-detail-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.month-detail-card.compact .month-detail-head {
  padding-bottom: 8px;
}
.month-detail-title {
  font-weight: 700;
  color: var(--text);
  font-size: 13px;
}
.month-detail-sub {
  color: var(--text-faint);
  font-size: 11px;
  margin-top: 3px;
}
.month-detail-price {
  text-align: right;
  font-family: var(--font-mono);
  color: var(--text-dim);
  white-space: nowrap;
}
.month-detail-price span {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  color: var(--text-faint);
}
.month-detail-price.up,
.month-detail-price.up span { color: var(--up); }
.month-detail-price.down,
.month-detail-price.down span { color: var(--down); }
.month-detail-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}
.month-detail-card.compact .month-detail-grid {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
  margin-top: 8px;
}
.month-detail-grid div {
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
}
.month-detail-card.compact .month-detail-grid div {
  padding: 6px;
}
.month-detail-grid span {
  display: block;
  color: var(--text-faint);
  font-size: 10px;
  margin-bottom: 4px;
}
.month-detail-grid b {
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
}
.month-detail-card.compact .month-detail-grid b {
  font-size: 11px;
}
.month-detail-grid b.up { color: var(--up); }
.month-detail-grid b.down { color: var(--down); }
.chart-value-title {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-mute);
  margin-bottom: 8px;
}
.mini-data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  font-family: var(--font-mono);
}
.mini-data-table th,
.mini-data-table td {
  padding: 6px 7px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  white-space: nowrap;
}
.mini-data-table th:first-child,
.mini-data-table td:first-child { text-align: left; }
.mini-data-table th {
  color: var(--text-faint);
  font-weight: 500;
}
.mini-data-table td { color: var(--text-dim); }
.mini-data-table .up { color: var(--up); }
.mini-data-table .down { color: var(--down); }
.chart-block-title {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-mute);
  margin-bottom: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.svg-chart {
  width: 100%;
  display: block;
  border-radius: var(--r-md);
}
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}
.legend-item {
  display: flex; align-items: center; gap: 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-mute);
}
.legend-swatch { width: 14px; height: 3px; border-radius: 2px; }

/* ═══════════════════════════════════════════════════════════════
   COLUMN PICKER MODAL
   ═══════════════════════════════════════════════════════════════ */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: oklch(18% 0.010 240 / 0.45);
  backdrop-filter: blur(4px);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal {
  background: var(--bg-2);
  border: 1px solid var(--border-2);
  border-radius: var(--r-lg);
  width: 600px;
  max-height: 80vh;
  display: flex; flex-direction: column;
  box-shadow: 0 24px 64px -16px oklch(18% 0.01 240 / 0.15);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 14px; font-weight: 600; color: var(--text); }
.modal-sub { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-mute); margin-top: 2px; }
.modal-close {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: var(--r-sm);
  color: var(--text-mute);
  font-size: 16px;
  transition: all 0.1s;
}
.modal-close:hover { background: var(--surface); color: var(--text); }
.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.col-chip {
  padding: 5px 11px;
  border: 1px solid var(--border);
  border-radius: 99px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  cursor: pointer;
  color: var(--text-mute);
  background: var(--surface);
  user-select: none;
  transition: all 0.1s;
}
.col-chip:hover { color: var(--text-dim); border-color: var(--border-2); }
.col-chip.on {
  background: var(--accent-bg);
  border-color: var(--accent-dim);
  color: var(--accent);
}
.modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}
.modal-btn {
  height: 32px;
  padding: 0 16px;
  border-radius: var(--r-md);
  font-size: 12px;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}
.modal-btn:not(.primary) {
  background: var(--surface);
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.modal-btn:not(.primary):hover { color: var(--text); background: var(--surface-2); }
.modal-btn.primary {
  background: var(--accent);
  color: white;
  font-weight: 600;
}
.modal-btn.primary:hover { background: var(--accent-dim); }

/* ═══════════════════════════════════════════════════════════════
   TOAST
   ═══════════════════════════════════════════════════════════════ */
.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--up);
  color: white;
  padding: 12px 18px;
  border-radius: var(--r-md);
  font-family: var(--font-mono);
  font-size: 11.5px;
  z-index: 200;
  display: none;
  box-shadow: 0 12px 32px -8px oklch(54% 0.18 25 / 0.3);
  letter-spacing: 0.02em;
}
.toast.show {
  display: block;
  animation: toast-in 0.25s ease-out, toast-out 0.3s ease-in 3.5s forwards;
}
.toast.success { background: var(--down); box-shadow: 0 12px 32px -8px oklch(50% 0.12 155 / 0.3); }
@keyframes toast-in { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes toast-out { to { transform: translateY(20px); opacity: 0; } }

/* responsive cap */
@media (max-width: 1280px) {
  .dist-card { width: calc(50% - 7px); }
  .chart-panel.open { width: 520px; }
}
@media (max-width: 1024px) {
  .dist-card { width: 100%; }
  .kpi-strip { grid-template-columns: repeat(3, 1fr); }
}

/* ═══════════════════════════════════════════════════════════════
   TICKER MARQUEE (頂部跑馬燈)
   ═══════════════════════════════════════════════════════════════ */
.ticker-bar {
  display: flex;
  align-items: center;
  height: 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 11.5px;
}
.ticker-label {
  padding: 0 14px;
  background: var(--accent-bg);
  color: var(--accent);
  font-size: 10px;
  letter-spacing: 0.14em;
  height: 100%;
  display: flex; align-items: center;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
  text-transform: uppercase;
}
.ticker-viewport {
  flex: 1;
  overflow: hidden;
  position: relative;
  height: 100%;
}
.ticker-track {
  display: flex;
  gap: 28px;
  align-items: center;
  height: 100%;
  white-space: nowrap;
  animation: ticker-scroll 60s linear infinite;
  padding-left: 14px;
}
.ticker-bar:hover .ticker-track { animation-play-state: paused; }
.tk {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  flex-shrink: 0;
}
.tk-id { color: var(--text-mute); font-weight: 500; }
.tk-name { color: var(--text-dim); font-family: var(--font-sans); margin-right: 2px; }
.tk-px { color: var(--text); font-weight: 500; }
.tk-chg { font-size: 10.5px; font-weight: 500; }
.tk-chg.up   { color: var(--up); }
.tk-chg.down { color: var(--down); }
.tk-chg.flat { color: var(--flat); }
@keyframes ticker-scroll {
  from { transform: translateX(0); }
  to   { transform: translateX(-50%); }
}

/* ═══════════════════════════════════════════════════════════════
   WATCHLIST STAR + VIEW
   ═══════════════════════════════════════════════════════════════ */
.row-star {
  display: inline-block;
  width: 18px;
  text-align: center;
  color: var(--text-faint);
  font-size: 14px;
  transition: all 0.12s;
}
.row-star:hover { color: var(--accent); transform: scale(1.2); }
.row-star.on { color: var(--accent); }

.watchlist-tab {
  flex: 1;
  display: none;
  flex-direction: column;
  overflow: hidden;
}
.watchlist-tab.show { display: flex; }

.dual-tab {
  flex: 1;
  display: none;
  flex-direction: column;
  overflow: hidden;
}
.dual-tab.show { display: flex; }

/* ═══════════════════════════════════════════════════════════════
   DB STATUS / UPDATE PANEL
   ═══════════════════════════════════════════════════════════════ */
.db-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 10.5px;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.db-bar .item { display: flex; align-items: baseline; gap: 6px; }
.db-bar .lbl { color: var(--text-faint); letter-spacing: 0.06em; text-transform: uppercase; }
.db-bar .val { color: var(--text-dim); font-weight: 500; }
.db-bar .update-btn {
  margin-left: auto;
  padding: 5px 12px;
  border: 1px solid var(--border-2);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--r-sm);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  transition: all 0.12s;
  display: inline-flex; align-items: center; gap: 6px;
}
.db-bar .update-btn:hover { background: var(--accent-bg); border-color: var(--accent-dim); color: var(--accent); }
.db-bar .update-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.db-bar .update-btn.running { background: var(--accent-bg); border-color: var(--accent-dim); color: var(--accent); }

/* Update dropdown */
.update-menu {
  position: absolute;
  background: var(--bg-2);
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  padding: 6px;
  min-width: 200px;
  box-shadow: 0 12px 32px -8px oklch(18% 0.01 240 / 0.12);
  z-index: 50;
  display: none;
}
.update-menu.show { display: block; }
.update-menu-item {
  padding: 8px 12px;
  border-radius: var(--r-sm);
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  font-family: var(--font-sans);
}
.update-menu-item:hover { background: var(--surface); color: var(--text); }
.update-menu-item .sub { font-family: var(--font-mono); font-size: 10px; color: var(--text-faint); margin-top: 2px; }

/* ═══════════════════════════════════════════════════════════════
   TOPBAR NAV — 頁面導覽列
   ═══════════════════════════════════════════════════════════════ */
.topbar-nav {
  display: flex;
  gap: 0;
  margin-left: 12px;
}
.tnav {
  height: 52px;
  padding: 0 15px;
  display: flex;
  align-items: center;
  font-size: 13px;
  color: var(--text-mute);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  transition: color .15s;
  white-space: nowrap;
}
.tnav:hover { color: var(--text-dim); }
.tnav.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ═══════════════════════════════════════════════════════════════
   2026-06-27 頁籤重構：範圍切換 / 自訂徽章 / 收合 / 自選靠右
   ═══════════════════════════════════════════════════════════════ */

/* 自訂中徽章（偏離預設條件時顯示） */
.custom-badge {
  display: none;
  margin-left: 8px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  background: var(--accent-bg, rgba(245,158,11,.16));
  color: var(--accent, #f59e0b);
}
.custom-badge.show { display: inline-block; }

/* 範圍切換：策略入選 / 全市場 */
.scope-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px 4px;
}
.scope-label {
  font-size: 10.5px;
  color: var(--text-faint);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.scope-toggle {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 2px;
  gap: 2px;
}
.scope-btn {
  padding: 3px 10px;
  border: none;
  background: transparent;
  color: var(--text-mute);
  font-size: 11px;
  font-family: var(--font-mono);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.12s;
}
.scope-btn:hover { color: var(--text-dim); }
.scope-btn.active { background: var(--info-bg); color: var(--info); font-weight: 500; }

/* 左欄收合 */
.sidebar { transition: width 0.18s ease, opacity 0.18s ease; }
.layout.sidebar-collapsed .sidebar {
  width: 0;
  opacity: 0;
  border-right: none;
  pointer-events: none;
}

/* 自選股頁籤靠右 */
.ctabs { flex: 1; }
.ctab-watch { margin-left: auto; }

/* 作者模式：範圍切換、執行/重設 預設隱藏，解鎖後才出現 */
.scope-row, .sidebar-footer { display: none; }
.layout.author-mode .scope-row { display: flex; }
.layout.author-mode .sidebar-footer { display: flex; }

/* 左欄上鎖畫面 */
.lock-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  padding: 40px 22px;
}
.lock-icon { font-size: 30px; opacity: 0.7; }
.lock-title { font-size: 14px; font-weight: 600; color: var(--text); }
.lock-sub { font-size: 11.5px; color: var(--text-mute); line-height: 1.6; }
.lock-input {
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: 13px;
  text-align: center;
  outline: none;
}
.lock-input:focus { border-color: var(--accent); }
.lock-btn {
  width: 100%;
  padding: 8px 10px;
  background: var(--accent-bg, rgba(245,158,11,.16));
  color: var(--accent, #f59e0b);
  border: 1px solid var(--accent-dim, rgba(245,158,11,.4));
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s;
}
.lock-btn:hover { background: var(--accent, #f59e0b); color: #fff; }

/* #3 選股洞察：頁首說明、文字解讀、正負配色（此處綠=正向/紅=負向，是好壞語意，非股價漲跌） */
.dist-head {
  width: 100%;
  font-size: 12px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  letter-spacing: 0.03em;
  padding: 2px 2px 0;
}
.dist-insight {
  margin-top: 10px;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--text-dim);
  background: var(--surface);
  border-radius: var(--r-sm);
  padding: 7px 9px;
}
.bar-fill.pos { background: linear-gradient(to top, oklch(54% 0.16 155), oklch(72% 0.13 155 / 0.4)); }
.bar-fill.neg { background: linear-gradient(to top, oklch(54% 0.18 25),  oklch(70% 0.16 25 / 0.4)); }
.bar-col:hover .bar-fill.pos { background: linear-gradient(to top, oklch(54% 0.16 155), oklch(72% 0.13 155 / 0.65)); }
.bar-col:hover .bar-fill.neg { background: linear-gradient(to top, oklch(54% 0.18 25),  oklch(70% 0.16 25 / 0.65)); }

/* ═══════════════════════════════════════════════════════════════
   2026-06-28 手機版：清單卡片 + 抽屜 + 全頁捲動
   ═══════════════════════════════════════════════════════════════ */

/* K 線圖控制列 */
.kline-ctrl {
  display: flex; align-items: center; gap: 4px;
  padding: 10px 14px 2px;
  flex-wrap: wrap;
}
.kline-sep { color: var(--border-2); font-size: 11px; }
.kbtn {
  padding: 3px 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-mute);
  font-size: 11.5px; font-family: var(--font-mono);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: all 0.12s;
}
.kbtn:hover { color: var(--text-dim); background: var(--surface); }
.kbtn.active { background: var(--info-bg); color: var(--info); border-color: var(--border-2); font-weight: 500; }
/* 雙策略表：分數後的策略內排名 (1) */
.rank-in-strat {
  margin-left: 4px;
  font-size: 10px;
  color: var(--text-faint);
  font-weight: 400;
}

/* K線圖：水平拖曳看十字線、垂直手勢仍可捲動頁面 */
.kline-svg { touch-action: pan-y; }

/* 均線開關列 */
.kline-mas { padding-top: 2px; }
.kbtn-ma { display: inline-flex; align-items: center; gap: 5px; }
.kbtn-ma.on { font-weight: 600; }
.ma-dot { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }

/* 該股資訊列（開高低收/漲跌%/量） */
.kline-info {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-mute);
  padding: 2px 14px 6px;
  display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline;
}
.kline-info b { font-weight: 600; color: var(--text); }
.kline-info b.up { color: var(--up); }
.kline-info b.down { color: var(--down); }
.kline-info .ki-d { color: var(--text-faint); }

/* 全螢幕 K 線檢視 */
.kline-zoom {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  z-index: 500;
  display: flex; align-items: center; justify-content: center;
  padding: 12px;
}
.kline-zoom-box {
  width: min(1000px, 100%);
  max-height: 96vh;
  background: var(--bg-2);
  border: 1px solid var(--border-2);
  border-radius: var(--r-lg);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.kline-zoom-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.kline-zoom-title { font-family: var(--font-mono); font-size: 13px; color: var(--text); }
.kline-zoom-body { flex: 1; overflow: auto; padding: 4px 6px 10px; }
.kline-zoom-body .svg-chart { width: 100%; height: auto; }
@media (max-width: 768px) {
  .kline-zoom { padding: 0; }
  .kline-zoom-box { width: 100%; height: 100%; max-height: none; border-radius: 0; border: none; }
}

/* 手機股票卡片（桌機隱藏，由 renderTable 同步產生） */
.stock-cards { display: none; }
.stock-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 12px 14px;
  cursor: pointer;
}
.stock-card:active { background: var(--surface); }
.sc-top { display: flex; align-items: center; gap: 8px; }
.sc-rank { font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); min-width: 18px; }
.sc-id { font-family: var(--font-mono); font-weight: 600; font-size: 15px; color: var(--accent); }
.sc-name { font-size: 14px; color: var(--text); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sc-score { font-family: var(--font-mono); font-weight: 600; font-size: 14px; color: var(--info); }
.sc-metrics { display: flex; flex-wrap: wrap; gap: 9px 18px; margin-top: 11px; align-items: center; }
.sc-m { display: flex; flex-direction: column; gap: 1px; }
.sc-k { font-size: 10px; color: var(--text-faint); letter-spacing: 0.04em; }
.sc-m > span:last-child { font-family: var(--font-mono); font-size: 13px; color: var(--text); }
.sc-metrics .up { color: var(--up); }
.sc-metrics .down { color: var(--down); }
.stock-card .row-star { font-size: 16px; }

/* 抽屜遮罩（桌機永遠隱藏） */
.drawer-backdrop { display: none; }

@media (max-width: 768px) {
  /* 1) 解鎖整頁捲動：改為自然文件流 */
  html, body { height: auto; overflow: auto; -webkit-overflow-scrolling: touch; }
  .app { height: auto; min-height: 100vh; }
  .layout { flex-direction: column; overflow: visible; }
  .main { overflow: visible; }
  .table-tab { overflow: visible; display: block; }
  .table-wrap { overflow: visible; }
  .dist-wrap, .watchlist-tab.show, .dual-tab.show { overflow: visible; }

  /* 2) 左欄變側邊抽屜，預設收起 */
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 84vw; max-width: 320px;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 300;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25);
  }
  .layout.drawer-open .sidebar { transform: none; }
  .drawer-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 290;
  }
  .layout.drawer-open .drawer-backdrop { display: block; }
  /* 抽屜不受桌機收合規則影響 */
  .layout.sidebar-collapsed .sidebar { width: 84vw; }

  /* 3) 清單改卡片，置中全寬 */
  #mainTable { display: none !important; }
  #mainCards { display: flex; flex-direction: column; gap: 10px; padding: 12px; }

  /* 4) 個股圖表改全螢幕抽屜（從右滑入） */
  .chart-panel {
    position: fixed; top: 0; right: 0; bottom: 0;
    width: 0; border-left: none; z-index: 320;
  }
  .chart-panel.open { width: 100%; max-width: 100%; }

  /* 5) 頂部 / KPI / 頁籤 收斂 */
  .topbar { height: auto; flex-wrap: wrap; padding: 8px 12px; gap: 8px 10px; }
  .topbar-meta { display: none; }
  .topbar-nav { margin-left: 0; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .kpi-strip { grid-template-columns: repeat(2, 1fr); }
  .tabs-bar { flex-wrap: wrap; padding: 0 12px; }
  .ctabs { flex: 1 1 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .ctab { white-space: nowrap; flex-shrink: 0; padding: 0 11px; }
  .ctab-watch { margin-left: 0; }
  .tabs-actions { flex: 1 1 100%; padding: 6px 0; }
  .opts-bar { flex-wrap: wrap; padding: 9px 12px; }
}
