/* ============================================================
   Hyperliquid 移动版交易工具 — 样式 v2（卡片布局·可滚动）
   ============================================================ */

:root {
  --bg: #0a1628;
  --bg-card: #0f1e36;
  --bg-card-alt: #122240;
  --border: #1a3355;
  --border-glow: #2a5580;
  --text: #dce6f0;
  --text-dim: #6b7d99;
  --text-muted: #4a5a72;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --orange: #f97316;
  --cyan: #22d3ee;
  --purple: #a855f7;
  --blue: #3b82f6;
  --font: 'Inter', 'SF Pro', -apple-system, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Courier New', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
  background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 13px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
input, button { font-family: inherit; font-size: inherit; }
input:focus { outline: none; }
button { cursor: pointer; background: none; border: none; color: inherit; }
.hidden { display: none !important; }

/* ========== 标题栏 ========== */
#header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  background: linear-gradient(180deg, var(--bg-card), var(--bg-card-alt));
  border-bottom: 1px solid var(--border); height: 42px;
}
.h-left { display: flex; align-items: center; gap: 8px; }
.h-symbol { font-size: 15px; font-weight: 700; font-family: var(--font-mono); }
.h-mode { font-size: 9px; background: rgba(34,211,238,0.15); color: var(--cyan); padding: 3px 7px; border-radius: 4px; font-weight: 600; text-transform: uppercase; }
.h-price { font-size: 17px; font-weight: 700; font-family: var(--font-mono); color: var(--green); }

/* ========== 页面容器 ========== */
#page-container { height: calc(100vh - 80px); overflow: hidden; display: flex; flex-direction: column; }
.tab-page { display: none; height: 100%; }
.tab-page.active { display: flex; flex-direction: column; }
/* 交易页 — flex 布局，按钮固定底部 */
#tab-trade { display: none; height: 100%; flex-direction: column; }
#tab-trade.active { display: flex; }
#tab-trade .tab-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 10px 14px 6px; }
.trade-footer { flex-shrink: 0; padding: 6px 14px 120px; }
.trade-footer .execute-btn { margin: 0; }

/* 滚动页面（持仓/账户） */
.tab-page.scrollable .tab-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 10px 14px 16px; }

/* ========== 行情页 ========== */
#interval-bar { display: flex; gap: 4px; padding: 6px 14px; flex-shrink: 0; }
.int-btn {
  padding: 5px 12px; font-size: 13px; font-weight: 600;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text-dim);
}
.int-btn.active { background: rgba(34,211,238,0.15); color: var(--cyan); border-color: var(--cyan); }
#chart-wrap { padding: 0 14px; }
#chart-container { width: 100%; height: 440px; }
#chart-tools { padding: 8px 14px 12px; }
.tool-row { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; flex-wrap: nowrap; }
.tool-label { font-size: 13px; color: var(--text-dim); }
.swing-inp { width: 52px; padding: 4px 6px; font-size: 13px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 4px; color: var(--text); text-align: center; }
.hint { font-size: 12px; color: var(--text-muted); }
.btn-sm { padding: 5px 10px; font-size: 12px; font-weight: 600; background: var(--bg-card); border: 1px solid var(--border); border-radius: 6px; color: var(--text-dim); white-space: nowrap; }
.price-mode-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pmode-btn { padding: 4px 10px; font-size: 12px; border: 1px solid var(--border); border-radius: 4px; color: var(--text-dim); }
.pmode-btn.active { background: rgba(59,130,246,0.2); color: var(--blue); border-color: var(--blue); }

/* 品种选择弹窗 */
.overlay {
  position: fixed; top:0; left:0; right:0; bottom:0;
  background: rgba(0,0,0,0.7); z-index: 999;
  display: flex; align-items: center; justify-content: center;
}
.overlay-content {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 14px; width: 90%; max-width: 340px; max-height: 70vh;
  display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.overlay-header { display: flex; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); font-weight: 700; font-size: 14px; }
.close-btn { font-size: 18px; color: var(--text-dim); padding: 4px 8px; }
.search-input { width: 100%; padding: 10px 16px; font-size: 13px; background: var(--bg); border: none; border-bottom: 1px solid var(--border); color: var(--text); }
.pair-list { flex: 1; overflow-y: auto; }
.pair-item { display: flex; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid rgba(26,51,85,0.4); cursor: pointer; }
.pair-item:active { background: rgba(255,255,255,0.03); }
.pair-item .pair-name { font-weight: 600; }
.pair-item .pair-price { font-family: var(--font-mono); font-size: 12px; color: var(--text-dim); }

/* ========== 卡片 ========== */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px; margin-bottom: 10px;
}

/* 模式切换 */
.mode-row { display: flex; justify-content: space-between; align-items: center; }
.mode-switch {
  padding: 5px 12px; font-size: 11px; font-weight: 700;
  background: rgba(34,211,238,0.1); border: 1px solid rgba(34,211,238,0.25);
  border-radius: 8px; color: var(--cyan);
}
.lev-info { font-size: 12px; color: var(--text-dim); font-family: var(--font-mono); font-weight: 600; }

/* 方向 */
.row-dir { display: flex; gap: 8px; margin-bottom: 6px; }
.dir-btn {
  flex: 1; padding: 10px; font-size: 14px; font-weight: 700;
  border: 1px solid var(--border); border-radius: 8px; text-align: center;
}
.dir-btn.long { color: var(--green); }
.dir-btn.long.active { background: rgba(34,197,94,0.15); border-color: var(--green); }
.dir-btn.short { color: var(--red); }
.dir-btn.short.active { background: rgba(239,68,68,0.15); border-color: var(--red); }
.row-entry { display: flex; gap: 6px; }
.entry-btn {
  flex: 1; padding: 6px; font-size: 11px; font-weight: 600;
  border: 1px solid var(--border); border-radius: 6px; color: var(--text-dim); text-align: center;
}
.entry-btn.active { background: rgba(59,130,246,0.15); color: var(--blue); border-color: var(--blue); }

/* 输入行 */
.input-row {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px;
}
.input-row label { font-size: 12px; color: var(--text-dim); width: 56px; flex-shrink: 0; }
.num-input {
  flex: 1; padding: 7px 10px; font-size: 13px; font-family: var(--font-mono);
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); text-align: right;
}
.num-input:focus { border-color: var(--cyan); box-shadow: 0 0 0 2px rgba(34,211,238,0.12); }
.row-grow { display: flex; align-items: center; gap: 4px; flex: 1; }
.unit { font-size: 11px; color: var(--text-dim); width: 36px; flex-shrink: 0; }

/* 以损定量 / 按数量 */
.size-toggle { display: flex; gap: 6px; margin-bottom: 8px; }
.size-btn {
  flex: 1; padding: 5px; font-size: 11px; font-weight: 600;
  border: 1px solid var(--border); border-radius: 6px; color: var(--text-dim); text-align: center;
}
.size-btn.active { background: rgba(168,85,247,0.15); color: var(--purple); border-color: var(--purple); }

/* 快捷金额 */
.quick-risk { display: flex; gap: 6px; }
.qrisk {
  flex: 1; padding: 5px; font-size: 11px; font-weight: 600;
  border: 1px solid var(--border); border-radius: 5px; color: var(--text-dim); text-align: center;
}
.qrisk.active { background: rgba(34,197,94,0.15); color: var(--green); border-color: var(--green); }

/* 快捷杠杆 */
.lev-quick { display: flex; gap: 6px; margin-bottom: 6px; }
.lbtn {
  flex: 1; padding: 5px; font-size: 11px; font-weight: 600;
  border: 1px solid var(--border); border-radius: 5px; color: var(--text-dim); text-align: center;
}
.lbtn.active { background: rgba(34,211,238,0.15); color: var(--cyan); border-color: var(--cyan); }
.lbtn.max { color: var(--yellow); }

/* 逐仓/全仓 */
.mm-row { display: flex; gap: 6px; }
.mm-btn {
  flex: 1; padding: 6px; font-size: 11px; font-weight: 600;
  border: 1px solid var(--border); border-radius: 6px; color: var(--text-dim); text-align: center;
}
.mm-btn.active { background: rgba(34,211,238,0.1); color: var(--cyan); border-color: var(--cyan); }

/* 交易计划 */
.plan-card { padding: 12px 14px; }
.plan-empty { text-align: center; padding: 20px; color: var(--text-muted); font-size: 12px; }
.plan-result { animation: fadeIn 0.2s ease; }
.plan-hdr { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
#plan-symbol { font-weight: 700; font-size: 15px; }
.dir-tag { padding: 2px 8px; border-radius: 4px; font-size: 10px; font-weight: 700; }
.dir-tag.long { background: rgba(34,197,94,0.15); color: var(--green); }
.dir-tag.short { background: rgba(239,68,68,0.15); color: var(--red); }
.plan-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-bottom: 6px; }
.plan-grid > div { background: rgba(0,0,0,0.15); padding: 6px 8px; border-radius: 6px; display: flex; flex-direction: column; }
.pl { font-size: 9px; color: var(--text-muted); margin-bottom: 1px; }
.pv { font-size: 14px; font-weight: 700; font-family: var(--font-mono); }
.pv.red { color: var(--red); }
.plan-detail { border-top: 1px solid var(--border); padding-top: 6px; display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; }
.plan-detail > div { display: flex; justify-content: space-between; font-size: 10px; padding: 2px 0; color: var(--text-dim); }
.plan-detail > div span:last-child { color: var(--text); font-family: var(--font-mono); font-weight: 600; }

/* 执行按钮 */
.execute-btn {
  width: 100%; padding: 12px; font-size: 14px; font-weight: 700;
  background: linear-gradient(135deg, #00d4aa, #00b894);
  color: #000; border: none; border-radius: 10px; margin: 0;
  box-shadow: 0 4px 16px rgba(0,212,170,0.25);
  flex-shrink: 0;
}
.execute-btn:active { transform: scale(0.98); }
.execute-btn.sell { background: linear-gradient(135deg, #ef4444, #dc2626); color: #fff; box-shadow: 0 4px 16px rgba(239,68,68,0.25); }
.execute-btn:disabled { opacity: 0.5; }

/* 订单状态 */
.order-status { padding: 10px 12px; border-radius: 8px; font-size: 11px; margin-bottom: 8px; animation: fadeIn 0.2s ease; }
.order-status.success { background: rgba(34,197,94,0.1); border: 1px solid rgba(34,197,94,0.3); color: var(--green); }
.order-status.error { background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.3); color: var(--red); }
.order-status .os-row { display: flex; justify-content: space-between; padding: 3px 0; font-size: 11px; }

/* ========== 持仓页 ========== */
.section-hdr { display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 12px; margin-bottom: 8px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.list-area { min-height: 36px; }
.empty-state { text-align: center; padding: 20px; color: var(--text-muted); font-size: 12px; }

.po-item { padding: 10px 0; border-bottom: 1px solid rgba(26,51,85,0.3); font-size: 12px; }
.po-item:last-child { border-bottom: none; }
.po-top { display: flex; justify-content: space-between; margin-bottom: 4px; }
.po-mid { display: flex; justify-content: space-between; font-size: 11px; font-family: var(--font-mono); color: var(--text-dim); }
.po-side.buy { color: var(--green); font-weight: 700; }
.po-side.sell { color: var(--red); font-weight: 700; }
.po-actions { display: flex; gap: 6px; margin-top: 5px; }
.po-act-btn { padding: 4px 10px; font-size: 10px; font-weight: 600; border: 1px solid var(--border); border-radius: 5px; background: var(--bg); color: var(--text-dim); }
.po-act-btn.red { color: var(--red); border-color: rgba(239,68,68,0.3); }
.po-sl-input-wrap { display: flex; gap: 4px; margin-top: 4px; align-items: center; }
.po-sl-input-wrap.hidden { display: none !important; }
.po-sl-input { flex: 1; padding: 3px 6px; font-size: 10px; font-family: var(--font-mono); background: var(--bg); border: 1px solid var(--border); border-radius: 4px; color: var(--text); text-align: right; }
.po-sl-confirm { padding: 3px 8px; font-size: 9px; font-weight: 600; background: rgba(34,197,94,0.2); border: 1px solid rgba(34,197,94,0.3); border-radius: 4px; color: var(--green); }

.pos-item { padding: 10px 0; border-bottom: 1px solid rgba(26,51,85,0.3); font-size: 12px; }
.pos-item:last-child { border-bottom: none; }
.pos-top { display: flex; justify-content: space-between; margin-bottom: 4px; }
.pos-mid { display: flex; justify-content: space-between; font-family: var(--font-mono); font-size: 11px; color: var(--text-dim); }
.pos-bot { display: flex; gap: 6px; flex-wrap: wrap; }
.pos-side.l { color: var(--green); font-weight: 700; }
.pos-side.s { color: var(--red); font-weight: 700; }
.pos-pnl { font-weight: 700; font-family: var(--font-mono); }
.pos-pnl.pos { color: var(--green); }
.pos-pnl.neg { color: var(--red); }
.pos-close-btn { padding: 4px 10px; font-size: 10px; font-weight: 600; border-radius: 5px; border: 1px solid rgba(239,68,68,0.3); color: var(--red); background: transparent; }
.pos-close-btn.market { border-color: rgba(239,68,68,0.3); color: var(--red); }
.pos-close-btn.limit { border-color: rgba(59,130,246,0.35); color: var(--blue, #60a5fa); }
.pos-close-btn.sl { border-color: rgba(245,158,11,0.35); color: var(--yellow, #f59e0b); }
.pos-close-input { width: 70px; padding: 3px 5px; font-size: 10px; font-family: var(--font-mono); background: var(--bg); border: 1px solid var(--border); border-radius: 4px; color: var(--text); text-align: right; }
.pos-close-confirm { padding: 3px 8px; font-size: 10px; font-weight: 600; background: rgba(34,197,94,0.2); border: 1px solid rgba(34,197,94,0.3); border-radius: 4px; color: var(--green); }
/* 持仓内联输入（挂单平仓/止损） */
.pos-inline { display: flex; gap: 6px; margin-top: 6px; align-items: center; }
.pos-inline.hidden { display: none; }
.pos-inline .pos-limit-input { flex: 1; padding: 6px 8px; font-size: 13px; font-family: var(--font-mono); background: var(--bg); border: 1px solid var(--border); border-radius: 6px; color: var(--text); }
.pos-inline .pos-limit-confirm { padding: 6px 12px; font-size: 12px; font-weight: 700; background: rgba(34,197,94,0.2); border: 1px solid rgba(34,197,94,0.3); border-radius: 6px; color: var(--green); }
.pos-inline-status { font-size: 11px; margin-top: 4px; }
.pos-inline-status.hidden { display: none; }

/* ========== 账户页 ========== */
.acc-info { font-size: 12px; }
.acc-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid rgba(26,51,85,0.3); }
.acc-row:last-child { border-bottom: none; }
.acc-row span:first-child { color: var(--text-dim); font-size: 11px; }
.acc-row span:last-child { font-weight: 700; font-family: var(--font-mono); font-size: 15px; }
.acc-sub span:first-child { color: var(--text-muted) !important; }
.acc-sub span:last-child { font-weight: 400 !important; font-size: 12px !important; color: var(--text-dim) !important; }
.fee-quick { display: flex; gap: 6px; }
.fbtn { flex: 1; padding: 6px; font-size: 10px; font-weight: 600; border: 1px solid var(--border); border-radius: 6px; color: var(--text-dim); text-align: center; }
.fbtn.active { background: rgba(59,130,246,0.15); color: var(--blue); border-color: var(--blue); }

/* ========== 底部导航 ========== */
#bottom-tabs {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; background: var(--bg-card);
  border-top: 1px solid var(--border);
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
#bottom-tabs .tab-btn {
  flex: 1; padding: 10px 4px 8px; font-size: 12px; font-weight: 600;
  color: var(--text-dim); text-align: center; position: relative;
}
#bottom-tabs .tab-btn::after {
  content: ''; position: absolute; top: 0; left: 25%; right: 25%;
  height: 2px; background: var(--cyan); border-radius: 0 0 3px 3px;
  opacity: 0;
}
#bottom-tabs .tab-btn.active { color: #fff; }
#bottom-tabs .tab-btn.active::after { opacity: 1; }

/* ========== 动画 ========== */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }

/* ========== 滚动条 ========== */
::-webkit-scrollbar { width: 2px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ========== 下单确认弹窗 ========== */
.confirm-overlay {
  position: fixed; top:0; left:0; right:0; bottom:0;
  background: rgba(0,0,0,0.7); z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(8px);
}
.confirm-overlay.hidden { display: none !important; }
.confirm-dialog {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 14px; width: 340px; max-width: 90vw;
  box-shadow: 0 24px 80px rgba(0,0,0,0.6);
  animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.confirm-header { padding: 16px 18px 10px; font-size: 15px; font-weight: 700; border-bottom: 1px solid var(--border); }
.confirm-body { padding: 12px 18px; font-size: 12px; line-height: 1.5; }
.confirm-body .cr-row { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid rgba(26,51,85,0.3); }
.confirm-body .cr-row:last-child { border-bottom: none; }
.confirm-body .cr-label { color: var(--text-dim); }
.confirm-body .cr-value { color: var(--text); font-weight: 600; font-family: var(--font-mono); }
.confirm-body .cr-value.long { color: var(--green); }
.confirm-body .cr-value.short { color: var(--red); }
.confirm-footer { display: flex; gap: 10px; padding: 10px 18px 16px; justify-content: flex-end; }
.confirm-btn { padding: 10px 22px; border-radius: 10px; font-size: 13px; font-weight: 700; border: 1px solid var(--border); background: transparent; color: var(--text); }
.confirm-btn.cancel { color: var(--text-dim); }
.confirm-btn.confirm { background: linear-gradient(135deg, #00d4aa, #00b894); color: #000; border-color: #00d4aa; box-shadow: 0 4px 16px rgba(0,212,170,0.3); }
.confirm-btn.confirm:disabled { opacity: 0.5; }
