:root {
  --bg: #0e1117;
  --panel: #1a1d24;
  --panel-2: #262730;
  --border: rgba(255, 255, 255, 0.10);
  --text: #e6e6e6;
  --muted: #8b909a;
  --accent: #ff4b4b;
  --up: #d62728;   /* 台股慣例：紅漲 */
  --down: #2ca02c; /* 綠跌 */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  font-size: 14px;
}

#app { display: flex; min-height: 100vh; }

/* ---- 側邊欄 ---- */
#sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 1rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
#sidebar h1 { font-size: 1.15rem; margin: 0 0 0.3rem; }

.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field > label { font-size: 0.8rem; color: var(--muted); }

select, input[list] {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
  font-size: 0.9rem;
  width: 100%;
}

/* 分段按鈕（功能/區間）*/
.seg { display: flex; gap: 0.3rem; }
.seg.wrap { flex-wrap: wrap; }
.seg-btn {
  flex: 1;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.5rem;
  font-size: 0.82rem;
  cursor: pointer;
  white-space: nowrap;
}
.seg.wrap .seg-btn { flex: 0 0 auto; min-width: 3.4rem; }
.seg-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

.footer { margin-top: auto; padding-top: 0.6rem; border-top: 1px solid var(--border); }
.muted { color: var(--muted); font-size: 0.8rem; }
.hidden { display: none !important; }

/* ---- 主內容 ---- */
#main { flex: 1; padding: 1.6rem 2rem; max-width: 1180px; overflow-x: hidden; }
#main h2 { font-size: 1.85rem; margin: 0 0 0.2rem; }
#main h3 { font-size: 1.1rem; margin: 1.2rem 0 0.5rem; }
.subcaption { color: var(--muted); font-size: 0.85rem; margin-bottom: 0.6rem; }

/* 分頁 */
.tabs { display: flex; gap: 0.2rem; border-bottom: 1px solid var(--border); margin: 0.8rem 0 1rem; }
.tab {
  background: none; border: none; color: var(--muted);
  padding: 0.5rem 0.9rem; cursor: pointer; font-size: 0.92rem;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* 基本面數字卡 */
.metric-row { display: flex; flex-wrap: wrap; gap: 1.8rem; margin: 1rem 0; }
.metric { display: flex; flex-direction: column; }
.metric .label { font-size: 0.8rem; color: var(--muted); }
.metric .value { font-size: 1.5rem; font-weight: 600; }

/* 指標勾選 */
.checks { display: flex; gap: 1rem; margin-bottom: 0.5rem; flex-wrap: wrap; }
.checks label { font-size: 0.88rem; cursor: pointer; }

/* 表格 */
table { border-collapse: collapse; width: 100%; font-size: 0.88rem; }
th, td { border: 1px solid var(--border); padding: 0.45rem 0.6rem; text-align: right; }
th { background: var(--panel-2); position: sticky; top: 0; }
td:first-child, th:first-child { text-align: left; }
.pos { color: var(--up); }
.neg { color: var(--down); }

/* 股票籌碼按鈕（群組比較挑股）*/
.chip-group { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; margin-bottom: 0.5rem; }
.chip-label { font-size: 0.8rem; color: var(--muted); margin-right: 0.3rem; min-width: 4.5rem; }
.chip {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 20px;
  padding: 0.3rem 0.8rem; font-size: 0.85rem; cursor: pointer;
}
.chip:hover { border-color: var(--muted); }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.chip.sec { border-radius: 8px; }

.chart { width: 100%; }
/* 每個 K 線子圖獨立一塊：有自己的框、間距 */
.kblock {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
  padding: 0.3rem 0.4rem;
  margin-bottom: 1.1rem;
}
.explain { font-size: 0.9rem; line-height: 1.6; }
.explain h4 { margin: 1rem 0 0.3rem; font-size: 1rem; color: var(--text); }
.explain p { margin: 0.2rem 0; }
.info-box { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 0.8rem 1rem; color: var(--muted); }
details { margin-top: 1rem; }
details summary { cursor: pointer; color: var(--muted); }
