:root {
  color-scheme: light;
  --bg: #f5f4f1;
  --bg-soft: #eeece8;
  --panel: #ffffff;
  --panel-soft: #faf9f7;
  --line: #e3e0da;
  --line-strong: #d6d1c8;
  --text: #2c2c2a;
  --muted: #7a7974;
  --faint: #aaa79f;
  --green: #08745f;
  --green-bg: #f2faf7;
  --red: #b3261e;
  --red-bg: #fff6f3;
  --amber: #a35a00;
  --amber-bg: #fff7e8;
  --blue: #3b73ff;
  --blue-bg: #edf3ff;
  --orange: #f05a00;
  --shadow: 0 16px 36px rgba(44, 44, 42, 0.08);
  --shadow-soft: 0 8px 20px rgba(44, 44, 42, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 78% 6%, rgba(240, 90, 0, 0.08), transparent 26%),
    linear-gradient(180deg, var(--bg-soft) 0, var(--bg) 220px, var(--bg) 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  overflow-x: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(250, 249, 247, 0.82);
  backdrop-filter: blur(18px);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.25;
  font-weight: 780;
}

h2 {
  font-size: 16px;
  font-weight: 760;
}

#snapshotMeta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.toolbar {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.refresh-group {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.control-label {
  color: var(--muted);
  font-size: 12px;
}

.refresh-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
}

.refresh-row button {
  min-width: 72px;
  font-size: 14px;
  line-height: 1;
}

.refresh-status {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  min-width: 112px;
  max-width: 180px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

select,
button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  font: inherit;
  box-shadow: 0 1px 0 rgba(44, 44, 42, 0.04);
}

select {
  min-width: 150px;
  padding: 0 12px;
}

button {
  padding: 0 14px;
  cursor: pointer;
  font-weight: 650;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

button:hover {
  border-color: var(--line-strong);
  background: #ffffff;
}

button:active {
  transform: translateY(1px);
}

.layout {
  display: grid;
  grid-template-columns: minmax(680px, 1fr);
  gap: 14px;
  padding: 18px 24px 28px;
}

.rule-strip {
  grid-column: 1 / -1;
  min-width: 0;
  width: 100%;
  margin: 4px 0 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(250, 249, 247, 0.74);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.rule-head,
.rule-grid {
  min-width: 0;
}

.rule-head {
  padding: 0 2px 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.rule-summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.rule-head strong {
  color: var(--text);
  font-size: 14px;
  font-weight: 760;
  white-space: nowrap;
}

.rule-head span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  text-align: right;
}

.rule-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.rule-row {
  display: grid;
  gap: 6px;
  align-content: start;
  min-height: 78px;
  padding: 12px;
  border: 1px solid #eeebe6;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.rule-row-foundation {
  grid-column: 1 / -1;
  min-height: 0;
  grid-template-columns: auto auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.82);
}

.rule-row-large {
  grid-column: 1 / -1;
}

.rule-step {
  width: fit-content;
  max-width: 100%;
  padding: 2px 7px;
  border: 1px solid #e7e2da;
  border-radius: 999px;
  background: #fbfaf8;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.4;
  white-space: nowrap;
}

.rule-row strong {
  color: var(--text);
  font-size: 12px;
  font-weight: 760;
  white-space: nowrap;
}

.rule-row span {
  min-width: 0;
}

.rule-row-muted {
  background: rgba(255, 255, 255, 0.56);
}

.rule-detail {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.rule-title-line {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid #eeebe6;
}

.rule-title-line strong {
  flex: 0 0 auto;
  color: var(--text);
  font-size: 12px;
  font-weight: 760;
}

.rule-title-line span {
  color: var(--muted);
  line-height: 1.45;
}

.rule-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.rule-mini {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid #eeebe6;
  border-radius: 8px;
  background: rgba(250, 249, 247, 0.74);
}

.rule-detail-grid b {
  display: block;
  margin-bottom: 6px;
  color: var(--text);
  font-size: 12px;
}

.rule-detail-grid ul {
  display: grid;
  gap: 5px;
  margin: 0;
  padding-left: 15px;
}

.rule-trigger {
  width: fit-content;
  max-width: 100%;
  padding: 6px 10px;
  border: 1px solid #eeebe6;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.74);
  color: var(--muted);
}

.panel {
  min-width: 0;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.panel-wide {
  grid-column: 1 / -1;
}

.panel-large {
  grid-column: 1 / -1;
}

.combo-wrap {
  max-height: 360px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(250, 249, 247, 0.9);
}

.panel-head span {
  color: var(--muted);
  font-size: 12px;
}

.table-wrap {
  overflow: auto;
  max-height: 520px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 11px 14px;
  border-bottom: 1px solid #eeebe6;
  text-align: left;
  white-space: nowrap;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f7f5f1;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.numeric-th,
.numeric-cell {
  text-align: right;
}

.numeric-cell .funding-cell {
  justify-items: end;
}

.help-th {
  overflow: visible;
}

.depth-help {
  cursor: help;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}

.depth-help:focus {
  outline: 2px solid rgba(59, 115, 255, 0.32);
  outline-offset: 3px;
  border-radius: 4px;
}

.depth-tooltip {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 8;
  display: none;
  width: 340px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fffdf9;
  box-shadow: var(--shadow-soft);
  color: var(--text);
  font-size: 12px;
  font-weight: 520;
  line-height: 1.55;
  text-transform: none;
  white-space: normal;
}

.depth-help:hover + .depth-tooltip,
.depth-help:focus + .depth-tooltip {
  display: block;
}

tbody tr {
  cursor: pointer;
  transition: background 120ms ease;
}

tbody tr:hover,
tbody tr.selected {
  background: #f7f3ed;
}

.symbol {
  font-weight: 750;
  color: #222220;
}

.symbol-price {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  white-space: nowrap;
}

.symbol-price-separator {
  color: var(--faint);
  font-size: 12px;
}

.symbol-price-value {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.muted {
  color: var(--muted);
}

.tag-row {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-top: 5px;
  max-width: 300px;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 21px;
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #f8f7f4;
  color: var(--muted);
  font-size: 12px;
  font-weight: 680;
  line-height: 1.2;
  white-space: nowrap;
}

.tag-overflow {
  color: var(--faint);
  background: rgba(248, 247, 244, 0.7);
}

.level-候选对冲组合 {
  color: #0d5f51;
  border-color: #cfe3dc;
  background: #f7fbf9;
}

.level-高危禁入 {
  color: #914235;
  border-color: #ead0c9;
  background: #fff9f6;
}

.level-资金费异常,
.level-价差异常 {
  color: var(--amber);
  border-color: #f0d39b;
  background: var(--amber-bg);
}

.positive {
  color: var(--green);
}

.negative {
  color: var(--red);
}

.funding-cell {
  display: grid;
  gap: 2px;
  line-height: 1.25;
}

.funding-cell small {
  color: var(--muted);
  font-size: 10px;
}

.detail-empty,
.detail-body {
  padding: 14px;
  color: var(--muted);
  font-size: 13px;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(44, 44, 42, 0.08);
}

.detail-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 30;
  width: min(520px, calc(100vw - 32px));
  height: 100vh;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -18px 0 42px rgba(44, 44, 42, 0.12);
  transform: translateX(100%);
  transition: transform 160ms ease;
  overflow: auto;
  will-change: transform;
}

.detail-drawer.open {
  transform: translateX(0);
}

.drawer-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: #faf9f7;
}

.drawer-head p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.icon-button {
  width: 30px;
  min-width: 30px;
  min-height: 30px;
  padding: 0;
  border-radius: 8px;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}

.row-action {
  min-height: 28px;
  padding: 0 11px;
  border-radius: 8px;
  color: var(--text);
  border-color: var(--line-strong);
  background: #fbfaf8;
  font-size: 12px;
  box-shadow: none;
}

.row-action:hover {
  border-color: #bdb7ac;
  background: #f4f1eb;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 0;
}

.detail-body {
  display: grid;
  gap: 10px;
}

.detail-card,
.detail-section-card {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 253, 249, 0.84);
}

.detail-overview {
  background: rgba(250, 249, 247, 0.9);
}

.detail-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.detail-section-head strong {
  color: var(--text);
  font-size: 13px;
  font-weight: 760;
}

.detail-section-head span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 680;
}

.detail-section {
  margin-top: 16px;
}

.detail-section > strong {
  display: block;
  margin-bottom: 9px;
  color: var(--text);
}

.detail-note {
  margin: -2px 0 9px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.history-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.history-table {
  min-width: 430px;
  font-size: 11px;
}

.history-table th,
.history-table td {
  padding: 8px 9px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 9px;
  background: #fffdf9;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.metric strong {
  display: block;
  margin-top: 4px;
  font-size: 14px;
  color: var(--text);
}

.metric-hint {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 520;
  line-height: 1.45;
  white-space: normal;
}

.reason-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  color: var(--text);
  list-style: none;
}

.reason-list li {
  padding: 7px 9px;
  border: 1px solid #eeebe6;
  border-radius: 8px;
  background: rgba(250, 249, 247, 0.72);
  line-height: 1.45;
}

.review-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.combo-detail-list {
  display: grid;
  gap: 7px;
}

.combo-detail-item {
  border: 1px solid #eeebe6;
  border-radius: 9px;
  padding: 9px 10px;
  background: rgba(255, 255, 255, 0.74);
  box-shadow: none;
}

.combo-detail-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--text);
  font-weight: 700;
  font-size: 13px;
}

.combo-status {
  flex: 0 0 auto;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid currentColor;
  font-size: 11px;
  font-weight: 760;
  line-height: 1.35;
}

.combo-detail-direction {
  margin-top: 5px;
  color: var(--text);
  font-size: 12px;
  line-height: 1.4;
}

.combo-detail-reason {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.combo-ok {
  color: var(--green);
  border-color: #b8ded4;
  background: var(--green-bg);
}

.combo-blocked {
  color: #9b4d45;
  border-color: #eadbd6;
  background: rgba(255, 252, 250, 0.78);
}

@media (max-width: 980px) {
  .topbar,
  .layout {
    display: block;
  }

  .rule-strip {
    margin-bottom: 14px;
  }

  .rule-head {
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
  }

  .rule-summary,
  .rule-title-line {
    display: grid;
    gap: 5px;
  }

  .rule-summary span {
    text-align: left;
  }

  .rule-grid,
  .rule-detail-grid {
    grid-template-columns: 1fr;
  }

  .toolbar {
    margin-top: 14px;
  }

  .panel {
    margin-bottom: 14px;
  }

  .detail-drawer {
    top: auto;
    bottom: 0;
    width: 100vw;
    height: min(78vh, 720px);
    border-left: 0;
    border-top: 1px solid var(--line);
    transform: translateY(100%);
  }

  .detail-drawer.open {
    transform: translateY(0);
  }
}
