/* ==========================================================================
   盈途模拟盘 · 移动端
   设计基准：华为 Mate 50 Pro 实测视口 388 × 692 CSS px，DPR 3.125
   内核：Chromium 132（现代 CSS 可放心使用）
   视觉令牌沿用桌面端 sim_web/index.html
   ========================================================================== */

:root {
  --bg: #080B12;
  --s1: #131A29;
  --s2: #1B2438;
  --s3: #242F49;
  --line: #232936;
  --line2: #2E3646;
  --text: #E9EEF7;
  --dim: #93A1B8;
  --dimmer: #7C8AA3;
  --accent: #3FB8AF;
  --accent-hi: #63D6CE;
  --up: #F0555C;      /* 红涨 */
  --down: #37B87C;    /* 绿跌 */
  --warn: #D9A441;
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --ease: cubic-bezier(.4, 0, .2, 1);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --topbar-h: 48px;
  --tabbar-h: 54px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* ★ 关键：作者样式里的 display 会覆盖 [hidden] 的 UA 规则（display:none），
   导致 hidden 元素仍然可见。这里统一兜底。 */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, "HarmonyOS Sans SC", "HarmonyOS Sans", Roboto, "PingFang SC", sans-serif;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* 数字等宽，防止跳动 */
b, .num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* ============================ 顶栏 ============================ */
.topbar {
  flex: 0 0 auto;
  height: calc(var(--topbar-h) + var(--safe-t));
  padding-top: var(--safe-t);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 12px;
  padding-right: 10px;
  background: rgba(19, 26, 41, .92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 30;
}
.tb-ver {
  display: flex; align-items: center; gap: 6px;
  background: transparent; border: 0; color: var(--text);
  font-size: 15px; font-weight: 600; padding: 6px 4px;
  cursor: pointer;
}
.tb-ver:active { opacity: .6; }
.ver-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.caret { color: var(--dimmer); font-size: 11px; }
.tb-right { display: flex; align-items: center; gap: 10px; }
.tb-quote { font-size: 12px; color: var(--dimmer); font-variant-numeric: tabular-nums; }
.tb-icon {
  background: transparent; border: 0; color: var(--dim);
  font-size: 18px; padding: 4px 8px; cursor: pointer; line-height: 1;
}
.tb-icon:active { color: var(--accent); }
.tb-icon.spin { animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================ 主区 ============================ */
main {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  /* 额外留出 FAB 的高度，避免最后一张卡片被悬浮按钮遮住 */
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 76px);
}
.page { display: none; padding: 12px; }
.page.active { display: block; animation: fade .18s var(--ease); }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.sec-title {
  font-size: 13px; font-weight: 600; color: var(--dim);
  margin: 16px 2px 8px; display: flex; align-items: center; justify-content: space-between;
}
.sec-title:first-child { margin-top: 4px; }
.sec-hint { font-size: 12px; color: var(--dimmer); font-weight: 400; }

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

.hero { text-align: center; padding: 20px 14px 18px; }
.hero-label { font-size: 12px; color: var(--dim); margin-bottom: 6px; }
.hero-value {
  font-size: 32px; font-weight: 700; letter-spacing: -.5px;
  font-variant-numeric: tabular-nums; line-height: 1.1;
}
.hero-sub { margin-top: 10px; font-size: 13px; color: var(--dim); display: flex; justify-content: center; gap: 10px; }
.hero-sub b { font-weight: 600; }
.sep { color: var(--line2); }

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

/* ============================ 账户列表 ============================ */
.acct-list { display: flex; flex-direction: column; gap: 8px; }
.acct {
  background: var(--s1); border: 1px solid var(--line); border-radius: var(--r);
  padding: 12px 14px; display: flex; align-items: center; gap: 12px;
  cursor: pointer; transition: border-color .15s var(--ease), background .15s var(--ease);
}
.acct:active { background: var(--s2); }
.acct.cur { border-color: var(--accent); }
.acct-main { flex: 1 1 auto; min-width: 0; }
.acct-name { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.acct-tag {
  font-size: 10px; padding: 1px 5px; border-radius: 4px;
  background: var(--s3); color: var(--dim); font-weight: 400;
}
.acct-sub { font-size: 11.5px; color: var(--dimmer); margin-top: 3px; }
.acct-right { text-align: right; flex: 0 0 auto; }
.acct-eq { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.acct-pct { font-size: 12px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }

/* ============================ 统计条 ============================ */
.stat-row { display: flex; padding: 12px 6px; }
.stat { flex: 1; text-align: center; }
.stat-k { display: block; font-size: 11.5px; color: var(--dim); margin-bottom: 4px; }
.stat b { font-size: 15px; font-weight: 600; }

/* ============================ 持仓 ============================ */
.pos-list { display: flex; flex-direction: column; gap: 10px; }
.pos {
  background: var(--s1); border: 1px solid var(--line); border-radius: var(--r);
  padding: 13px 14px;
}
.pos-head { display: flex; justify-content: space-between; align-items: baseline; }
.pos-name { font-size: 15px; font-weight: 600; }
.pos-code { font-size: 11.5px; color: var(--dimmer); margin-left: 6px; font-weight: 400; }
.pos-pnl { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.pos-pnl small { display: block; font-size: 11.5px; font-weight: 500; text-align: right; }
.pos-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 8px 4px; margin-top: 11px; padding-top: 11px; border-top: 1px solid var(--line);
}
.pos-cell { text-align: center; }
.pos-cell span { display: block; font-size: 11px; color: var(--dimmer); margin-bottom: 2px; }
.pos-cell b { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.pos-acts { display: flex; gap: 8px; margin-top: 12px; }
.pos-acts .btn { flex: 1; }

.frozen-tip {
  font-size: 11px; color: var(--warn); margin-top: 8px;
  display: flex; align-items: center; gap: 4px;
}

/* ============================ 信号 ============================ */
.seg {
  display: flex; gap: 6px; overflow-x: auto; padding-bottom: 10px;
  scrollbar-width: none;
}
.seg::-webkit-scrollbar { display: none; }
.seg-item {
  flex: 0 0 auto; padding: 6px 13px; border-radius: 20px;
  background: var(--s1); border: 1px solid var(--line);
  color: var(--dim); font-size: 12.5px; cursor: pointer; white-space: nowrap;
}
.seg-item.active { background: var(--accent); border-color: var(--accent); color: #06201E; font-weight: 600; }

/* 窄屏下让元信息独占一行，避免被按钮挤到换行 */
.sig-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; padding: 11px 14px; }
.sig-meta { font-size: 12px; color: var(--dim); flex: 1 1 100%; min-width: 0; line-height: 1.55; }
.sig-meta.stale { color: var(--warn); }
.sig-actions { display: flex; gap: 6px; flex: 1 1 auto; justify-content: flex-end; }

.sig-list { display: flex; flex-direction: column; gap: 8px; }
.sig {
  background: var(--s1); border: 1px solid var(--line); border-radius: var(--r);
  padding: 12px 14px; display: flex; align-items: center; gap: 12px;
}
.sig-main { flex: 1 1 auto; min-width: 0; }
.sig-name { font-size: 14.5px; font-weight: 600; }
.sig-code { font-size: 11.5px; color: var(--dimmer); margin-left: 6px; font-weight: 400; }
.sig-extra { font-size: 11.5px; color: var(--dim); margin-top: 4px; font-variant-numeric: tabular-nums; }
.sig-right { text-align: right; flex: 0 0 auto; }
.sig-price { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.sig-stop { font-size: 11.5px; color: var(--down); margin-top: 2px; font-variant-numeric: tabular-nums; }
.sig-badge {
  display: inline-block; font-size: 10px; padding: 1px 5px; border-radius: 4px;
  margin-left: 6px; vertical-align: 1px;
}
.sig-badge.stale { background: rgba(217,164,65,.18); color: var(--warn); }
.sig-badge.fresh { background: rgba(63,184,175,.16); color: var(--accent); }

/* ============================ 行情 ============================ */
.watch-add { display: flex; gap: 8px; padding: 10px; }
.watch-add input { flex: 1 1 auto; min-width: 0; }
.watch-add .btn { flex: 0 0 auto; white-space: nowrap; }
.watch-list { display: flex; flex-direction: column; gap: 8px; }
.watch {
  background: var(--s1); border: 1px solid var(--line); border-radius: var(--r);
  padding: 12px 14px; display: flex; align-items: center; gap: 12px; cursor: pointer;
}
.watch:active { background: var(--s2); }
.watch-main { flex: 1 1 auto; min-width: 0; }
.watch-name { font-size: 14.5px; font-weight: 600; }
.watch-code { font-size: 11.5px; color: var(--dimmer); margin-left: 6px; font-weight: 400; }
.watch-right { text-align: right; flex: 0 0 auto; }
.watch-price { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.watch-pct { font-size: 12px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.watch-del {
  flex: 0 0 auto; background: transparent; border: 0; color: var(--dimmer);
  font-size: 16px; padding: 4px 2px 4px 8px; cursor: pointer;
}

/* ============================ 表单 / 按钮 ============================ */
.field { display: block; margin-bottom: 12px; }
.field:last-of-type { margin-bottom: 14px; }
.field > span { display: block; font-size: 12.5px; color: var(--dim); margin-bottom: 6px; }
input {
  width: 100%; background: var(--bg); border: 1px solid var(--line2);
  border-radius: var(--r-sm); color: var(--text);
  font-size: 16px; padding: 10px 12px; font-family: inherit;
  font-variant-numeric: tabular-nums;
}
input::placeholder { color: var(--dimmer); }
input:focus { outline: none; border-color: var(--accent); }
input:disabled { opacity: .45; }

.btn {
  background: var(--accent); color: #06201E; border: 0;
  border-radius: var(--r-sm); font-size: 14px; font-weight: 600;
  padding: 11px 16px; cursor: pointer; font-family: inherit;
  transition: transform .1s var(--ease), opacity .1s var(--ease);
}
.btn:active { transform: scale(.97); opacity: .85; }
.btn:disabled { opacity: .4; transform: none; cursor: not-allowed; }
.btn.sm { padding: 7px 12px; font-size: 12.5px; }
.btn.ghost { background: transparent; color: var(--dim); border: 1px solid var(--line2); }
.btn.buy { background: var(--up); color: #fff; }
.btn.sell { background: var(--down); color: #fff; }
.btn.danger { background: transparent; color: var(--up); border: 1px solid rgba(240,85,92,.4); }
.btn.full { width: 100%; }

.fab {
  position: fixed; right: 16px;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px);
  width: 52px; height: 52px; border-radius: 26px;
  background: var(--accent); color: #06201E; border: 0;
  font-size: 14px; font-weight: 700; cursor: pointer;
  box-shadow: 0 6px 20px rgba(63,184,175,.35);
  z-index: 20;
}
.fab:active { transform: scale(.94); }

/* ============================ 菜单 ============================ */
.menu { padding: 0; overflow: hidden; }
.menu-item {
  width: 100%; background: transparent; border: 0;
  border-bottom: 1px solid var(--line);
  color: var(--text); font-size: 14.5px; font-family: inherit;
  padding: 14px; display: flex; justify-content: space-between; align-items: center;
  cursor: pointer; text-align: left;
}
.menu-item:last-child { border-bottom: 0; }
.menu-item:active { background: var(--s2); }
.menu-item.danger { color: var(--up); }
.arrow { color: var(--dimmer); font-size: 18px; }

.about { font-size: 13px; }
.about-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); }
.about-row:last-of-type { border-bottom: 0; }
.about-row span { color: var(--dim); }
.about-note {
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line);
  font-size: 12px; color: var(--dimmer); line-height: 1.6;
}

/* ============================ 空态 ============================ */
.empty { text-align: center; padding: 48px 20px; color: var(--dim); font-size: 14px; }
.empty-icon { font-size: 36px; color: var(--line2); margin-bottom: 12px; }
.empty-sub { font-size: 12.5px; color: var(--dimmer); margin-top: 6px; }

/* ============================ 底部 Tab ============================ */
.tabbar {
  flex: 0 0 auto;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex;
  background: rgba(19, 26, 41, .96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  z-index: 40;
}
.tab {
  flex: 1; background: transparent; border: 0; color: var(--dimmer);
  font-family: inherit; font-size: 10.5px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding: 0; transition: color .15s var(--ease);
}
.tab i { font-size: 18px; font-style: normal; line-height: 1; }
.tab.active { color: var(--accent); }
.tab:active i { transform: scale(.9); }

/* ============================ 底部弹层 ============================ */
.sheet-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  z-index: 90; animation: fadein .16s var(--ease);
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0;
  max-height: 88dvh;
  background: var(--s1);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  border-top: 1px solid var(--line2);
  z-index: 100;
  display: flex; flex-direction: column;
  padding-bottom: var(--safe-b);
  animation: slideup .22s var(--ease);
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: none; } }
.sheet-head {
  flex: 0 0 auto; display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.sheet-head b { font-size: 16px; }
.sheet-close {
  background: transparent; border: 0; color: var(--dimmer);
  font-size: 17px; cursor: pointer; padding: 2px 4px;
}
.sheet-body { flex: 1 1 auto; overflow-y: auto; padding: 16px; }

/* 下单表单 */
.quote-line {
  display: flex; justify-content: space-between; align-items: baseline;
  padding-bottom: 12px; margin-bottom: 14px; border-bottom: 1px solid var(--line);
}
.quote-line .ql-name { font-size: 16px; font-weight: 600; }
.quote-line .ql-price { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.side-toggle { display: flex; gap: 8px; margin-bottom: 14px; }
.side-toggle button {
  flex: 1; padding: 11px; border-radius: var(--r-sm); font-size: 14px; font-weight: 600;
  border: 1px solid var(--line2); background: transparent; color: var(--dim);
  font-family: inherit; cursor: pointer;
}
.side-toggle button.on-buy { background: var(--up); border-color: var(--up); color: #fff; }
.side-toggle button.on-sell { background: var(--down); border-color: var(--down); color: #fff; }
.calc-box {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 11px 12px; margin: 14px 0; font-size: 12.5px;
}
.calc-row { display: flex; justify-content: space-between; padding: 3px 0; color: var(--dim); }
.calc-row b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.calc-row.total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 8px; font-size: 13.5px; }
.calc-row.total b { color: var(--accent-hi); font-size: 15px; }
.qty-quick { display: flex; gap: 6px; margin-top: 8px; }
.qty-quick button {
  flex: 1; padding: 7px; font-size: 12px; border-radius: 6px;
  background: var(--s2); border: 1px solid var(--line2); color: var(--dim);
  font-family: inherit; cursor: pointer;
}

.warn-line {
  font-size: 12px; color: var(--warn); background: rgba(217,164,65,.1);
  border: 1px solid rgba(217,164,65,.25); border-radius: var(--r-sm);
  padding: 9px 11px; margin-bottom: 12px; line-height: 1.5;
}

/* K线图 */
.chart-wrap { background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.chart-wrap canvas { display: block; width: 100%; }
.chart-info { display: flex; gap: 12px; font-size: 12px; color: var(--dim); padding: 10px 12px; flex-wrap: wrap; }
.chart-info b { color: var(--text); font-variant-numeric: tabular-nums; }
.period-seg { display: flex; gap: 6px; margin-bottom: 12px; }
.period-seg button {
  flex: 1; padding: 7px; font-size: 12.5px; border-radius: 6px;
  background: var(--s2); border: 1px solid var(--line2); color: var(--dim);
  font-family: inherit; cursor: pointer;
}
.period-seg button.active { background: var(--accent); border-color: var(--accent); color: #06201E; font-weight: 600; }

/* 成交记录 */
.trade-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13px;
}
.trade-row:last-child { border-bottom: 0; }
.trade-side { font-size: 11px; padding: 1px 5px; border-radius: 4px; margin-right: 6px; font-weight: 600; }
.trade-side.buy { background: rgba(240,85,92,.16); color: var(--up); }
.trade-side.sell { background: rgba(55,184,124,.16); color: var(--down); }
.trade-mid { flex: 1 1 auto; min-width: 0; color: var(--dim); font-size: 12px; text-align: center; }
.trade-right { text-align: right; font-variant-numeric: tabular-nums; }
.trade-right small { display: block; color: var(--dimmer); font-size: 11px; }

/* ============================ Toast ============================ */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 28px);
  transform: translateX(-50%);
  background: var(--s3); color: var(--text);
  border: 1px solid var(--line2); border-radius: 20px;
  padding: 10px 18px; font-size: 13.5px; max-width: 84vw; text-align: center;
  z-index: 200; box-shadow: 0 8px 24px rgba(0,0,0,.4);
  animation: toastin .2s var(--ease);
}
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
.toast.err { background: rgba(240,85,92,.94); color: #fff; border-color: transparent; }
.toast.ok { background: rgba(55,184,124,.94); color: #fff; border-color: transparent; }

/* 滚动条隐藏 */
::-webkit-scrollbar { width: 0; height: 0; }
