:root {
  --bg: #0b0e11;
  --bg-2: #131722;
  --panel: #1c2030;
  --panel-2: #23283a;
  --border: #2a2f42;
  --text: #eaecef;
  --text-dim: #848e9c;
  --orange: #f0b90b;
  --orange-dark: #d4a30a;
  --orange-glow: rgba(240, 185, 11, 0.14);
  --green: #0ecb81;
  --red: #f6465d;
  --blue: #1e88e5;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

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

/* 滚动条 */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: #2a2f42; border-radius: 3px; }
::-webkit-scrollbar-track { background: transparent; }

/* ============ 顶栏 ============ */
.topbar {
  height: 56px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { width: 34px; height: 34px; border-radius: 50%; }
.brand .name { font-weight: 700; font-size: 18px; letter-spacing: 0.5px; }
.brand .name .accent { color: var(--orange); }
.brand .sub { font-size: 11px; color: var(--text-dim); margin-top: -2px; }

.topbar-nav { display: flex; gap: 4px; margin-left: 32px; flex: 1; }
.topbar-nav a {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 14px;
  color: var(--text-dim);
  transition: all .15s;
}
.topbar-nav a:hover { color: var(--text); }
.topbar-nav a.active { color: var(--orange); font-weight: 600; }

.topbar-right { display: flex; align-items: center; gap: 10px; }
.btn {
  padding: 7px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  transition: all .15s;
}
.btn:hover { background: var(--panel-2); }
.btn-primary {
  background: var(--orange);
  color: #0b0e11;
  border: none;
  font-weight: 700;
}
.btn-primary:hover { background: var(--orange-dark); }
.btn-ghost { background: transparent; }

/* ============ 布局 ============ */
.layout {
  display: grid;
  grid-template-columns: 210px 1fr 300px;
  gap: 0;
  height: calc(100vh - 56px);
  overflow: hidden;
}

.col { display: flex; flex-direction: column; min-height: 0; }
.col-border { border-right: 1px solid var(--border); }

/* 左侧交易对列表 */
.markets-panel { background: var(--bg-2); overflow-y: auto; }
.markets-header {
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.market-item {
  padding: 10px 14px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(42,47,66,.5);
  transition: background .12s;
}
.market-item:hover { background: var(--panel); }
.market-item.active { background: var(--orange-glow); border-left: 3px solid var(--orange); }
.market-item .pair { font-weight: 600; font-size: 13px; }
.market-item .pair .quote { color: var(--text-dim); font-weight: 400; }
.market-item .price { font-size: 12px; color: var(--green); text-align: right; }
.market-item .chg { font-size: 11px; margin-top: 2px; }
.up { color: var(--green); }
.down { color: var(--red); }

/* 中间 */
.center { padding: 0; }
.center-panel { overflow-y: auto; }
.pair-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  gap: 12px;
  background: var(--bg-2);
}
.pair-header .big { font-size: 20px; font-weight: 700; }
.pair-header .last-price { font-size: 20px; font-weight: 700; color: var(--green); }
.pair-header .chg-badge { font-size: 12px; padding: 2px 8px; border-radius: 4px; }

.chart-wrap { height: 280px; border-bottom: 1px solid var(--border); position: relative; background: var(--bg); }
#kline-chart { width: 100%; height: 100%; }

.trade-form {
  padding: 16px;
  background: var(--bg-2);
}
.tabs { display: flex; gap: 0; border-radius: 6px; overflow: hidden; border: 1px solid var(--border); margin-bottom: 14px; }
.tabs button { flex: 1; padding: 9px; font-size: 14px; font-weight: 600; border: none; background: var(--panel); color: var(--text-dim); transition: all .15s; }
.tabs button:hover { color: var(--text); }
.tabs button.buy-active { background: var(--green); color: #fff; }
.tabs button.sell-active { background: var(--red); color: #fff; }

.field { margin-bottom: 10px; }
.field label { font-size: 12px; color: var(--text-dim); display: block; margin-bottom: 4px; }
.field .input-wrap { position: relative; }
.field input {
  width: 100%;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border .15s;
}
.field input:focus { border-color: var(--orange); }
.field .unit { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-size: 12px; color: var(--text-dim); }

.total-line { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-dim); margin: 8px 0 14px; }
.total-line b { color: var(--text); font-size: 13px; }

/* 右侧订单簿 + 成交 */
.side-panel { background: var(--bg-2); }
.side-tabs { display: flex; border-bottom: 1px solid var(--border); }
.side-tabs button {
  flex: 1;
  padding: 10px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  border-bottom: 2px solid transparent;
}
.side-tabs button.active { color: var(--orange); border-bottom-color: var(--orange); }

.orderbook { flex: 1; overflow-y: auto; padding: 8px 14px; }
.ob-row { display: grid; grid-template-columns: 1fr 1fr 1fr; font-size: 12px; padding: 3px 0; font-variant-numeric: tabular-nums; }
.ob-row.head { color: var(--text-dim); font-size: 11px; }
.ob-row .p-bid { color: var(--green); }
.ob-row .p-ask { color: var(--red); }
.ob-row .amt { text-align: right; color: var(--text); }
.ob-mid { text-align: center; padding: 8px 0; font-size: 13px; }
.ob-mid .lp { font-size: 18px; font-weight: 700; }

/* 订单/成交表格 */
.table { width: 100%; font-size: 12px; border-collapse: collapse; }
.table th { color: var(--text-dim); font-weight: 500; text-align: right; padding: 6px 8px; font-size: 11px; }
.table td { text-align: right; padding: 6px 8px; font-variant-numeric: tabular-nums; }
.table td:first-child, .table th:first-child { text-align: left; }

.badge { font-size: 11px; padding: 1px 7px; border-radius: 4px; }
.badge-open { background: rgba(240,185,11,.15); color: var(--orange); }
.badge-filled { background: rgba(14,203,129,.15); color: var(--green); }
.badge-partial { background: rgba(30,136,229,.15); color: var(--blue); }
.badge-cancel { background: rgba(132,142,156,.15); color: var(--text-dim); }

/* 弹窗 */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-backdrop.show { display: flex; }
.modal {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
}
.modal h3 { font-size: 18px; margin-bottom: 16px; }

.toast {
  position: fixed;
  top: 70px;
  right: 20px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--orange);
  padding: 12px 18px;
  border-radius: 6px;
  font-size: 13px;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  animation: slideIn .25s ease;
  display: none;
}
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; height: auto; overflow: visible; }
  .col-border { border-right: none; }
}

/* ============ 钱包页（集成自 rcpu-wallet，非托管钱包） ============ */
.hidden { display: none !important; }

.wallet-wrap { max-width: 720px; margin: 0 auto; padding: 28px 16px; }
.center-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px 28px;
  text-align: center;
  margin-top: 20px;
}
.center-card h1 { font-size: 26px; margin: 16px 0 8px; }
.center-card h2 { font-size: 20px; margin-bottom: 12px; }
.big-logo { width: 72px; height: 72px; border-radius: 50%; }
.dim { color: var(--text-dim); font-size: 14px; }
.tiny { font-size: 12px; }
.btn-row { display: flex; gap: 12px; justify-content: center; margin-top: 20px; }

.mnemonic-box {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin: 16px 0;
  text-align: left;
}
.mnemonic-word { font-size: 13px; padding: 6px 8px; background: var(--panel-2); border-radius: 6px; }
.mnemonic-word .idx { color: var(--text-dim); margin-right: 6px; font-size: 11px; }

.input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.input:focus { border-color: var(--orange); }

.wallet-field { margin-bottom: 12px; text-align: left; }
.wallet-field label { font-size: 12px; color: var(--text-dim); display: block; margin-bottom: 4px; }

.balance-card {
  background: linear-gradient(135deg, #1c2030, #23283a);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  text-align: center;
}
.balance-num { font-size: 40px; font-weight: 700; margin: 8px 0; }
.balance-num .unit { font-size: 16px; color: var(--text-dim); font-weight: 400; }
.addr-row { display: flex; align-items: center; gap: 8px; margin-top: 16px; font-size: 13px; }
.addr-row .mono { font-family: "SF Mono", Consolas, monospace; word-break: break-all; }
.mono { font-family: "SF Mono", Consolas, monospace; }

.action-row { display: flex; gap: 12px; margin: 20px 0; }
.action-row .btn { flex: 1; }

.tx-list { margin-top: 20px; }
.tx-item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.tx-item .dir { font-weight: 600; font-size: 14px; }
.tx-item .dir.in { color: var(--green); }
.tx-item .dir.out { color: var(--red); }
.tx-item .amt { font-size: 15px; font-weight: 600; }
.tx-item .meta { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

.qr-box { background: #fff; width: 180px; height: 180px; margin: 16px auto; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.qr-box canvas, .qr-box img { width: 170px; height: 170px; }

.wallet-total-line { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-dim); margin: 12px 0; text-align: left; }
.wallet-total-line b { color: var(--text); }

#send-result.success { color: var(--green); }
#send-result.error { color: var(--red); }

