:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #16191d;
  --muted: #6b7280;
  --line: #e8eaee;
  --pos: #d92d20;
  --neg: #12805c;
  --buy: #0b6bcb;
  --buy-bg: #e7f0fb;
  --sell: #c4620a;
  --sell-bg: #fdf1e6;
  --accent: #1f6feb;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .04);
  --tabbar: 58px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131519; --card: #1b1e23; --text: #e9ebee; --muted: #98a1ac; --line: #282d34;
    --pos: #ff6b60; --neg: #3ecf8e; --buy: #6aa9ee; --buy-bg: #1a2735;
    --sell: #e2a05e; --sell-bg: #32251a; --accent: #4d8dff; --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { max-width: 100%; overflow-x: hidden; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  padding-bottom: calc(var(--tabbar) + 24px + env(safe-area-inset-bottom));
}
header {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px;
  padding: 13px 14px; background: var(--bg);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { font-size: 17px; font-weight: 650; letter-spacing: .2px; }
header .spacer { flex: 1; }
select.acct {
  font: inherit; font-size: 13px; color: var(--muted); background: var(--card);
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px;
}
main { padding: 12px 12px 0; max-width: 720px; margin: 0 auto; }
h2 {
  font-size: 13px; font-weight: 600; color: var(--muted); margin: 20px 4px 10px;
  letter-spacing: .4px; display: flex; align-items: baseline; gap: 8px;
}
h2 .sub { font-weight: 400; font-size: 12px; opacity: .85; }
.hide { display: none !important; }

/* 卡片与数字 */
.hero { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 18px; box-shadow: var(--shadow); }
.hero .k { font-size: 12px; color: var(--muted); }
.hero .v { font-size: 32px; font-weight: 700; letter-spacing: -.6px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.hero .v small { font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.grid { display: grid; gap: 10px; margin-top: 10px; }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid > * { min-width: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 13px; box-shadow: var(--shadow); min-width: 0; }
.card .k { font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.card .v { font-size: 19px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -.3px; }
.card .note, .note { font-size: 11px; color: var(--muted); margin-top: 4px; }
.pos { color: var(--pos); } .neg { color: var(--neg); } .muted { color: var(--muted); }

/* 条形 */
.bars { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 6px 14px; box-shadow: var(--shadow); }
.bar-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.bar-row:last-child { border-bottom: 0; }
.bar-label { width: 48px; font-size: 13px; color: var(--muted); flex: none; }
.bar-track { flex: 1; height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: currentColor; min-width: 3px; }
.bar-value { width: 88px; text-align: right; font-size: 14px; font-variant-numeric: tabular-nums; flex: none; }

/* 列表与行 */
.list { background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row-main { flex: 1; min-width: 0; }
.title { font-size: 15px; font-weight: 550; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.title .code { color: var(--muted); font-weight: 400; font-size: 12px; }
.meta { font-size: 12px; color: var(--muted); margin-top: 3px; font-variant-numeric: tabular-nums; }
.row-value { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; flex: none; }
.side { font-size: 11px; font-weight: 600; border-radius: 6px; padding: 2px 6px; flex: none; }
.side.BUY { color: var(--buy); background: var(--buy-bg); }
.side.SELL { color: var(--sell); background: var(--sell-bg); }
.empty { padding: 24px 16px; text-align: center; color: var(--muted); font-size: 14px; line-height: 1.7; }

/* 按钮 */
button { font: inherit; cursor: pointer; }
.ghost {
  font-size: 14px; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 7px 14px;
}
.ghost:disabled { opacity: .5; cursor: default; }
.primary {
  font-size: 14px; font-weight: 600; color: #fff; background: var(--accent);
  border: 1px solid transparent; border-radius: 10px; padding: 9px 16px;
}
.primary:active { transform: scale(.98); }
.primary.block { display: block; width: 100%; padding: 13px; font-size: 16px; margin-top: 14px; }
button.tiny { font-size: 13px; padding: 6px 11px; border-radius: 9px; }
button.danger { color: var(--pos); border-color: var(--line); background: var(--card); }
.actions-row { display: flex; gap: 8px; margin-bottom: 12px; }
.summary {
  display: flex; gap: 14px; flex-wrap: wrap; padding: 12px 14px; margin-bottom: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
}
.summary div { font-size: 13px; color: var(--muted); }
.summary b { font-size: 16px; color: var(--text); font-variant-numeric: tabular-nums; }

/* 配对卡 */
.pcard { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow); }
.pcard .head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.pcard .head .title { font-size: 16px; }
.pcard .legs { display: flex; flex-direction: column; gap: 6px; }
.legbox { display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); }
.legbox.pick { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.legbox .l-main { flex: 1; min-width: 0; }
.legbox .l-date { font-size: 12px; color: var(--muted); }
.legbox .l-price { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.cand { display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: 10px; border: 1px dashed var(--line); margin-top: 6px; cursor: pointer; }
.cand.on { border-style: solid; border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.pcard .calc { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0 4px; padding-top: 10px; border-top: 1px solid var(--line); }
.pcard .calc div { font-size: 13px; color: var(--muted); }
.pcard .calc b { font-size: 16px; font-variant-numeric: tabular-nums; }
.pcard .ops { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.pcard.waiting { opacity: .75; }
.tagHint { font-size: 12px; color: var(--muted); margin-top: 8px; }
.qtyInput { width: 84px; font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--text); }

/* 表单 */
.form { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; box-shadow: var(--shadow); position: relative; }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.field input {
  width: 100%; font: inherit; font-size: 16px; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px;
}
.field input:focus { outline: none; border-color: var(--accent); }
.row2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.seg { display: flex; gap: 8px; margin-bottom: 14px; }
.seg button {
  flex: 1; font-size: 15px; font-weight: 600; padding: 11px; color: var(--muted);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
.seg button.active[data-side="BUY"] { color: var(--buy); border-color: var(--buy); background: var(--buy-bg); }
.seg button.active[data-side="SELL"] { color: var(--sell); border-color: var(--sell); background: var(--sell-bg); }
.calc {
  font-size: 13px; color: var(--muted); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 12px; font-variant-numeric: tabular-nums;
}
.calc b { color: var(--text); font-size: 15px; }
.suggest {
  position: absolute; left: 14px; right: 14px; z-index: 15; margin-top: -6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, .12); overflow: hidden; max-height: 240px; overflow-y: auto;
}
.suggest button {
  display: flex; width: 100%; gap: 8px; align-items: center; text-align: left;
  padding: 10px 12px; background: transparent; border: 0; border-bottom: 1px solid var(--line);
  font-size: 14px; color: var(--text);
}
.suggest button:last-child { border-bottom: 0; }
.suggest .s-code { color: var(--muted); font-size: 12px; }

/* 设置页：关注品种标签 */
.tags { display: flex; flex-wrap: wrap; gap: 8px; min-height: 30px; }
.tags .tag {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 999px; font-size: 13px;
  background: var(--buy-bg); color: var(--buy);
}
.tags .tag button {
  background: transparent; border: 0; color: inherit; font-size: 15px;
  line-height: 1; padding: 0 1px; opacity: .65; cursor: pointer;
}
.tags .none { font-size: 13px; color: var(--muted); }

/* 仓位 */
.qtyTag {
  font-size: 13px; font-variant-numeric: tabular-nums; padding: 3px 9px;
  border-radius: 8px; background: var(--bg); border: 1px solid var(--line); white-space: nowrap;
}
.qtyTag b { font-size: 15px; }
.qtyTag.long { color: var(--accent); }
.qtyTag.roll { color: var(--text); }
.qtyTag.zero { color: var(--muted); }
.detailHead { display: flex; align-items: center; gap: 10px; margin: 4px 0 12px; }
.detailHead .title { font-size: 17px; font-weight: 650; }
.blockTitle {
  font-size: 13px; font-weight: 600; color: var(--muted); margin: 18px 4px 8px;
  display: flex; align-items: baseline; gap: 8px;
}
.blockTitle .sub { font-weight: 400; font-size: 12px; opacity: .85; }
.opsInline { display: flex; gap: 6px; flex: none; }

/* 弹层 */
.modal { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.modal-mask { position: absolute; inset: 0; background: rgba(0, 0, 0, .35); }
.modal-card {
  position: relative; width: 100%; max-width: 520px; max-height: 88vh; overflow-y: auto;
  background: var(--card); border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .2);
}
.modal-title { font-size: 17px; font-weight: 650; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.modal-title .spacer { flex: 1; }
.modal-title button { background: transparent; border: 0; color: var(--muted); font-size: 15px; cursor: pointer; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }
.modal-actions > button { flex: 1; }

/* 底部导航 */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; height: calc(var(--tabbar) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabbar button {
  flex: 1; min-width: 0; background: transparent; border: 0; color: var(--muted); font-size: 13px;
  display: flex; align-items: center; justify-content: center; gap: 5px;
}
.tabbar button.active { color: var(--accent); font-weight: 650; }
.badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--pos); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}

/* 提示 */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar) + 20px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 50;
  background: #16191d; color: #fff; font-size: 14px; padding: 10px 16px; border-radius: 10px;
  max-width: 86vw; text-align: center; box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
.toast.err { background: var(--pos); }

/* ---------------- 配对工作台：左买右卖两栏 ---------------- */

/* 两栏在窄容器里太挤：支持 :has 的浏览器放宽（不支持则退回默认宽度，仍可用） */
main:has(#view-pairing:not(.hide)) { max-width: 1080px; }

.pair-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-items: start;
}

.pair-col {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.pair-head {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 600;
  border-bottom: 1px solid var(--line);
}

.pair-list { max-height: 48vh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.pair-list > .empty.tiny { padding: 20px 12px; font-size: 12px; text-align: center; color: var(--muted); }

.pair-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 11px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  user-select: none;
}
.pair-row:last-child { border-bottom: 0; }
.pair-row.on { background: var(--buy-bg); }

.pr-chk {
  flex: 0 0 18px;
  height: 18px;
  line-height: 16px;
  text-align: center;
  border: 1.5px solid var(--line);
  border-radius: 5px;
  font-size: 12px;
  color: transparent;
}
.pair-row.on .pr-chk { background: var(--accent); border-color: var(--accent); color: #fff; }

.pr-main { flex: 1; min-width: 0; }
.pr-price { font-size: 13.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.pr-date { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.pr-rel { flex: 0 0 auto; font-size: 12.5px; font-weight: 650; font-variant-numeric: tabular-nums; }

/* 部分配对后的剩余量：高亮提示，避免忘了还有半截没配 */
.rest { color: var(--sell); font-weight: 600; }

/* 底部确认条：跟随滚动停在视口下方 */
.pair-bar {
  position: sticky;
  bottom: 10px;
  z-index: 6;
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--accent);
  border-radius: 14px;
  box-shadow: 0 10px 28px rgba(16, 24, 40, .18);
}
.pb-head { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; color: var(--muted); }
.pb-body { margin: 8px 0 10px; }
.pb-row { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; padding: 2px 0; font-variant-numeric: tabular-nums; }
.pb-row.total { margin-top: 5px; padding-top: 7px; border-top: 1px dashed var(--line); font-size: 14.5px; }
.pb-left { margin-top: 7px; font-size: 12px; color: var(--muted); }

/* 手机：上下分栏（买在上、卖在下），确认条仍固定在视口内 */
@media (max-width: 720px) {
  .pair-cols { grid-template-columns: 1fr; }
  .pair-list { max-height: 30vh; }
}
