/* SPY 0DTE Trading Desk — Styles */
/* ★ 颜色规范（中国惯例）：红=涨/盈利  绿=跌/亏损 */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { height: 100%; overflow: hidden; }
body {
  background: #0d1117; color: #e6edf3;
  font-family: -apple-system, 'SF Pro Text', 'Helvetica Neue', monospace;
  font-size: 13px;
  height: 100%; overflow: hidden;
  display: flex; flex-direction: column;  /* ★ 整页 flex column，横幅出现时 .main 自动压缩 */
}

/* ═══════════════════════════════
   顶栏 — 高度固定 52px (触摸区域)
═══════════════════════════════ */
.topbar {
  background: #161b22; border-bottom: 1px solid #30363d;
  height: 52px; padding: 0 16px;
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0; position: sticky; top: 0; z-index: 100;
}
.topbar-left  { display: flex; align-items: center; gap: 10px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.title { font-size: 14px; font-weight: 800; color: #58a6ff; letter-spacing: 1px; }
.badge { padding: 3px 9px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.badge-green  { background: #1f4a2a; color: #3fb950; border: 1px solid #2ea043; }
.badge-red    { background: #4a1f1f; color: #f85149; border: 1px solid #f85149; }
.badge-yellow { background: #3d3010; color: #d29922; border: 1px solid #d29922; }
.badge-gray   { background: #21262d; color: #8b949e; border: 1px solid #30363d; }
.badge-blue   { background: #1a2e4a; color: #58a6ff; border: 1px solid #58a6ff; }
.badge-purple { background: #2d1f4a; color: #bc8cff; border: 1px solid #bc8cff; }
.clock { color: #8b949e; font-size: 11px; white-space: nowrap; }
.env-toggle { display: flex; border: 1px solid #30363d; border-radius: 6px; overflow: hidden; }
.env-toggle button {
  padding: 4px 12px; border: none; cursor: pointer; font-size: 11px; font-weight: 700;
  background: #21262d; color: #8b949e; font-family: inherit;
  min-height: 32px;
}
.env-toggle button.active-sim  { background: #1a2e4a; color: #58a6ff; }
.env-toggle button.active-real { background: #4a1f1f; color: #f85149; }
.env-toggle button.active-paper { background: #2d1f4a; color: #bc8cff; }
.env-toggle button.active-backtest { background: #1f3010; color: #3fb950; border-left: 1px solid #2ea043; }
.icon-btn {
  background: #21262d; border: 1px solid #30363d; color: #8b949e;
  border-radius: 6px; padding: 4px 10px; font-size: 11px; cursor: pointer;
  min-height: 32px; min-width: 44px;
}

/* ═══════════════════════════════
   SPY 横幅
═══════════════════════════════ */
.spy-bar {
  background: #0d1117; border-bottom: 1px solid #21262d;
  padding: 6px 16px; height: 50px;
  display: flex; align-items: center; gap: 14px;
  flex-shrink: 0; overflow: hidden;
}
.spy-price-main { font-size: 26px; font-weight: 800; letter-spacing: -1px; white-space: nowrap; }
.spy-chg { font-size: 16px; font-weight: 700; white-space: nowrap; color: #8b949e; }
/* ★ 红涨绿跌 */
.spy-chg.up   { color: #f85149; }
.spy-chg.down { color: #3fb950; }
.spy-meta { display: flex; gap: 12px; font-size: 11px; color: #8b949e; flex-wrap: nowrap; overflow: hidden; }
.spy-meta b { color: #c9d1d9; }
.signal-pill {
  display: flex; align-items: center; gap: 6px; margin-left: auto; flex-shrink: 0;
  padding: 4px 12px; border-radius: 20px; font-size: 11px; font-weight: 700;
  white-space: nowrap;
}
.signal-pill.CALL    { background: #2a1515; color: #f85149; border: 1px solid #f85149; }
.signal-pill.PUT     { background: #152a15; color: #3fb950; border: 1px solid #3fb950; }
.signal-pill.NEUTRAL { background: #21262d; color: #8b949e; border: 1px solid #30363d; }

/* ═══════════════════════════════
   休市警告
═══════════════════════════════ */
#staleWarning {
  display: none; background: #3d3010; border-bottom: 1px solid #d29922;
  color: #d29922; padding: 4px 16px; font-size: 11px; text-align: center;
  flex-shrink: 0;
}

/* ═══════════════════════════════
   主体布局：左右两栏 + 中间拖拽
═══════════════════════════════ */
.main {
  display: grid;
  grid-template-columns: 1fr 6px 1fr;  /* 左 | 拖拽条 | 右 */
  grid-template-rows: 1fr;              /* 单行 */
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.col-left       { grid-column: 1; grid-row: 1; }
.main-resizer   { grid-column: 2; grid-row: 1; cursor: col-resize; background: #21262d;
                   display: flex; align-items: center; justify-content: center; user-select: none;
                   transition: background .15s; }
.main-resizer:hover { background: rgba(88,166,255,.25); }
.main-resizer > div { width: 2px; height: 32px; border-radius: 1px; background: #484f58; pointer-events: none; }
.col-right-panel { grid-column: 3; grid-row: 1; }
/* ★ 期权链：左栏内 flex 子项（K线下方） */
.chain-bottom   { flex-shrink: 0; max-height: 200px; overflow-y: auto;
                   border-top: 1px solid #30363d; background: #0d1117; }

@media (max-width: 768px) {
  .main {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    height: auto;
    overflow-y: auto;
  }
  .col-left       { grid-column: 1; grid-row: 1; }
  .main-resizer   { display: none; }
  .col-right-panel { grid-column: 1; grid-row: 2; }
  .chain-bottom   { max-height: none; }
  .col { height: auto; max-height: none; overflow: visible; }
  .col-mid, .col-right-panel { border-top: 1px solid #21262d; }
  .col-left { border-right: none; }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .main { grid-template-columns: 1fr 6px 1fr; grid-template-rows: 1fr; flex: 1; min-height: 0; }
}

/* 右侧大列：持仓（上）+ 操作栏（下），内部竖向分割 */
.col-right-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  border-left: 1px solid #21262d;
}
.col-right-panel .col-mid {
  flex: 1 1 0;
  min-height: 0;
  border-right: none;
}
.col-right-panel .col-right {
  flex: 0 0 auto;
  max-height: 20vh;
  border-top: 1px solid #21262d;
  overflow-y: auto;
}

/* ═══════════════════════════════
   策略建议侧边抽屉
═══════════════════════════════ */
.strategy-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 2000;
}
.strategy-overlay.open { display: block; }

.strategy-drawer {
  position: fixed;
  top: 52px;               /* 顶栏高度 */
  right: -380px;           /* 初始隐藏在屏幕右侧 */
  width: 360px;
  max-width: 92vw;
  height: calc(100vh - 52px - 50px);  /* 去掉顶栏和底部 */
  background: #161b22;
  border-left: 1px solid #30363d;
  z-index: 2100;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: right 0.28s cubic-bezier(.4,0,.2,1);
  box-shadow: -4px 0 24px rgba(0,0,0,.5);
}
.strategy-drawer.open { right: 0; }

.strategy-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 8px;
  border-bottom: 1px solid #21262d;
  flex-shrink: 0;
  background: #0d1117;
}

.strategy-drawer #advicePanel {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px;
  font-size: 9px;
  color: #8b949e;
}

/* 策略按钮激活状态 */
#btnStrategy.active {
  background: #2a3520;
  border-color: #3fb950;
  color: #3fb950;
}

.col {
  display: flex; flex-direction: column;
  height: 100%; overflow: hidden;
}
.col-left  { /* border-right 已在新规则里 */ }
.col-mid   { /* border-right 由 col-right-panel 内部控制 */ }
.col-right { background: #0d1117; }

/* ═══════════════════════════════
   卡片 / 区块
═══════════════════════════════ */
.card {
  background: #161b22; border: 1px solid #30363d;
  border-radius: 8px; padding: 10px 12px;
}
.sec-title {
  font-size: 10px; font-weight: 700; color: #8b949e;
  text-transform: uppercase; letter-spacing: 1px;
  margin-bottom: 6px; display: flex; align-items: center; gap: 5px;
}
.dot { width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0; }

/* ═══════════════════════════════
   左栏：图表区 + 期权链
═══════════════════════════════ */
:root {
  --chain-h: 130px;
}
.col-left {
  display: flex !important;
  flex-direction: column;
  overflow: hidden;
}

.chart-wrap {
  padding: 8px 12px 4px;
  min-height: 300px;
  flex: 1;
  border-bottom: 1px solid #21262d;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
#chartResizer:hover > div { background: #58a6ff; }
#chartResizer:hover { background: rgba(88,166,255,0.06); }
#spyCanvas { width: 100%; height: 80px; display: block; }
/* klineCanvas/volCanvas/macdCanvas flex 比例由 HTML klineWrap 内 inline style 控制（6:2:2.5）*/
/* ★ 隐藏 Lightweight Charts TradingView attribution logo */
#lwTick a[href*="tradingview"],
#lwKline a[href*="tradingview"],
#lwVol a[href*="tradingview"],
#lwMacd a[href*="tradingview"] {
  display: none !important;
}


.chain-area {
  overflow-y: auto;
  padding: 6px 12px 8px;
  min-height: 0;
}
.chain-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 5px; font-size: 10px; color: #8b949e;
}
.qty-input {
  width: 40px; background: #0d1117; border: 1px solid #30363d;
  border-radius: 4px; padding: 2px 4px; color: #e6edf3;
  font-size: 12px; text-align: center; outline: none;
}
.chain-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.chain-table th {
  padding: 3px 3px; font-size: 10px; font-weight: 600; color: #8b949e;
  border-bottom: 1px solid #21262d; white-space: nowrap;
}
.chain-table td { padding: 3px 3px; border-bottom: 1px solid #0d1117; }
.chain-table tr:hover td { background: #1c2128; }
.chain-table tr.atm td      { background: #1a1f2e; }
.chain-table tr.rec-call td { background: #1a1f0a; }
.chain-table tr.rec-put td  { background: #0a1a0a; }

.btn-buy, .btn-sell-chain {
  padding: 6px 10px; border-radius: 5px; font-size: 11px; font-weight: 700;
  cursor: pointer; white-space: nowrap; font-family: inherit;
  min-height: 36px; min-width: 44px;
}
.btn-buy        { border: 1px solid #f85149; background: #2a1515; color: #f85149; }
.btn-sell-chain { border: 1px solid #3fb950; background: #152a15; color: #3fb950; }
.btn-buy:hover        { background: #f85149; color: #fff; }
.btn-sell-chain:hover { background: #3fb950; color: #fff; }
.btn-buy:disabled, .btn-sell-chain:disabled { opacity: .4; cursor: not-allowed; }
.btn-buy:active { background: #f85149; color: #fff; }
.btn-sell-chain:active { background: #3fb950; color: #fff; }

/* ═══════════════════════════════
   中栏：持仓监控 + 挂单
═══════════════════════════════ */
.col-mid { overflow: hidden; }
.mid-top { flex: 1; overflow-y: auto; padding: 8px 10px; min-height: 0; border-bottom: 1px solid #21262d; }
.mid-bot { flex-shrink: 0; overflow-y: auto; max-height: 200px; padding: 6px 10px; }

.pos-card {
  border-radius: 8px; padding: 10px 12px; margin-bottom: 6px;
  border: 1px solid #30363d;
}
/* ★ 红=盈利  绿=亏损 */
.pos-card.profit { border-color: #f85149; }
.pos-card.loss   { border-color: #2ea043; }
.pos-card.closing { border-color: #d29922; animation: pulse .8s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.75} }
.pos-dir-badge { font-size: 10px; font-weight: 800; padding: 2px 7px; border-radius: 4px; }
.pos-dir-badge.CALL { background: #2a1515; color: #f85149; border: 1px solid #f85149; }
.pos-dir-badge.PUT  { background: #152a15; color: #3fb950; border: 1px solid #3fb950; }
.pos-pnl { font-weight: 800; }
/* ★ 红=盈利  绿=亏损 */
.pos-pnl.profit { color: #f85149; }
.pos-pnl.loss   { color: #3fb950; }
.btn-sell-pos {
  padding: 6px 14px; border: 1px solid #f85149;
  background: #2a1515; color: #f85149; border-radius: 6px;
  font-size: 12px; font-weight: 700; cursor: pointer; font-family: inherit;
  min-height: 36px;
}
.btn-sell-pos:hover, .btn-sell-pos:active { background: #f85149; color: #fff; }

.prog-wrap { margin: 4px 0; }
.prog-label { display: flex; justify-content: space-between; font-size: 9px; color: #8b949e; margin-bottom: 2px; }
.prog-bar { height: 4px; background: #21262d; border-radius: 2px; overflow: hidden; position: relative; }
.prog-fill { height: 100%; border-radius: 2px; transition: width .4s; }
/* ★ 红=盈利  绿=亏损 */
.prog-fill.pnl-pos  { background: linear-gradient(90deg, #da3633, #f85149); }
.prog-fill.pnl-neg  { background: linear-gradient(90deg, #1a7f37, #3fb950); }
.prog-fill.time     { background: #58a6ff; }
.prog-fill.time-warn{ background: #f85149; }

.order-row {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 0; border-bottom: 1px solid #0d1117;
  font-size: 11px;
}
.order-row:last-child { border-bottom: none; }
.btn-cancel {
  padding: 4px 10px; border: 1px solid #f85149;
  background: #2a1515; color: #f85149; border-radius: 5px;
  font-size: 10px; font-weight: 700; cursor: pointer; font-family: inherit;
  min-height: 32px; margin-left: auto; white-space: nowrap;
}
.btn-cancel:hover, .btn-cancel:active { background: #f85149; color: #fff; }
.order-empty { text-align: center; color: #8b949e; padding: 12px 0; font-size: 11px; }
.pos-empty   { text-align: center; color: #8b949e; padding: 20px 0; font-size: 11px; }

/* ═══════════════════════════════
   右栏：操作 + 参数 + 统计 + 日志
═══════════════════════════════ */
.col-right { overflow-y: auto; padding: 8px 10px; gap: 8px; display: flex; flex-direction: column; }

.btn-scan {
  width: 100%; padding: 12px; border: 1px solid #3fb950;
  background: #1f2d1f; color: #3fb950; border-radius: 8px;
  font-size: 13px; font-weight: 700; cursor: pointer; font-family: inherit;
  min-height: 44px;
}
.btn-scan:hover, .btn-scan:active { background: #3fb950; color: #fff; }
.btn-scan:disabled { opacity: .4; cursor: not-allowed; }

.param-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
}
.param-item {
  background: #0d1117; border: 1px solid #21262d;
  border-radius: 5px; padding: 4px 7px;
}
.param-label { font-size: 9px; color: #8b949e; margin-bottom: 2px; }
.param-input-row { display: flex; align-items: center; gap: 4px; }
.param-input-row input {
  width: 48px; background: #161b22; border: 1px solid #30363d;
  border-radius: 4px; color: #e6edf3; text-align: center;
  font-size: 12px; padding: 2px 4px; outline: none; font-family: inherit;
  min-height: 26px;
}
.param-input-row span { font-size: 10px; color: #8b949e; }

.stats-row { display: flex; gap: 5px; }
.stat-box {
  flex: 1; background: #0d1117; border: 1px solid #21262d;
  border-radius: 5px; padding: 5px 4px; text-align: center;
}
.s-label { font-size: 9px; color: #8b949e; margin-bottom: 1px; }
.s-value { font-size: 14px; font-weight: 700; }
.s-green { color: #3fb950; }
.s-blue  { color: #58a6ff; }

.log-box {
  background: #0d1117; border: 1px solid #21262d; border-radius: 6px;
  padding: 6px 8px; height: 160px; overflow-y: auto;
  font-size: 10px; line-height: 1.8; flex-shrink: 0;
}
.log-box::-webkit-scrollbar { width: 3px; }
.log-box::-webkit-scrollbar-thumb { background: #30363d; border-radius: 2px; }
.log-info   { color: #8b949e; }
.log-signal { color: #58a6ff; }
.log-buy    { color: #d29922; }
/* ★ 红=盈利  绿=亏损 */
.log-profit { color: #f85149; }
.log-loss   { color: #3fb950; }
.log-warn   { color: #d29922; font-weight: 700; }

/* ═══════════════════════════════
   通用
═══════════════════════════════ */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: #30363d; border-radius: 2px; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.3} }
.blink { animation: blink 1s infinite; }
.close-reason { font-size: 10px; color: #8b949e; margin-top: 4px; padding: 3px 6px; background: #21262d; border-radius: 3px; }
