:root {
  --bg: #0b0e13; --panel: #12161d; --panel2: #171c24; --line: #222936; --ink: #e8ebf1; --muted: #8a93a3;
  --up: #16c784; --down: #ea3943; --accent: #3b82f6; --warn: #f5a524;
  --upbg: rgba(22,199,132,.12); --downbg: rgba(234,57,67,.12);
  font-size: 14px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: "Noto Sans TC", system-ui, sans-serif; }
button { font: inherit; cursor: pointer; }
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.r { text-align: right; }
.up { color: var(--up); } .down { color: var(--down); }
.num { font-variant-numeric: tabular-nums; }

/* 共用元件（後台也用） */
.brand { font-weight: 800; font-size: 18px; letter-spacing: .3px; }
.ghost { background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 6px; padding: 5px 10px; text-decoration: none; display: inline-block; }
.ghost:hover { color: var(--ink); }
.primary, .btn-primary { width: 100%; border: 0; border-radius: 8px; padding: 10px; background: var(--accent); color: #fff; font-weight: 700; margin-top: 10px; }
.btn-primary.sm { width: auto; padding: 6px 12px; margin: 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.cardh { display: flex; justify-content: space-between; align-items: center; font-weight: 700; margin-bottom: 10px; }
.h { font-weight: 700; padding: 10px 12px; }
.card .h { padding: 0 0 10px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { color: var(--muted); font-weight: 500; text-align: left; padding: 7px 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
td { padding: 8px 12px; border-bottom: 1px solid var(--line); }
.note { color: var(--muted); font-size: 12px; padding: 8px 12px; }
label { display: grid; grid-template-columns: 56px 1fr; align-items: center; gap: 8px; margin: 6px 0; color: var(--muted); }
input, select { background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; font: inherit; width: 100%; }
input:focus, select:focus { outline: none; border-color: var(--accent); }
.msg { min-height: 18px; font-size: 13px; margin-top: 6px; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 50; overflow: auto; }
.sheet { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; width: min(720px, 94vw); padding: 16px; }
.sheet.wide { width: min(1000px, 96vw); }
.formrow { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.center-page { min-height: 100vh; display: grid; place-items: center; }
.authbox { width: min(380px, 92vw); padding: 22px; }
.authbox label { grid-template-columns: 64px 1fr; }
.seg { display: flex; gap: 6px; margin-bottom: 10px; }
.seg button { flex: 1; background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 6px; padding: 7px; }
.seg button.on { color: var(--ink); border-color: var(--accent); }
.tag { font-size: 11px; color: var(--warn); border: 1px solid #5a4210; border-radius: 4px; padding: 1px 6px; margin-left: 8px; }
.pill { display: inline-block; border-radius: 9px; padding: 1px 8px; font-size: 12px; border: 1px solid var(--line); color: var(--muted); }
.pill.up { border-color: #0f5c40; color: var(--up); } .pill.down { border-color: #6d1f25; color: var(--down); } .pill.warn { border-color: #6b4a0e; color: var(--warn); }

/* 頂部列 */
.top { display: flex; align-items: center; gap: 14px; padding: 0 14px; height: 56px; border-bottom: 1px solid var(--line); background: var(--panel); }
.top button, .top a { white-space: nowrap; }
.acctpick, .usermenu { position: relative; }
.acctbtn { background: var(--panel2); border: 1px solid var(--line); color: var(--ink); border-radius: 8px; padding: 6px 10px; display: flex; gap: 8px; align-items: center; max-width: 340px; }
.acctbtn #acctLabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.caret { color: var(--muted); }
.menu { position: absolute; top: calc(100% + 6px); left: 0; min-width: 300px; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 6px; z-index: 40; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.menu.right { left: auto; right: 0; min-width: 140px; }
.menu button, .menu a { display: flex; width: 100%; justify-content: space-between; gap: 12px; background: none; border: 0; color: var(--ink); text-align: left; padding: 8px 10px; border-radius: 6px; text-decoration: none; }
.menu button:hover, .menu a:hover, .menu button.on { background: #1f2632; }
.menu .sub { color: var(--muted); font-size: 12px; }
.kpis { display: flex; gap: 22px; margin-left: 6px; font-variant-numeric: tabular-nums; overflow: hidden; }
.kpis div { display: flex; flex-direction: column; line-height: 1.25; white-space: nowrap; }
.kpis small { color: var(--muted); font-size: 11px; }
.kpis b { font-size: 14px; }
.views { display: flex; gap: 2px; margin-left: auto; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.views button { background: none; border: 0; color: var(--muted); padding: 5px 12px; border-radius: 6px; }
.views button.on { background: var(--panel2); color: var(--ink); }
#views[hidden] + .btn-primary { margin-left: auto; }

/* 交易畫面 */
.grid { display: grid; grid-template-columns: 300px minmax(0, 1fr) 320px; height: calc(100vh - 56px); }
.watch { border-right: 1px solid var(--line); overflow: auto; display: flex; flex-direction: column; }
.wtools { padding: 10px; display: flex; flex-direction: column; gap: 8px; border-bottom: 1px solid var(--line); }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chips button { background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 14px; padding: 2px 8px; font-size: 12px; }
.chips button.on { color: var(--ink); border-color: var(--accent); background: rgba(59,130,246,.12); }
.whead, .wrow { display: grid; grid-template-columns: minmax(0,1.3fr) 1fr 1fr 58px; gap: 6px; padding: 7px 12px; align-items: center; }
.whead { color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--line); }
.wrow { cursor: pointer; border-bottom: 1px solid #181d26; font-variant-numeric: tabular-nums; font-size: 13px; }
.wrow:hover { background: #151a22; }
.wrow.sel { background: #1a2130; box-shadow: inset 2px 0 var(--accent); }
.wrow .s b { display: block; font-size: 13px; }
.wrow .s span { color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.chg { text-align: right; font-size: 12px; border-radius: 4px; padding: 2px 4px; }
.chg.up { background: var(--upbg); } .chg.down { background: var(--downbg); }
.flash-up { color: var(--up) !important; } .flash-down { color: var(--down) !important; }

.center { display: flex; flex-direction: column; min-width: 0; }
.charthead { padding: 8px 14px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); }
.charthead .sym { display: flex; align-items: center; gap: 8px; }
.tfs { display: flex; gap: 2px; }
.tfs button { background: none; border: 0; color: var(--muted); padding: 4px 9px; border-radius: 5px; font-size: 13px; }
.tfs button.on { background: var(--panel2); color: var(--ink); }
#chart { flex: 1; min-height: 260px; }
.bottom { border-top: 1px solid var(--line); height: 240px; display: flex; flex-direction: column; }
.tabs { display: flex; align-items: center; gap: 4px; padding: 0 10px; border-bottom: 1px solid var(--line); }
.tabs button { background: none; border: 0; color: var(--muted); padding: 9px 10px; border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--ink); border-color: var(--accent); }
.tabs .spacer { flex: 1; }
.cnt { background: var(--panel2); border-radius: 8px; padding: 0 6px; font-size: 12px; }
#floatSum { font-variant-numeric: tabular-nums; margin-right: 8px; }
.tabbody { flex: 1; overflow: auto; }
.tabbody td, .tabbody th { padding: 6px 12px; font-size: 13px; }
.x { background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 5px; padding: 2px 8px; font-size: 12px; }
.x:hover { color: var(--ink); }
.x.danger { color: var(--down); border-color: #4d1d22; }
.side-tag { font-weight: 700; font-size: 12px; padding: 1px 6px; border-radius: 4px; }
.side-tag.buy { color: var(--up); background: var(--upbg); } .side-tag.sell { color: var(--down); background: var(--downbg); }

.side { border-left: 1px solid var(--line); padding: 10px; display: flex; flex-direction: column; gap: 10px; overflow: auto; }
.bs { display: grid; grid-template-columns: 1fr auto 1fr; gap: 6px; align-items: stretch; margin-bottom: 10px; }
.bs button { border: 0; border-radius: 8px; padding: 9px 6px; color: #fff; display: flex; flex-direction: column; align-items: center; gap: 1px; }
.bs small { font-size: 12px; opacity: .9; }
.bs b { font-variant-numeric: tabular-nums; font-size: 16px; }
.sell { background: #c62f39; } .buy { background: #12a46d; }
.sell:hover { background: #d93a44; } .buy:hover { background: #15b97b; }
.spread { align-self: center; font-size: 11px; color: var(--muted); background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 2px 5px; font-variant-numeric: tabular-nums; }
.seg3 { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 2px; margin-bottom: 8px; }
.seg3 button { background: none; border: 0; color: var(--muted); padding: 5px; border-radius: 5px; font-size: 13px; }
.seg3 button.on { background: var(--panel2); color: var(--ink); }
.row { display: grid; grid-template-columns: 84px 1fr; align-items: center; gap: 8px; margin: 6px 0; color: var(--muted); font-size: 13px; }
/* 交易日誌 */
.jbar { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; font-size: 13px; }
.jbar .seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.jbar .seg button { background: none; border: 0; color: var(--muted); padding: 4px 10px; font-size: 12px; }
.jbar .seg button.on { background: var(--panel2); color: var(--ink); }
.jbar input { width: 120px; padding: 4px 8px; }
.jbar .sum { margin-left: auto; color: var(--muted); }
.an-side { display: grid; grid-template-columns: 52px 1fr auto; gap: 8px; align-items: center; font-size: 13px; margin: 6px 0; }
.an-side .bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.an-side .bar i { display: block; height: 100%; background: var(--up); }
.wrow .star { color: var(--muted); cursor: pointer; margin-right: 5px; font-weight: 400; }
.wrow .star.on { color: #f0b90b; }
/* 新聞、經濟日曆 */
.newswarn { margin-top: 8px; border: 1px solid #78350f; background: rgba(245,165,36,.1); color: var(--warn); border-radius: 8px; padding: 7px 10px; font-size: 12px; line-height: 1.5; }
.news a { display: block; padding: 9px 12px; border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.news a:hover { background: var(--panel2); }
.news .meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.imp { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--line); }
.imp.High { background: var(--down); } .imp.Medium { background: var(--warn); } .imp.Low { background: #6b7280; }
tr.past td { opacity: .45; }
tr.mine td:nth-child(2) { color: var(--accent); font-weight: 700; }
.row.stop { grid-template-columns: 84px 1fr 64px; }
.row .smode { padding: 6px 4px; }
.stepper { display: grid; grid-template-columns: 30px 1fr 30px; }
.stepper button { background: var(--panel2); border: 1px solid var(--line); color: var(--ink); }
.stepper button:first-child { border-radius: 6px 0 0 6px; } .stepper button:last-child { border-radius: 0 6px 6px 0; }
.stepper input { border-radius: 0; text-align: center; border-left: 0; border-right: 0; }
.risk { display: flex; align-items: center; gap: 6px; font-size: 13px; margin: 8px 0 4px; grid-template-columns: none; }
.risk input { width: auto; }
.calc { font-size: 12px; color: var(--muted); background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 8px 10px; display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; font-variant-numeric: tabular-nums; }
.calc:empty { display: none; }
.calc b { color: var(--ink); font-weight: 500; text-align: right; }

.status { font-weight: 700; margin-bottom: 6px; }
.goal { padding: 8px 0; border-bottom: 1px solid #1a1f29; }
.goal:last-child { border-bottom: 0; }
.goal .gh { display: flex; justify-content: space-between; font-size: 13px; gap: 8px; }
.goal .gh span:first-child { color: var(--muted); }
.goal .gh span:last-child { font-variant-numeric: tabular-nums; text-align: right; }
.ok-ico { color: var(--up); } .bad-ico { color: var(--down); }
.bar { height: 5px; background: var(--line); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); }
.bar i.ok { background: var(--up); } .bar i.warn { background: var(--warn); } .bar i.bad { background: var(--down); }

/* 沒有帳戶 */
.empty { padding: 40px 24px; max-width: 1100px; margin: 0 auto; }
.emptyhead h1 { font-size: 22px; margin: 0 0 6px; }
.plangrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; margin-top: 18px; }
.plan { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; }
.plan .ptop { display: flex; justify-content: space-between; align-items: baseline; }
.plan .size { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.plan .price { color: var(--muted); }
.plan .pname { color: var(--muted); margin: 2px 0 10px; }
.plan table td { padding: 6px 0; border-bottom: 1px solid #1f2530; font-size: 13px; }
.plan table td:last-child { text-align: right; }
.plan .split { margin-top: 10px; font-size: 13px; color: var(--muted); }
.plan .btn-primary { margin-top: auto; }
.plan .phs { margin-bottom: 12px; }

/* 考試進度 */
.metrix { padding: 18px; max-width: 1300px; margin: 0 auto; }
.mhead { display: flex; flex-wrap: wrap; gap: 26px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 18px; margin-bottom: 14px; }
.mhead div { display: flex; flex-direction: column; gap: 2px; }
.mhead small { color: var(--muted); font-size: 12px; }
.mhead b { font-size: 16px; font-variant-numeric: tabular-nums; }
.mgrid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 14px; }
.obj td { padding: 9px 4px; }
.obj td:nth-child(2), .obj td:nth-child(3) { text-align: right; }
#eqChart { height: 280px; }
.statgrid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.statgrid div { display: flex; flex-direction: column; gap: 3px; }
.statgrid small { color: var(--muted); font-size: 12px; }
.statgrid b { font-variant-numeric: tabular-nums; font-size: 15px; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal .dh { color: var(--muted); font-size: 11px; text-align: center; }
.cal .d { border: 1px solid var(--line); border-radius: 6px; padding: 5px; min-height: 48px; font-size: 11px; display: flex; flex-direction: column; justify-content: space-between; }
.cal .d b { font-size: 12px; font-variant-numeric: tabular-nums; text-align: right; }
.cal .d.up { background: var(--upbg); border-color: #0f5c40; } .cal .d.down { background: var(--downbg); border-color: #6d1f25; }
.cal .d.off { opacity: .35; }

@media (max-width: 1100px) {
  .grid { grid-template-columns: 240px minmax(0, 1fr) 290px; }
  .kpis div:nth-child(n+4) { display: none; }
}
@media (max-width: 860px) {
  .top { height: auto; flex-wrap: wrap; padding: 8px 12px; }
  .kpis { order: 9; width: 100%; }
  .grid { grid-template-columns: 1fr; height: auto; }
  .watch { max-height: 240px; border-right: 0; border-bottom: 1px solid var(--line); }
  #chart { height: 320px; flex: none; }
  .side { border-left: 0; }
  .mgrid { grid-template-columns: 1fr; }
  .statgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* 違規明細 */
.card.breach { border-color: #6d1f25; background: linear-gradient(180deg, var(--downbg), var(--panel) 60%); margin-bottom: 14px; }
.card.breach p { margin: 6px 0; }
.card.breach .calc-line { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px; flex-wrap: wrap; }
.card.breach .calc-line span:first-child { color: var(--muted); }
.card.breach table { margin-top: 10px; }

/* 客服對話（交易終端、業者後台共用） */
.chatlog { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; padding: 4px 2px; }
.chatlog .bub { max-width: 80%; padding: 8px 12px; border-radius: 12px; font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.chatlog .bub.me { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.chatlog .bub.them { align-self: flex-start; background: var(--panel2); border-bottom-left-radius: 4px; }
.chatlog .bub small { display: block; opacity: .7; font-size: 11px; margin-top: 3px; }
.chatsend { display: flex; gap: 8px; margin-top: 10px; }
.chatsend textarea { flex: 1; resize: none; height: 44px; font: inherit; }
.chatsend button { width: auto; margin: 0; padding: 0 18px; }
.badge.inline { background: var(--down); color: #fff; border-radius: 9px; padding: 0 6px; font-size: 11px; margin-left: 4px; }
