/* 臨時介面的樣式。刻意不引任何外部資源(字型/CDN),整包可離線跑。 */

:root {
  --bg: #12141a;
  --card: #1b1e26;
  --line: #2c313d;
  --text: #e6e8ee;
  --muted: #949cb0;
  --accent: #4c8dff;
  --ok: #3fb950;
  --err: #f85149;
  /* 漲紅跌綠(台股慣例),沿用第一代 PNNumber 的色碼 */
  --up: #ff4d4d;
  --down: #35c759;
}

* { box-sizing: border-box; }

/* hidden 屬性只帶 display:none,任何 display 宣告(.pane 的 flex 等)都會蓋掉它。
   下面很多區塊都要 flex,所以在這裡一次補強,不然「隱藏」會失效。 */
[hidden] { display: none !important; }

body {
  margin: 0;
  padding: 0 1rem 3rem;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 system-ui, "Segoe UI", "Microsoft JhengHei", sans-serif;
}

main { max-width: 1180px; margin: 0 auto; display: flex; flex-direction: column; gap: 1rem; }

/* --- 頂欄 --- */

.topbar {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.5rem 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.topbar h1 { margin: 0; font-size: 1.15rem; font-weight: 600; }
.topbar small { color: var(--muted); font-size: .75rem; font-weight: 400; margin-left: .35rem; }

.who { display: flex; align-items: center; gap: .75rem; font-size: .85rem; color: var(--muted); }

/* --- 卡片 --- */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.25rem;
}

/* 登入 / 選策略這種窄內容,不要被撐到跟表格一樣寬 */
.card.narrow { max-width: 460px; width: 100%; margin: 0 auto; }

.card h2 { margin: 0; font-size: 1rem; font-weight: 600; }
.card.narrow h2 { margin-bottom: 1rem; }

.section-head {
  display: flex;
  align-items: baseline;
  gap: .75rem;
  margin-bottom: 1rem;
}

.section-head h2 { font-family: ui-monospace, Consolas, monospace; }
.section-head .hint { margin: 0; }

/* --- 分頁 --- */

.tabs { display: flex; gap: .5rem; margin-bottom: 1.25rem; }

.scroll-tabs { overflow-x: auto; padding-bottom: .25rem; }

.tab {
  flex: 1;
  white-space: nowrap;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  padding: .5rem .75rem;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  font-size: .85rem;
}

.tab.active { border-color: var(--accent); color: var(--text); }

/* 策略子頁導覽是連結不是按鈕,而且不要撐滿整列 */
#strategy-nav .tab {
  flex: 0 0 auto;
  text-decoration: none;
  display: inline-block;
}

/* --- 表單 --- */

.pane { display: flex; flex-direction: column; gap: .85rem; }

label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; color: var(--muted); }
label.inline { flex-direction: row; align-items: center; gap: .5rem; }

input, select {
  background: #101217;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  padding: .55rem .7rem;
  font: inherit;
}

select { padding: .3rem .4rem; font-size: .85rem; }

input:focus, select:focus { outline: none; border-color: var(--accent); }

button {
  background: var(--accent);
  border: none;
  border-radius: 6px;
  color: #fff;
  padding: .6rem;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}

button:disabled { opacity: .4; cursor: default; }

button.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  padding: .3rem .7rem;
  font-size: .8rem;
}

/* --- 策略清單 --- */

.strategies { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }

.strategies a {
  display: block;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  padding: .7rem .85rem;
  font-family: ui-monospace, Consolas, monospace;
}

.strategies a:hover { border-color: var(--accent); background: rgba(76, 141, 255, .08); }

.back { color: var(--muted); text-decoration: none; font-size: .85rem; white-space: nowrap; }
.back:hover { color: var(--accent); }

/* --- 績效圖(配色沿用 underdoggy_quanto 的 viz/static)--- */

.summary {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  padding: .75rem .9rem;
  margin-bottom: 1rem;
  background: #131a24;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: .85rem;
  color: var(--muted);
}

.summary b { color: var(--text); }

.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: .5rem;
}

.chart-title { font-size: .9rem; font-weight: 600; }

/* --- 績效指標數字磚 --- */

.block-title { margin: 0 0 .7rem; font-size: .9rem; font-weight: 600; }

#metrics-panel, #annual-panel { margin-bottom: 1.5rem; }
#annual-panel { margin: 1.5rem 0 0; }

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: .5rem;
}

.tile {
  display: flex;
  flex-direction: column;
  gap: .2rem;
  padding: .6rem .75rem;
  background: #131a24;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.tile-label { font-size: .75rem; color: var(--muted); }

/* 數字本身用文字色,只有正負值才吃漲紅跌綠(.up/.down 由 pn() 加上) */
.tile-value {
  font-size: 1.05rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* 年度表的「策略 / 大盤」分組表頭 */
th.group {
  border-bottom: 1px solid var(--accent);
  color: var(--text);
  text-align: center;
}

/* 兩列表頭都 sticky 會疊在一起;年度表只有幾列,本來就不需要 sticky */
#annual-panel th { position: static; }
#annual-panel td { font-variant-numeric: tabular-nums; }

/* 隨縮放更新的區間報酬,吃掉中間的空間把右側控制項推到最右 */
.range-return { flex: 1; font-size: .8rem; color: var(--muted); }

.range-buttons { display: flex; gap: .4rem; }

/* 選中的槓桿分頁 */
button.ghost.on { border-color: var(--accent); color: var(--text); }

/* --- 次日操作(live.json)--- */

.kv { display: flex; flex-direction: column; gap: 1.25rem; }

.kv section h3 { margin: 0 0 .6rem; font-size: .9rem; font-weight: 600; }

.kv dl {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: .5rem .75rem;
}

.kv dl > div {
  display: flex;
  justify-content: space-between;
  gap: .75rem;
  padding: .5rem .7rem;
  background: #131a24;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: .82rem;
}

.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: ui-monospace, Consolas, monospace; }
.kv .muted { color: var(--muted); }
.chart-head label { font-size: .8rem; }
.chart-head input[type="checkbox"] { accent-color: var(--accent); }

.chart {
  width: 100%;
  height: 58vh;
  min-height: 340px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

/* 下面那張標的日 K 是配角,矮一點,兩張加起來才塞得進一個畫面 */
.chart.short { height: 32vh; min-height: 210px; }

#price-panel { margin-top: 1rem; }

/* --- 兩張圖並存(txma1)--- */
/* 只有這時候才壓扁淨值圖:doggy3 只有一張,維持 58vh 才看得清楚。
   高度變了要靠 ResizeObserver 通知 lightweight-charts 重算 canvas(見 ensureChart)。 */
#report.stacked #chart { height: 38vh; min-height: 250px; }

/* 兩張圖共用下面那條 legend(K 線那條連進出場明細一起顯示),
   上面這條就整塊收掉 —— 不然中間卡一行文字,兩張圖被推得很遠。 */
#report.stacked #chart-legend { display: none; }

/* --- 次日操作:極簡版 ---
   整頁只回答「明天要怎麼做」,所以只有一句結論 + 兩張數字卡。 */
.verdict {
  margin: 0 0 1.2rem;
  font-size: 1.05rem;
  line-height: 1.7;
}

.ranges {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: .8rem;
  max-width: 720px;
}

.range-card {
  padding: 1rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #171b24;
}

/* 到不了的條件整張卡壓暗,數字不要跟可用的條件搶注意力 */
.range-card.empty { opacity: .55; }

.range-label { color: var(--muted); font-size: .8rem; }

.range-need {
  margin: .3rem 0 .5rem;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 1.7rem;
  font-weight: 600;
}

.range-hit { font-size: .82rem; color: var(--muted); }
.range-hit b { color: var(--text); }

/* 持倉時的「明日收盤落在哪一段 → 做什麼」。所有賣出規則都只看收盤,
   所以攤成同一條軸上的幾段,比一條一條列規則好讀。 */
.segments {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .25rem 1.2rem;
  align-items: baseline;
  max-width: 680px;
  margin-bottom: .9rem;
}

.seg-head { color: var(--muted); font-size: .78rem; padding-bottom: .3rem; }

/* 買 / 賣 交界處的分隔線。跨兩欄才會是一條連續的線(欄間距不會斷開) */
.seg-sep {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line);
  margin: .45rem 0 .2rem;
}

.seg-range {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 1.05rem;
  white-space: nowrap;
}

.seg-act { font-size: .9rem; }
.seg-empty { color: var(--muted); font-size: .9rem; margin-bottom: .9rem; }

.legend {
  margin-top: .6rem;
  min-height: 3.2rem;
  font-size: .8rem;
  color: var(--muted);
}

.legend > span { margin-right: 1.1rem; }
.legend b { color: var(--text); }

.legend-trades {
  margin-top: .4rem;
  padding-top: .4rem;
  border-top: 1px solid var(--line);
  line-height: 1.7;
}

/* 圖上的買賣箭頭顏色,與 lightweight-charts 的 marker 對齊 */
.mk-buy { color: #eab308; font-weight: 600; }
.mk-sell { color: #38bdf8; font-weight: 600; }
/* 加權指數對照線(左軸),與 CHART_COLORS.bench 對齊 */
.mk-bench { color: #94a3b8; font-weight: 600; }

/* --- 狗池表格 --- */

/* 表格比視窗寬時自己橫向捲動,不讓整個頁面跟著捲 */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }

/* 上百列的表格(txma1 的進出紀錄)擺在績效頁裡要限高自己捲;th 本來就是 sticky */
.table-wrap.tall { max-height: 26rem; overflow-y: auto; }

table { width: 100%; border-collapse: collapse; font-size: .85rem; }

th, td {
  text-align: left;
  padding: .6rem .7rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: #232733;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(255, 255, 255, .02); }

td.right, th.right { text-align: right; }
td { white-space: nowrap; }

.code { font-family: ui-monospace, Consolas, monospace; font-size: .95rem; }

/* 上市 / 上櫃 / 興櫃 這種短標籤 */
.tag {
  display: inline-block;
  margin-top: .15rem;
  padding: .05rem .35rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  font-size: .72rem;
}
td.sub { color: var(--muted); font-size: .78rem; line-height: 1.5; white-space: nowrap; }
td.empty { text-align: center; color: var(--muted); padding: 2rem; }

/* 表格與圖表 legend 裡的超連結(股票代號、公司網址等):瀏覽器預設的深藍
   在深色底上太刺眼,改用主題色、平常不畫底線,hover 才出現 */
td a, .legend a { color: var(--accent); text-decoration: none; }
td a:hover, .legend a:hover { text-decoration: underline; }

td hr { border: none; border-top: 1px solid var(--line); margin: .4rem 0; }

.up { color: var(--up); font-weight: 600; }
.down { color: var(--down); font-weight: 600; }

/* --- 個股頁 --- */

/* 首頁「工具」小標,跟上面的策略清單隔開 */
.tools-title { margin-top: 1.5rem !important; margin-bottom: 1rem !important; }

.stock-form { display: flex; align-items: flex-end; gap: .6rem; margin-bottom: 1.25rem; }
.stock-form input { width: 12rem; }
.stock-form button { padding: .55rem 1.2rem; }

#stock-body > section { margin-top: 1.75rem; }
#stock-body > section:first-child { margin-top: 0; }

/* 外部網站連結(GoodInfo / 玩股網 / 股市同學會 / 財報狗) */
.ext-links { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-top: .8rem; }

.ext-label { color: var(--muted); font-size: .8rem; }

.ext-links a {
  display: inline-block;
  padding: .3rem .75rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--accent);
  text-decoration: none;
  font-size: .8rem;
}

.ext-links a:hover { border-color: var(--accent); background: rgba(76, 141, 255, .08); }

/* 日 K 的控制列東西多(起迄日 + 按鈕),窄螢幕允許換行 */
.chart-head.wrap { flex-wrap: wrap; justify-content: flex-start; }

input[type="date"] { padding: .3rem .5rem; font-size: .85rem; color-scheme: dark; }

/* 均線圖例兼開關:色塊是線的顏色,關掉整顆壓暗 */
.ma-toggles { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; }

.ma-chip {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  padding: .25rem .6rem;
  font: inherit;
  font-size: .78rem;
  cursor: pointer;
  opacity: .45;
}

.ma-chip.on { opacity: 1; color: var(--text); }
.ma-chip .dot { width: .8rem; height: 3px; border-radius: 2px; display: inline-block; }

/* --- 換頁 --- */

.pager {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-top: .85rem;
  font-size: .8rem;
  color: var(--muted);
}

.pager #pool-range { margin-left: auto; }

/* --- 訊息 --- */

.hint { color: var(--muted); font-size: .8rem; margin: .75rem 0 0; }
.hint code { font-family: ui-monospace, Consolas, monospace; }

.msg {
  padding: .7rem .85rem;
  border-radius: 6px;
  border: 1px solid var(--line);
  font-size: .85rem;
}

.msg.ok { border-color: var(--ok); color: var(--ok); }
.msg.err { border-color: var(--err); color: var(--err); }
