/* ============ 基础 ============ */
:root {
  --bg: #0a0d12;
  --panel: #11161d;
  --panel-2: #161c25;
  --panel-3: #1b222c;
  --line: #212a36;
  --line-soft: #1a222c;
  --text: #e9eef5;
  --dim: #8895a7;
  --dim-2: #5d6878;
  --accent: #4c8dff;
  --accent-soft: rgba(76, 141, 255, .13);
  --up: #f6465d;
  --down: #2ebd85;
  --warn: #f0b90b;
  --radius: 4px;
  --shadow: 0 8px 30px rgba(0, 0, 0, .45);
}

body[data-scheme="intl"] { --up: #0ecb81; --down: #f6465d; }

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", Roboto, sans-serif;
  font-size: 13px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button, input, select { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }

.num, .mono {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

.up { color: var(--up) !important; }
.down { color: var(--down) !important; }
.dim { color: var(--dim); }
.dim2 { color: var(--dim-2); }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2a3441; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #3a4655; }

/* ============ 顶栏 ============ */
.topbar {
  height: 52px;
  flex: 0 0 52px;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 50;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: .2px;
}

.brand-mark {
  width: 24px; height: 24px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #4c8dff, #2f6fe0);
  border-radius: 6px;
  font-size: 14px;
  font-weight: 800;
  color: #fff;
}

.nav { display: flex; gap: 4px; }

.nav a {
  padding: 6px 13px;
  border-radius: var(--radius);
  color: var(--dim);
  font-weight: 500;
  white-space: nowrap;
  transition: color .15s, background .15s;
}

.nav a:hover { color: var(--text); background: var(--panel-3); }
.nav a.active { color: var(--text); background: var(--panel-3); }

.top-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px 5px 6px;
  border-radius: 20px;
  background: var(--panel-3);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: border-color .15s;
}
.user-chip:hover { border-color: #33404f; }

.avatar {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4c8dff, #7d5cff);
  display: grid; place-items: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
}

/* ============ 通用组件 ============ */
.btn {
  height: 30px;
  padding: 0 14px;
  border-radius: var(--radius);
  background: var(--panel-3);
  color: var(--text);
  border: 1px solid var(--line);
  font-weight: 500;
  transition: background .15s, border-color .15s, opacity .15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}
.btn:hover { background: #232c38; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: #3d7ef0; }

.btn-buy { background: var(--up); border-color: var(--up); color: #fff; }
.btn-buy:hover { filter: brightness(1.08); }
.btn-sell { background: var(--down); border-color: var(--down); color: #fff; }
.btn-sell:hover { filter: brightness(1.08); }

.btn-sm { height: 24px; padding: 0 9px; font-size: 12px; }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--panel-3); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-hd {
  height: 38px;
  flex: 0 0 38px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line-soft);
  font-weight: 600;
  font-size: 12.5px;
  color: var(--text);
}
.panel-hd .spacer { flex: 1; }
.panel-bd { flex: 1; min-height: 0; overflow: auto; }

.tabs { display: flex; gap: 2px; }
.tabs button {
  padding: 4px 10px;
  font-size: 12px;
  color: var(--dim);
  border-radius: var(--radius);
  transition: color .12s, background .12s;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--accent); background: var(--accent-soft); }
.tabs.underline { gap: 18px; }
.tabs.underline button {
  padding: 0 0 9px;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  font-weight: 500;
}
.tabs.underline button.active {
  color: var(--text);
  background: none;
  border-bottom-color: var(--accent);
}

.empty {
  padding: 36px 16px;
  text-align: center;
  color: var(--dim-2);
  font-size: 12.5px;
}

/* ============ 表格 ============ */
table.grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
table.grid th {
  position: sticky;
  top: 0;
  background: var(--panel);
  color: var(--dim);
  font-weight: 500;
  text-align: right;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
  z-index: 2;
}
table.grid th:first-child, table.grid td:first-child { text-align: left; }
table.grid td {
  padding: 10px 12px;
  text-align: right;
  border-bottom: 1px solid var(--line-soft);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
table.grid tbody tr { transition: background .12s; }
table.grid tbody tr:hover { background: var(--panel-2); }
table.grid tbody tr.clickable { cursor: pointer; }

/* ============ 行情页 ============ */
.app {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.app.trade-mode { overflow: hidden; }

.page {
  padding: 16px;
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px 16px;
}
.stat-card .k { color: var(--dim); font-size: 12px; margin-bottom: 6px; }
.stat-card .v { font-size: 20px; font-weight: 650; letter-spacing: -.3px; font-variant-numeric: tabular-nums; }

.coin-icon {
  width: 22px; height: 22px;
  border-radius: 50%;
  display: inline-grid; place-items: center;
  font-size: 10px; font-weight: 700;
  color: #fff;
  flex: 0 0 22px;
}

.pair-cell { display: flex; align-items: center; gap: 9px; }
.pair-cell .sym { font-weight: 600; }
.pair-cell .sym i { font-style: normal; color: var(--dim); font-weight: 400; }

/* 涨跌幅热力格 */
.pct-heat {
  position: relative;
  width: 108px;
  height: 22px;
  margin-left: auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
.pct-heat .fill {
  position: absolute;
  right: 0;
  top: 1px;
  bottom: 1px;
  border-radius: 2px;
  opacity: .13;
}
.pct-heat b {
  position: relative;
  padding-right: 7px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* ============ 交易页 ============ */
.app.trade-mode { overflow: hidden; }

.trade-layout {
  height: 100%;
  display: grid;
  grid-template-columns: 258px minmax(0, 1fr) 302px;
  gap: 8px;
  padding: 8px;
}

.col-left, .col-center, .col-right {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  min-width: 0;
}

.col-left .pairs { flex: 0 0 auto; }
.col-left .book { flex: 1 1 auto; }

.col-center .head { flex: 0 0 auto; }
.col-center .chart-panel { flex: 1 1 auto; min-height: 200px; }
.col-center .bottom-panel { flex: 0 0 208px; }

/* 币种标题 */
.sym-head { padding: 12px 14px; display: flex; align-items: flex-start; gap: 18px; flex-wrap: wrap; }
.sym-head .name { font-size: 17px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.sym-head .name span { color: var(--dim); font-weight: 500; font-size: 12px; }
.sym-head .big-price { font-size: 25px; font-weight: 650; letter-spacing: -.5px; line-height: 1.15; }
.sym-head .meta-grid {
  display: grid;
  grid-template-columns: repeat(4, auto);
  gap: 2px 26px;
  margin-left: auto;
}
.sym-head .meta-grid div { font-size: 12px; color: var(--dim); }
.sym-head .meta-grid b {
  display: block;
  color: var(--text);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
}

/* 交易对列表 */
.pair-list { padding: 4px 0; }
.pair-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  cursor: pointer;
  transition: background .12s;
}
.pair-row:hover { background: var(--panel-2); }
.pair-row.active { background: var(--panel-3); }
.pair-row .n { flex: 1; font-weight: 500; }
.pair-row .n i { font-style: normal; color: var(--dim-2); font-size: 11px; }
.pair-row .p { text-align: right; font-variant-numeric: tabular-nums; }
.pair-row .c { width: 52px; text-align: right; font-size: 12px; font-variant-numeric: tabular-nums; }

/* 盘口 */
.book-head {
  display: flex;
  justify-content: space-between;
  padding: 5px 12px;
  color: var(--dim-2);
  font-size: 11px;
  border-bottom: 1px solid var(--line-soft);
}
.book-side { position: relative; }

/* 买卖两侧等分剩余空间；卖盘贴底对齐，保证最优价始终紧邻中间价 */
#bookAsks, #bookBids {
  flex: 1 1 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
#bookAsks { justify-content: flex-end; }
#bookAsks .book-row, #bookBids .book-row { flex: 0 0 21px; }
.book-row {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr 0.85fr;
  gap: 4px;
  padding: 2px 12px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  height: 21px;
  align-items: center;
}
.book-row:hover { background: var(--panel-3); }
.book-row .bar {
  position: absolute;
  top: 0; bottom: 0;
  right: 0;
  opacity: .085;
  pointer-events: none;
}
.book-row .bar.up-bg { background: var(--up); }
.book-row .bar.down-bg { background: var(--down); }
.book-row .px { text-align: left; position: relative; }
.book-row .amt, .book-row .sum { text-align: right; color: var(--dim); position: relative; }

.mid-price {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-top: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  background: var(--panel-2);
}
.mid-price .lp { font-size: 16px; font-weight: 650; font-variant-numeric: tabular-nums; }
.mid-price .eq { color: var(--dim-2); font-size: 12px; margin-left: auto; }

/* 逐笔 */
.tape-row {
  display: grid;
  grid-template-columns: 1fr 1fr 0.8fr;
  padding: 3px 12px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.tape-row .t { text-align: right; color: var(--dim-2); }
.tape-row .a { text-align: right; color: var(--dim); }

/* 图表 */
.chart-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line-soft);
  flex: 0 0 auto;
}
.chart-toolbar .tf {
  padding: 3px 9px;
  font-size: 12px;
  border-radius: var(--radius);
  color: var(--dim);
}
.chart-toolbar .tf:hover { color: var(--text); }
.chart-toolbar .tf.active { color: var(--accent); background: var(--accent-soft); }

.chart-box { flex: 1; min-height: 0; position: relative; }
.chart-box canvas { display: block; width: 100%; height: 100%; }

/* 下单面板 */
.order-form { padding: 0 12px 12px; }
.side-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 10px 0;
}
.side-tabs button {
  height: 32px;
  border-radius: var(--radius);
  background: var(--panel-3);
  color: var(--dim);
  font-weight: 600;
  transition: all .15s;
}
.side-tabs button.active.buy { background: var(--up); color: #fff; }
.side-tabs button.active.sell { background: var(--down); color: #fff; }

.type-tabs { display: flex; gap: 16px; margin-bottom: 12px; }
.type-tabs button {
  font-size: 12.5px;
  color: var(--dim);
  padding-bottom: 6px;
  border-bottom: 1.5px solid transparent;
  font-weight: 500;
}
.type-tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

.field {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: var(--radius);
  padding: 6px 10px;
  margin-bottom: 9px;
  display: flex;
  align-items: center;
  transition: border-color .15s;
}
.field:focus-within { border-color: #3a4a5e; }
.field.disabled { opacity: .5; }
.field .lbl {
  font-size: 11px;
  color: var(--dim-2);
  width: 52px;
  flex: 0 0 52px;
}
.field input {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  outline: none;
  text-align: right;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
}
.field .unit {
  color: var(--dim);
  font-size: 11.5px;
  margin-left: 7px;
  min-width: 30px;
  text-align: right;
}

.pct-row { display: flex; gap: 5px; margin: 4px 0 10px; }
.pct-row button {
  flex: 1;
  height: 22px;
  font-size: 11px;
  border-radius: 2px;
  background: var(--panel-3);
  color: var(--dim);
  border: 1px solid transparent;
  transition: all .12s;
}
.pct-row button:hover { color: var(--text); border-color: var(--line); }

.avail-row {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--dim);
  margin-bottom: 10px;
}
.avail-row b { font-weight: 500; color: var(--text); font-variant-numeric: tabular-nums; }

.submit-btn {
  width: 100%;
  height: 38px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 13.5px;
  color: #fff;
}

/* 我的委托（右栏） */
.mini-order {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.mini-order .info { flex: 1; min-width: 0; }
.mini-order .info div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-order .side-tag {
  font-size: 10.5px;
  padding: 1px 5px;
  border-radius: 2px;
  font-weight: 600;
}
.mini-order .side-tag.buy { background: rgba(246, 70, 93, .16); color: var(--up); }
.mini-order .side-tag.sell { background: rgba(46, 189, 133, .16); color: var(--down); }
.order-x {
  width: 22px; height: 22px;
  border-radius: 3px;
  color: var(--dim-2);
  display: grid; place-items: center;
  font-size: 14px;
  line-height: 1;
}
.order-x:hover { background: var(--panel-3); color: var(--text); }

/* ============ 资产页 ============ */
.balance-total {
  padding: 18px 20px;
  display: flex;
  align-items: flex-end;
  gap: 14px;
  border-bottom: 1px solid var(--line-soft);
}
.balance-total .label { color: var(--dim); font-size: 12px; margin-bottom: 4px; }
.balance-total .amount { font-size: 30px; font-weight: 680; letter-spacing: -1px; font-variant-numeric: tabular-nums; }
.balance-total .sub { color: var(--dim); font-size: 12px; }

.asset-cell { display: flex; align-items: center; gap: 10px; }
.asset-cell .nm { font-weight: 600; }
.asset-cell .nm i { font-style: normal; color: var(--dim-2); font-weight: 400; font-size: 11px; display: block; }

/* ============ 登录注册 ============ */
.auth-wrap {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(900px 500px at 20% 0%, rgba(76, 141, 255, .10), transparent 60%),
    radial-gradient(700px 400px at 90% 100%, rgba(125, 92, 255, .08), transparent 60%);
}
.auth-card {
  width: 100%;
  max-width: 372px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.auth-card h1 { font-size: 19px; margin: 0 0 6px; }
.auth-card p.sub { color: var(--dim); font-size: 12.5px; margin: 0 0 22px; }
.auth-card .field { padding: 9px 12px; }
.auth-card .field input { text-align: left; }
.auth-card .submit-btn { margin-top: 6px; }
.auth-alt { text-align: center; margin-top: 16px; font-size: 12.5px; color: var(--dim); }
.auth-alt a { color: var(--accent); }
.form-err {
  background: rgba(246, 70, 93, .1);
  border: 1px solid rgba(246, 70, 93, .3);
  color: #ff7b8a;
  padding: 8px 11px;
  border-radius: var(--radius);
  font-size: 12.5px;
  margin-bottom: 12px;
}

/* ============ 后台 ============ */
.admin-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 500;
}
.badge.ok { background: rgba(46, 189, 133, .14); color: var(--down); }
.badge.off { background: rgba(138, 149, 167, .14); color: var(--dim); }
.badge.admin { background: var(--accent-soft); color: var(--accent); }

/* ============ Toast / Modal ============ */
.toast-wrap {
  position: fixed;
  top: 62px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 999;
  pointer-events: none;
}
.toast {
  padding: 9px 15px;
  border-radius: 5px;
  background: var(--panel-3);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 12.5px;
  animation: toastIn .18s ease-out;
  max-width: 460px;
}
.toast.err { border-color: rgba(246, 70, 93, .45); color: #ff8b98; }
.toast.ok { border-color: rgba(46, 189, 133, .45); color: #4fd8a4; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  display: grid;
  place-items: center;
  z-index: 900;
  animation: fadeIn .15s;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: 372px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  box-shadow: var(--shadow);
}
.modal h3 { margin: 0 0 4px; font-size: 15px; }
.modal .hint { color: var(--dim); font-size: 12px; margin-bottom: 16px; }
.modal .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* ============ 响应式 ============ */
@media (max-width: 1180px) {
  .trade-layout { grid-template-columns: 220px minmax(0, 1fr) 282px; }
  .sym-head .meta-grid { display: none; }
}

@media (max-width: 980px) {
  body { overflow: auto; }
  .app.trade-mode { overflow: auto; height: auto; }
  .topbar { gap: 10px; padding: 0 12px; }
  .nav { gap: 1px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { padding: 6px 7px; font-size: 12.5px; }
  .top-right { gap: 6px; }
  .trade-layout {
    grid-template-columns: 1fr;
    height: auto;
  }
  .col-left .pairs, .col-left .book,
  .col-center .chart-panel, .col-center .bottom-panel { flex: none; }
  .col-center .chart-panel { height: 340px; }
  .col-left .book { height: 320px; }
  .stat-row, .admin-grid { grid-template-columns: repeat(2, 1fr); }
  .nav a { padding: 6px 9px; }
  .brand-text { display: none; }
}
