/* 動態選股網頁 — 深色 GitHub 風、純靜態、手機/桌面共用 */
:root {
  --bg: #0d1117; --bg2: #161b22; --bg3: #21262d;
  --border: #30363d; --border2: #3d444d;
  --fg: #e6edf3; --fg2: #9198a1; --fg3: #6e7681;
  --accent: #2f81f7; --accent2: #1f6feb;
  --green: #3fb950; --red: #f85149; --amber: #d29922;
  --radius: 8px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--fg);
  font-family: -apple-system, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
  font-size: 14px; line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }

/* ── 頂欄 ── */
header {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--bg2);
  border-bottom: 1px solid var(--border);
}
header h1 { font-size: 16px; margin: 0; font-weight: 600; white-space: nowrap; }
header h1 .sub { color: var(--fg2); font-weight: 400; font-size: 12px; margin-left: 6px; }
.spacer { flex: 1; }
header .meta { color: var(--fg2); font-size: 12px; white-space: nowrap; }

select, input, button {
  background: var(--bg3); color: var(--fg);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 9px; font-size: 13px; font-family: inherit;
}
input::placeholder { color: var(--fg3); }
button { cursor: pointer; }
button:hover { border-color: var(--border2); background: #262c36; }
label.chk { display: inline-flex; align-items: center; gap: 5px; color: var(--fg2); font-size: 12px; cursor: pointer; }

/* ── 主體 ── */
main { display: flex; align-items: flex-start; gap: 0; }
#panel {
  width: 320px; flex-shrink: 0; padding: 12px;
  border-right: 1px solid var(--border);
  height: calc(100vh - 53px); overflow-y: auto;
  position: sticky; top: 53px;
}
#results { flex: 1; min-width: 0; padding: 12px 16px; }

/* ── 策略列 ── */
.section-title { font-size: 12px; color: var(--fg2); text-transform: uppercase; letter-spacing: .5px; margin: 4px 0 8px; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.preset-chip {
  padding: 5px 10px; border-radius: 14px; background: var(--bg3);
  border: 1px solid var(--border); font-size: 12px; cursor: pointer; white-space: nowrap;
}
.preset-chip:hover { border-color: var(--accent); }
.preset-chip.active { background: var(--accent2); border-color: var(--accent); color: #fff; }
.preset-chip.util { background: transparent; color: var(--fg2); }

/* ── 維度列 ── */
.dim {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 10px; margin-bottom: 7px; background: var(--bg2);
}
.dim.off { opacity: .5; }
.dim-head { display: flex; align-items: center; gap: 7px; }
.dim-head .name { font-weight: 600; font-size: 13px; }
.dim-head .grp { font-size: 10px; padding: 1px 5px; border-radius: 4px; background: var(--bg3); color: var(--fg2); }
.dim-head .cov { font-size: 10px; color: var(--fg3); margin-left: auto; }
.dim-desc { font-size: 11px; color: var(--fg3); margin: 3px 0 6px; }
.dim-controls { display: grid; grid-template-columns: auto 1fr auto; gap: 6px 8px; align-items: center; font-size: 11px; color: var(--fg2); }
.dim-controls input[type=range] { width: 100%; accent-color: var(--accent); }
.dim-controls .val { font-family: var(--mono); color: var(--fg); min-width: 30px; text-align: right; }
.grp-price   { border-left: 3px solid #58a6ff; }
.grp-chip    { border-left: 3px solid #d2a8ff; }
.grp-fundamental { border-left: 3px solid #3fb950; }
.grp-risk    { border-left: 3px solid #d29922; }

/* ── 結果表 ── */
.results-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; flex-wrap: wrap; }
.results-head .count { font-size: 13px; color: var(--fg2); }
.results-head .count b { color: var(--fg); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  position: sticky; top: 53px; background: var(--bg); z-index: 10;
  text-align: right; padding: 7px 8px; color: var(--fg2); font-weight: 600;
  border-bottom: 1px solid var(--border); white-space: nowrap; cursor: pointer; user-select: none;
}
thead th.left { text-align: left; }
thead th:hover { color: var(--fg); }
thead th.sorted { color: var(--accent); }
tbody td { padding: 6px 8px; text-align: right; border-bottom: 1px solid #1c2128; white-space: nowrap; }
tbody td.left { text-align: left; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--bg2); }
.code { font-family: var(--mono); color: var(--accent); }
.nm { color: var(--fg); }
.ind { color: var(--fg3); font-size: 11px; }
.pos { color: var(--green); } .neg { color: var(--red); } .flat { color: var(--fg2); }
.forbidden-tag { font-size: 10px; color: var(--red); border: 1px solid var(--red); border-radius: 4px; padding: 0 4px; margin-left: 5px; }

/* 組合分數燈條 */
.scorebar { display: inline-flex; align-items: center; gap: 6px; }
.scorebar .bar { width: 54px; height: 7px; border-radius: 4px; background: var(--bg3); overflow: hidden; }
.scorebar .fill { height: 100%; border-radius: 4px; }
.scorebar .num { font-family: var(--mono); font-weight: 600; min-width: 34px; text-align: right; }
.mini { font-family: var(--mono); font-size: 12px; }
.delta { font-family: var(--mono); font-size: 11px; }

/* ── 詳情卡（右側抽屜）── */
#drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: min(680px, 100vw);
  background: var(--bg2); border-left: 1px solid var(--border);
  transform: translateX(100%); transition: transform .18s ease;
  z-index: 50; overflow-y: auto; box-shadow: -12px 0 40px rgba(0,0,0,.4);
}
#drawer.open { transform: translateX(0); }
.drawer-head { position: sticky; top: 0; background: var(--bg2); padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; z-index: 5; }
.drawer-head .t { font-size: 18px; font-weight: 700; }
.drawer-head .close { margin-left: auto; font-size: 20px; line-height: 1; padding: 2px 10px; }
.drawer-body { padding: 14px 16px 40px; }
.chart { width: 100%; height: 220px; margin-bottom: 6px; }
.chart-title { font-size: 12px; color: var(--fg2); margin: 10px 0 2px; }
.ev-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 16px; margin-top: 8px; }
.ev-row { display: flex; justify-content: space-between; border-bottom: 1px dashed #21262d; padding: 3px 0; font-size: 12px; }
.ev-row .k { color: var(--fg2); } .ev-row .v { font-family: var(--mono); }

/* 各維度分數 × 真實數值 */
.dimbk { border: 1px solid var(--border); border-left-width: 3px; border-radius: 6px; padding: 7px 10px; margin-bottom: 6px; background: var(--bg); }
.dimbk-head { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.dimbk-head .nm { font-weight: 600; font-size: 13px; }
.dimbk-head .dim-w { font-size: 10px; color: var(--fg3); border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; }
.dimbk-head .dim-score { font-family: var(--mono); font-weight: 700; font-size: 15px; margin-left: auto; }
.dimbk-evs { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.ev-item { display: inline-flex; gap: 5px; font-size: 12px; white-space: nowrap; }
.ev-item .k { color: var(--fg2); } .ev-item .v { font-family: var(--mono); color: var(--fg); }
.dimbk-evs .none { color: var(--fg3); font-size: 11px; }
#backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 40; display: none; }
#backdrop.open { display: block; }

.empty { color: var(--fg3); padding: 40px; text-align: center; }
.loading { color: var(--fg2); padding: 20px; text-align: center; }

/* ── 手機 ── */
.panel-toggle { display: none; }
@media (max-width: 860px) {
  main { flex-direction: column; }
  #panel {
    position: fixed; left: 0; top: 0; height: 100vh; width: min(340px, 90vw);
    z-index: 45; transform: translateX(-100%); transition: transform .18s ease;
    background: var(--bg2); border-right: 1px solid var(--border);
  }
  #panel.open { transform: translateX(0); box-shadow: 12px 0 40px rgba(0,0,0,.4); }
  #results { padding: 10px; width: 100%; }
  .panel-toggle { display: inline-flex; }
  thead th, tbody td { padding: 6px 5px; }
  .hide-sm { display: none; }
  header h1 .sub { display: none; }
}
