:root {
  --bg: #0b0f14;
  --panel: #111820;
  --panel-2: #151e29;
  --line: #223041;
  --text: #e6edf3;
  --muted: #8b9bb0;
  --accent: #3ba7f0;
  --up: #ff5c5c;      /* 红涨 */
  --down: #2ecc8f;    /* 绿跌 */
  --amber: #f5b940;
  --call: var(--up);
  --put: var(--down);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
}

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 6px;
  padding: 5px 10px;
}
button:hover { border-color: var(--accent); }
button.active { background: var(--accent); border-color: var(--accent); color: #04121e; }

input[type="number"] {
  width: 58px;
  background: #0d1420;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 6px;
  font: inherit;
  text-align: center;
}
input[type="number"]:focus { outline: none; border-color: var(--accent); }

#app { height: 100vh; display: flex; flex-direction: column; }

header {
  height: 52px;
  flex: 0 0 52px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
header h1 { font-size: 16px; margin: 0; }
header .spacer { flex: 1; }
.header-meta { color: var(--muted); font-size: 12px; }
#countdown { color: var(--amber); font-variant-numeric: tabular-nums; }

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 330px 1fr;
}

/* 左侧列表 */
.screen-panel {
  border-right: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.screen-head {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.screen-head .rule { color: var(--muted); font-size: 12px; margin-top: 4px; }
#screen-list {
  flex: 1;
  overflow: auto;
  padding: 6px;
}
.screen-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 6px;
  cursor: pointer;
  background: var(--panel-2);
}
.screen-item:hover { border-color: var(--accent); }
.screen-item.selected { border-color: var(--accent); background: #132435; }
.screen-item .row1 { display: flex; align-items: baseline; gap: 8px; }
.screen-item .name { font-weight: 600; font-size: 15px; }
.screen-item .code { color: var(--muted); font-size: 12px; }
.screen-item .rank { color: var(--amber); font-size: 12px; }
.screen-item .row2 { display: flex; gap: 12px; margin-top: 5px; font-size: 12px; color: var(--muted); }
.screen-item .iv { color: var(--put); }
.screen-item .rv { color: var(--call); }
.screen-item .gap { color: var(--amber); }

/* 左侧今日门信号卡片 */
.gate-signal-card {
  border-top: 1px solid var(--line);
  background: var(--panel);
  flex: 0 0 38%;
  max-height: 42%;
  min-height: 130px;
  display: flex;
  flex-direction: column;
}
.gate-signal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
#gate-signal-list { overflow: auto; padding: 6px; }
.gate-signal-group {
  font-size: 11px;
  color: var(--amber);
  margin: 4px 2px;
}
.gate-signal-item {
  font-size: 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 6px;
  margin-bottom: 4px;
  background: var(--panel-2);
}
.gate-signal-item.match {
  border-color: var(--up);
  background: rgba(255, 92, 92, .08);
}
.gate-signal-item .gs-line1 { display: flex; justify-content: space-between; gap: 6px; }
.gate-signal-item .gs-sym { font-weight: 700; }
.gate-signal-item .gs-badge {
  font-size: 10px;
  color: var(--up);
  white-space: nowrap;
}
.gate-signal-item .gs-gap {
  margin-top: 3px;
  font-size: 11px;
  color: var(--amber);
}
.gate-signal-item .gs-kind {
  font-size: 10px;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 20px;
  padding: 0 5px;
  white-space: nowrap;
}
.gate-signal-item .gs-contract {
  margin-top: 3px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text);
}

/* 右侧详情 */
.detail {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 14px;
}
.placeholder {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  flex-direction: column;
  gap: 8px;
}

.product-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.product-head h2 { margin: 0; font-size: 18px; }
.product-head .meta { color: var(--muted); font-size: 12px; }
.badges { display: flex; gap: 8px; flex-wrap: wrap; }
.badge { border: 1px solid var(--line); border-radius: 20px; padding: 3px 9px; font-size: 12px; color: var(--muted); }
.badge .strong { color: var(--text); font-weight: 600; }

.exp-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0; }
.exp-tab { font-size: 12px; }

.info-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
  margin: 10px 0 14px;
}
.info-card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.info-card .k { color: var(--muted); font-size: 11px; }
.info-card .v { font-size: 16px; font-weight: 600; margin-top: 2px; }

.chain-table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: auto;
  max-height: 420px;
}
table.chain { border-collapse: collapse; width: 100%; min-width: 860px; font-size: 12px; }
table.chain th, table.chain td {
  border-bottom: 1px solid var(--line);
  padding: 4px 6px;
  white-space: nowrap;
  text-align: center;
}
table.chain th {
  position: sticky;
  top: 0;
  background: #182433;
  color: var(--muted);
  z-index: 1;
}
table.chain .strike { font-weight: 700; background: #101a26; }
table.chain .call-cell { color: var(--call); }
table.chain .put-cell { color: var(--put); }
table.chain .sub { color: var(--muted); font-size: 11px; }
table.chain td.atm { background: #1b2940; }
.qty-box input.holding { border-color: var(--accent); background: #102a45; }

/* 持仓汇总 + 希腊字母金额 */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  margin: 14px 0;
}
.greek-card {
  background: linear-gradient(180deg, #132033 0%, #101824 100%);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
.greek-card .symbol { color: var(--muted); font-size: 12px; }
.greek-card .value { font-size: 20px; font-weight: 700; margin-top: 3px; font-variant-numeric: tabular-nums; }
.greek-card .note { color: var(--muted); font-size: 11px; margin-top: 2px; }
.positive { color: var(--up); }   /* 正数 / 上涨 = 红 */
.negative { color: var(--down); } /* 负数 / 下跌 = 绿 */

.section-title { margin: 18px 0 8px; color: var(--text); font-size: 15px; font-weight: 600; }

.leg-list { display: flex; flex-direction: column; gap: 6px; }
.leg-row {
  display: grid;
  grid-template-columns: 42px 1fr 70px 110px 90px 90px 90px 90px;
  gap: 8px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
}
.leg-row .type-call { color: var(--call); font-weight: 700; }
.leg-row .type-put { color: var(--put); font-weight: 700; }

.whatif {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
@media (max-width: 1100px) {
  .whatif { grid-template-columns: 1fr; }
  .leg-row { grid-template-columns: 1fr 1fr; }
}
.whatif-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
.whatif-card h3 { margin: 0 0 8px; font-size: 14px; }
.whatif-row { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px dashed var(--line); }
.whatif-row .l { color: var(--muted); }
.whatif-row .v { font-weight: 600; }
.delta-change-positive { color: var(--up); }
.delta-change-negative { color: var(--down); }

.cost-input {
  width: 76px;
  margin-left: 4px;
  background: #0d1420;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 4px;
  text-align: right;
}

.capital-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
}
.capital-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  align-items: end;
}
.cash-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}
.cash-input {
  width: 100%;
  background: #0d1420;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
}
.cash-input:focus { outline: none; border-color: var(--accent); }
.seg {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.seg label {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 8px;
  padding: 7px 9px;
  font-size: 12px;
  cursor: pointer;
  color: var(--muted);
}
.seg label.active { border-color: var(--accent); color: var(--text); background: #132435; }
.seg input { margin-right: 4px; }

.plan-group-title { margin: 14px 0 6px; font-size: 14px; }
.plan-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
.plan-card.best { border-color: var(--amber); background: #1d1a10; }
.plan-title { font-weight: 600; margin-bottom: 8px; }
.best-tag {
  color: #201500;
  background: var(--amber);
  border-radius: 20px;
  padding: 1px 8px;
  font-size: 11px;
  margin-left: 6px;
}
.plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
}
.plan-grid .k { color: var(--muted); font-size: 11px; }
.plan-grid .v { font-size: 14px; font-weight: 600; margin-top: 2px; }

/* 行权价横线 + 期权块 */
.board-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.board-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 8px 12px;
}
.board-canvas {
  width: max-content;
  min-width: 100%;
}
.board-row {
  display: grid;
  grid-template-columns: repeat(var(--cols), 76px);
  width: max-content;
}
.board-calls,
.board-puts {
  position: relative;
  display: block;
  height: 96px;
  min-width: calc(var(--cols) * 76px);
}
.opt-block-wrap {
  position: absolute;
  width: 72px;
  z-index: 3;
  cursor: grab;
  touch-action: none;
}
.board-calls .opt-block-wrap { bottom: 8px; }
.board-puts .opt-block-wrap { top: 8px; }
.opt-block-wrap.dragging { z-index: 8; cursor: grabbing; opacity: .94; transform: scale(1.04); }
.drag-hint { color: var(--muted); font-size: 10px; cursor: grab; }
.opt-block { width: 72px; }
.board-cell {
  min-height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
}
.board-cell-call { align-items: flex-end; }
.board-cell-put { align-items: flex-start; }
.board-line-row {
  position: relative;
  height: 34px;
}
.board-line-row::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 2px;
  background: var(--muted);
}
.board-strike {
  padding-top: 9px;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  border-left: 1px dashed #26364a;
}
.board-strike span { display: block; }
.board-strike em { font-style: normal; color: var(--amber); font-size: 10px; }
.board-strike.atm span { color: var(--text); font-weight: 700; }

.opt-block {
  width: 72px;
  border-radius: 8px;
  padding: 4px 4px 6px;
  font-size: 11px;
  text-align: center;
  background: #0d1420;
  border: 1px solid var(--line);
}
.opt-block.call { border-color: var(--up); }
.opt-block.put { border-color: var(--down); }
.opt-block.call b { color: var(--up); }
.opt-block.put b { color: var(--down); }
.opt-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2px;
}
.opt-block-head b { font-size: 10px; }
.block-delete {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 0;
  width: 14px;
  height: 14px;
  line-height: 12px;
  font-size: 13px;
}
.block-delete:hover { color: var(--up); }
.opt-block-price { margin: 3px 0; font-size: 11px; }
.opt-block-qty { display: flex; align-items: center; justify-content: center; gap: 5px; }
.opt-block-qty button {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 4px;
  width: 18px;
  height: 18px;
  line-height: 14px;
  padding: 0;
  font-size: 13px;
}
.opt-block-qty button:disabled { opacity: .35; cursor: default; }
.opt-block-qty span { min-width: 16px; font-weight: 700; }

.add-call {
  background: rgba(255, 92, 92, .12);
  border-color: var(--up);
  color: var(--up);
  font-weight: 700;
}
.add-call:hover { background: rgba(255, 92, 92, .22); border-color: var(--up); }
.add-put {
  background: rgba(46, 204, 143, .12);
  border-color: var(--down);
  color: var(--down);
  font-weight: 700;
}
.add-put:hover { background: rgba(46, 204, 143, .22); border-color: var(--down); }

.board-canvas { position: relative; }
.board-scroll.placing { cursor: crosshair; touch-action: none; }

.place-marker {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 76px;
  pointer-events: none;
  z-index: 5;
}
.place-line {
  position: absolute;
  left: 37px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--amber);
  box-shadow: 0 0 6px rgba(245,185,64,.55);
}
.place-marker.call .place-line { background: var(--up); box-shadow: 0 0 6px rgba(255,92,92,.55); }
.place-marker.put .place-line { background: var(--down); box-shadow: 0 0 6px rgba(46,204,143,.55); }
.place-chip {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  background: #0d1420;
  border: 1px solid var(--amber);
  color: var(--text);
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 11px;
  white-space: nowrap;
  z-index: 2;
}
.place-marker.call .place-chip { border-color: var(--up); }
.place-marker.put .place-chip { border-color: var(--down); }

.add-option-mask {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  align-items: center;
  justify-content: center;
  z-index: 40;
}
.add-option-dialog {
  width: 320px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.add-option-dialog h3 { margin: 0; }
.add-option-dialog label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}
.add-option-dialog select {
  background: #0d1420;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px;
  font: inherit;
}
.add-option-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* 右侧项目抽屉 */
.layout { transition: margin-right .18s ease; }
.layout.project-open { margin-right: 320px; }
.project-drawer {
  position: fixed;
  top: 52px;
  right: 0;
  bottom: 0;
  width: 320px;
  display: flex;
  z-index: 35;
  transform: translateX(calc(100% - 40px));
  transition: transform .18s ease;
}
.project-drawer.open { transform: translateX(0); }
.project-tab {
  width: 40px;
  border: 1px solid var(--line);
  border-right: none;
  border-radius: 8px 0 0 8px;
  background: var(--panel);
  color: var(--text);
  font-weight: 700;
  writing-mode: vertical-rl;
  letter-spacing: 2px;
  cursor: pointer;
}
.project-panel {
  flex: 1;
  min-width: 0;
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}
.project-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
#project-list { flex: 1; overflow: auto; padding: 10px; }
.project-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 8px;
  background: var(--panel-2);
  cursor: pointer;
}
.project-card:hover { border-color: var(--accent); }
.project-card.active { border-color: var(--accent); background: #132435; }
.project-card .p-title { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.project-card .p-name { font-weight: 700; }
.project-card .p-status {
  font-size: 10px;
  border: 1px solid var(--down);
  color: var(--down);
  border-radius: 20px;
  padding: 1px 6px;
}
.project-card .p-status.closed {
  border-color: var(--muted);
  color: var(--muted);
}
.project-card .p-meta { color: var(--muted); font-size: 11px; margin-top: 3px; }
.project-pnl { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin-top: 8px; }
.project-pnl .k { color: var(--muted); font-size: 10px; }
.project-pnl .v { font-size: 13px; font-weight: 700; }
.project-empty { color: var(--muted); font-size: 12px; padding: 12px 4px; }

/* 项目动作流水 */
.project-actions { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.actions-toolbar { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.action-list { display: flex; flex-direction: column; gap: 8px; }
.action-card { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--panel-2); }
.action-card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.action-fill-line { padding: 3px 0 3px 8px; border-left: 3px solid var(--line); margin: 3px 0; font-size: 12px; }
.action-fill-line.buy { border-color: var(--up); }
.action-fill-line.sell { border-color: var(--down); }
.action-card-foot { display: flex; justify-content: space-between; margin-top: 6px; color: var(--muted); }
.action-mask { position: fixed; inset: 0; background: rgba(0,0,0,.55); align-items: center; justify-content: center; z-index: 50; }
.action-dialog { width: min(760px, 94vw); max-height: 88vh; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.action-dialog h3 { margin: 0 0 10px; }
.action-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.action-form-grid label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
.action-form-grid label.wide { grid-column: 1 / -1; }
.action-form-grid label.checkbox { flex-direction: row; align-items: center; gap: 6px; }
.action-form-grid input, .action-form-grid select {
  background: #0d1420; color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font: inherit;
}
.action-fill-row {
  display: grid;
  grid-template-columns: 58px 62px 90px 60px 1fr 1fr 26px;
  gap: 6px;
  align-items: center;
  margin-top: 8px;
}
.action-fill-row input, .action-fill-row select {
  width: 100%;
  background: #0d1420; color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 5px 6px; font: inherit;
}
.action-fill-remove { border: none; background: transparent; color: var(--muted); font-size: 16px; cursor: pointer; }
.action-fill-remove:hover { color: var(--up); }

.record-action {
  background: var(--accent);
  border-color: var(--accent);
  color: #04121e;
  font-weight: 700;
}
.diff-dialog { width: min(620px, 94vw); }
.diff-fill-row {
  display: grid;
  grid-template-columns: 190px 1fr;
  gap: 10px;
  align-items: start;
  margin-top: 10px;
}
.diff-fill-row[data-kind="sell"] { grid-template-columns: 190px 1fr 1fr; }
.diff-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
}
.diff-fill-row input {
  width: 100%;
  background: #0d1420;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
}
.diff-fill-row input:disabled {
  opacity: .55;
  color: var(--muted);
  cursor: not-allowed;
}
.diff-note {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  margin-top: 12px;
}
.diff-note input {
  background: #0d1420;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 8px;
  font: inherit;
}

/* 盈亏明细 */
.pnl-detail { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.pnl-leg-row { border-bottom: 1px dashed var(--line); padding: 8px 0; }
.pnl-leg-name { font-weight: 700; margin-bottom: 4px; }
.pnl-leg-nums { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; color: var(--text); }
.pnl-leg-nums span { white-space: nowrap; }
.pnl-leg-formula { margin-top: 4px; color: var(--muted); }
.pnl-action-row { border-bottom: 1px dashed var(--line); padding: 8px 0; }

.error-box {
  background: #2a1518;
  border: 1px solid #713;
  color: #ffb4bd;
  padding: 10px 12px;
  border-radius: 8px;
  margin: 10px 0;
}
.muted { color: var(--muted); }
.small { font-size: 11px; }
.nowrap { white-space: nowrap; }
