:root {
  --bg: #071018;
  --panel: #0d1722;
  --panel-2: #111e2b;
  --panel-3: #162534;
  --border: #213549;
  --border-soft: rgba(123, 155, 181, .16);
  --text: #e8f0f6;
  --muted: #8297aa;
  --muted-2: #5f7589;
  --cyan: #45c3dc;
  --cyan-soft: rgba(69, 195, 220, .14);
  --amber: #f5bd4f;
  --red: #ff5964;
  --red-soft: rgba(255, 89, 100, .14);
  --green: #21c896;
  --green-soft: rgba(33, 200, 150, .14);
  --blue: #5aa9ff;
  --shadow: 0 18px 45px rgba(0, 0, 0, .25);
  --radius: 12px;
  font-family: Inter, "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 1180px;
  background:
    radial-gradient(circle at 15% -10%, rgba(45, 134, 160, .13), transparent 30%),
    linear-gradient(180deg, #071018 0%, #09131d 65%, #070d13 100%);
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

button, select, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .38; }

.app-shell { max-width: 1560px; margin: 0 auto; padding: 14px 18px 30px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 66px;
  margin-bottom: 12px;
  padding: 0 4px;
}

.brand-block { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: grid; place-items: center; width: 42px; height: 42px;
  border: 1px solid rgba(69, 195, 220, .5); border-radius: 9px;
  color: var(--cyan); background: linear-gradient(145deg, rgba(69,195,220,.16), rgba(69,195,220,.03));
  font-weight: 800; font-size: 21px; box-shadow: inset 0 0 24px rgba(69,195,220,.07);
}
.brand-block h1 { margin: 0; font-size: 20px; letter-spacing: .07em; }
.brand-block p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.topbar-status { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 10px var(--amber); }
.status-dot.ok { background: var(--green); box-shadow: 0 0 10px var(--green); }
.status-dot.error { background: var(--red); box-shadow: 0 0 10px var(--red); }
.data-chip, .market-badge, .pending-badge, .result-badge {
  display: inline-flex; align-items: center; min-height: 24px; padding: 3px 9px;
  border: 1px solid var(--border); border-radius: 999px; background: rgba(255,255,255,.025);
  color: var(--muted); font-size: 11px;
}

.card {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(17,30,43,.96), rgba(11,22,32,.97));
  box-shadow: var(--shadow);
}

.session-toolbar {
  display: flex; align-items: end; gap: 12px; padding: 12px 14px; margin-bottom: 10px;
}
.field-group { display: flex; flex-direction: column; gap: 5px; }
.field-group label, .quantity-row label, .replay-controls label { color: var(--muted); font-size: 11px; }
.primary-field { min-width: 210px; }
select, input[type="number"] {
  height: 36px; border: 1px solid var(--border); border-radius: 7px; outline: none;
  background: #0a141e; color: var(--text); padding: 0 10px;
}
select:focus, input:focus { border-color: var(--cyan); box-shadow: 0 0 0 2px rgba(69,195,220,.12); }

.switch-field, .check-field { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; user-select: none; }
.switch-field { height: 36px; margin: 0 5px; }
.switch-field input { position: absolute; opacity: 0; }
.switch { width: 36px; height: 20px; padding: 2px; border-radius: 999px; background: #263849; transition: .2s; }
.switch::after { content: ""; display: block; width: 16px; height: 16px; border-radius: 50%; background: #c2ccd5; transition: .2s; }
.switch-field input:checked + .switch { background: rgba(69,195,220,.55); }
.switch-field input:checked + .switch::after { transform: translateX(16px); background: white; }
.check-field input { accent-color: var(--cyan); }

.btn, .icon-btn {
  height: 36px; padding: 0 14px; border: 1px solid var(--border); border-radius: 7px;
  color: var(--text); background: #122131; font-weight: 650; font-size: 12px;
  transition: transform .12s, border-color .12s, background .12s;
}
.btn:hover, .icon-btn:hover { border-color: #3a5770; background: #172b3d; }
.btn:active, .icon-btn:active { transform: translateY(1px); }
.btn-primary { margin-left: auto; color: #041116; border-color: #52c8dc; background: linear-gradient(135deg, #65d0e2, #35a9c0); }
.btn-primary:hover { background: linear-gradient(135deg, #79d9e8, #44b9cf); }
.btn-ghost { background: transparent; }
.btn-danger-ghost { color: #ff8b92; border-color: rgba(255,89,100,.35); background: transparent; }
.full { width: 100%; }

.advanced-panel {
  display: flex; align-items: end; gap: 18px; margin: -2px 0 10px; padding: 12px 14px;
  border-color: rgba(69,195,220,.22); box-shadow: none;
}
.advanced-panel[hidden] { display: none; }
.advanced-panel input[type="number"] { width: 112px; }
.model-note { flex: 1; margin: 0 0 2px auto; color: var(--muted-2); font-size: 11px; line-height: 1.5; text-align: right; }

.market-strip { display: grid; grid-template-columns: 1.7fr repeat(4, minmax(150px, .72fr)); gap: 10px; margin-bottom: 10px; }
.quote-card, .metric-card { min-height: 92px; padding: 14px 16px; }
.quote-card { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.quote-identity .eyebrow, .eyebrow { color: var(--muted-2); font-size: 10px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.quote-identity h2 { display: inline-block; margin: 6px 8px 0 0; font-size: 20px; }
.quote-main { display: flex; align-items: baseline; gap: 10px; }
.last-price { font-size: 34px; font-weight: 780; letter-spacing: -.02em; }
.price-change { font-size: 14px; font-weight: 700; }
.metric-card { display: flex; flex-direction: column; justify-content: center; }
.metric-card span { color: var(--muted); font-size: 11px; }
.metric-card strong { margin: 7px 0 3px; font-size: 21px; }
.metric-card small { color: var(--muted-2); font-size: 10px; }
.positive { color: var(--red) !important; }
.negative { color: var(--green) !important; }
.neutral { color: var(--text) !important; }

.terminal-grid { display: grid; grid-template-columns: minmax(760px, 1fr) 330px; gap: 10px; }
.chart-column { min-width: 0; padding: 13px 14px 11px; overflow: hidden; }
.chart-header, .index-header, .volume-header, .section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.chart-header h3, .index-header h3, .section-title h3 { margin: 0; font-size: 14px; letter-spacing: .02em; }
.chart-scope { margin-left: 6px; color: var(--cyan); font-size: 9px; font-weight: 650; letter-spacing: .03em; }
.legend-row { display: flex; gap: 15px; margin-top: 7px; color: var(--muted); font-size: 10px; }
.legend-row span { display: inline-flex; align-items: center; gap: 5px; }
.legend-swatch { width: 8px; height: 8px; border-radius: 1px; }
.candle-up { background: var(--red); } .candle-down { background: var(--green); }
.candle-previous { background: #71879a; }
.legend-line { width: 14px; height: 2px; border-radius: 2px; }
.legend-line.vwap { background: var(--amber); }
.legend-line.five { background: #b987ff; }
.legend-line.limit { background: var(--red); }
.legend-line.down-limit { background: var(--green); }
.chart-readout { min-width: 360px; text-align: right; }
.ohlc { color: var(--text); font-size: 11px; }
.range-note { margin-top: 4px; color: var(--muted-2); font-size: 9px; }
.chart-wrap { height: 340px; margin-top: 10px; background: #08111a; border: 1px solid #172839; border-radius: 8px; overflow: hidden; }
.volume-header { margin: 9px 2px 5px; }
.volume-header h4 { display: inline; margin: 0 8px 0 0; font-size: 12px; }
.volume-header span { color: var(--muted); font-size: 10px; }
.volume-header .volume-color-note { margin-left: 8px; color: var(--muted-2); white-space: nowrap; }
.volume-header strong { color: var(--cyan); font-size: 13px; }
.volume-wrap { height: 110px; background: #08111a; border: 1px solid #172839; border-radius: 8px; overflow: hidden; }
.index-header { margin: 10px 2px 6px; }
.index-header span { color: var(--muted-2); font-size: 10px; }
.index-wrap { height: 110px; background: #08111a; border: 1px solid #172839; border-radius: 8px; overflow: hidden; }

.replay-controls { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.icon-btn { background: #0d1b28; }
.btn-play { min-width: 96px; color: #071018; border-color: var(--amber); background: var(--amber); }
.replay-controls select { height: 34px; }
.timeline { position: relative; flex: 1; height: 5px; margin: 0 8px; border-radius: 999px; overflow: hidden; background: #263747; }
.timeline span { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, var(--cyan), #7de4f0); transition: width .18s; }

.order-column { display: flex; flex-direction: column; gap: 10px; }
.order-ticket, .position-card, .signal-card { padding: 15px; }
.section-title { margin-bottom: 14px; }
.section-title.compact { margin-bottom: 10px; }
.section-title > span, .section-title.compact span { color: var(--muted); font-size: 10px; }
.pending-badge.active { color: var(--amber); border-color: rgba(245,189,79,.45); background: rgba(245,189,79,.09); }
.price-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 10px; border: 1px solid var(--border-soft); border-radius: 8px; background: #09131d; }
.price-grid div { display: flex; flex-direction: column; gap: 5px; text-align: center; }
.price-grid span { color: var(--muted-2); font-size: 10px; }
.price-grid strong { font-size: 14px; }
.buying-power-line { margin-top: 10px; padding: 11px 12px 10px; border: 1px solid rgba(90,169,255,.34); border-radius: 9px; background: linear-gradient(135deg, rgba(90,169,255,.12), rgba(90,169,255,.04)); }
.buying-power-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.buying-power-heading > span { color: #bad8ff; font-size: 12px; font-weight: 750; letter-spacing: .03em; }
.buying-power-heading small { color: var(--muted-2); font-size: 9px; white-space: nowrap; }
.buying-power-heading b { color: var(--muted); font-weight: 650; }
.buying-power-line > strong { display: block; margin: 5px 0 7px; color: #73b8ff; font-size: 23px; font-weight: 820; line-height: 1.05; letter-spacing: .01em; }
.buying-power-line > small { display: block; margin-top: 6px; color: var(--muted); font-size: 9px; line-height: 1.4; }
.buying-power-meter { height: 5px; overflow: hidden; border-radius: 999px; background: rgba(90,169,255,.14); }
.buying-power-meter span { display: block; width: 100%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #3a8fe8, #79c1ff); transition: width .2s ease, background .2s ease; }
.buying-power-line.warning { border-color: rgba(245,189,79,.45); background: linear-gradient(135deg, rgba(245,189,79,.12), rgba(245,189,79,.035)); }
.buying-power-line.warning > strong { color: var(--amber); }
.buying-power-line.warning .buying-power-meter span { background: var(--amber); }
.buying-power-line.critical { border-color: rgba(255,89,100,.52); background: linear-gradient(135deg, rgba(255,89,100,.13), rgba(255,89,100,.035)); }
.buying-power-line.critical > strong { color: #ff7d85; }
.buying-power-line.critical .buying-power-meter span { background: var(--red); }
.lot-presets { display: grid; grid-template-columns: 58px repeat(5, 1fr); align-items: center; gap: 5px; margin-top: 10px; }
.lot-presets > span { color: var(--muted); font-size: 10px; }
.lot-preset { height: 29px; border: 1px solid var(--border); border-radius: 6px; color: var(--text); background: #10202e; font-size: 11px; font-weight: 750; }
.lot-preset:hover { border-color: #3a5770; background: #172b3d; }
.lot-preset.active { color: #061318; border-color: var(--cyan); background: var(--cyan); }
.quantity-row { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 8px; margin: 15px 0 12px; }
.stepper { display: grid; grid-template-columns: 34px 1fr 34px; }
.stepper button { border: 1px solid var(--border); color: var(--text); background: #132435; }
.stepper button:first-child { border-radius: 7px 0 0 7px; }
.stepper button:last-child { border-radius: 0 7px 7px 0; }
.stepper input { width: 100%; border-radius: 0; text-align: center; border-inline: 0; }
#shares-label { color: var(--muted); font-size: 10px; }
.order-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.trade-btn { min-height: 68px; padding: 10px; border-radius: 9px; font-size: 15px; font-weight: 800; }
.trade-btn span { display: block; margin-bottom: 5px; }
.trade-btn kbd { padding: 2px 5px; border: 1px solid currentColor; border-radius: 4px; font-size: 9px; opacity: .62; }
.short-btn { color: #d8fff3; border: 1px solid rgba(33,200,150,.65); background: linear-gradient(145deg, rgba(33,200,150,.3), rgba(33,200,150,.12)); }
.short-btn:hover { background: linear-gradient(145deg, rgba(33,200,150,.42), rgba(33,200,150,.18)); }
.cover-btn { color: #ffe2e4; border: 1px solid rgba(255,89,100,.65); background: linear-gradient(145deg, rgba(255,89,100,.3), rgba(255,89,100,.12)); }
.cover-btn:hover { background: linear-gradient(145deg, rgba(255,89,100,.42), rgba(255,89,100,.18)); }
.execution-hint { margin-top: 10px; color: var(--muted-2); font-size: 10px; line-height: 1.45; text-align: center; }

.position-list { display: grid; gap: 1px; margin: 0; }
.position-list div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 2px; border-bottom: 1px solid rgba(123,155,181,.08); }
.position-list dt { color: var(--muted); font-size: 11px; }
.position-list dd { margin: 0; font-size: 12px; font-weight: 700; }
.risk-rules { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 11px; }
.risk-rules div { padding: 8px; border: 1px solid var(--border-soft); border-radius: 7px; background: #0a151f; }
.risk-rules span, .risk-rules strong { display: block; font-size: 9px; }
.risk-rules span { color: var(--muted-2); margin-bottom: 4px; }
.risk-rules strong { color: var(--green); }
.risk-rules .off strong { color: var(--muted); }

.lower-grid { display: grid; grid-template-columns: 1.35fr .65fr; gap: 10px; margin-top: 10px; }
.blotter-card, .result-card, .stats-section { padding: 15px; }
.table-scroll { width: 100%; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 11px; }
th { position: sticky; top: 0; z-index: 1; padding: 9px 10px; color: var(--muted-2); background: #101d29; border-bottom: 1px solid var(--border); text-align: right; font-weight: 650; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
td { padding: 9px 10px; border-bottom: 1px solid rgba(123,155,181,.08); text-align: right; white-space: nowrap; }
tbody tr:hover { background: rgba(69,195,220,.035); }
.empty-cell { color: var(--muted-2); text-align: center !important; padding: 24px; }
.status-filled { color: var(--green); }
.status-pending { color: var(--amber); }
.status-cancelled { color: var(--muted-2); }
.result-card { min-height: 215px; }
.result-badge.win { color: var(--red); border-color: rgba(255,89,100,.4); }
.result-badge.loss { color: var(--green); border-color: rgba(33,200,150,.4); }
.empty-result { display: grid; place-items: center; min-height: 130px; padding: 20px; color: var(--muted-2); text-align: center; font-size: 11px; line-height: 1.7; }
.result-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.result-grid div { padding: 10px; border: 1px solid var(--border-soft); border-radius: 7px; background: #0a151f; }
.result-grid span, .result-grid strong { display: block; }
.result-grid span { color: var(--muted-2); font-size: 9px; }
.result-grid strong { margin-top: 5px; font-size: 14px; }
.result-note { margin: 11px 1px 0; color: var(--muted); font-size: 10px; line-height: 1.55; }

.stats-section { margin-top: 10px; }
.stats-row { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-bottom: 12px; }
.stats-row div { padding: 12px; border: 1px solid var(--border-soft); border-radius: 8px; background: #0a151f; }
.stats-row span, .stats-row strong { display: block; }
.stats-row span { color: var(--muted-2); font-size: 9px; }
.stats-row strong { margin-top: 6px; font-size: 16px; }
.history-scroll { max-height: 290px; }
.view-btn { height: 25px; padding: 0 8px; border: 1px solid var(--border); border-radius: 5px; color: var(--cyan); background: transparent; font-size: 10px; }

footer { display: flex; justify-content: space-between; gap: 24px; padding: 16px 4px 0; color: var(--muted-2); font-size: 10px; line-height: 1.55; }
footer p { max-width: 850px; margin: 0; }
footer p:last-child { text-align: right; }

.toast-stack { position: fixed; top: 82px; left: 50%; z-index: 100; display: grid; gap: 7px; width: min(430px, calc(100vw - 40px)); transform: translateX(-50%); pointer-events: none; }
.toast { padding: 10px 13px; border: 1px solid var(--border); border-radius: 8px; color: var(--text); background: rgba(19,34,49,.96); box-shadow: var(--shadow); font-size: 11px; line-height: 1.45; text-align: center; pointer-events: none; animation: toast-in .18s ease-out; }
.toast.error { border-color: rgba(255,89,100,.55); background: #29151b; }
.toast.success { border-color: rgba(33,200,150,.45); background: #10251f; }
@keyframes toast-in { from { transform: translateY(-8px); opacity: 0; } }
.loading-overlay { position: fixed; inset: 0; z-index: 120; display: flex; align-items: center; justify-content: center; gap: 10px; background: rgba(4,10,15,.58); backdrop-filter: blur(3px); }
.loading-overlay[hidden] { display: none; }
.loader { width: 20px; height: 20px; border: 2px solid rgba(255,255,255,.15); border-top-color: var(--cyan); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1380px) {
  .chart-wrap { height: 320px; }
  .volume-wrap { height: 100px; }
  .index-wrap { height: 100px; }
  .market-strip { grid-template-columns: 1.45fr repeat(4, minmax(140px, .7fr)); }
}

@media (min-width: 1900px) {
  .chart-wrap { height: 350px; }
  .volume-wrap { height: 115px; }
  .index-wrap { height: 115px; }
}
