/* ==========================================================================
   交易终端 · 深色扁平布局
   ========================================================================== */
body.terminal-page { background: #050506; }

.terminal {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  height: calc(100vh - var(--header-h));
  min-height: 640px;
  background: var(--line);
  gap: 1px;
}
.terminal.rail-hidden { grid-template-columns: 0 minmax(0, 1fr); }
.terminal.rail-hidden .mkt-rail { display: none; }

/* -------------------------------- 左侧列表 -------------------------------- */
.mkt-rail {
  background: #070708;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.rail-top { padding: 10px 10px 0; flex-shrink: 0; }
.rail-title { font-size: 13px; font-weight: 600; padding: 2px 4px 8px; display: block; }
.rail-search {
  position: relative;
  display: flex;
  align-items: center;
  height: 30px;
  border-radius: 7px;
  background: #111113;
  border: 1px solid #1e1e22;
  padding: 0 8px;
  gap: 6px;
  color: var(--text-3);
}
.rail-search svg { width: 13px; height: 13px; flex-shrink: 0; }
.rail-search input {
  width: 100%;
  background: transparent;
  border: 0;
  outline: none;
  color: #fff;
  font-size: 12px;
}
.rail-search input::placeholder { color: var(--text-4); }
.rail-cols {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 76px 66px;
  gap: 4px;
  padding: 11px 6px 6px;
  font-size: 10.5px;
  color: var(--text-4);
}
.rail-cols span:nth-child(2), .rail-cols span:nth-child(3) { text-align: right; }
.rail-list { flex: 1; overflow-y: auto; padding: 0 4px 10px; }
.rail-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 76px 66px;
  align-items: center;
  gap: 4px;
  width: 100%;
  height: 42px;
  padding: 0 6px;
  border-radius: 6px;
  text-align: left;
  border-left: 2px solid transparent;
}
.rail-item:hover { background: rgba(255, 255, 255, 0.05); }
.rail-item.active { background: rgba(255, 255, 255, 0.075); border-left-color: #fff; }
.ri-sym { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.ri-sym b { font-size: 12.5px; font-weight: 600; letter-spacing: -0.01em; }
.ri-sym i { font-style: normal; font-size: 10px; color: var(--text-4); }
.ri-price { text-align: right; font-size: 12px; }
.ri-ch { text-align: right; font-size: 11.5px; }

/* -------------------------------- 主区域 -------------------------------- */
.terminal-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #050506; }

.symbol-bar {
  display: flex;
  align-items: center;
  gap: 22px;
  height: 64px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: #070708;
  flex-shrink: 0;
  overflow: hidden;
}
.rail-toggle { display: none; width: 30px; height: 30px; color: var(--text-2); border-radius: 6px; }
.rail-toggle svg { width: 18px; height: 18px; }
.rail-toggle:hover { background: rgba(255, 255, 255, 0.07); color: #fff; }

.sb-pair { display: flex; align-items: center; gap: 9px; flex-shrink: 0; }
.sb-pair .coin-ico { width: 32px; height: 32px; font-size: 12px; }
.sb-name { display: flex; align-items: center; gap: 3px; font-size: 15px; line-height: 1.2; }
.sb-name b { font-weight: 680; letter-spacing: -0.01em; }
.sb-quote { color: var(--text-3); font-size: 13px; }
.star-btn { color: var(--text-4); font-size: 14px; width: 18px; height: 18px; line-height: 1; margin-left: 2px; }
.star-btn.on { color: #f5c542; }
.star-btn:hover { color: #f5c542; }
.sb-sub { font-size: 10.5px; color: var(--text-3); margin-top: 1px; white-space: nowrap; }

.sb-price-wrap { flex-shrink: 0; }
.sb-price { font-size: 21px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.15; }
.sb-price-sub { display: flex; align-items: center; gap: 7px; margin-top: 2px; font-size: 10.5px; color: var(--text-3); }
.sb-price-sub .tag { height: 18px; padding: 0 6px; font-size: 10.5px; }

.sb-stats { display: flex; gap: 22px; margin-left: 6px; }
.sb-stat { display: flex; flex-direction: column; gap: 2px; }
.sb-stat span { font-size: 10.5px; color: var(--text-3); white-space: nowrap; }
.sb-stat b { font-size: 11.5px; font-weight: 500; white-space: nowrap; }
.sb-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.sb-actions .pill { height: 24px; font-size: 11px; }
.sb-actions .icon-btn { width: 30px; height: 30px; }
.sb-actions svg { width: 16px; height: 16px; }

/* --------------------------------- 网格 --------------------------------- */
.trade-grid {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 308px;
  grid-template-rows: minmax(280px, 1fr) 356px;
  grid-template-areas:
    "chart rail"
    "lower rail";
  gap: 1px;
  min-height: 0;
  background: var(--line);
}
.panel { background: #070708; min-width: 0; min-height: 0; }
.chart-panel { grid-area: chart; display: flex; flex-direction: column; overflow: hidden; }
.orders-panel {
  grid-area: lower;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* 占用下半部分右侧（下单面板贴左，订单面板贴右） */
  grid-column: 1;
  position: relative;
}
.form-panel {
  grid-area: lower;
  display: flex;
  flex-direction: column;
  width: 372px;
  z-index: 2;
  border-right: 1px solid var(--line);
  border-top: 1px solid var(--line);
  align-self: start;
  justify-self: start;
  height: 356px;
  margin-top: -1px;
  background: #070708;
}
.orders-panel { padding-left: 373px; border-top: 1px solid var(--line); }
.right-rail {
  grid-area: rail;
  display: grid;
  grid-template-rows: minmax(240px, 1fr) 270px;
  gap: 1px;
  min-height: 0;
  background: var(--line);
}

/* --------------------------------- K 线 --------------------------------- */
.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 38px;
  padding: 0 10px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  gap: 10px;
}
.tf-tabs { display: flex; gap: 2px; }
.tf-tabs button {
  height: 25px;
  min-width: 32px;
  padding: 0 7px;
  border-radius: 5px;
  font-size: 11.5px;
  color: var(--text-3);
  font-weight: 500;
}
.tf-tabs button:hover { color: #fff; background: rgba(255, 255, 255, 0.06); }
.tf-tabs button.active { color: #fff; background: #222226; }
.chart-tools { display: flex; gap: 2px; }
.chart-tool { padding: 4px 8px; font-size: 11.5px; color: var(--text-3); border-radius: 5px; }
.chart-tool:hover { color: #fff; background: rgba(255, 255, 255, 0.06); }

.chart-body { position: relative; flex: 1; min-height: 0; }
#kline { width: 100%; height: 100%; cursor: crosshair; }
.chart-legend {
  position: absolute;
  left: 10px;
  top: 7px;
  display: flex;
  flex-wrap: wrap;
  gap: 11px;
  font-size: 10.5px;
  color: var(--text-3);
  pointer-events: none;
  z-index: 2;
  max-width: calc(100% - 80px);
}
.chart-legend b { margin-left: 4px; color: #e6e6e9; font-weight: 500; }
.chart-legend b.up { color: var(--up); }
.chart-legend b.down { color: var(--down); }
.chart-legend #lgTf { color: var(--text-4); }
.chart-tip {
  position: absolute;
  z-index: 5;
  display: none;
  min-width: 148px;
  padding: 9px 11px;
  background: rgba(20, 20, 23, 0.97);
  border: 1px solid #2e2e34;
  border-radius: 9px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.6);
  font-size: 11px;
  color: var(--text-2);
  pointer-events: none;
  line-height: 1.75;
  font-family: var(--mono);
  backdrop-filter: blur(6px);
}
.chart-tip.show { display: block; }
.chart-tip .r { display: flex; justify-content: space-between; gap: 16px; }
.chart-tip .r b { color: #fff; font-weight: 500; }
.chart-tip .tt { margin-bottom: 5px; color: var(--text-3); font-size: 10.5px; font-family: var(--font); }
.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 12px;
  color: var(--text-3);
}

.chart-panel.fullscreen {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: #050506;
  height: auto;
  width: auto;
}
.chart-panel.fullscreen .chart-body { height: calc(100vh - 38px); }

/* ------------------------------- 右侧订单簿 ------------------------------- */
.book-panel { display: flex; flex-direction: column; overflow: hidden; }
.book-head { height: 36px; padding: 0 10px; }
.book-head .panel-title { font-size: 12.5px; }
.mini-select {
  margin-left: auto;
  height: 24px;
  padding: 0 22px 0 8px;
  border-radius: 5px;
  background: #121215;
  border: 1px solid #232327;
  color: var(--text-2);
  font-size: 11px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%239b9b9f' stroke-width='2.6'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  cursor: pointer;
}
.book-cols, .trades-head {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 3px 10px 4px;
  font-size: 10px;
  color: var(--text-4);
  flex-shrink: 0;
}
.book-cols span:last-child, .trades-head span:last-child { text-align: right; }
.book-asks, .book-bids {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  overflow: hidden;
  flex: 1 1 0;
  min-height: 0;
}
.book-bids { justify-content: flex-start; }
.book-row {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  height: 21px;
  align-items: center;
  padding: 0 10px;
  font-size: 11px;
  cursor: pointer;
  overflow: hidden;
}
.book-row:hover { background: rgba(255, 255, 255, 0.06); }
.book-row .bar {
  position: absolute;
  right: 0;
  top: 1px;
  bottom: 1px;
  border-radius: 1px 0 0 1px;
  opacity: 0.13;
  pointer-events: none;
}
.book-row .p { position: relative; color: var(--up); }
.book-row.ask .p { color: var(--down); }
.book-row .s { position: relative; text-align: right; color: #ccc; }
.book-row .bar.up { background: var(--up); }
.book-row .bar.down { background: var(--down); }

.book-mid {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 30px;
  padding: 0 10px;
  flex-shrink: 0;
  border-top: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
}
.book-last { font-size: 14px; font-weight: 650; }
.book-spread { font-size: 10.5px; color: var(--text-3); }
.book-arrow { margin-left: auto; color: var(--up); }
.book-arrow.down { color: var(--down); transform: rotate(180deg); }
.book-foot {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 10px;
  font-size: 10px;
  color: var(--text-3);
  border-top: 1px solid var(--line-soft);
  flex-shrink: 0;
}

/* --------------------------------- 成交 --------------------------------- */
.trades-panel { display: flex; flex-direction: column; overflow: hidden; }
.trades-panel .panel-head { height: 34px; padding: 0 10px; }
.trades-panel .panel-title { font-size: 12.5px; }
.trades-head { grid-template-columns: 1fr 1fr 58px; }
.trades-list { flex: 1; overflow-y: auto; }
.trade-row {
  display: grid;
  grid-template-columns: 1fr 1fr 58px;
  gap: 6px;
  height: 20px;
  align-items: center;
  padding: 0 10px;
  font-size: 10.5px;
}
.trade-row:hover { background: rgba(255, 255, 255, 0.045); }
.trade-row .tp { color: var(--up); }
.trade-row .tp.down { color: var(--down); }
.trade-row .ta { text-align: right; color: #ccc; }
.trade-row .tt { text-align: right; color: var(--text-4); }

/* -------------------------------- 下单面板 -------------------------------- */
.form-panel { overflow: hidden; }
.form-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 38px;
  padding: 0 14px 0 10px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.form-head .tabs { border: 0; gap: 16px; }
.form-head .tab { padding: 9px 0; font-size: 12px; }
.form-body {
  padding: 9px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  overflow-y: auto;
}
.side-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 3px;
  background: #101012;
  border-radius: 8px;
  border: 1px solid #1c1c20;
  flex-shrink: 0;
}
.side-switch .side {
  height: 30px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-2);
  transition: 0.15s;
}
.side-switch .side.buy.active { background: var(--up); color: #fff; }
.side-switch .side.sell.active { background: var(--down); color: #fff; }
.side-switch .side:not(.active):hover { color: #fff; background: rgba(255, 255, 255, 0.05); }

.otype { display: flex; gap: 16px; padding: 0 2px; flex-shrink: 0; }
.otype button {
  position: relative;
  padding: 2px 0 5px;
  font-size: 11.5px;
  color: var(--text-3);
}
.otype button:hover { color: #fff; }
.otype button.active { color: #fff; }
.otype button.active::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 2px; border-radius: 2px; background: #fff;
}

.of-field { display: flex; flex-direction: column; gap: 4px; flex-shrink: 0; }
.of-label { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-3); }
.of-input-wrap { position: relative; }
.of-input {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  background: #0e0e10;
  border: 1px solid #232327;
  border-radius: 7px;
  color: #fff;
  font-size: 13px;
  outline: none;
}
.of-input::placeholder { color: var(--text-4); }
.of-input:hover { border-color: #33333a; }
.of-input:focus { border-color: #6b6b74; background: #121215; }
.of-input:disabled { color: var(--text-3); background: #0b0b0d; }
.of-input-wrap .of-input { padding-right: 28px; }
.steppers {
  position: absolute;
  right: 2px; top: 2px; bottom: 2px;
  width: 24px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.steppers button {
  flex: 1;
  font-size: 7px;
  color: var(--text-3);
  border-radius: 4px;
  line-height: 1;
}
.steppers button:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }

.avail-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10.5px;
  color: var(--text-3);
  gap: 8px;
}
.avail-row b { color: #d8d8dc; font-weight: 500; }
.avail-row button { font-size: 10.5px; color: #fff; }
.avail-row button:hover { text-decoration: underline; }

.pct-wrap { flex-shrink: 0; }
.pct {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 3px;
  border-radius: 99px;
  background: #26262b;
  outline: none;
  cursor: pointer;
  --fill: 0%;
  background-image: linear-gradient(90deg, var(--fill-color, var(--up)) 0 var(--fill), transparent var(--fill) 100%);
}
.pct::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 11px; height: 11px;
  border-radius: 50%;
  background: #fff;
  border: 0;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
  cursor: pointer;
}
.pct::-moz-range-thumb { width: 11px; height: 11px; border: 0; border-radius: 50%; background: #fff; cursor: pointer; }
.pct-marks { display: flex; justify-content: space-between; padding: 4px 0 0; font-size: 9.5px; color: var(--text-4); }

.of-rows { display: flex; flex-direction: column; gap: 3px; font-size: 10.5px; color: var(--text-3); flex-shrink: 0; }
.of-row { display: flex; justify-content: space-between; gap: 10px; }
.of-row b { color: #e8e8ea; font-weight: 500; }

.of-submit {
  height: 36px;
  border-radius: 7px;
  font-size: 13.5px;
  font-weight: 650;
  color: #fff;
  flex-shrink: 0;
  transition: 0.15s;
  margin-top: 1px;
}
.of-submit.buy { background: var(--up); }
.of-submit.buy:hover { background: #00a98b; }
.of-submit.sell { background: var(--down); }
.of-submit.sell:hover { background: #e03e52; }
.of-submit[disabled] { opacity: 0.5; cursor: not-allowed; }
.of-submit:active { transform: translateY(1px); }

/* -------------------------------- 订单列表 -------------------------------- */
.orders-head {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 38px;
  padding: 0 10px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.orders-head .tabs { border: 0; gap: 18px; flex: 1; min-width: 0; overflow-x: auto; }
.orders-head .tab { padding: 10px 0; font-size: 12px; }
.orders-head .tab .count { font-size: 10px; }
.orders-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.orders-actions .btn { height: 26px; font-size: 11.5px; padding: 0 9px; border-radius: 6px; }
.orders-actions .icon-btn { width: 26px; height: 26px; }
.orders-actions svg { width: 14px; height: 14px; }

.orders-body { flex: 1; overflow: auto; }
.ord-table { width: 100%; border-collapse: collapse; }
.ord-table th {
  position: sticky; top: 0; z-index: 2;
  padding: 6px 8px;
  font-size: 10px;
  font-weight: 400;
  color: var(--text-4);
  text-align: left;
  background: #070708;
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
}
.ord-table td {
  padding: 7px 8px;
  font-size: 10.5px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.035);
  white-space: nowrap;
  color: #d5d5d8;
}
.ord-table tbody tr:hover { background: rgba(255, 255, 255, 0.035); }
.ord-table .right { text-align: right; }
.ord-table .sym { color: #fff; font-weight: 550; }
.ord-table .side-buy { color: var(--up); }
.ord-table .side-sell { color: var(--down); }
.ord-table .cancel { color: #fff; font-size: 10.5px; padding: 2px 6px; border-radius: 4px; background: rgba(255, 255, 255, 0.08); }
.ord-table .cancel:hover { background: rgba(255, 255, 255, 0.16); }
.ord-table .status { font-size: 10px; }
.ord-table .status.open { color: #f5c542; }
.ord-table .status.filled { color: var(--up); }
.ord-table .status.canceled { color: var(--text-3); }
.ord-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; height: 100%; min-height: 130px; color: var(--text-4); font-size: 11.5px;
}
.ord-empty svg { width: 30px; height: 30px; opacity: 0.5; }
.ord-empty a { color: var(--text-2); text-decoration: underline; text-underline-offset: 2px; }

/* 资产 tab */
.asset-tab { display: flex; flex-direction: column; height: 100%; }
.asset-total {
  display: flex; align-items: baseline; gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 11px; color: var(--text-3);
}
.asset-total b { font-size: 17px; color: #fff; font-weight: 650; }
.asset-list { flex: 1; overflow: auto; }
.asset-row {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr 1fr;
  gap: 8px;
  padding: 7px 12px;
  font-size: 10.5px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}
.asset-row.head { color: var(--text-4); font-size: 10px; position: sticky; top: 0; background: #070708; }
.asset-row span:not(:first-child) { text-align: right; }
.asset-row .an { display: flex; align-items: center; gap: 7px; }
.asset-row .an .dotc { width: 16px; height: 16px; border-radius: 50%; display: grid; place-items: center; font-size: 8px; font-weight: 700; background: #26262b; }

/* -------------------------------- 响应式 -------------------------------- */
@media (max-width: 1400px) {
  .sb-stats { gap: 16px; }
  .form-panel { width: 340px; }
  .orders-panel { padding-left: 341px; }
}
@media (max-width: 1180px) {
  .terminal { grid-template-columns: 200px minmax(0, 1fr); }
  .trade-grid { grid-template-columns: minmax(0, 1fr) 280px; }
  .sb-stats .sb-stat:nth-child(3), .sb-stats .sb-stat:nth-child(4) { display: none; }
  .form-panel { width: 320px; }
  .orders-panel { padding-left: 321px; }
}
@media (max-width: 960px) {
  body.terminal-page { overflow: auto; }
  .terminal { grid-template-columns: 1fr; height: auto; min-height: 0; }
  .mkt-rail { display: none; }
  .terminal.rail-open .mkt-rail {
    display: flex;
    position: fixed;
    top: var(--header-h);
    bottom: 0;
    left: 0;
    width: min(78%, 320px);
    z-index: 120;
    background: #070708;
    border-right: 1px solid var(--line);
    box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.55);
  }
  .rail-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .symbol-bar { height: auto; flex-wrap: wrap; padding: 10px 12px; gap: 10px 14px; }
  .sb-stats { display: none; }
  .sb-actions .pill { display: none; }
  .sb-price { font-size: 19px; }
  .trade-grid {
    display: flex;
    flex-direction: column;
    height: auto;
    gap: 1px;
  }
  .chart-panel { height: 340px; flex: none; }
  .form-panel { width: 100%; height: auto; border-right: 0; order: 2; }
  .form-body { overflow: visible; }
  .orders-panel { padding-left: 0; order: 3; height: 340px; border-top: 0; }
  .right-rail { display: flex; flex-direction: column; order: 4; }
  .book-panel { height: 380px; }
  .trades-panel { height: 260px; }
  .chart-legend { gap: 8px; font-size: 10px; }
  .chart-legend span:nth-child(n + 6) { display: none; }
}
@media (max-width: 520px) {
  .chart-panel { height: 290px; }
  .chart-tool[data-chart-tool="深度"], .chart-tool[data-chart-tool="设置"] { display: none; }
}

/* 中等宽度：折叠左侧行情栏，避免下单区与委托区被压缩 */
@media (max-width: 1280px) {
  .terminal { grid-template-columns: minmax(0, 1fr); }
  .mkt-rail { display: none; }
  .terminal.rail-open .mkt-rail {
    display: flex;
    position: fixed;
    top: var(--header-h);
    bottom: 0;
    left: 0;
    width: min(78%, 320px);
    z-index: 120;
    background: #070708;
    border-right: 1px solid var(--line);
    box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.55);
  }
  .rail-toggle { display: inline-flex; align-items: center; justify-content: center; }
}
