/* TW Stock Dashboard — 台股慣例：漲紅、跌綠 */
:root {
  --bg: #0d1117; --panel: #161b22; --panel2: #1c2330; --line: #2a3340;
  --text: #e6edf3; --muted: #9aa7b6;
  --up: #ff5c5c; --down: #2ecc71; --warn: #f0b429; --danger: #ff8a3d; --info: #58a6ff;
  --radius: 10px; --ma5: #f0b429; --ma20: #58a6ff; --ma60: #c678dd;
}
* { box-sizing: border-box; }
html, body { margin: 0; word-break: keep-all; line-break: strict; overflow-wrap: anywhere; background: var(--bg); color: var(--text); font-variant-numeric: tabular-nums;
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif; }
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.r { text-align: right; }
.up { color: var(--up); }
.down { color: var(--down); }

/* ---------- 頂欄 ---------- */
.topbar { background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar-in { max-width: 1280px; margin: 0 auto; display: flex; align-items: center; gap: 18px; padding: 10px 20px; }
.brand { color: var(--text); font-weight: 700; white-space: nowrap; }
.tabs { display: flex; gap: 4px; flex: 1; min-width: 0; overflow-x: auto; }
.tabs a { color: var(--muted); padding: 6px 12px; border-radius: 8px; white-space: nowrap; }
.tabs a.on { color: var(--text); background: var(--panel2); }
.tabs a:hover { text-decoration: none; color: var(--text); }
.logout button { background: none; border: 1px solid var(--line); color: var(--muted);
  padding: 5px 12px; border-radius: 8px; cursor: pointer; font: inherit; font-size: 13px; }

.page { max-width: 1280px; margin: 0 auto; padding: 18px 20px 30px; }
.foot { max-width: 1280px; margin: 0 auto; padding: 0 20px 30px; color: var(--muted); font-size: 12px; }
.pagehead { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.pagehead h1 { margin: 0; font-size: 22px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 16px; min-width: 0; }
.card h2 { margin: 0 0 12px; font-size: 16px; }
.count { display: inline-block; min-width: 22px; padding: 0 7px; border-radius: 11px;
  background: var(--panel2); color: var(--muted); font-size: 12.5px; text-align: center; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.grid2 > .card { margin-bottom: 0; }
.empty { color: var(--muted); margin: 6px 0; }

/* ---------- 大盤 ---------- */
.market { display: grid; grid-template-columns: auto 1fr; gap: 6px 40px; border-left: 4px solid var(--line); align-items: center; }
.market-bull { border-left-color: var(--up); }
.market-bear { border-left-color: var(--warn); }
.market-severe { border-left-color: var(--danger); }
.market .label { color: var(--muted); font-size: 13px; }
.market .big { font-size: 34px; font-weight: 700; line-height: 1.15; }
.market-state { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.market-stats { display: flex; flex-wrap: wrap; gap: 8px 36px; }
.kv b.key { font-size: 19px; }
.state-pill { padding: 4px 12px; border-radius: 999px; background: var(--panel2); font-weight: 600; }
.market-bull .state-pill { color: var(--up); }
.market-bear .state-pill { color: var(--warn); background: rgba(240, 180, 41, .12); }
.market-severe .state-pill { color: var(--danger); background: rgba(255, 138, 61, .14); }
.kv { display: flex; flex-direction: column; }
.kv span { color: var(--muted); font-size: 12.5px; }
.kv b { font-size: 17px; }
.market-note { grid-column: 1 / -1; margin: 6px 0 0; color: var(--muted); text-wrap: pretty; }

/* ---------- 警報 ---------- */
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 10px; border: 1px solid var(--line); }
.alert-bad { background: rgba(240, 180, 41, .10); border-color: rgba(240, 180, 41, .45); }
.alert-good { background: rgba(255, 92, 92, .08); border-color: rgba(255, 92, 92, .4); }
.alert-info { background: rgba(88, 166, 255, .08); border-color: rgba(88, 166, 255, .4); }

/* ---------- 表格 ---------- */
.scroll-x { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { color: var(--muted); font-weight: 500; text-align: left; padding: 6px 8px;
  border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl th.r, .tbl td.r { text-align: right; }
.act { display: inline-block; padding: 1px 8px; border-radius: 6px; font-weight: 600; font-size: 13px; }
.act-buy { color: var(--up); background: rgba(255, 92, 92, .12); }
.act-exit { color: var(--down); background: rgba(46, 204, 113, .12); }
.tag { display: inline-block; padding: 0 7px; margin: 1px 4px 1px 0; border-radius: 6px;
  background: var(--panel2); color: var(--muted); font-size: 12.5px; }
.tag.warn { color: var(--warn); }
.tag.star { color: var(--warn); }
.recent { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 13px; }
.recent .muted { flex: none; }
.day { flex: none; padding: 2px 8px; border: 1px solid var(--line); border-radius: 6px; color: var(--text); }
.day span { margin-left: 4px; }

/* ---------- 持倉 ---------- */
.acct + .acct { margin-top: 18px; padding-top: 16px; border-top: 2px solid var(--line); }
.acct-head b { font-size: 16px; }
.acct-head { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; margin-bottom: 6px; }
.hold { padding: 8px 0; border-bottom: 1px dashed var(--line); }
.hold:last-child { border-bottom: none; }
.hold-line { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 4px 14px; align-items: baseline; }
.hold-line a { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hold-line .px { text-align: right; min-width: 92px; }
.hold-line .pct { text-align: right; min-width: 58px; font-weight: 600; }
.advice { text-wrap: pretty; margin-top: 4px; padding: 6px 10px; border-radius: 6px; background: var(--panel2); font-size: 14px; }
.advice-reduce { border-left: 3px solid var(--danger); }
.advice-add { border-left: 3px solid var(--up); }
.advice-hold-warn { border-left: 3px solid var(--warn); }
.advice-done, .advice-hold { border-left: 3px solid var(--muted); }

/* ---------- 個股 ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; margin-bottom: 12px; }
.search { flex: 1 1 260px; min-width: 0; background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  color: var(--text); padding: 8px 12px; font-size: 16px; }
.search:focus { outline: none; border-color: var(--info); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { background: var(--panel2); border: 1px solid var(--line); color: var(--muted); border-radius: 999px;
  padding: 5px 12px; font: inherit; font-size: 13.5px; cursor: pointer; }
.chips button.on { color: var(--text); border-color: var(--info); background: rgba(88, 166, 255, .12); }
.tbl tr[hidden] { display: none; }
@media (min-width: 861px) { #stocks td:first-child { width: 32%; } }
.show-sm { display: none; }
.tbl tr.sec td.sec-td { white-space: normal; }
#stocks th:last-child, #stocks td:last-child { padding-left: 28px; }
.tbl tr.sec td { color: var(--muted); font-size: 12.5px; padding-top: 16px; background: transparent;
  border-bottom: 1px solid var(--line); letter-spacing: .5px; }
.more-btn { margin-top: 10px; background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 7px 14px; font: inherit; font-size: 13.5px; cursor: pointer; }
.back { color: var(--muted); font-size: 14px; }
.stock-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 40px; }
.stock-head .big { font-size: 32px; font-weight: 700; line-height: 1.15; }
.kv em { font-style: normal; font-size: 12.5px; }
.held-row { flex-basis: 100%; }
.ma5c { color: var(--ma5); } .ma20c { color: var(--ma20); } .ma60c { color: var(--ma60); }
.chart-card { padding-bottom: 12px; }
.chart-bar { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 16px; align-items: center; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; }
.hover { min-height: 42px; margin: 10px 0 4px; font-size: 13px; }
.chart { height: 520px; width: 100%; }

/* ---------- 訊號紀錄 ---------- */
.health { display: grid; grid-template-columns: 9px max-content 1fr; gap: 6px 10px; align-items: center; padding: 12px 18px; }
.health .dot { width: 9px; height: 9px; border-radius: 50%; background: #3fb950; }
.health .dot.bad { background: var(--danger); }
.health .hint { color: var(--danger); font-size: 13px; }
.perf-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(380px, 100%), 1fr)); gap: 14px; align-items: start; }
.perf { background: var(--panel2); border-radius: 8px; padding: 12px 14px; min-width: 0; }
.perf-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; margin-bottom: 6px; }
.tbl.compact td, .tbl.compact th { padding: 5px 6px; }
.perf .tbl td { border-bottom-color: rgba(42, 51, 64, .7); }
.delta { font-size: 11.5px; margin-left: 2px; color: var(--muted); }
.delta.better { color: #3fb950; }
.delta.worse { color: var(--danger); }
.perf-exit .delta.better { color: var(--danger); }
.perf-exit .delta.worse { color: #3fb950; }
svg.weeks { max-width: 100%; height: auto; }
svg.weeks .bar-buy { fill: var(--up); opacity: .85; }
svg.weeks .bar-exit { fill: var(--down); opacity: .75; }
svg.weeks .bar-n { fill: var(--down); font-size: 12px; }
svg.weeks tspan.up { fill: var(--up); }
svg.weeks .bar-lbl { fill: var(--muted); font-size: 11.5px; }
a.chip { display: inline-block; background: var(--panel2); border: 1px solid var(--line); color: var(--muted);
  border-radius: 999px; padding: 4px 12px; font-size: 13.5px; }
a.chip.on { color: var(--text); border-color: var(--info); background: rgba(88, 166, 255, .12); }
a.chip:hover { text-decoration: none; color: var(--text); }
a.plain { color: var(--text); }

/* ---------- 持股 ---------- */
.acct-title { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.acct-title h2 { font-size: 18px; }
.acct-title .hint { color: var(--danger); }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; background: var(--line);
  border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-bottom: 14px; }
.stat { background: var(--panel); padding: 10px 14px; display: flex; flex-direction: column; }
.stat span { color: var(--muted); font-size: 12.5px; }
.stat b { font-size: 20px; }
.stat em { font-style: normal; font-size: 12.5px; }
.weightbar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--panel2); }
.weightbar .seg { height: 100%; }
.seg0 { background: #58a6ff; } .seg1 { background: #c678dd; } .seg2 { background: #f0b429; }
.seg3 { background: #56d4dd; } .seg4 { background: #e06c75; }
.weightlegend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 6px 0 12px; }
.weightlegend .sw { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }
.hold-tbl { table-layout: fixed; }
.hold-tbl th:first-child { width: 22%; }
.hold-tbl .sub { font-size: 12px; color: var(--muted); }
.hold-tbl tr:not(.adv-row) td { border-bottom: none; padding-bottom: 2px; }
.hold-tbl .adv-row td { white-space: normal; padding-top: 0; padding-bottom: 12px; }
.hold-tbl .adv-row .advice { margin-top: 2px; }
.hcards { display: none; }
.hcard { padding: 10px 0 12px; border-bottom: 1px dashed var(--line); }
.hcard:last-child { border-bottom: none; }
.hc-top { display: flex; align-items: baseline; gap: 6px; }
.hc-top a { color: var(--text); }
.hc-pct { margin-left: auto; font-weight: 700; font-size: 16px; }
.hc-grid { display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 3px 10px; margin: 6px 0 4px; font-size: 13.5px; }
.hc-grid span { color: var(--muted); }
.hc-grid b { font-weight: 500; text-align: right; padding-right: 18px; }
.hc-grid b:nth-of-type(2n) { padding-right: 0; }
.risk { margin-top: 14px; padding: 12px 14px; border-radius: 8px; background: var(--panel2); }
.risk h3 { margin: 0 0 6px; font-size: 14.5px; }
.risk p { margin: 4px 0; }
.risk-note { color: #b4bfcc; }
.nw { white-space: nowrap; }

/* ---------- 登入 ---------- */
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 28px 24px; display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { margin: 0; font-size: 20px; }
.login-card p { margin: 0; }
.login-card label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 14px; }
.login-card input { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; color: var(--text);
  padding: 10px 12px; font-size: 16px; }
.login-card button { background: #1f6feb; color: #fff; border: 0; border-radius: 8px; padding: 11px;
  font-size: 16px; font-weight: 600; cursor: pointer; }
.login-card input:focus { outline: none; border-color: var(--info); box-shadow: 0 0 0 3px rgba(88, 166, 255, .25); }
.login-error { color: var(--warn); background: rgba(240, 180, 41, .1); padding: 8px 10px; border-radius: 6px; }

/* ---------- 手機 ---------- */
@media (max-width: 860px) {
  .grid2 { grid-template-columns: minmax(0, 1fr); }
  #stocks .tag { display: none; }
  #stocks th:last-child, #stocks td:last-child { padding-left: 10px; }
}
@media (max-width: 640px) {
  .topbar-in { flex-wrap: wrap; gap: 6px 12px; padding: 8px 12px; }
  .tabs { order: 3; flex-basis: 100%; }
  .logout { margin-left: auto; }
  .page { padding: 12px 12px 24px; }
  .foot { padding: 0 12px 24px; }
  .market { grid-template-columns: minmax(0, 1fr); }
  .market .big { font-size: 28px; }
  .market-stats { gap: 8px 22px; }
  .hold-line { grid-template-columns: minmax(0, 1fr) auto; }
  .hold-line .qty { grid-column: 1; grid-row: 2; }
  .hold-line .px { grid-column: 2; grid-row: 1; min-width: 0; }
  .hold-line .pct { grid-column: 2; grid-row: 2; min-width: 0; }
  .advice { font-size: 13.5px; }
  .chart { height: 420px; }
  .hide-sm { display: none; }
  .show-sm { display: block; }
  #stocks td.stk { white-space: normal; min-width: 7.5em; }
  #stocks td.stk .nm { display: block; color: var(--muted); font-size: 12.5px; }
  #stocks th:last-child, #stocks td:last-child { padding-left: 8px; }
  .tbl { font-size: 13.5px; }
  .tbl th, .tbl td { padding: 7px 4px; }
  .perf { padding: 10px 8px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hcards { display: block; }
  .htable { display: none; }
  .stat { padding: 8px 10px; }
  .stat b { font-size: 17px; }
  .health { padding: 12px; }
  .perf .tbl.compact td, .perf .tbl.compact th { padding: 5px 3px; }
  .delta { display: none; }
  .stock-head { gap: 10px 22px; }
  .stock-head .big { font-size: 26px; }
  .card { padding: 14px 12px; }
}
@media (max-width: 360px) {
  .chips button { padding: 5px 9px; }
  .stock-head .kv b { font-size: 15px; }
  html, body { font-size: 14px; }
  .tbl { font-size: 12.5px; }
  .tbl th, .tbl td { padding: 6px 3px; }
  .act { padding: 1px 5px; }
  .page { padding: 10px 8px 20px; }
  .card { padding: 12px 10px; }
}
