/* ================================
   Global Reset & Base
================================ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

html, body {
  height: 100%;
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
  margin: 0;
}

body {
  background: linear-gradient(180deg, #0f1115, #0b0d11);
  color: #e6e6e6;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ================================
   Header (Desktop)
================================ */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0;
  background: #161a22;
  border-bottom: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-logo {
  width: 36px;
  height: 36px;
  border-radius: 50%;
}

.brand-name {
  font-family: "Teko", system-ui, sans-serif;
  font-size: 22px;
  font-weight: 600;
  color: #e6e6e6;
}

.change-mode-link {
  margin-left: 12px;
  font-size: 12px;
  color: #9aa0a6;
  text-decoration: none;
  padding: 6px 10px;
  border: 1px solid #2a2f3a;
  border-radius: 6px;
  background: #252b38;
}

.change-mode-link:hover {
  color: #e6e6e6;
  background: #2a2f3a;
}

@media (min-width: 769px) {
  .stock-bar .stock-info h2 {
    font-size: 18px;
    font-weight: 700;
  }

  .stock-bar .price-box {
    font-size: 24px;
  }

  .stock-bar .fundamentals {
    font-size: 14px;
  }

  #toggle-btn {
    font-size: 15px;
    font-weight: 600;
    padding: 10px 22px;
  }
}

.pnl-positive { color: #2ecc71; }
.pnl-negative { color: #e74c3c; }

/* ================================
   Stock Bar (Always Visible)
================================ */
.stock-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #1e2430;
  padding: 10px 14px;
  border-bottom: 1px solid #2a2f3a;
  position: sticky;
  top: 0;
  width: 100%;
  z-index: 10;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: nowrap;
  min-height: auto;
}

.left-group {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.trade-header-metrics {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 10px;
  min-width: 0;
}

.trade-header-metric {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 76px;
  padding: 4px 8px 5px;
  border: 1px solid #2a2f3a;
  border-radius: 999px;
  background: #161a22;
  white-space: nowrap;
}

.trade-header-metric .label {
  font-size: 11px;
  color: #9aa0a6;
  line-height: 1;
}

.trade-header-metric .value {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}

.play-group {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.stock-bar .stock-info {
  display: flex;
  align-items: center;
  gap: 24px;
}

.stock-bar .stock-info h2 {
  font-size: 16px;
  white-space: nowrap;
}

.stock-bar .price-box {
  font-size: 22px;
  font-weight: 700;
  white-space: nowrap;
}

.stock-bar .fundamentals {
  display: flex;
  gap: 16px;
  font-size: 13px;
}

.fundamentals .label { color: #ffffff; }
.fundamentals .eps-value { color: #3a86ff; }
.fundamentals .pe-value { font-weight: 600; }

.pe-up { color: #2ecc71; }
.pe-down { color: #e74c3c; }

#toggle-btn {
  padding: 10px 24px;
  font-size: 14px;
}

.session-controls {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* ================================
   Main Container (Home View)
================================ */
.container {
  max-width: 1000px;
  margin: 32px auto;
  padding: 0 20px;
  display: grid;
  row-gap: 12px;
}

.container.trade-home-split {
  row-gap: 0;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  margin: 0 auto;
  padding-top: 12px;
  padding-bottom: 12px;
  display: flex;
  flex-direction: column;
}

/* ================================
   Chart Section
================================ */
.chart-section {
  background: #1e2430;
  padding: 20px;
  border-radius: 10px;
  border: 1px solid #2a2f3a;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.container.trade-home-split .chart-section {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-bottom-width: 0;
}

/* Chart toolbar (minimal addition for candle timeframe selector) */
.chart-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
  flex: 0 0 auto;
}

.left-controls,
.right-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.right-controls {
  margin-left: auto;
}

/* Live price label next to timeframe selector (display-only) */
.chart-toolbar-price {
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: #e6e6e6;
}

.chart-toolbar-label {
  font-size: 12px;
  color: #9aa0a6;
}

.chart-toolbar-select {
  appearance: none;
  -webkit-appearance: none;
  padding: 8px 13px;
  background: linear-gradient(180deg, rgba(40,48,70,.92), rgba(23,29,45,.94));
  color: #e8ecf6;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .01em;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.06), 0 4px 14px rgba(0,0,0,.28);
  transition: border-color .16s ease, box-shadow .16s ease, transform .08s ease, filter .16s ease;
}
.chart-toolbar-select:hover {
  border-color: rgba(103,232,249,.55);
  box-shadow: 0 0 0 1px rgba(103,232,249,.25), 0 6px 18px rgba(0,0,0,.34);
  filter: brightness(1.05);
}
.chart-toolbar-select:focus-visible {
  outline: none;
  border-color: #67e8f9;
  box-shadow: 0 0 0 2px rgba(103,232,249,.35);
}
.chart-toolbar-select:active { transform: translateY(1px); }

/* Native <select> gets a custom chevron (the Indicators <button> keeps its own) */
select.chart-toolbar-select {
  padding-right: 30px;
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='7' viewBox='0 0 11 7'%3E%3Cpath d='M1 1l4.5 4.5L10 1' fill='none' stroke='%239aa6bd' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"),
    linear-gradient(180deg, rgba(40,48,70,.92), rgba(23,29,45,.94));
  background-repeat: no-repeat, no-repeat;
  background-position: right 11px center, 0 0;
  background-size: 11px 7px, 100% 100%;
}
select.chart-toolbar-select option { background: #161d2e; color: #e8ecf6; }

.indicator-selector-btn { display: inline-flex; align-items: center; gap: 6px; }

.chart-history-back-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 9px;
  background: linear-gradient(180deg, rgba(40,48,70,.92), rgba(23,29,45,.94));
  color: #c5ccd4;
  font-size: 14px;
  line-height: 1;
  font-weight: 700;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.06), 0 4px 14px rgba(0,0,0,.28);
  transition: border-color .16s ease, box-shadow .16s ease, color .16s ease, transform .08s ease;
}

.chart-history-back-btn:hover {
  color: #fff;
  border-color: rgba(103,232,249,.55);
  box-shadow: 0 0 0 1px rgba(103,232,249,.25), 0 6px 18px rgba(0,0,0,.34);
}
.chart-history-back-btn:active { transform: translateY(1px); }

.chart-history-back-btn:disabled {
  opacity: 0.45;
  cursor: default;
  box-shadow: none;
}

@media (min-width: 769px) {
  .chart-toolbar-price {
    font-size: 14px;
    font-weight: 700;
  }

  .chart-toolbar-label {
    font-size: 13px;
  }

  .chart-toolbar-select {
    font-size: 14px;
    font-weight: 600;
    padding: 9px 11px;
  }

  .indicator-menu-item {
    font-size: 14px;
    padding: 9px 10px;
  }
}

/* OHLC hover readout (next to the Indicators tab) */
.chart-ohlc {
  display: none;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: #9aa0a6;
  white-space: nowrap;
}

.chart-ohlc.visible {
  display: inline-flex;
}

.chart-ohlc .ohlc-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.chart-ohlc .ohlc-k {
  color: #9aa0a6;
  font-weight: 600;
}

.chart-ohlc .ohlc-v {
  color: #e6e6e6;
  font-weight: 600;
}

.chart-ohlc.ohlc-up .ohlc-v {
  color: #26a69a;
}

.chart-ohlc.ohlc-down .ohlc-v {
  color: #ef5350;
}

@media (min-width: 769px) {
  .chart-ohlc {
    font-size: 13px;
  }
}

/* Per-pane indicator legend — pinned to the top-left of each oscillator pane,
   TradingView-style. Persistent (no hover needed); the live value also shows on
   the pane's Y-axis natively. pointer-events:none so it never blocks the chart. */
.pane-indicator-legend {
  position: absolute;
  top: 2px;
  left: 6px;
  z-index: 3;
  pointer-events: none;
  font-size: 11px;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
}

.pane-indicator-legend .pil-name {
  font-weight: 700;
}

.pane-indicator-legend .pil-k {
  color: #9aa0a6;
  margin-left: 3px;
}

.pane-indicator-legend .pil-v {
  font-weight: 600;
  margin-left: 2px;
}

@media (min-width: 769px) {
  .pane-indicator-legend {
    font-size: 12px;
  }
}

/* Indicators selector (dropdown button) */
.indicator-selector {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.indicator-selector-btn {
  appearance: none;
}

.indicator-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 180px;
  background: linear-gradient(180deg, rgba(27,34,54,.98), rgba(15,20,33,.98));
  border: 1px solid rgba(124,58,237,.32);
  border-radius: 13px;
  padding: 7px;
  z-index: 200;
  box-shadow: 0 20px 52px rgba(0,0,0,.55), inset 0 1px 0 rgba(255,255,255,.05);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  animation: indMenuIn .16s ease both;
  transform-origin: top left;
}
@keyframes indMenuIn { from { opacity: 0; transform: translateY(-6px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

.indicator-menu-item {
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 11px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: #e3e7f2;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background .14s ease, color .14s ease, padding-left .14s ease;
}
.indicator-menu-item::before {
  content: '';
  width: 6px; height: 6px; border-radius: 50%;
  background: linear-gradient(135deg, #7c3aed, #06b6d4);
  box-shadow: 0 0 8px rgba(103,232,249,.6);
  flex: none;
  opacity: .65;
  transition: opacity .14s ease, transform .14s ease;
}
.indicator-menu-item:hover {
  background: linear-gradient(90deg, rgba(124,58,237,.22), rgba(6,182,212,.12));
  color: #fff;
  padding-left: 13px;
}
.indicator-menu-item:hover::before { opacity: 1; transform: scale(1.25); }

/* Indicator badge inside chart canvas (TradingView-style) */
.chart-overlay-ui {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 150;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

/* Collapse/expand toggle for indicator badge stack (UI-only) */
.indicator-stack-toggle {
  pointer-events: auto;
  width: 28px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 9px;
  background: linear-gradient(180deg, rgba(28,34,52,.92), rgba(17,22,35,.92));
  color: #9aa0a6;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  transition: color .15s ease, border-color .15s ease, box-shadow .15s ease;
}

.indicator-stack-toggle:hover {
  color: #67e8f9;
  border-color: rgba(103,232,249,.5);
  box-shadow: 0 0 0 1px rgba(103,232,249,.2);
}

.chart-overlay-ui.is-collapsed .indicator-badge {
  display: none;
}

.indicator-badge {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 9px;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(28,34,52,.94), rgba(16,21,34,.94));
  color: #e6e6e6;
  font-size: 13px;
  box-shadow: 0 6px 18px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.05);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.indicator-badge:hover {
  border-color: rgba(103,232,249,.45);
  box-shadow: 0 8px 22px rgba(0,0,0,.42), 0 0 0 1px rgba(103,232,249,.18);
}

.indicator-badge-name {
  font-weight: 700;
  letter-spacing: 0.2px;
}

.indicator-badge-value {
  font-weight: 800;
}

.indicator-badge.is-hidden .indicator-badge-name {
  text-decoration: line-through;
  opacity: 0.75;
}

/* Eye icon strike-through when indicator is hidden (visual only) */
.indicator-badge.is-hidden .indicator-badge-btn-eye {
  text-decoration: line-through;
  opacity: 0.85;
}

.indicator-badge-controls {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.indicator-badge:hover .indicator-badge-controls,
.indicator-badge.show-controls .indicator-badge-controls {
  opacity: 1;
}

.indicator-badge-btn {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 7px;
  background: rgba(255,255,255,.04);
  color: #cfd6e4;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  transition: background .14s ease, border-color .14s ease, color .14s ease, transform .08s ease;
}

.indicator-badge-btn:hover {
  background: rgba(124,58,237,.22);
  border-color: rgba(103,232,249,.5);
  color: #fff;
}
.indicator-badge-btn:active { transform: scale(.92); }

/* Settings panel (generic container) */
.indicator-settings-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(5, 8, 16, 0.62);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  z-index: 9998;
  padding: 18px;
}

.indicator-settings-panel {
  position: relative;
  width: 100%;
  max-width: 390px;
  background: linear-gradient(165deg, rgba(27,34,54,.98), rgba(15,20,33,.98));
  border: 1px solid rgba(124,58,237,.34);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 28px 70px rgba(0,0,0,.6), inset 0 1px 0 rgba(255,255,255,.06);
  animation: indMenuIn .18s ease both;
}
/* Accent hairline along the top edge */
.indicator-settings-panel::before {
  content: '';
  position: absolute; left: 18px; right: 18px; top: 0; height: 2px; border-radius: 2px;
  background: linear-gradient(90deg, transparent, #7c3aed, #06b6d4, transparent);
  opacity: .8;
}

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

.indicator-settings-title {
  font-weight: 800;
  font-size: 15px;
  letter-spacing: .01em;
  color: #f0f3fa;
}

.indicator-settings-close {
  border: none;
  background: rgba(255,255,255,.05);
  color: #9aa0a6;
  cursor: pointer;
  font-size: 16px;
  width: 28px; height: 28px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .14s ease, color .14s ease;
}
.indicator-settings-close:hover { background: rgba(255,255,255,.12); color: #fff; }

.indicator-settings-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 12px;
  align-items: center;
  margin-top: 12px;
}

.indicator-settings-row label {
  font-size: 12px;
  font-weight: 600;
  color: #9aa6bd;
}

.indicator-settings-row input,
.indicator-settings-row select {
  padding: 9px 11px;
  background: rgba(12, 16, 26, .85);
  color: #e8ecf6;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.indicator-settings-row input:focus,
.indicator-settings-row select:focus {
  outline: none;
  border-color: #67e8f9;
  box-shadow: 0 0 0 2px rgba(103,232,249,.28);
}
/* Colour pickers in settings look like neat swatches */
.indicator-settings-row input[type="color"] {
  padding: 3px;
  height: 36px;
  cursor: pointer;
}

/* overlay=false indicator panels (e.g., RSI) */
.indicator-panels-host {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.indicator-panel {
  border: 1px solid #2a2f3a;
  border-radius: 10px;
  background: #1e2430;
  overflow: hidden;
}

.indicator-panel-chart {
  width: 100%;
}

/* TradingView-style stacked panes splitter (price chart + sub-panels like RSI) */
.chart-pane-splitter {
  width: 100%;
  height: 6px;
  cursor: row-resize;
  background: rgba(15, 17, 21, 0.6);
  border-top: 1px solid #2a2f3a;
  border-bottom: 1px solid #2a2f3a;
}

.chart-pane-splitter:hover {
  background: rgba(37, 43, 56, 0.85);
}

#chart-container {
  width: 100%;
  height: auto;
  min-height: 48px;
  flex: 1 1 auto;
  border-radius: 6px;
  overflow: hidden;
}

.btn {
  padding: 10px 18px;
  font-weight: 700;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.12);
  cursor: pointer;
  letter-spacing: .01em;
  transition: transform .08s ease, box-shadow .16s ease, filter .16s ease, border-color .16s ease;
}
.btn:active { transform: translateY(1px); }

@media (min-width: 769px) {
  .btn {
    font-size: 15px;
    font-weight: 700;
    padding: 10px 20px;
  }
}

.btn-buy {
  background: linear-gradient(180deg, #2fd385, #16a35a);
  color: #fff;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.25), 0 6px 18px rgba(38,166,122,.32);
}
.btn-buy:hover { filter: brightness(1.07); box-shadow: inset 0 1px 0 rgba(255,255,255,.25), 0 8px 22px rgba(38,166,122,.5); }

.btn-sell {
  background: linear-gradient(180deg, #ff6a5c, #df3f38);
  color: #fff;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.18), 0 6px 18px rgba(231,76,60,.32);
}
.btn-sell:hover { filter: brightness(1.07); box-shadow: inset 0 1px 0 rgba(255,255,255,.18), 0 8px 22px rgba(231,76,60,.5); }

.btn-secondary {
  background: linear-gradient(180deg, rgba(40,48,70,.95), rgba(23,29,45,.95));
  color: #e8ecf6;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.06), 0 4px 14px rgba(0,0,0,.28);
}
.btn-secondary:hover { border-color: rgba(103,232,249,.5); filter: brightness(1.06); }

/* Play / Pause — animated "live" while the game is running, static when paused.
   A status dot precedes the label; the game state is driven by .is-playing /
   .is-paused set in JS (syncToggleButtonState / fullscreen mirror). */
#toggle-btn, .fs-play {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
#toggle-btn::before, .fs-play::before {
  content: '';
  width: 8px; height: 8px; border-radius: 50%;
  flex: none;
  background: #9aa6bd;
}
/* LIVE — game running (button reads "Pause") */
#toggle-btn.is-playing, .fs-play.is-playing {
  color: #eafff3;
  border-color: rgba(46,204,113,.55);
  background: linear-gradient(180deg, rgba(33,74,55,.96), rgba(19,40,31,.96));
  animation: livePulse 2s ease-in-out infinite;
}
#toggle-btn.is-playing::before, .fs-play.is-playing::before {
  background: #34e08a;
  box-shadow: 0 0 8px rgba(52,224,138,.95);
  animation: liveDot 1.2s ease-in-out infinite;
}
@keyframes livePulse {
  0%, 100% { box-shadow: inset 0 1px 0 rgba(255,255,255,.06), 0 0 0 0 rgba(46,204,113,0), 0 4px 14px rgba(0,0,0,.28); }
  50%      { box-shadow: inset 0 1px 0 rgba(255,255,255,.06), 0 0 0 4px rgba(46,204,113,.16), 0 6px 18px rgba(46,204,113,.28); }
}
@keyframes liveDot {
  0%, 100% { transform: scale(.8); opacity: .65; }
  50%      { transform: scale(1.2); opacity: 1; }
}
/* PAUSED — game halted (button reads "Play"); static, calm amber */
#toggle-btn.is-paused, .fs-play.is-paused { animation: none; }
#toggle-btn.is-paused::before, .fs-play.is-paused::before {
  background: #f5b14a;
  box-shadow: none;
  animation: none;
}
@media (prefers-reduced-motion: reduce) {
  #toggle-btn.is-playing, .fs-play.is-playing { animation: none; }
  #toggle-btn.is-playing::before, .fs-play.is-playing::before { animation: none; }
}

/* ================================
   Positions Table (Home View)
================================ */
.positions {
  background: #1e2430;
  padding: 20px;
  border-radius: 10px;
  border: 1px solid #2a2f3a;
  overflow-x: auto;
}

.container.trade-home-split .positions {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  border-top-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.positions-table-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

.positions-table-scroll table {
  margin-bottom: 0;
}

.trade-home-splitter {
  position: relative;
  height: 8px;
  background: #11161f;
  border-top: 1px solid #2a2f3a;
  border-bottom: 1px solid #2a2f3a;
  cursor: ns-resize;
  touch-action: none;
  user-select: none;
}

.trade-home-splitter::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44px;
  height: 2px;
  transform: translate(-50%, -50%);
  background: #3a4555;
  border-radius: 2px;
  opacity: 0.9;
}

.trade-home-splitter:hover {
  background: #1b2330;
}

.trade-home-splitter:active {
  background: #263349;
}

body.trade-tab-active.trade-home-resizing,
body.trade-tab-active.trade-home-resizing * {
  cursor: ns-resize !important;
  user-select: none !important;
}

body.trade-tab-active.trade-home-resizing {
  overflow: hidden !important;
  overscroll-behavior: none !important;
  touch-action: none !important;
}

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

th, td {
  padding: 12px 10px;
  text-align: center;
}

th {
  color: #9aa0a6;
  border-bottom: 1px solid #2a2f3a;
}

.col-buy-price,
.col-sell-price {
  white-space: nowrap;
}

/* The position-type filter + fullscreen toggle now live in the table's Action
   header cell (see .positions-header-controls), so this bar no longer wastes a
   whole line in the normal/split view. It is only revealed when positions are
   maximized, where it carries the fullscreen essentials (price / PnL / Play). */
.positions-filter-bar {
  display: none;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin: 0 0 14px;
}

.container.trade-home-split.panel-max-positions .positions-filter-bar {
  display: flex;
}

/* Filter + maximize controls relocated into the Action column header. */
.positions-header-controls {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

th.col-action {
  text-align: right;
}

/* Action-cell labels: full text everywhere; single letters only on the mobile
   All view (toggled in the media query above). */
.pos-action-short { display: none; }

/* Keep the header (and its controls) pinned while the positions list scrolls —
   essential in the maximized/fullscreen view where the table grows tall. */
.positions-table-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #1e2430;
}

.positions-filter-bar label {
  color: #9aa0a6;
  font-size: 12px;
}

/* Small "Reset Stock" button in the positions filter bar.
   margin-right:auto pushes it to the far-left of the right-aligned bar
   so it sits next to the Show dropdown without crowding it. */
.reset-stock-btn {
  margin-right: auto;
  padding: 5px 11px;
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  color: #e74c3c;
  background: transparent;
  border: 1px solid #e74c3c;
  border-radius: 6px;
  cursor: pointer;
  line-height: 1.3;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}

.reset-stock-btn:hover {
  background: #e74c3c;
  color: #fff;
}

@media (min-width: 769px) {
  .reset-stock-btn {
    font-size: 12px;
    padding: 6px 12px;
  }
}

.positions-filter-select {
  padding: 8px 10px;
  background: #161a22;
  color: #e6e6e6;
  border: 1px solid #2a2f3a;
  border-radius: 6px;
  font-size: 13px;
}

@media (min-width: 769px) {
  table {
    font-size: 14px;
  }

  th, td {
    padding: 13px 11px;
  }

  .positions-filter-bar label {
    font-size: 13px;
  }

  .positions-filter-select {
    font-size: 14px;
    font-weight: 600;
    padding: 9px 11px;
  }
}

.position-row-closed {
  opacity: 0.72;
  background: rgba(154, 160, 166, 0.05);
}

.position-status-label,
.position-status-text {
  display: inline-block;
  margin-left: 6px;
  color: #9aa0a6;
  font-size: 11px;
  font-weight: 600;
}

/* Side column — a small button-like badge: green (BUY) / red (SELL), white text */
.position-side-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 46px;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .03em;
  line-height: 1.5;
  color: #fff;
}
.position-side-badge.is-buy {
  background: linear-gradient(180deg, #2fd385, #16a35a);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.22), 0 2px 8px rgba(38,166,122,.3);
}
.position-side-badge.is-sell {
  background: linear-gradient(180deg, #ff6a5c, #df3f38);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.16), 0 2px 8px rgba(231,76,60,.3);
}

.position-details {
  display: none;
}

/* ================================
   Home Panel Fullscreen Toggle
   One panel (chart or positions) can take the whole home area.
================================ */
.panel-expand-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  padding: 0;
  background: #161a22;
  color: #9aa0a6;
  border: 1px solid #2a2f3a;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.panel-expand-btn:hover {
  background: #2a2f3a;
  color: #e6e6e6;
}

.panel-expand-btn.active {
  background: #3a86ff;
  border-color: #3a86ff;
  color: #fff;
}

.panel-expand-btn svg {
  width: 16px;
  height: 16px;
}

.panel-expand-btn .icon-collapse {
  display: none;
}

.panel-expand-btn.active .icon-expand {
  display: none;
}

.panel-expand-btn.active .icon-collapse {
  display: block;
}

/* Chart maximized: hide positions + splitter, chart fills the home area. */
/* Chart fullscreen keeps the splitter + positions in the DOM (sized by JS): the
   chart starts maximized with positions collapsed, and the user can drag the
   separator up to peek at positions without leaving fullscreen. So unlike
   positions-fullscreen, nothing is hidden here — the split engine drives sizing. */

/* Positions maximized: hide chart + splitter, positions fill the home area. */
.container.trade-home-split.panel-max-positions .chart-section,
.container.trade-home-split.panel-max-positions .trade-home-splitter {
  display: none !important;
}

.container.trade-home-split.panel-max-positions .positions {
  flex: 1 1 auto;
  height: auto !important;
  min-height: 0;
  border-top-width: 1px;
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
}

/* Fullscreen reclaims every header row: the app header (logo/tabs/stats in the
   embedded page) and the trade stock bar. Their essentials (price, PnL, Play)
   move into the maximized panel's toolbar via the fs-cluster below. */
body.trade-tab-active.trade-panel-fullscreen .app-header {
  display: none !important;
}

body.trade-panel-fullscreen .stock-bar {
  display: none !important;
}

.fs-cluster {
  display: none;
  align-items: center;
  gap: 6px;
}

.container.trade-home-split.panel-max-chart #chart-fs-cluster,
.container.trade-home-split.panel-max-positions #positions-fs-cluster {
  display: inline-flex;
}

.fs-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  background: linear-gradient(180deg, rgba(40,48,70,.92), rgba(23,29,45,.94));
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #e8ecf6;
  white-space: nowrap;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.05);
}

.fs-chip-label {
  color: #9aa6bd;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: .03em;
  text-transform: uppercase;
}

.fs-cluster .fs-play {
  padding: 8px 16px;
  flex: 0 0 auto;
}

/* ================================
   Mobile View
================================ */
@media (max-width: 768px) {
  .container {
    margin: 16px auto;
    padding: 0 12px;
    row-gap: 16px;
    max-width: 100%;
  }

  .header {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 12px;
    padding: 12px;
    max-width: 100%;
  }

  .header-left {
    justify-content: center;
  }

  .header-logo {
    width: 28px;
    height: 28px;
  }

  .brand-name {
    font-size: 18px;
  }

  .stock-bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "stock stock"
      "metrics play";
    align-items: center;
    column-gap: 8px;
    row-gap: 6px;
    padding: 8px 10px;
  }

  .header-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "stock stock"
      "metrics play";
    align-items: center;
    column-gap: 8px;
    row-gap: 6px;
    padding: 8px 10px;
    min-height: auto;
  }

  .left-group {
    display: contents;
  }

  .stock-bar .stock-info {
    grid-area: stock;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 6px;
    text-align: left;
    min-width: 0;
    justify-content: flex-start;
  }

  .stock-bar .stock-info h2 {
    font-size: 12px;
    width: auto;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .stock-bar .price-box {
    font-size: 16px;
  }

  .stock-bar .fundamentals {
    font-size: 10px;
    gap: 6px;
  }

  #toggle-btn {
    flex-shrink: 0;
    padding: 7px 10px;
    font-size: 11px;
  }

  .trade-header-metrics {
    grid-area: metrics;
    width: 100%;
    max-width: none;
    min-width: 0;
    margin-left: 0;
    gap: 6px;
    justify-self: stretch;
  }

  .trade-header-metric {
    flex: 1 1 0;
    min-width: 0;
    gap: 2px;
    padding: 3px 5px 4px;
  }

  .trade-header-metric .label {
    font-size: 9px;
  }

  .trade-header-metric .value {
    font-size: 10px;
  }

  .play-group {
    grid-area: play;
    margin-left: 0;
    justify-self: end;
  }

  /* Detail columns always collapse on phones (full values live in the
     expandable per-row details). Open view stays at: Side, Qty, PnL, Action. */
  .col-stock, .col-avg, .col-ltp, .col-change {
    display: none !important;
  }

  /* Closed / All views: the Buy + Sell price columns convey direction, so drop
     the Side badge there and let the price columns show. View: Qty, Buy, Sell,
     PnL, Action. Tighten spacing/typography so all five fit without overflow. */
  .positions table[data-filter="closed"] .col-side,
  .positions table[data-filter="all"] .col-side {
    display: none !important;
  }

  .positions table[data-filter="closed"],
  .positions table[data-filter="all"] {
    font-size: 11px;
  }

  .positions table[data-filter="closed"] th,
  .positions table[data-filter="closed"] td,
  .positions table[data-filter="all"] th,
  .positions table[data-filter="all"] td {
    padding: 9px 4px;
    white-space: nowrap;
  }

  .positions table[data-filter="closed"] .positions-filter-select,
  .positions table[data-filter="all"] .positions-filter-select {
    padding: 6px 6px;
    font-size: 12px;
  }

  .positions table[data-filter="closed"] .panel-expand-btn,
  .positions table[data-filter="all"] .panel-expand-btn {
    width: 32px;
    height: 32px;
  }

  /* All view only: collapse the Action cell text to single letters (C / M). */
  .positions table[data-filter="all"] .pos-action-full { display: none; }
  .positions table[data-filter="all"] .pos-action-short { display: inline; }
  .positions table[data-filter="all"] .btn-manage { padding: 7px 12px; }

  th, td {
    padding: 10px 5px;
  }

  .position-row {
    cursor: pointer;
  }

  .position-details.active {
    display: table-row !important;
    background: #161a22;
  }

  .position-details td {
    padding: 10px;
  }

  .details-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 12px;
    font-size: 12px;
  }

  #toggle-btn {
    padding: 8px 16px;
    font-size: 13px;
  }

  .container.trade-home-split {
    row-gap: 0;
    margin: 0 auto;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .trade-home-splitter {
    display: block !important;
    height: 6px;
    cursor: default;
  }

  .right-controls {
    width: 100%;
    justify-content: center;
  }

  .right-controls .btn {
    flex: 1;
  }

  .panel-expand-btn {
    width: 38px;
    height: 38px;
  }

  /* Fullscreen essentials cluster gets its own row: chips left, Play right. */
  .positions-filter-bar {
    flex-wrap: wrap;
  }

  .fs-cluster {
    flex: 1 1 100%;
    justify-content: space-between;
  }

  .fs-cluster .fs-play {
    flex: 0 0 auto;
  }

}

.btn.disabled {
  pointer-events: none;
  opacity: 0.5;
}

/* ================================
   Order Modal
================================ */

.order-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(6, 8, 12, 0.72);
}

.order-modal-card {
  width: min(520px, calc(100vw - 40px));
  max-width: calc(100vw - 40px);
  min-width: 0;
  box-sizing: border-box;
  max-height: min(90vh, 720px);
  overflow-y: auto;
  background: #1e2430;
  border: 1px solid #2a2f3a;
  border-radius: 10px;
  padding: 22px;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.42);
}

.order-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.order-modal-header h3 {
  font-size: 22px;
  margin: 0;
}

.order-modal-close {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 6px;
  background: #252b38;
  color: #e6e6e6;
  font-size: 20px;
  cursor: pointer;
}

.order-modal-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 14px;
}

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

.grid-row > * {
  min-width: 0;
  box-sizing: border-box;
}

.order-modal-field {
  padding: 12px;
  border: 1px solid #2a2f3a;
  border-radius: 8px;
  background: #161a22;
  overflow: hidden;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.order-modal-field span,
.order-input-label {
  display: block;
  color: #9aa0a6;
  font-size: 12px;
  margin-bottom: 6px;
}

.order-input-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.order-mode-toggle {
  display: inline-flex;
  border: 1px solid #2a2f3a;
  border-radius: 6px;
  overflow: hidden;
  background: #161a22;
  flex: 0 0 auto;
}

.order-mode-btn {
  min-width: 28px;
  height: 24px;
  padding: 0 7px;
  border: 0;
  border-right: 1px solid #2a2f3a;
  background: transparent;
  color: #9aa0a6;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.order-mode-btn:last-child {
  border-right: 0;
}

.order-mode-btn.active {
  background: #3a86ff;
  color: #ffffff;
}

.order-risk-percent-label {
  color: #e6e6e6;
  margin-left: 4px;
  white-space: nowrap;
}

.order-modal-field strong {
  color: #ffffff;
  font-size: 16px;
}

.order-side-toggle,
.order-input-row,
.order-modal-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.order-side-btn {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #2a2f3a;
  border-radius: 8px;
  background: #161a22;
  color: #e6e6e6;
  cursor: pointer;
}

.order-side-btn.active[data-side="BUY"] {
  background: #2ecc71;
  color: #ffffff;
}

.order-side-btn.active[data-side="SELL"] {
  background: #e74c3c;
  color: #ffffff;
}

.order-modal-card input {
  width: 100%;
  padding: 10px 12px;
  background: #161a22;
  color: #e6e6e6;
  border: 1px solid #2a2f3a;
  border-radius: 8px;
}

.order-input-help {
  display: block;
  margin-top: 6px;
  color: #9aa0a6;
  font-size: 11px;
  line-height: 1.35;
  opacity: 0.72;
}

.order-input-row input {
  flex: 1;
}

.order-qty-hint {
  margin: -8px 0 14px;
  font-size: 12px;
  color: #9aa0a6;
  min-height: 14px;
}

.order-primary {
  width: 100%;
}

.order-modal-actions {
  flex-wrap: wrap;
}

.order-modal-actions .btn {
  flex: 1;
  min-width: min(140px, 100%);
}

.order-modal-actions .order-exit-action {
  order: 10;
  margin-left: auto;
}

/* News modal animation (reuses order modal look) */
.news-modal-enter {
  opacity: 0;
  animation: newsModalBackdropIn 0.2s ease forwards;
}

.news-modal-card-enter {
  transform: scale(0.95);
  opacity: 0;
  animation: newsModalCardIn 0.2s ease forwards;
}

@keyframes newsModalBackdropIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes newsModalCardIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@media (max-width: 768px) {
  .order-modal-backdrop {
    padding: 10px;
    overflow-x: hidden;
  }

  .order-modal-card {
    width: 100%;
    max-width: calc(100vw - 20px);
    min-width: 0;
  }

  .order-modal-header h3 {
    overflow-wrap: break-word;
  }

  .grid-row {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 10px;
  }

  .grid-row > * {
    width: 100% !important;
    min-width: 0;
    box-sizing: border-box;
  }

  .order-modal-field,
  .order-input-label {
    overflow: hidden;
    word-wrap: break-word;
    overflow-wrap: break-word;
  }

  .order-modal-field div,
  .order-input-label input {
    width: 100%;
    box-sizing: border-box;
  }

  .full-width {
    grid-column: span 2;
  }

  .order-modal-actions {
    flex-wrap: wrap;
    gap: 10px;
  }

  .order-modal-actions .btn {
    flex: 1 1 calc(50% - 5px);
    min-width: 0;
    white-space: normal;
    overflow-wrap: break-word;
  }
}

.news-tooltip {
  position: fixed;
  z-index: 1200;
  max-width: min(320px, calc(100vw - 24px));
  background: #1e2430;
  border: 1px solid #2a2f3a;
  border-radius: 10px;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.42);
  padding: 12px;
}

.news-tooltip p {
  color: #e6e6e6;
  font-size: 13px;
  line-height: 1.4;
  margin: 0 0 10px;
  white-space: pre-wrap;
}

#newsOverlay,
#newsOverlay-full,
.news-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.news-label {
  position: absolute;
  transform: translate(-50%, -100%);
  background: #4da3ff;
  color: #ffffff;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  pointer-events: auto;
  cursor: pointer;
  z-index: 10;
}
