:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel2: #1c2330;
  --line: #2a3240;
  --text: #e6edf3;
  --muted: #8b949e;
  --up: #f0483e;   /* 台式習慣：紅漲 */
  --down: #26a269; /* 綠跌 */
  --accent: #ff6b4a;
  --buy: #f0483e;
  --sell: #26a269;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: -apple-system, "Segoe UI", "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  font-size: 15px;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input { font: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted); }

/* ---- top bar ---- */
#topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
  background: var(--panel); position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 800; font-size: 18px; white-space: nowrap; }
.brand span { color: var(--accent); }
.assets { display: flex; align-items: center; gap: 18px; margin-left: auto; flex-wrap: wrap; }
.asset small { display: block; color: var(--muted); font-size: 11px; }
.asset b { font-variant-numeric: tabular-nums; font-size: 14px; }

.btn { padding: 8px 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); }
.btn.ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn.buy-bg { background: var(--buy); border: none; color: #fff; font-weight: 700; width: 100%; padding: 12px; border-radius: 10px; }
.btn.buy-bg:disabled { opacity: .45; cursor: not-allowed; }
.btn.sell-bg { background: var(--sell); border: none; color: #fff; font-weight: 700; width: 100%; padding: 12px; border-radius: 10px; }

/* ---- layout ---- */
#layout {
  display: grid; gap: 12px; padding: 12px;
  grid-template-columns: minmax(300px, 380px) 1fr;
  grid-template-areas: "left right" "bottom bottom";
  max-width: 1400px; margin: 0 auto;
}
#leftPane { grid-area: left; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; min-height: 480px; max-height: 78vh; overflow: hidden; }
#rightPane { grid-area: right; display: flex; flex-direction: column; gap: 12px; }
#bottomPane { grid-area: bottom; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }

/* ---- tabs ---- */
#tabs { display: flex; overflow-x: auto; border-bottom: 1px solid var(--line); scrollbar-width: none; }
#tabs button { padding: 10px 14px; white-space: nowrap; color: var(--muted); border-bottom: 2px solid transparent; }
#tabs button.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 700; }
#listCtl { padding: 8px 10px; border-bottom: 1px solid var(--line); }
#search { width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
#quoteList { overflow-y: auto; flex: 1; }
.q-row { display: grid; grid-template-columns: 28px 1fr auto auto; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid #202836; cursor: pointer; }
.q-row:hover { background: var(--panel2); }
.q-row.on { background: #212a3a; box-shadow: inset 3px 0 0 var(--accent); }
.q-name { font-weight: 600; }
.q-code { color: var(--muted); font-size: 12px; }
.q-num { text-align: right; font-variant-numeric: tabular-nums; }
.q-chg { font-size: 12px; }
.star { font-size: 15px; color: #4a5462; }
.star.on { color: #f7c948; }
.up { color: var(--up); } .down { color: var(--down); } .flat { color: var(--muted); }

/* ---- symbol head / chart ---- */
#symHead { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
#symName { font-size: 20px; }
.sym-sub { color: var(--muted); font-size: 13px; display: flex; gap: 10px; margin-top: 2px; }
.sym-price { text-align: right; }
.big { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.chg { font-size: 14px; font-variant-numeric: tabular-nums; }
#chart { height: 320px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
#ranges { display: flex; gap: 6px; }
#ranges button { padding: 5px 12px; border-radius: 6px; background: var(--panel); border: 1px solid var(--line); color: var(--muted); font-size: 13px; }
#ranges button.on { color: #fff; background: var(--accent); border-color: var(--accent); }

/* ---- trade panel ---- */
#tradePanel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: grid; gap: 10px; }
.side-tabs { display: flex; gap: 8px; }
.side-tabs button { flex: 1; padding: 10px; border-radius: 8px; background: var(--panel2); color: var(--muted); font-weight: 700; border: 1px solid var(--line); }
.side-tabs button.buy.on { background: var(--buy); color: #fff; border-color: var(--buy); }
.side-tabs button.sell.on { background: var(--sell); color: #fff; border-color: var(--sell); }
.trade-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.qty-box { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.qty-box button { width: 42px; padding: 8px 0; background: var(--panel2); color: var(--muted); font-size: 18px; }
.qty-box input { width: 120px; padding: 8px; border: none; background: var(--bg); color: var(--text); text-align: center; -moz-appearance: textfield; }
.qty-box input::-webkit-outer-spin-button, .qty-box input::-webkit-inner-spin-button { -webkit-appearance: none; }
.est { color: var(--muted); font-size: 13px; }
.est span:last-child { color: var(--text); font-variant-numeric: tabular-nums; }

/* ---- bottom tables ---- */
.panel-tabs { display: flex; gap: 4px; padding: 10px 12px 0; }
.panel-tabs .pt { padding: 8px 16px; border-radius: 8px 8px 0 0; color: var(--muted); font-weight: 600; }
.panel-tabs .pt.on { color: var(--accent); background: var(--panel2); }
.table-wrap { overflow-x: auto; padding: 8px 12px 14px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--muted); font-weight: 500; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid #202836; white-space: nowrap; font-variant-numeric: tabular-nums; }
tr.empty td { text-align: center; color: var(--muted); padding: 22px; }
td .mini { padding: 4px 10px; border-radius: 6px; border: 1px solid var(--line); font-size: 12px; }
.badge { padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge.BUY { background: rgba(240,72,62,.15); color: var(--up); }
.badge.SELL { background: rgba(38,162,105,.15); color: var(--down); }
.badge.FX { background: rgba(137,180,255,.15); color: #8ab4ff; }

[hidden] { display: none !important; }

/* ---- 自選排序 ---- */
.reorder-bar { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 2; }
.reorder-bar .muted { font-size: 12px; color: var(--muted); }
.btn.sm { padding: 4px 10px; font-size: 12px; border-radius: 6px; }
.btn.reorder-on { border-color: var(--accent); color: var(--accent); }
.mvbox { display: flex; flex-direction: column; gap: 2px; margin-left: 8px; flex: none; }
.mv { width: 24px; height: 17px; line-height: 1; padding: 0; border: 1px solid var(--line); background: transparent; color: var(--muted); border-radius: 5px; cursor: pointer; font-size: 11px; }
.mv:hover { border-color: var(--accent); color: var(--accent); }
/* ---- masks ---- */
.mask { position: fixed; inset: 0; background: rgba(0,0,0,.62); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px; width: min(380px, 94vw); display: grid; gap: 12px; }
.card h3 { font-size: 18px; }
.card input { width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.field span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 4px; }

/* ---- toast ---- */
.toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); background: #232c3b; border: 1px solid var(--line); padding: 10px 18px; border-radius: 10px; z-index: 99; box-shadow: 0 8px 30px rgba(0,0,0,.5); max-width: 90vw; }
.toast.err { border-color: var(--up); }
.toast.ok { border-color: var(--sell); }

/* ---- mobile ---- */
@media (max-width: 860px) {
  #layout { grid-template-columns: 1fr; grid-template-areas: "left" "right" "bottom"; }
  #leftPane { max-height: 56vh; }
  .assets { gap: 12px; }
  .asset b { font-size: 13px; }
  #chart { height: 240px; }
  .big { font-size: 22px; }
}
