/* ============================================
   Live Trading View
   ============================================ */

/* ---- Key Banner (below chart, centered, when no API keys) ---- */
.live-key-banner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px 20px;
  margin: 8px 10px 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  text-align: center;
}
.live-key-banner svg {
  flex-shrink: 0;
  color: var(--gold);
}
.live-key-banner-text {
  font-size: 16px;
  color: var(--text-secondary);
  line-height: 1.6;
}
.live-key-banner .btn-primary {
  padding: 8px 28px;
  font-size: 14px;
}

/* ---- Symbol Search ---- */
.live-search-wrap {
  position: relative;
  width: 140px;
  flex-shrink: 0;
}
.live-search-input {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 6px 10px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 700;
  outline: none;
  transition: border-color 0.15s;
}
.live-search-input:focus {
  border-color: var(--gold);
}
.live-search-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 50;
  min-width: 220px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.live-search-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.1s;
}
.live-search-item:hover,
.live-search-item.active {
  background: var(--bg-hover);
}
.live-search-item .symbol-name {
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-primary);
}
.live-search-item .symbol-full {
  color: var(--text-tertiary);
  font-size: 12px;
}

/* ---- Timeframe Select ---- */
.live-tf-select {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 6px 8px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13px;
  cursor: pointer;
}

/* ---- Price Display ---- */
.live-price-display {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin-left: auto;
}

/* ---- Connection Status ---- */
.live-conn-status {
  display: flex;
  align-items: center;
  margin-left: var(--spacing-2);
}
.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  transition: background var(--transition-fast), box-shadow var(--transition-fast);
}
.conn-dot.connected {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  animation: pulse-green 2s ease-in-out infinite;
}
.conn-dot.disconnected {
  background: var(--red);
}

@keyframes pulse-green {
  0%, 100% { box-shadow: 0 0 4px var(--green); }
  50% { box-shadow: 0 0 10px var(--green), 0 0 16px var(--green-glow); }
}

/* ---- Live Account Bar (below chart, matching training .account-bar) ---- */
.live-account-bar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  margin: 4px 10px 0;
  font-size: 13px;
  flex-wrap: wrap;
}
.live-account-item {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.live-account-item .account-label {
  color: var(--text-secondary);
  font-size: 12px;
}
.live-account-item .account-value {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text-primary);
  font-size: 14px;
}
.live-wallet-item {
  margin-left: auto;
}

.live-account-bar .win { color: var(--green); }
.live-account-bar .lose { color: var(--red); }
.live-wallet-addr {
  font-size: 12px !important;
  color: var(--text-tertiary) !important;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- Chart Area (matching training chart) ---- */
.live-candles {
  position: relative;
}
.live-chart {
  width: calc(100% - 58px);
  height: 600px;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  margin-left: 38px;
}

/* ---- Vertical Toolbar (left of live chart) ---- */
.live-candles > #liveToolbar {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 0;
  gap: 6px;
  width: 38px;
  height: 100%;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  border-radius: var(--radius-md) 0 0 var(--radius-md);
  overflow-y: auto;
  overflow-x: hidden;
}
/* Match #showHistoryGraphics special styling */
.tool-item#liveShowHistory { margin-bottom: 4px; opacity: 0.85; }
.tool-item#liveShowHistory:hover { opacity: 1; }
#liveEye.show { display: inline-block; }
#liveEye.hide { display: none; }
#liveEyeClose.show { display: inline-block; }
#liveEyeClose.hide { display: none; }

/* ---- Drawing tool active state ---- */
.live-draw-active {
  background: var(--bg-hover) !important;
  opacity: 1 !important;
}

/* ---- Trading Controls (4 buttons like training) ---- */
.live-controls {
  margin: 8px 10px;
}
.live-controls .settings-item select,
.live-controls .live-type-select {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 4px 6px;
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
}
.live-controls .live-size-input {
  width: 80px;
  padding: 4px 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13px;
  outline: none;
}
.live-controls .live-size-input:focus {
  border-color: var(--gold);
}
.live-est-size {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--gold);
  font-weight: 600;
}

/* ---- 4-Column Data Grid (2/8 : 1/8 : 3/8 : 2/8) ---- */
.live-data-grid {
  display: flex;
  gap: 10px;
  margin: 8px 10px;
  height: 520px;
}
.live-grid-col {
  min-width: 0;
  display: flex;
  flex-direction: column;
}
/* Col 1: Orderbook — 2/8 */
.live-grid-col:nth-child(1) { flex: 2; }
/* Col 2: Recent Trades — 1/8 */
.live-grid-col:nth-child(2) { flex: 1; }
/* Col 3: Positions + Orders — 3/8 */
.live-grid-col:nth-child(3) { flex: 3; }
/* Col 4: Fills — 2/8 */
.live-grid-col:nth-child(4) { flex: 2; }
.live-grid-col h2 {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin: 0 0 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.live-panel {
  flex: 1;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.live-panel-table {
  overflow-y: auto;
}
/* ---- Section header with filter checkbox (h2 left, checkbox right) ---- */
.live-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.live-section-header h2 {
  margin: 0 !important;
}
.live-filter-check {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-tertiary);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  background: var(--bg-tertiary);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  transition: border-color 0.15s;
}
.live-filter-check:hover {
  border-color: var(--gold);
  color: var(--text-secondary);
}
.live-filter-check input[type="checkbox"] {
  accent-color: var(--gold);
  cursor: pointer;
  width: 13px;
  height: 13px;
  margin: 0;
}

/* Col 3: Positions + Orders stacked vertically */
.live-grid-col-stack {
  gap: 10px;
}
.live-stack-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.live-stack-item h2 {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin: 0 0 6px;
}
.live-stack-item .live-panel {
  flex: 1;
}

/* ---- Orderbook (Professional Exchange Style) ---- */
.live-orderbook-wrap {
  font-family: var(--font-mono);
  font-size: 12px;
}
.live-ob-header {
  display: flex;
  align-items: center;
  padding: 4px 10px;
  color: var(--text-tertiary);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-tertiary);
}
.live-ob-header span:nth-child(1) { width: 38%; }
.live-ob-header span:nth-child(2) { width: 28%; text-align: right; }
.live-ob-header span:nth-child(3) { width: 34%; text-align: right; }
.live-ob-row {
  display: flex;
  align-items: center;
  padding: 1px 10px;
  position: relative;
  line-height: 20px;
  cursor: default;
  transition: background 0.1s;
}
.live-ob-row:hover {
  background: rgba(255,255,255,0.04);
}
.live-ob-px {
  width: 38%;
  z-index: 1;
}
.live-ob-sz {
  width: 28%;
  text-align: right;
  z-index: 1;
  color: var(--text-tertiary);
}
.live-ob-total {
  width: 34%;
  text-align: right;
  z-index: 1;
  color: var(--text-tertiary);
  font-size: 11px;
}
.live-ob-bar {
  position: absolute;
  right: 0;
  top: 0;
  height: 100%;
  opacity: 0.12;
  z-index: 0;
}
.live-ob-ask .live-ob-px { color: var(--red); }
.live-ob-ask .live-ob-bar { background: var(--red); }
.live-ob-bid .live-ob-px { color: var(--green); }
.live-ob-bid .live-ob-bar { background: var(--green); }
.live-orderbook-spread {
  display: flex;
  justify-content: space-between;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  background: var(--bg-tertiary);
  border-top: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
}
.live-ob-spread-val {
  color: var(--text-primary);
}
.live-ob-spread-pct {
  color: var(--text-tertiary);
  font-weight: 400;
}

/* ---- Recent Trades Panel ---- */
.live-recent-trades-wrap {
  font-family: var(--font-mono);
  font-size: 12px;
}
.live-rt-header {
  display: flex;
  align-items: center;
  padding: 4px 10px;
  color: var(--text-tertiary);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-tertiary);
}
.live-rt-header span:nth-child(1) { width: 38%; }
.live-rt-header span:nth-child(2) { width: 28%; text-align: right; }
.live-rt-header span:nth-child(3) { width: 34%; text-align: right; }
.live-recent-trades-list {
  flex: 1;
  overflow-y: auto;
}
.live-rt-row {
  display: flex;
  align-items: center;
  padding: 1px 10px;
  line-height: 20px;
  transition: background 0.1s;
}
.live-rt-row:hover {
  background: rgba(255,255,255,0.04);
}
.live-rt-row .live-rt-price {
  width: 38%;
}
.live-rt-row .live-rt-sz {
  width: 28%;
  text-align: right;
  color: var(--text-tertiary);
}
.live-rt-row .live-rt-time {
  width: 34%;
  text-align: right;
  color: var(--text-tertiary);
  font-size: 11px;
}
.live-rt-buy .live-rt-price { color: var(--green); }
.live-rt-sell .live-rt-price { color: var(--red); }

/* ---- Live Tables (compact for 25% columns) ---- */
.live-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.live-table th {
  text-align: center;
  padding: 4px 4px;
  color: var(--text-tertiary);
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--bg-secondary);
  z-index: 1;
}
.live-table td {
  padding: 3px 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-primary);
  border-bottom: 1px solid rgba(43,49,57,0.3);
  text-align: center;
  white-space: nowrap;
}
.live-table .live-pnl {
  font-weight: 700;
}
.live-pnl.positive { color: var(--green); }
.live-pnl.negative { color: var(--red); }
.live-table .live-side-long { color: var(--green); font-weight: 700; }
.live-table .live-side-short { color: var(--red); font-weight: 700; }

.live-btn-close,
.live-btn-cancel {
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}
.live-btn-close:hover {
  border-color: var(--red);
  color: var(--red);
  background: var(--red-bg);
}
.live-btn-cancel:hover {
  border-color: var(--gold);
  color: var(--gold);
  background: var(--gold-dim);
}

.live-empty {
  text-align: center;
  padding: 16px 8px;
  color: var(--text-tertiary);
  font-size: 12px;
}

/* ---- Pagination ---- */
.live-pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
}
.live-pag-btn {
  padding: 4px 14px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}
.live-pag-btn:hover:not(:disabled) {
  border-color: var(--gold);
  color: var(--gold);
}
.live-pag-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.live-pag-info {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-tertiary);
}

/* ---- Symbol Search Modal ---- */
.live-symbol-modal .modal-body {
  padding: 0;
}
.live-symbol-modal .live-symbol-search-wrap {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  background: var(--bg-elevated);
  z-index: 2;
}
.live-symbol-modal .live-symbol-search-input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 14px;
  outline: none;
  box-sizing: border-box;
}
.live-symbol-modal .live-symbol-search-input:focus {
  border-color: var(--gold);
}
.live-symbol-modal .live-symbol-search-count {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 6px;
}
.live-symbol-modal-list {
  max-height: 360px;
  overflow-y: auto;
  padding: 4px 0;
}
.live-symbol-modal-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  cursor: pointer;
  transition: background 0.1s;
}
.live-symbol-modal-item:hover {
  background: var(--bg-hover);
}
.live-symbol-modal-item.active {
  background: var(--bg-hover);
}
.live-symbol-modal-item .sym-name {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 14px;
  color: var(--text-primary);
}
.live-symbol-modal-item .sym-tag {
  font-size: 11px;
  color: var(--text-tertiary);
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 3px;
}

/* ---- Order Confirm Modal ---- */
.live-order-confirm .live-confirm-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-color);
  font-size: 14px;
}
.live-order-confirm .live-confirm-row span:first-child {
  color: var(--text-secondary);
  flex-shrink: 0;
}
.live-modal-input {
  width: 140px;
  padding: 4px 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13px;
  text-align: right;
  outline: none;
  transition: border-color 0.15s;
}
.live-modal-input:focus {
  border-color: var(--gold);
}
.live-modal-input::placeholder {
  color: var(--text-tertiary);
  font-size: 11px;
}
/* TP/SL input + percentage badge wrapper */
.live-input-pct-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}
.live-pct-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  min-width: 52px;
  text-align: center;
  white-space: nowrap;
  color: var(--text-tertiary);
}
.live-pct-pos {
  color: var(--green);
  background: rgba(0, 230, 118, 0.1);
}
.live-pct-neg {
  color: var(--red);
  background: rgba(255, 2, 0, 0.1);
}
/* End TP/SL input + percentage badge wrapper */
.live-order-confirm .live-confirm-total {
  border-top: 2px solid var(--border-color);
  border-bottom: none;
  font-weight: 700;
  margin-top: 8px;
  padding-top: 12px;
}

/* ---- Pending Order Floating Panel ---- */
.live-pending-order-panel {
  position: absolute;
  right: 80px;
  top: 60px;
  z-index: 20;
  background: rgba(18, 22, 26, 0.95);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  padding: 14px 18px;
  min-width: 220px;
  font-size: 13px;
  backdrop-filter: blur(8px);
}
.pending-order-title {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
}
.pending-order-title.live-side-long { color: var(--green); }
.pending-order-title.live-side-short { color: var(--red); }
.pending-order-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}
.pending-order-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
.pending-order-row span:first-child {
  color: var(--text-secondary);
  font-size: 12px;
}
.pending-order-row span:last-child {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text-primary);
}
.pending-order-actions {
  display: flex;
  gap: 8px;
}
.pending-order-actions button {
  flex: 1;
  padding: 6px 0;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border-color);
  transition: all 0.15s;
}
.pending-confirm-buy {
  background: var(--green);
  color: #000;
  border-color: var(--green) !important;
}
.pending-confirm-buy:hover {
  opacity: 0.85;
}
.pending-confirm-sell {
  background: var(--red);
  color: #fff;
  border-color: var(--red) !important;
}
.pending-confirm-sell:hover {
  opacity: 0.85;
}
.pending-cancel-btn {
  background: transparent;
  color: var(--text-secondary);
}
.pending-cancel-btn:hover {
  border-color: var(--gold);
  color: var(--gold);
}

/* ---- Responsive Live ---- */
@media (max-width: 1200px) {
  .live-data-grid {
    height: auto;
    flex-wrap: wrap;
  }
  .live-grid-col {
    flex: 1 1 calc(50% - 5px);
    height: 460px;
  }
  .live-grid-col-stack {
    height: auto;
    min-height: 460px;
  }
}
@media (max-width: 768px) {
  .live-data-grid {
    flex-direction: column;
    height: auto;
  }
  .live-grid-col {
    flex: 1 1 100%;
    height: 360px;
  }
  .live-grid-col-stack {
    min-height: 360px;
  }
  .live-chart {
    height: 400px;
  }
  .live-account-bar {
    gap: 12px;
    padding: 8px 12px;
    font-size: 12px;
  }
  .live-search-wrap {
    width: 100px;
  }
}
@media (max-width: 480px) {
  .live-account-bar {
    flex-direction: column;
    gap: 4px;
    align-items: flex-start;
  }
  .live-wallet-item {
    margin-left: 0;
  }
  .live-chart {
    height: 350px;
  }
}
