.trading-layout {
  display: grid;
  grid-template-columns: 320px 240px 1fr;
  grid-template-rows: 1fr;
  gap: 1px;
  background: var(--border-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  min-height: calc(100vh - 120px);
}

.trading-layout > * {
  background: var(--bg-secondary);
  min-width: 0; /* Prevents grid blowout from child elements like iframe/tables */
}

/* ── Symbol List ──────────────────────────────────────── */
.symbol-panel {
  grid-column: 2;
  grid-row: 1;
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
}

.symbol-search {
  padding: 12px;
  border-bottom: 1px solid var(--border-color);
}

.symbol-search input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
}

.symbol-search input:focus { border-color: var(--yellow); }

.symbol-list {
  flex: 1;
  overflow-y: auto;
  max-height: 720px; /* Approx 20 items at 36px each */
}

.symbol-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  cursor: pointer;
  transition: var(--transition);
  font-size: 13px;
}

.symbol-item:hover { background: var(--bg-hover); }
.symbol-item.active { background: var(--yellow-bg); }

.symbol-name { font-weight: 600; }
.symbol-price { color: var(--text-secondary); }
.symbol-change { font-weight: 500; }

/* ── Price / Chart Area ───────────────────────────────── */
.chart-panel {
  grid-column: 3;
  grid-row: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
}

.price-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 16px;
}

.price-header-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.price-header-main {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.current-symbol {
  font-size: 16px;
  font-weight: 700;
}

.current-price {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
}

.price-change {
  font-size: 16px;
  font-weight: 600;
}

.price-stats {
  display: flex;
  gap: 24px;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.price-stat span { color: var(--text-primary); font-weight: 500; margin-left: 4px; }

.chart-container {
  flex: 1;
  background: var(--bg-primary);
  border-radius: var(--radius-md);
  min-height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

/* ── Order Panel ──────────────────────────────────────── */
.order-panel {
  grid-column: 1;
  grid-row: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-right: 1px solid var(--border-color);
}

.order-tabs {
  display: flex;
  background: var(--bg-input);
  border-radius: var(--radius-md);
  padding: 2px;
}

.order-tab {
  flex: 1;
  padding: 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.order-tab.active { background: var(--bg-secondary); color: var(--text-primary); }

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

.side-tab {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  background: var(--bg-input);
  color: var(--text-secondary);
}

.side-tab.buy.active { background: var(--green); color: #fff; }
.side-tab.sell.active { background: var(--red); color: #fff; }
.side-tab.buy:hover:not(.active) { background: var(--green-bg); color: var(--green); }
.side-tab.sell:hover:not(.active) { background: var(--red-bg); color: var(--red); }

.order-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.order-input-group {
  display: flex;
  align-items: center;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: var(--transition);
}

.order-input-group:focus-within {
  border-color: var(--yellow);
}

.order-input-label {
  padding: 0 12px;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  min-width: 50px;
}

.order-input-group input {
  flex: 1;
  background: transparent;
  border: none;
  padding: 10px 0;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  text-align: right;
  font-family: var(--font);
}

.order-input-suffix {
  padding: 0 12px;
  font-size: 12px;
  color: var(--text-tertiary);
  white-space: nowrap;
}

/* Percentage slider */
.percent-row {
  display: flex;
  gap: 4px;
}

.percent-btn {
  flex: 1;
  padding: 4px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 11px;
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font);
}

.percent-btn:hover, .percent-btn.active {
  border-color: var(--yellow);
  color: var(--yellow);
}

.order-summary {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-secondary);
}

.order-summary span { color: var(--text-primary); }

/* ── TP/SL Section ────────────────────────────────────── */
.tpsl-section {
  border-top: 1px solid var(--border-color);
  padding-top: 12px;
}

.tpsl-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  margin-bottom: 10px;
}

.tpsl-toggle input[type="checkbox"] {
  appearance: none;
  width: 36px; height: 20px;
  border-radius: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  position: relative;
  cursor: pointer;
  transition: var(--transition);
}

.tpsl-toggle input[type="checkbox"]::after {
  content: '';
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--text-tertiary);
  position: absolute;
  top: 1px; left: 1px;
  transition: var(--transition);
}

.tpsl-toggle input[type="checkbox"]:checked {
  background: var(--yellow-bg);
  border-color: var(--yellow);
}

.tpsl-toggle input[type="checkbox"]:checked::after {
  background: var(--yellow);
  left: 17px;
}

.tpsl-inputs {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ── Leverage Selector ────────────────────────────────── */
.leverage-selector {
  display: flex;
  align-items: center;
  gap: 8px;
}

.leverage-badge {
  background: var(--yellow-bg);
  color: var(--yellow);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: var(--transition);
}

.leverage-badge:hover { border-color: var(--yellow); }

.leverage-slider {
  flex: 1;
}

.leverage-slider input[type="range"] {
  width: 100%;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--bg-input);
  outline: none;
}

.leverage-slider input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--yellow);
  cursor: pointer;
  box-shadow: 0 0 4px rgba(240, 185, 11, 0.4);
}

/* ── Bottom Panels ────────────────────────────────────── */
.bottom-panels {
  margin-top: 1px;
}

.positions-table, .orders-table, .history-table {
  max-height: 300px;
  overflow-y: auto;
}

/* ── Batch Operations ─────────────────────────────────── */
.batch-accounts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.batch-account-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
}

.batch-account-item:hover { border-color: var(--border-light); }
.batch-account-item.selected { border-color: var(--yellow); background: var(--yellow-bg); }

.batch-account-item .badge { margin-left: auto; }

.batch-progress {
  margin-top: 16px;
}

.batch-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-color);
  font-size: 13px;
}

.batch-result-item:last-child { border-bottom: none; }

.result-icon { width: 20px; text-align: center; font-size: 16px; }

/* ── Responsive Trading ───────────────────────────────── */
@media (max-width: 1200px) {
  .trading-layout {
    grid-template-columns: 1fr 300px;
  }
  .symbol-panel { display: none; }
  .chart-panel { grid-column: 1; }
  .order-panel { grid-column: 2; }
}

@media (max-width: 900px) {
  .trading-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    min-height: auto;
    gap: 16px;
    border: none;
    background: transparent;
  }
  .symbol-panel { 
    display: flex !important; /* Restore visibility on mobile */
    grid-row: 1; grid-column: 1; height: 160px; border-bottom: 1px solid var(--border-color); 
  }
  .order-panel { grid-row: 2; grid-column: 1; padding: 0; width: 100%; border-bottom: 1px solid var(--border-color); }
  .chart-panel { grid-row: 3; grid-column: 1; padding: 0 0 8px 0; width: 100%; border-bottom: none; }
  .chart-container { display: none !important; }
  .bottom-panels { margin-top: 16px; width: 100%; }
}

@media (max-width: 600px) {
  .current-price { font-size: 20px; }
  .price-stats { gap: 12px; }
}
