/* momentum64 交易驾驶舱：纸面 / 回单风格。变量集中在 :root。 */
:root {
  --ink: #101828;
  --muted: #667085;
  --paper: #f5f7fa;
  --surface: #ffffff;
  --line: #d9e1ea;
  --accent: #c2412d;
  --accent-soft: #fbeee9;
  --up: #b3261e;
  --down: #147d64;
  --warn: #94641a;
  --crit: #a3281d;
  --font-sans: "PingFang SC", "Noto Sans SC", system-ui, -apple-system,
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, "IBM Plex Mono", monospace;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
  --max-width: 1080px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.65;
}

a { color: var(--accent); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.wrap { max-width: var(--max-width); margin: 0 auto; padding: 0 16px; }

/* ---------- 演示横幅 ---------- */
.demo-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  padding: 6px 12px;
  text-align: center;
  font-size: 12.5px;
  letter-spacing: 0.02em;
  color: #fff;
  background: var(--ink);
}
body.has-demo { padding-top: 30px; }

/* ---------- 顶栏 ---------- */
.masthead {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.masthead-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 0;
}
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand-mark {
  width: 10px;
  height: 10px;
  flex: none;
  background: var(--accent);
  border-radius: 2px;
  transform: rotate(45deg);
}
.brand-name { font-size: 16px; font-weight: 600; letter-spacing: 0.02em; white-space: nowrap; }
.brand-sub { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.nav { display: flex; gap: 2px; flex-wrap: wrap; }
.nav-item {
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13.5px;
  white-space: nowrap;
}
.nav-item:hover { background: var(--paper); color: var(--ink); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.masthead-tools { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.mode-toggle, .logout { margin: 0; }

main.wrap { padding-top: 20px; padding-bottom: 48px; }

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.page-head h1 { margin: 0; font-size: 21px; font-weight: 600; }
.page-head .meta { color: var(--muted); font-size: 12.5px; }

/* ---------- 首页两栏：交易票 + 大数字 ---------- */
.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

/* 交易票：唯一的记忆点 */
.ticket {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 18px 18px 26px;
  box-shadow: var(--shadow);
}
.ticket::after {
  content: "";
  position: absolute;
  left: -1px;
  right: -1px;
  bottom: -9px;
  height: 18px;
  background:
    radial-gradient(circle at 9px 0, transparent 8px, var(--surface) 8.5px) 0 0 / 18px 18px repeat-x,
    radial-gradient(circle at 9px 0, transparent 8px, var(--line) 8.5px) 0 -1px / 18px 18px repeat-x;
}
.ticket-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.ticket-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.ticket-headline { margin: 12px 0 4px; font-size: 19px; font-weight: 600; line-height: 1.45; }
.ticket-note { margin: 0 0 14px; color: var(--muted); font-size: 13px; }
.ticket-action { margin: 14px 0 2px; }
.action-link { font-weight: 600; }

.stamp {
  display: inline-block;
  padding: 3px 10px;
  border: 2px solid currentColor;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
  transform: rotate(-3deg);
  white-space: nowrap;
}
.stamp-ticket { font-size: 13px; }
.stamp-pending, .stamp-ticket-pending { color: var(--accent); }
.stamp-ticket-filling { color: var(--warn); }
.stamp-ticket-reconcile { color: var(--accent); }
.stamp-ticket-missing_fills { color: var(--warn); }
.stamp-done, .stamp-ticket-done, .stamp-filled, .stamp-ticket-safe { color: var(--down); }
.stamp-ticket-no_orders { color: var(--muted); }
.stamp-ticket-data_error, .stamp-ticket-halved, .stamp-ticket-stopped, .stamp-partial { color: var(--crit); }
.stamp-cancelled { color: var(--muted); }
.stamp-expired { color: var(--crit); }

/* 四步序列 */
.steps { list-style: none; margin: 0; padding: 0; }
.step {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px dashed var(--line);
}
.step-no {
  flex: none;
  width: 24px;
  height: 24px;
  border: 1px solid var(--line);
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  background: var(--surface);
}
.step-body { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.step-name { font-size: 13.5px; font-weight: 600; }
.step-status { font-size: 12.5px; font-weight: 600; }
.step-text { font-size: 13px; color: var(--muted); }
.step-done .step-no { color: var(--down); border-color: var(--down); }
.step-done .step-status { color: var(--down); }
.step-todo { background: var(--accent-soft); border-radius: 6px; padding-left: 8px; padding-right: 8px; }
.step-todo .step-no { color: var(--accent); border-color: var(--accent); }
.step-todo .step-status { color: var(--accent); }
.step-progress .step-no { color: var(--warn); border-color: var(--warn); }
.step-progress .step-status { color: var(--warn); }
.step-skip { opacity: 0.72; }

/* 三个大数字 */
.big-numbers {
  display: grid;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.big-number { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.big-number:last-of-type { border-bottom: 0; }
.big-number dt { font-size: 12.5px; color: var(--muted); }
.big-number dd {
  margin: 2px 0 0;
  font-size: 26px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
}
.big-hint { font-size: 12px; color: var(--muted); }
.more-numbers { padding: 10px 16px 12px; background: var(--paper); font-size: 12.5px; }
.more-numbers summary { cursor: pointer; color: var(--muted); }
.more-numbers dl { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 14px; margin: 8px 0 0; }
.more-numbers dl div { display: flex; justify-content: space-between; gap: 8px; }
.more-numbers dt { color: var(--muted); }
.more-numbers dd { margin: 0; font-variant-numeric: tabular-nums; }

/* 执行页概览 */
.exec-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 16px;
}
.exec-strip .big-number { border-bottom: 0; border-right: 1px solid var(--line); }
.exec-strip .big-number:last-child { border-right: 0; }
.exec-strip .big-number dd { font-size: 20px; }

/* ---------- 卡片与数字 ---------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.kpi { background: var(--surface); padding: 12px 14px; min-width: 0; }
.kpi dt { margin: 0; font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.kpi dd {
  margin: 5px 0 0;
  font-size: 17px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-top: 16px;
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--muted);
}
.card-head h2 { margin: 0; font-size: 14px; font-weight: 600; color: var(--ink); }
.card-body { padding: 12px 14px; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.grid-2 > .card { margin-top: 16px; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td {
  padding: 6px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}
thead th { color: var(--muted); font-weight: 500; font-size: 11.5px; }
tbody tr:last-child td { border-bottom: 0; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap-cell { white-space: normal; overflow-wrap: anywhere; min-width: 140px; }
td.mono, .mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.up { color: var(--up); }
.down { color: var(--down); }
.flat, .muted { color: var(--muted); }
.warn { color: var(--warn); }
.crit { color: var(--crit); }

.tag {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 11.5px;
  color: var(--muted);
  background: var(--surface);
  white-space: nowrap;
}
.tag.accent { color: var(--down); border-color: #b9d9ce; }
.tag.warn { color: var(--warn); border-color: #e6d3b4; }
.tag.crit { color: var(--crit); border-color: #e7c7c7; }

.spark { display: block; width: 100%; height: 120px; }

/* ---------- 订单卡 ---------- */
.order-list { display: grid; gap: 10px; }
.order-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--surface);
}
.order-card:has(.side.buy) { border-left-color: var(--accent); }
.order-card:has(.side.sell) { border-left-color: var(--down); }
.order-line { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.side { font-weight: 700; font-size: 13px; }
.side.buy { color: var(--accent); }
.side.sell { color: var(--down); }
.order-sleeve { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }
.order-code { font-family: var(--font-mono); font-size: 15px; font-weight: 600; }
.order-name { font-family: var(--font-sans); font-weight: 500; color: var(--muted); font-size: 13px; }
.order-facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 2px 12px;
  margin: 8px 0 0;
}
.order-facts div { display: flex; gap: 6px; align-items: baseline; }
.order-facts dt { color: var(--muted); font-size: 12px; }
.order-facts dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 600; }
.order-reason { margin: 8px 0 0; font-size: 12.5px; color: var(--muted); }
.order-progress { margin: 4px 0 0; font-size: 12.5px; color: var(--warn); }
.order-expired { margin: 4px 0 0; font-size: 12.5px; color: var(--crit); }
.order-side { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.order-detail { grid-column: 1 / -1; border-top: 1px dashed var(--line); padding-top: 6px; }
.order-detail summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.raw { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 2px 14px; margin: 8px 0 0; font-size: 12px; }
.raw div { display: flex; gap: 6px; justify-content: space-between; }
.raw dt { color: var(--muted); }
.raw dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- 风控大状态 ---------- */
.risk-banner {
  border: 1px solid var(--line);
  border-left: 5px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.risk-safe { border-left-color: var(--down); }
.risk-halved { border-left-color: var(--warn); }
.risk-stopped { border-left-color: var(--crit); }
.risk-headline { margin: 10px 0 4px; font-size: 18px; font-weight: 600; }
.risk-facts { margin: 0; color: var(--muted); font-size: 13px; }
.risk-facts strong { color: var(--ink); font-variant-numeric: tabular-nums; }

/* ---------- 术语 tooltip ---------- */
.term {
  border-bottom: 1px dashed var(--muted);
  cursor: help;
  color: inherit;
}
.term-tip {
  position: fixed;
  z-index: 60;
  max-width: min(320px, 86vw);
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  font-size: 12px;
  line-height: 1.5;
  box-shadow: 0 4px 14px rgba(16, 24, 40, 0.18);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.12s ease;
  pointer-events: none;
}
.term-tip.visible { opacity: 1; visibility: visible; }

/* ---------- 表单 ---------- */
.forms {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
  align-items: start;
}
form fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
form legend { font-size: 13px; font-weight: 600; padding: 0; margin-bottom: 8px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; font-size: 12px; color: var(--muted); }
.field > span { white-space: nowrap; }
input, select, textarea {
  width: 100%;
  font: inherit;
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}
input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
textarea { resize: vertical; }
button {
  font: inherit;
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
button:hover { background: #a83725; border-color: #a83725; }
button.ghost { background: transparent; color: var(--muted); border-color: var(--line); }
button.ghost:hover { background: var(--paper); color: var(--ink); }
.check { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
.check input { width: auto; }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0 8px; }
.preview { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

.system-side {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 14px;
  background: var(--paper);
}
.system-side h3 { margin: 0 0 6px; font-size: 12.5px; font-weight: 600; }
.system-facts { display: flex; gap: 18px; margin: 0 0 6px; flex-wrap: wrap; }
.system-facts dt { color: var(--muted); font-size: 12px; display: inline; }
.system-facts dd { margin: 0 8px 0 4px; display: inline; font-weight: 600; font-variant-numeric: tabular-nums; }
.system-positions { list-style: none; margin: 0; padding: 0; display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; }

/* ---------- dialog ---------- */
dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  width: min(560px, calc(100vw - 32px));
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 18px 50px rgba(16, 24, 40, 0.22);
}
dialog::backdrop { background: rgba(16, 24, 40, 0.4); }
dialog h2 { margin: 0 0 6px; font-size: 18px; }
.dialog-progress { margin: 0 0 10px; color: var(--warn); font-size: 13px; }
.dialog-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.onboarding ol { margin-top: 10px; }

/* ---------- 空状态 / 提示 ---------- */
.error { color: var(--crit); font-size: 13px; }
.message { color: var(--down); font-size: 13px; }
.empty { color: var(--muted); font-size: 13px; margin: 0; }
.empty-state { padding: 8px 2px; color: var(--muted); font-size: 13px; }
.empty-state p { margin: 4px 0; }
.empty-title { color: var(--ink); font-weight: 600; font-size: 14px; }
.notice {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  background: var(--surface);
}
.notice.warn { color: var(--warn); border-color: #e6d3b4; }
.report-pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.65;
}
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.list li:last-child { border-bottom: 0; }

.glossary { margin: 0; display: grid; gap: 12px; }
.glossary-item { border-bottom: 1px dashed var(--line); padding-bottom: 10px; }
.glossary-item:last-child { border-bottom: 0; padding-bottom: 0; }
.glossary-item dt { font-weight: 600; font-size: 14px; }
.glossary-item dd { margin: 2px 0 0; }
.glossary-item p { margin: 2px 0; font-size: 13px; }
.glossary-example { color: var(--muted); }

.login-shell { max-width: 360px; margin: 12vh auto 0; }
.login-shell .card { margin-top: 0; }
.expert-only { border-style: dashed; }

/* ---------- 响应式：≤640px 表格改卡片 ---------- */
@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .wrap { padding: 0 12px; }
  .brand-sub { display: none; }
  .nav { width: 100%; overflow-x: auto; flex-wrap: nowrap; padding-bottom: 2px; }
  .masthead-tools { margin-left: 0; }
  .kpis { grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); }
  .kpi dd { font-size: 15px; }
  .page-head h1 { font-size: 19px; }
  .grid-2 { grid-template-columns: 1fr; }
  .spark { height: 96px; }
  .ticket { padding: 14px 14px 24px; }
  .ticket-headline { font-size: 17px; }
  .big-number dd { font-size: 22px; }
  .exec-strip { grid-template-columns: 1fr; }
  .exec-strip .big-number { border-right: 0; border-bottom: 1px solid var(--line); }
  .exec-strip .big-number:last-child { border-bottom: 0; }
  .dialog-grid { grid-template-columns: 1fr; }
  .order-card { grid-template-columns: 1fr; }
  .order-side { flex-direction: row; align-items: center; justify-content: space-between; }
  .order-facts { grid-template-columns: 1fr 1fr; }

  /* 表格变卡片：靠 td[data-label] 提供字段名 */
  .table-wrap { overflow-x: visible; }
  table, tbody, tr, td, tbody th { display: block; width: 100%; }
  table { font-size: 13px; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 8px;
    background: var(--surface);
  }
  tbody tr:last-child { margin-bottom: 0; }
  td, tbody th {
    border: 0;
    padding: 2px 0;
    white-space: normal;
    overflow-wrap: anywhere;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    text-align: right;
  }
  td::before {
    content: attr(data-label);
    flex: none;
    color: var(--muted);
    font-size: 12px;
    text-align: left;
  }
  td:not([data-label])::before { content: none; }
  tbody th { font-weight: 600; text-align: left; }
  td.num { text-align: right; }
  td.wrap-cell { min-width: 0; }
}

@media (max-width: 400px) {
  .order-facts { grid-template-columns: 1fr; }
  .more-numbers dl { grid-template-columns: 1fr; }
  .big-number dd { font-size: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
