/* ========== GLOBAL SCROLLBAR (dark theme) ========== */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.25); }

/* ========== INSTRUMENT INFO BAR ========== */
.instrument-bar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 16px 32px 14px;
  background: #1a1a1f;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.inst-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  font-size: 12px;
}

.inst-breadcrumb a {
  color: #5a5a6a;
  text-decoration: none;
  transition: color 0.15s;
}

.inst-breadcrumb a:hover {
  color: #5cb8e6;
}

.inst-breadcrumb svg {
  color: #3a3a4a;
}

.inst-breadcrumb-current {
  color: #8a8a9a;
}

.inst-bar-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.inst-bar-symbol {
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 20px;
  font-weight: 700;
  color: #e0e0e8;
  letter-spacing: -0.3px;
}

.exchange-badge {
  font-size: 11px;
  font-weight: 600;
  color: #8a8a9a;
  background: rgba(255,255,255,0.06);
  padding: 3px 10px;
  border-radius: 4px;
  letter-spacing: 0.3px;
}

/* Contract Type Tags (Options) */
.type-tag {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 4px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}
.type-tag.call { color: #5cb8e6; background: rgba(92, 184, 230, 0.1); }
.type-tag.put { color: #e0a050; background: rgba(224, 160, 80, 0.1); }

.inst-bar-metrics {
  display: flex;
  align-items: flex-end;
  gap: 0;
}

.inst-metric {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: flex-start;
  padding: 0 20px;
  min-height: 48px;
}

.inst-metric:last-child {
  padding-right: 0;
}

.inst-metric-divider {
  width: 1px;
  height: 32px;
  background: rgba(255,255,255,0.06);
  flex-shrink: 0;
}

.metric-label {
  font-size: 10px;
  font-weight: 600;
  color: #4a4a5a;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.metric-value {
  font-size: 15px;
  font-weight: 600;
  color: #e0e0e8;
  font-variant-numeric: tabular-nums;
}

.metric-sub {
  font-size: 11px;
  font-weight: 500;
  margin-top: 2px;
}

.metric-sub.positive { color: #5cb8e6; }
.metric-sub.negative { color: #e0a050; }

.expiry-countdown {
  color: #5cb8e6 !important;
}

/* ========== GREEKS BAR ========== */
.greeks-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 0 32px;
  height: 40px;
  background: rgba(26, 26, 31, 0.6);
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.greek-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 20px;
  border-right: 1px solid rgba(255,255,255,0.04);
}

.greek-item:last-child {
  border-right: none;
}

.greek-label {
  font-size: 11px;
  font-weight: 500;
  color: #5a5a6a;
}

.greek-value {
  font-size: 12px;
  font-weight: 600;
  color: #a8a8b8;
  font-variant-numeric: tabular-nums;
}

.greek-value.negative { color: #e0a050; }

/* ========== TRADE MAIN ========== */
.trade-main {
  padding: 28px 40px 80px;
}

.trade-card {
  background: #1a1a1f;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 12px;
  padding: 20px;
}

.trade-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.trade-card-title {
  font-size: 15px;
  font-weight: 600;
  color: #e0e0e8;
}

/* ========== CHART + ORDER TOP GRID ========== */
.trade-top-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 16px;
  align-items: stretch;
}
.trade-top-grid > .trade-chart-card {
  flex: 1 1 500px;
  min-width: 0;
}
.trade-top-grid > .trade-orderbook {
  flex: 0 0 240px;
  min-width: 200px;
}
.trade-top-grid > .trade-order-panel {
  flex: 0 0 340px;
  min-width: 280px;
}

/* ===== TRADE PAGE RESPONSIVE ===== */

/* Option page legacy responsive — kept for trade-option.html only.
   Spot/Futures/Equity (body.trade-page-3up) get the new 3-tier layout below. */

/* Tablet: hide orderbook, stack chart and order panel side by side */
@media (max-width: 1100px) {
  .trade-top-grid > .trade-orderbook {
    display: none;
  }
  .trade-top-grid > .trade-chart-card {
    flex: 1 1 400px;
  }
  .trade-top-grid > .trade-order-panel {
    flex: 0 0 320px;
    min-width: 280px;
  }
  .trade-main {
    padding: 20px 20px 80px;
  }
}

/* Narrow tablet / large mobile: stack everything vertically */
@media (max-width: 860px) {
  .trade-top-grid {
    flex-direction: column;
  }
  .trade-top-grid > .trade-chart-card {
    flex: none;
    width: 100%;
    height: clamp(320px, 55vh, 480px);
    min-height: 300px;
  }
  .trade-top-grid > .trade-chart-card #futuresChart,
  .trade-top-grid > .trade-chart-card #optionsChart,
  .trade-top-grid > .trade-chart-card .chart-area {
    height: 100% !important;
    min-height: 0 !important;
  }
  .trade-top-grid > .trade-order-panel {
    flex: none;
    width: 100%;
    max-width: none;
  }
  .trade-top-grid > .trade-orderbook {
    display: none;
  }
  .instrument-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .inst-bar-metrics {
    flex-wrap: wrap;
    gap: 6px;
  }
  .inst-metric-divider {
    display: none;
  }
}

/* ===== BUG #15: Spot / Futures / Equity unified responsive layout =====
   - Wide (>=1440px): 3-column flex (Chart | OrderBook | OrderPanel) — inherits base
   - Mid  (1024-1439px): CSS Grid 2x2 — Chart top-left, OrderBook bottom-left
                         (280px), OrderPanel right spanning 2 rows.
   - Narrow (<1024px): vertical stack Chart -> OrderPanel -> OrderBook.
   Scoped to body.trade-page-3up so trade-option.html is unaffected.
*/

/* Mid: 1024-1439px */
@media (min-width: 1024px) and (max-width: 1439px) {
  body.trade-page-3up .trade-top-grid {
    display: grid;
    grid-template-columns: 1fr 340px;
    grid-template-rows: auto auto;
    gap: 16px;
    align-items: stretch;
  }
  body.trade-page-3up .trade-top-grid > .trade-chart-card,
  body.trade-page-3up .trade-top-grid > .spot-chart-card {
    grid-column: 1; grid-row: 1;
    flex: none;
    min-width: 0;
    height: clamp(460px, 58vh, 620px) !important;
  }
  body.trade-page-3up .trade-top-grid > .trade-orderbook,
  body.trade-page-3up .trade-top-grid > .spot-orderbook {
    grid-column: 1; grid-row: 2;
    display: block !important;
    flex: none;
    width: auto;
    height: 280px !important;
    max-height: 280px;
    overflow-y: auto;
  }
  body.trade-page-3up .trade-top-grid > .trade-order-panel,
  body.trade-page-3up .trade-top-grid > .spot-order-panel {
    grid-column: 2;
    grid-row: 1 / span 2;
    flex: none;
    max-width: none;
  }
}

/* Narrow: <1024px — vertical stack Chart -> OrderPanel -> OrderBook
   Chart card lower bound (420px) is set above the inner #spotTvChart
   min-height (400px) so the TradingView iframe never overflows. */
@media (max-width: 1023px) {
  body.trade-page-3up .trade-top-grid {
    display: flex;
    flex-direction: column;
  }
  body.trade-page-3up .trade-top-grid > .trade-chart-card,
  body.trade-page-3up .trade-top-grid > .spot-chart-card {
    flex: none;
    width: 100%;
    height: clamp(420px, 55vh, 540px) !important;
    min-height: 420px;
    order: 1;
  }
  body.trade-page-3up .trade-top-grid > .trade-order-panel,
  body.trade-page-3up .trade-top-grid > .spot-order-panel {
    flex: none;
    width: 100%;
    max-width: none;
    order: 2;
  }
  body.trade-page-3up .trade-top-grid > .trade-orderbook,
  body.trade-page-3up .trade-top-grid > .spot-orderbook {
    display: block !important;
    flex: none;
    width: 100%;
    height: 320px !important;
    max-height: 320px;
    order: 3;
  }

  /* #320: iOS Safari + TradingView Advanced Charts measure container size
     synchronously at widget construction. With only `flex: 1` on the inner
     chart div, iOS sometimes reports 0 height because flex basis hasn't
     propagated yet on mobile Safari. Force explicit `flex: 1 1 0` AND a
     concrete `min-height: 380px` fallback so the rect is always non-zero —
     even if the parent's vh-derived height hasn't finalized. 380px sits
     comfortably under the 420px parent min-height (no overflow). Card
     `position: relative` is a defensive anchor for absolutely-positioned
     children (BUG #80 loading overlay). Attribution typography is
     intentionally untouched — binding to TradingView's external DOM is
     fragile. */
  body.trade-page-3up .trade-top-grid > .trade-chart-card,
  body.trade-page-3up .trade-top-grid > .spot-chart-card {
    position: relative;
  }
  body.trade-page-3up .trade-top-grid > .trade-chart-card > #futuresChart,
  body.trade-page-3up .trade-top-grid > .spot-chart-card > #spotTvChart {
    flex: 1 1 0 !important;
    width: 100% !important;
    min-height: 380px !important;
  }
}

/* Chart Card */
.trade-chart-card, .spot-chart-card {
  display: flex;
  flex-direction: column;
}

/* TradingView attribution backlink (required by license) */
.tradingview-attribution {
  text-align: center;
  padding: 10px 0 0;
  margin: 4px 0 -6px;
  font-size: 12px;
  color: rgba(255,255,255,0.4);
  line-height: 1;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.tradingview-attribution a {
  color: #5cb8e6;
  text-decoration: none;
}
.tradingview-attribution a:hover {
  text-decoration: underline;
}

.chart-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.chart-type-tabs {
  display: flex;
  gap: 2px;
  background: rgba(255,255,255,0.03);
  border-radius: 6px;
  padding: 2px;
}

.chart-type-btn {
  background: none;
  border: none;
  color: #8a8a9a;
  font-size: 12px;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.chart-type-btn:hover {
  color: #e0e0e8;
}

.chart-type-btn.active {
  color: #e0e0e8;
  background: rgba(255,255,255,0.06);
}

.trade-chart-area {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* ========== ORDER PANEL ========== */
.trade-order-panel {
  display: flex;
  flex-direction: column;
}

.order-side-toggle {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: rgba(255,255,255,0.03);
  border-radius: 8px;
  padding: 3px;
}

.order-side-btn {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  background: transparent;
  color: #8a8a9a;
}

.order-side-btn.buy.active {
  background: rgba(92, 184, 230, 0.15);
  color: #5cb8e6;
}

.order-side-btn.sell.active {
  background: rgba(224, 160, 80, 0.15);
  color: #e0a050;
}

.order-side-btn:hover:not(.active) {
  color: #a8a8b8;
}

.order-type-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.order-type-label {
  font-size: 12px;
  color: #8a8a9a;
  font-weight: 500;
}

.order-type-tabs {
  display: flex;
  gap: 2px;
  background: rgba(255,255,255,0.03);
  border-radius: 4px;
  padding: 2px;
}

.order-type-btn {
  background: none;
  border: none;
  color: #8a8a9a;
  font-size: 11px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.15s;
}

.order-type-btn.active {
  color: #e0e0e8;
  background: rgba(255,255,255,0.06);
}

.order-field {
  margin-bottom: 14px;
}

.order-field label {
  display: block;
  font-size: 12px;
  color: #8a8a9a;
  font-weight: 500;
  margin-bottom: 6px;
}

.order-input-wrap {
  display: flex;
  align-items: center;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  overflow: hidden;
  transition: border-color 0.15s;
}

.order-input-wrap:focus-within {
  border-color: rgba(92, 184, 230, 0.3);
}

.order-step-btn {
  background: none;
  border: none;
  color: #8a8a9a;
  font-size: 16px;
  padding: 10px 14px;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}

.order-step-btn:hover {
  color: #e0e0e8;
  background: rgba(255,255,255,0.04);
}

.order-input {
  flex: 1;
  background: none;
  border: none;
  color: #e0e0e8;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  padding: 10px 0;
  outline: none;
  font-variant-numeric: tabular-nums;
  font-family: inherit;
}

.order-field-sub {
  font-size: 11px;
  color: #5a5a6a;
  margin-top: 4px;
  text-align: right;
}

.order-quick-btns {
  display: flex;
  gap: 4px;
  margin-top: 6px;
}

.quick-btn {
  flex: 1;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  color: #8a8a9a;
  font-size: 11px;
  font-weight: 600;
  padding: 5px 0;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.quick-btn:hover {
  color: #e0e0e8;
  border-color: rgba(255,255,255,0.12);
}

.quick-btn.active {
  color: #5cb8e6;
  border-color: rgba(92, 184, 230, 0.3);
  background: rgba(92, 184, 230, 0.06);
}

.order-options {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
}

.order-checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #8a8a9a;
  cursor: pointer;
}

.order-checkbox input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: #5cb8e6;
}

.order-summary {
  padding: 12px 0;
  border-top: 1px solid rgba(255,255,255,0.06);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  margin-bottom: 16px;
}

.order-summary-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #8a8a9a;
  padding: 4px 0;
}

.order-summary-row.total {
  color: #e0e0e8;
  font-weight: 600;
  font-size: 13px;
  padding-top: 8px;
}

.order-submit-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.3px;
  margin-bottom: 12px;
}

.order-submit-btn.buy, .order-submit-btn.long {
  background: linear-gradient(135deg, #5cb8e6, #4aa8d6);
  color: #fff;
}

.order-submit-btn.buy:hover:not(:disabled), .order-submit-btn.long:hover:not(:disabled) {
  background: linear-gradient(135deg, #6ec4f0, #5cb8e6);
  box-shadow: 0 4px 20px rgba(92, 184, 230, 0.3);
}

.order-submit-btn.sell, .order-submit-btn.short {
  background: linear-gradient(135deg, #e0a050, #d08e40);
  color: #fff;
}

.order-submit-btn.sell:hover:not(:disabled), .order-submit-btn.short:hover:not(:disabled) {
  background: linear-gradient(135deg, #eaaf60, #e0a050);
  box-shadow: 0 4px 20px rgba(224, 160, 80, 0.3);
}

/* Bug #278: make the disabled state unmistakable when the JS gates submission
   (e.g. "Exceeds Usable Margin", "Enter Amount", "Insufficient balance for
   margin + fee"). Inline opacity is set by trading-*.js — kept JS-controlled
   per existing convention. */
.order-submit-btn:disabled {
  cursor: not-allowed;
}

.order-balance-info {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #5a5a6a;
}

/* ========== INFO GRID (OB + TRADES + POSITION) ========== */
.trade-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

/* ========== ORDER BOOK ========== */
.ob-spread {
  font-size: 11px;
  color: #5a5a6a;
}

.ob-header-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  font-size: 10px;
  font-weight: 600;
  color: #4a4a5a;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  margin-bottom: 4px;
}
.ob-header-row span:nth-child(1) { text-align: left; }
.ob-header-row span:nth-child(2) { text-align: right; }
.ob-header-row span:nth-child(3) { text-align: right; }

.ob-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  align-items: center;
  padding: 5px 0;
  position: relative;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.ob-price {
  text-align: left;
  font-weight: 500;
}

.ob-row.ask .ob-price { color: #e0a050; }
.ob-row.bid .ob-price { color: #5cb8e6; }

.ob-size {
  text-align: right;
  color: #a8a8b8;
}

.ob-total {
  text-align: right;
  color: #8a8a9a;
  position: relative;
  z-index: 1;
}

.ob-bar {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  pointer-events: none;
  border-radius: 2px;
  z-index: 0;
}

.ob-bar.ask {
  background: rgba(224, 160, 80, 0.06);
}

.ob-bar.bid {
  background: rgba(92, 184, 230, 0.06);
}

.ob-spread-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  margin: 4px 0;
  border-top: 1px solid rgba(255,255,255,0.06);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.ob-mid-price {
  font-size: 16px;
  font-weight: 700;
  color: #e0e0e8;
}

.ob-spread-val {
  font-size: 11px;
  color: #5a5a6a;
}

/* ========== RECENT TRADES ========== */
.rt-header-row {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  font-weight: 600;
  color: #4a4a5a;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  margin-bottom: 4px;
}

.rt-list {
  max-height: 280px;
  overflow-y: auto;
}

.rt-list::-webkit-scrollbar {
  width: 3px;
}

.rt-list::-webkit-scrollbar-thumb {
  background: rgba(92, 184, 230, 0.3);
  border-radius: 2px;
}
.rt-list::-webkit-scrollbar-thumb:hover {
  background: rgba(92, 184, 230, 0.5);
}

.rt-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.rt-price {
  width: 80px;
  font-weight: 500;
}

.rt-row.buy .rt-price { color: #5cb8e6; }
.rt-row.sell .rt-price { color: #e0a050; }

.rt-size {
  width: 50px;
  text-align: center;
  color: #a8a8b8;
}

.rt-time {
  width: 70px;
  text-align: right;
  color: #5a5a6a;
  font-size: 11px;
}

/* ========== YOUR POSITION ========== */
.trade-your-position .trade-card-header {
  margin-bottom: 16px;
}

.pos-detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.pos-detail-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.pos-detail-label {
  font-size: 11px;
  font-weight: 500;
  color: #5a5a6a;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.pos-detail-value {
  font-size: 14px;
  font-weight: 600;
  color: #e0e0e8;
  font-variant-numeric: tabular-nums;
}

.pos-detail-value.positive { color: #5cb8e6; }
.pos-detail-value.negative { color: #e0a050; }

.pos-action-row {
  display: flex;
  gap: 8px;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.pos-action-btn {
  flex: 1;
  padding: 9px 0;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.pos-action-btn.close {
  background: rgba(224, 160, 80, 0.1);
  color: #e0a050;
}

.pos-action-btn.close:hover {
  background: rgba(224, 160, 80, 0.18);
}

.pos-action-btn.modify {
  background: rgba(255,255,255,0.04);
  color: #8a8a9a;
}

.pos-action-btn.modify:hover {
  background: rgba(255,255,255,0.08);
  color: #e0e0e8;
}

/* ========== OPTION CHAIN ========== */
.trade-option-chain {
  overflow: hidden;
}

.chain-expiry-tabs {
  display: flex;
  gap: 4px;
}

.chain-exp-btn {
  background: none;
  border: none;
  color: #8a8a9a;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.chain-exp-btn:hover {
  color: #e0e0e8;
  background: rgba(255,255,255,0.04);
}

.chain-exp-btn.active {
  color: #5cb8e6;
  background: rgba(92, 184, 230, 0.1);
}

.chain-scroll {
  overflow-x: auto;
}

.chain-table {
  min-width: 900px;
}

.chain-header {
  display: flex;
  align-items: center;
  padding: 0 0 10px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 2px;
}

.chain-calls-header,
.chain-puts-header {
  flex: 1;
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0 12px;
}

.chain-calls-header {
  color: #5cb8e6;
}

.chain-puts-header {
  color: #e0a050;
}

.chain-strike-header {
  width: 90px;
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  color: #8a8a9a;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.chain-row {
  display: flex;
  align-items: center;
  transition: background 0.1s;
}

.chain-row:hover {
  background: rgba(255,255,255,0.02);
}

.chain-calls,
.chain-puts {
  flex: 1;
  display: flex;
  justify-content: space-between;
  padding: 9px 12px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: #8a8a9a;
}

.chain-calls span,
.chain-puts span {
  width: 18%;
  text-align: right;
}

.chain-strike {
  width: 90px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: #e0e0e8;
  flex-shrink: 0;
  position: relative;
  padding: 9px 0;
}

/* ITM call rows */
.chain-row.itm-call .chain-calls {
  background: rgba(92, 184, 230, 0.03);
}

/* ATM row */
.chain-row.atm {
  border-top: 1px solid rgba(92, 184, 230, 0.15);
  border-bottom: 1px solid rgba(92, 184, 230, 0.15);
}

.chain-row.atm .chain-strike {
  color: #5cb8e6;
}

.atm-label {
  display: block;
  font-size: 9px;
  font-weight: 600;
  color: #5cb8e6;
  letter-spacing: 0.5px;
}

/* Current strike (your position) */
.chain-row.current-strike {
  background: rgba(92, 184, 230, 0.04);
  border-left: 3px solid #5cb8e6;
}

.chain-row.current-strike .chain-strike {
  color: #5cb8e6;
}

.current-label {
  display: block;
  font-size: 9px;
  font-weight: 700;
  color: #5cb8e6;
  letter-spacing: 0.5px;
}

.chain-last-highlight {
  color: #e0e0e8 !important;
  font-weight: 600;
}

/* Alternate row shading */
.chain-row:nth-child(even) {
  background: rgba(255,255,255,0.01);
}

.chain-row.current-strike:nth-child(even) {
  background: rgba(92, 184, 230, 0.04);
}

/* ========== EDUCATION TOOLTIPS ========== */
.has-tip {
  position: relative;
  cursor: help;
}

.tip-icon {
  opacity: 0.35;
  vertical-align: middle;
  margin-left: 2px;
  transition: opacity 0.15s;
}

.has-tip:hover .tip-icon {
  opacity: 0.7;
}

.has-tip::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  background: #2a2a32;
  color: #d0d0d8;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  width: 260px;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
  z-index: 100;
  white-space: normal;
}

.has-tip::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #2a2a32;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
  z-index: 101;
}

.has-tip:hover::after,
.has-tip:hover::before {
  opacity: 1;
  visibility: visible;
}

/* ========== ORDER MODE TOGGLE ========== */
.order-mode-toggle {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: rgba(255,255,255,0.03);
  border-radius: 8px;
  padding: 3px;
}

.mode-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  background: transparent;
  color: #8a8a9a;
  font-family: inherit;
}

.mode-btn:hover {
  color: #a8a8b8;
}

.mode-btn.active {
  background: rgba(92, 184, 230, 0.12);
  color: #5cb8e6;
}

.mode-btn svg {
  flex-shrink: 0;
}

/* ========== AI GUIDE MODE ========== */
.order-mode {
  /* container for guide/advanced */
}

.guide-step {
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.guide-greeting {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 20px;
}

.guide-greeting p {
  margin: 0;
  font-size: 14px;
  color: #a8a8b8;
  line-height: 1.5;
}

.guide-greeting strong {
  color: #e0e0e8;
}

.guide-ai-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(92,184,230,0.2), rgba(92,184,230,0.08));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #5cb8e6;
}

.guide-ai-avatar.small {
  width: 24px;
  height: 24px;
}

.guide-goals {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.guide-goal-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
  font-family: inherit;
  color: inherit;
}

.guide-goal-btn:hover {
  background: rgba(255,255,255,0.06);
  border-color: rgba(92, 184, 230, 0.2);
  transform: translateX(2px);
}

.goal-icon {
  font-size: 20px;
  flex-shrink: 0;
  width: 28px;
  text-align: center;
}

.goal-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.goal-text strong {
  font-size: 13px;
  font-weight: 600;
  color: #e0e0e8;
}

.goal-text small {
  font-size: 11px;
  color: #8a8a9a;
}

.guide-goal-btn svg {
  color: #4a4a5a;
  flex-shrink: 0;
  transition: color 0.15s, transform 0.15s;
}

.guide-goal-btn:hover svg {
  color: #5cb8e6;
  transform: translateX(2px);
}

/* Guide Step 2: Recommendation */
.guide-back {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #8a8a9a;
  cursor: pointer;
  margin-bottom: 16px;
  transition: color 0.15s;
}

.guide-back:hover {
  color: #5cb8e6;
}

.guide-rec {
  background: rgba(92, 184, 230, 0.06);
  border: 1px solid rgba(92, 184, 230, 0.12);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}

.guide-rec-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.guide-rec-title {
  font-size: 12px;
  font-weight: 700;
  color: #5cb8e6;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.guide-rec-body {
  font-size: 13px;
  color: #a8a8b8;
  line-height: 1.5;
}

.guide-rec-body strong {
  color: #e0e0e8;
}

.guide-rec-details {
  margin-bottom: 16px;
}

.rec-action {
  font-size: 16px;
  font-weight: 700;
  color: #e0e0e8;
  margin-bottom: 4px;
}

.rec-instrument {
  font-size: 12px;
  color: #8a8a9a;
  font-family: 'Inter', monospace;
  letter-spacing: 0.3px;
  margin-bottom: 14px;
}

.rec-details-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.rec-detail {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 8px;
  padding: 10px 12px;
}

.rec-detail.full {
  grid-column: 1 / -1;
}

.rec-detail span {
  display: block;
  font-size: 10px;
  font-weight: 600;
  color: #5a5a6a;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 4px;
}

.rec-detail strong {
  font-size: 13px;
  font-weight: 600;
  color: #e0e0e8;
}

.guide-place-btn {
  margin-top: 4px;
}

/* ========== OPTIONS WIZARD CTA ========== */
.options-wizard-cta {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: linear-gradient(135deg, rgba(92,184,230,0.08), rgba(224,160,80,0.08));
  border: 1px solid rgba(92,184,230,0.2);
  border-radius: 8px;
  margin-bottom: 12px;
  cursor: default;
}
.wizard-cta-icon { font-size: 20px; }
.wizard-cta-text { flex: 1; }
.wizard-cta-text strong { display: block; font-size: 12px; color: #e0e0e8; }
.wizard-cta-text span { font-size: 11px; color: #8a8a9a; }
.wizard-cta-btn {
  padding: 6px 14px;
  background: linear-gradient(135deg, #5cb8e6, #4aa0d0);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.wizard-cta-btn:hover { transform: scale(1.05); box-shadow: 0 2px 8px rgba(92,184,230,0.3); }

/* ========== AI CHAT WIDGET ========== */
.ai-chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5cb8e6, #4a9cd4);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(92, 184, 230, 0.35);
  transition: all 0.2s;
  z-index: 1000;
}

.ai-chat-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(92, 184, 230, 0.5);
}

.ai-chat-fab.hidden {
  opacity: 0;
  transform: scale(0.5);
  pointer-events: none;
}

.ai-chat-panel {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 380px;
  height: 520px;
  background: #1a1a1f;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 48px rgba(0,0,0,0.6);
  z-index: 1001;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  overflow: hidden;
}

.ai-chat-panel.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: linear-gradient(135deg, rgba(92,184,230,0.12), rgba(92,184,230,0.04));
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
  color: #e0e0e8;
}

.chat-ai-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #5cb8e6;
  box-shadow: 0 0 6px rgba(92, 184, 230, 0.4);
}

.chat-header-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-close, .chat-clear {
  background: none;
  border: none;
  color: #8a8a9a;
  cursor: pointer;
  padding: 4px;
  transition: color 0.15s;
}

.chat-close:hover, .chat-clear:hover {
  color: #e0e0e8;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(92, 184, 230, 0.3);
  border-radius: 2px;
}
.chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(92, 184, 230, 0.5);
}

.chat-msg {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.chat-msg.user {
  justify-content: flex-end;
}

.chat-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(92,184,230,0.2), rgba(92,184,230,0.08));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #5cb8e6;
}

.chat-msg-bubble {
  max-width: 280px;
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.55;
  color: #c8c8d0;
}

.chat-msg.ai .chat-msg-bubble {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
  border-top-left-radius: 4px;
}

.chat-msg.ai .chat-msg-bubble strong {
  color: #e0e0e8;
}

.chat-msg.user .chat-msg-bubble {
  background: linear-gradient(135deg, rgba(92,184,230,0.15), rgba(92,184,230,0.08));
  border: 1px solid rgba(92,184,230,0.15);
  border-top-right-radius: 4px;
  color: #e0e0e8;
}

/* Typing indicator */
.typing-dots { display: inline-flex; gap: 4px; }
.typing-dots span { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: #5a5a6a; animation: typingBounce 1.2s ease-in-out infinite; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-4px); } }

.chat-insight {
  display: block;
  margin-top: 10px;
  padding: 10px 12px;
  background: rgba(92, 184, 230, 0.08);
  border: 1px solid rgba(92, 184, 230, 0.12);
  border-radius: 8px;
  font-size: 12px;
  color: #5cb8e6;
  line-height: 1.4;
}

.chat-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,0.06);
  background: rgba(255,255,255,0.02);
}

.chat-input {
  flex: 1;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 20px;
  padding: 10px 16px;
  color: #e0e0e8;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.chat-input::placeholder {
  color: #4a4a5a;
}

.chat-input:focus {
  border-color: rgba(92, 184, 230, 0.3);
}

.chat-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5cb8e6, #4a9cd4);
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
  /* #328: remove legacy iOS 300ms tap delay + give visible tap feedback. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(92,184,230,0.3);
}

.chat-send:hover {
  transform: scale(1.06);
  box-shadow: 0 2px 12px rgba(92, 184, 230, 0.3);
}

/* ========== CHART TIMEFRAMES ========== */
.chart-timeframes {
  display: flex;
  gap: 2px;
  min-width: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tf-btn {
  background: none;
  border: none;
  color: #8a8a9a;
  font-size: 11px;
  white-space: nowrap;
  flex: 0 0 auto;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.3px;
  font-family: inherit;
}

.tf-btn:hover {
  color: #e0e0e8;
  background: rgba(255,255,255,0.04);
}

.tf-btn.active {
  color: #5cb8e6;
  background: rgba(92, 184, 230, 0.1);
}

/* ========== RESPONSIVE ========== */
@media (max-width: 1200px) {
  .instrument-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }
  .inst-bar-metrics {
    flex-wrap: wrap;
    gap: 8px;
  }
  .inst-metric-divider {
    display: none;
  }
  .inst-metric {
    padding: 0 16px 0 0;
  }
}

@media (max-width: 1024px) {
  .instrument-bar { padding: 16px 20px 14px; }
  .greeks-bar { padding: 0 20px; flex-wrap: wrap; height: auto; padding: 8px 20px; gap: 4px; }
  .greek-item { padding: 6px 12px; }
  .trade-main { padding: 16px 20px 60px; }
  .trade-order-panel { max-width: none; }
  .pos-table { font-size: 11px; }
  .pos-table thead th, .pos-table tbody td { padding: 8px 6px; }
  .instrument-bar { flex-direction: column !important; align-items: flex-start !important; gap: 10px !important; }
  .inst-bar-metrics { flex-wrap: wrap !important; gap: 6px !important; }
  .inst-metric-divider { display: none !important; }
}

@media (max-width: 768px) {
  .instrument-bar { padding: 12px 16px !important; }
  .inst-bar-symbol { font-size: 16px !important; }
  .trade-main { padding: 12px 16px 60px !important; }
  .greeks-bar { padding: 8px 16px; }
  .trade-order-panel { padding: 16px !important; }
  .pos-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .pos-table { min-width: 600px; }
  .pos-table thead th, .pos-table tbody td { padding: 8px 8px; font-size: 11px; }
  .chain-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  /* #328: two-line declaration so non-svh browsers fall back to vh (no regression on
     older iOS / older Android). svh excludes the on-screen keyboard area so the Send
     button stays tappable on iPhone Safari. */
  .ai-chat-panel { width: calc(100vw - 32px) !important; right: 16px !important; bottom: 70px !important; max-height: 60vh !important; max-height: min(60vh, 60svh) !important; }
}

@media (max-width: 480px) {
  .trade-main { padding: 8px 8px 60px !important; }
  .inst-bar-symbol { font-size: 14px !important; }
  .metric-label { font-size: 9px !important; }
  .metric-value { font-size: 12px !important; }
  .greeks-bar { padding: 6px 8px; gap: 2px; }
  .greek-item { padding: 4px 8px; font-size: 10px; }
  .greek-label { font-size: 9px; }
  .greek-value { font-size: 10px; }
  .price-row-with-bbo { flex-direction: column; gap: 6px; }
  .bbo-btn { width: 100%; padding: 8px 0; text-align: center; }
  /* #328: see comment at @1023 — svh keeps Send button above iOS keyboard. */
  .ai-chat-panel { width: calc(100vw - 16px) !important; right: 8px !important; left: 8px !important; bottom: 60px !important; max-height: 70vh !important; max-height: min(70vh, 70svh) !important; }
}

/* ===== Bug #193 — Order Panel narrow-viewport overflow fix (v2) =====
   Prior art: PR #262 (commit 54b7186) added a partial fix scoped to
   body.trade-page-3up that shrank some internal flex children at <=768px.
   Re-verification (2026-05-19) found the panel still overflowed — that fix
   never addressed the upstream root cause.

   Root cause: .app-body is `display:flex`; .app-sidebar is `position:fixed`
   (out of flow); .app-content-wrapper is the sole in-flow flex item, with
   `flex:1` and the default `min-width:auto`. `min-width:auto` pins a flex
   item to its content's min-content width, so on a ~544px viewport the
   Order Panel's non-wrapping flex rows (order-type tabs, quick-amount
   buttons, leverage marks, label/value summary rows) forced the wrapper —
   and therefore the `width:100%` panel inside it — wider than the viewport.
   Every right-side UI element was pushed off-screen at the same edge.

   Fix: (1) let the content flex-item shrink to the viewport with
   `min-width:0`; (2) let every internal flex row shrink/wrap so no
   descendant re-introduces an over-wide min-content.
   Scope: body.trade-page-3up only — /trade-futures + /trade-spot.
   trade-option.html (no trade-page-3up body class) is intentionally
   unaffected. Verified at 360 / 480 / 544 / 640 / 768 / 1024px. */

/* (1) Root cause — let the content flex-item shrink to the viewport.
   No-op at desktop widths (content fits the viewport there). */
body.trade-page-3up .app-content-wrapper { min-width: 0; }

/* (2) Stacked layout (<=1023px) — allow the panel + its flex rows to shrink. */
@media (max-width: 1023px) {
  body.trade-page-3up .trade-order-panel,
  body.trade-page-3up .spot-order-panel { min-width: 0; }
}

@media (max-width: 768px) {
  body.trade-page-3up .order-side-toggle { gap: 2px; }
  body.trade-page-3up .order-side-btn { min-width: 0; padding: 8px 4px; font-size: 12px; }

  /* Order Type row + tabs (Limit / Market / Stop Market / Stop Limit) */
  body.trade-page-3up .order-type-row { flex-wrap: wrap; gap: 6px; }
  body.trade-page-3up .order-type-tabs { flex-wrap: wrap; }
  body.trade-page-3up .order-type-btn { min-width: 0; padding: 5px 8px; font-size: 10px; }

  body.trade-page-3up .input-mode-toggle { gap: 2px; }
  body.trade-page-3up .input-mode-btn { min-width: 0; padding: 6px 2px; font-size: 11px; }

  body.trade-page-3up .leverage-marks { padding: 0; }
  body.trade-page-3up .leverage-marks > span { min-width: 0; font-size: 9px; white-space: nowrap; }

  /* Price / amount inputs shrink instead of overflowing the panel */
  body.trade-page-3up .order-input { min-width: 0; }

  /* Quick-amount buttons (100..10,000) wrap to 3 per row */
  /* MCP Phase 3 (Codex Medium + Gemini Low): use calc((100% - 8px) / 3)
     instead of 33.333% — derives basis from parent gap directly (4px gap × 2
     gaps in 3-col row = 8px), avoids fractional rounding that sometimes drops
     buttons to 2-col, and makes the gap relation obvious for maintenance. */
  body.trade-page-3up .order-quick-btns { flex-wrap: wrap; gap: 4px; }
  body.trade-page-3up .quick-btn { flex: 1 1 calc((100% - 8px) / 3); min-width: 0; padding: 5px 2px; font-size: 10px; }

  body.trade-page-3up .margin-calc-result { flex-wrap: wrap; }
  body.trade-page-3up .tpsl-toggle { min-width: 0; padding: 6px 4px; font-size: 11px; }
  body.trade-page-3up .more-options-summary { font-size: 11px; }

  /* Label/value rows — keep label intact; value span may shrink (no clipping:
     a long value degrades by wrapping, never by being hidden). */
  body.trade-page-3up .order-summary-row,
  body.trade-page-3up .order-balance-info,
  body.trade-page-3up .order-balance-info-secondary { gap: 8px; }
  body.trade-page-3up .order-summary-row > span:last-child,
  body.trade-page-3up .order-balance-info > span:last-child,
  body.trade-page-3up .order-balance-info-secondary > span:last-child { min-width: 0; text-align: right; }
}

@media (max-width: 480px) {
  body.trade-page-3up .order-side-btn { padding: 7px 2px; font-size: 11px; }
  body.trade-page-3up .input-mode-btn { padding: 5px 2px; font-size: 10px; }
  body.trade-page-3up .order-type-btn { padding: 4px 6px; font-size: 9px; }
  body.trade-page-3up .quick-btn { font-size: 9px; padding: 4px 1px; }
}
