/* ========== MARGIN TRADING PAGE ========== */

/* ---- Margin Mode Toggle ---- */
.margin-mode-toggle {
  display: flex;
  gap: 2px;
  background: rgba(255,255,255,0.04);
  border-radius: 6px;
  padding: 2px;
  margin-left: 12px;
}

.margin-mode-btn {
  background: transparent;
  border: none;
  color: #5a5a6a;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 14px;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: 'Inter', -apple-system, sans-serif;
}

.margin-mode-btn:hover {
  color: #8a8a9a;
}

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

/* ---- Margin Account Info Bar ---- */
.margin-info-bar {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 12px 32px;
  background: #111827;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  overflow-x: auto;
}

.margin-info-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 24px;
  border-right: 1px solid rgba(255,255,255,0.04);
  white-space: nowrap;
}

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

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

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

.margin-info-value.safe {
  color: #00c087;
}

.margin-info-value.warning {
  color: #f0b90b;
}

.margin-info-value.danger {
  color: #e74c3c;
}

/* ---- Main Grid Layout ---- */
.margin-top-grid {
  display: grid;
  grid-template-columns: 1fr 280px 320px;
  gap: 1px;
  background: rgba(255,255,255,0.03);
  min-height: 560px;
}

/* Chart Card */
.margin-chart-card {
  border-radius: 0 !important;
  border: none !important;
  display: flex;
  flex-direction: column;
}

.chart-area {
  flex: 1;
  min-height: 400px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: #2a2a3a;
  font-size: 13px;
}

/* ---- Order Book ---- */
.margin-orderbook-card {
  border-radius: 0 !important;
  border: none !important;
  border-left: 1px solid rgba(255,255,255,0.04) !important;
  border-right: 1px solid rgba(255,255,255,0.04) !important;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.orderbook-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.orderbook-header h3 {
  font-size: 13px;
  font-weight: 600;
  color: #e0e0e8;
  margin: 0;
}

.orderbook-view-btns {
  display: flex;
  gap: 4px;
}

.ob-view-btn {
  width: 26px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.ob-view-btn:hover {
  border-color: rgba(255,255,255,0.12);
}

.ob-view-btn.active {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.12);
}

.orderbook-columns {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  padding: 6px 16px;
  font-size: 10px;
  font-weight: 600;
  color: #3a3a4a;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.orderbook-asks,
.orderbook-bids {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.orderbook-asks {
  justify-content: flex-end;
}

.ob-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  padding: 3px 16px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  position: relative;
  cursor: pointer;
  transition: background 0.1s;
}

.ob-row:hover {
  background: rgba(255,255,255,0.03);
}

.ob-bar {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  pointer-events: none;
}

.ob-row.ask .ob-bar {
  background: rgba(231,76,60,0.08);
}

.ob-row.bid .ob-bar {
  background: rgba(0,192,135,0.08);
}

.ob-price {
  position: relative;
  z-index: 1;
  font-weight: 500;
}

.ob-row.ask .ob-price {
  color: #e74c3c;
}

.ob-row.bid .ob-price {
  color: #00c087;
}

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

.orderbook-spread {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: rgba(255,255,255,0.02);
  border-top: 1px solid rgba(255,255,255,0.04);
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.spread-price {
  font-size: 16px;
  font-weight: 700;
  color: #00c087;
  font-variant-numeric: tabular-nums;
}

.spread-label {
  font-size: 11px;
  color: #4a4a5a;
}

/* ---- Order Form ---- */
.margin-order-card {
  border-radius: 0 !important;
  border: none !important;
  padding: 16px !important;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

.margin-action-tabs {
  display: flex;
  gap: 2px;
  background: rgba(255,255,255,0.03);
  border-radius: 8px;
  padding: 3px;
}

.margin-action-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: #5a5a6a;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 0;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: 'Inter', -apple-system, sans-serif;
}

.margin-action-btn:hover {
  color: #8a8a9a;
}

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

/* Long/Short Toggle */
.order-side-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  background: rgba(255,255,255,0.03);
  border-radius: 8px;
  padding: 3px;
}

.order-side-btn {
  border: none;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 0;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: 'Inter', -apple-system, sans-serif;
}

.order-side-btn.buy {
  background: transparent;
  color: #5a5a6a;
}

.order-side-btn.sell {
  background: transparent;
  color: #5a5a6a;
}

.order-side-btn.buy.active {
  background: rgba(0,192,135,0.15);
  color: #00c087;
}

.order-side-btn.sell.active {
  background: rgba(231,76,60,0.15);
  color: #e74c3c;
}

/* Leverage Slider */
.leverage-section {
  padding: 0 2px;
}

.leverage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.leverage-label {
  font-size: 12px;
  font-weight: 600;
  color: #5a5a6a;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.leverage-value {
  font-size: 14px;
  font-weight: 700;
  color: #5cb8e6;
}

.leverage-slider {
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: linear-gradient(to right, #00c087, #f0b90b, #e74c3c);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.leverage-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #e0e0e8;
  border: 3px solid #5cb8e6;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.leverage-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #e0e0e8;
  border: 3px solid #5cb8e6;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.leverage-marks {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: #3a3a4a;
  margin-top: 4px;
  padding: 0 2px;
}

/* Order Type */
.order-type-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.order-type-btn {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: #5a5a6a;
  font-size: 12px;
  font-weight: 600;
  padding: 8px 0;
  cursor: pointer;
  transition: all 0.15s;
  font-family: 'Inter', -apple-system, sans-serif;
}

.order-type-btn:hover {
  color: #8a8a9a;
}

.order-type-btn.active {
  color: #e0e0e8;
  border-bottom-color: #5cb8e6;
}

/* Order Fields */
.order-fields {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.order-field label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: #4a4a5a;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 5px;
}

.order-input-wrap {
  display: flex;
  align-items: center;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 8px;
  overflow: hidden;
}

.order-input-wrap input {
  flex: 1;
  background: transparent;
  border: none;
  color: #e0e0e8;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 12px;
  text-align: center;
  outline: none;
  font-variant-numeric: tabular-nums;
  font-family: 'Inter', -apple-system, sans-serif;
}

.order-input-btn {
  width: 36px;
  height: 38px;
  background: rgba(255,255,255,0.03);
  border: none;
  color: #5a5a6a;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.order-total-input {
  width: 100%;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 8px;
  color: #8a8a9a;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 12px;
  text-align: right;
  outline: none;
  font-variant-numeric: tabular-nums;
  font-family: 'Inter', -apple-system, sans-serif;
}

.quick-amount-btns {
  display: flex;
  gap: 6px;
}

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

.quick-btn:hover {
  border-color: rgba(92,184,230,0.2);
  color: #8a8a9a;
}

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

/* Margin Order Summary */
.margin-order-summary {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  background: rgba(255,255,255,0.02);
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.04);
}

.summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
}

.summary-row span {
  color: #5a5a6a;
}

.summary-row strong {
  color: #b0b0c0;
  font-weight: 600;
}

.summary-row strong.warning {
  color: #f0b90b;
}

/* Submit Button */
.order-submit-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.3px;
  font-family: 'Inter', -apple-system, sans-serif;
}

.order-submit-btn.buy {
  background: linear-gradient(135deg, #00c087, #00a070);
  color: #fff;
}

.order-submit-btn.buy:hover {
  background: linear-gradient(135deg, #00d094, #00c087);
  box-shadow: 0 4px 16px rgba(0,192,135,0.25);
}

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

.order-submit-btn.sell:hover {
  background: linear-gradient(135deg, #f05545, #e74c3c);
  box-shadow: 0 4px 16px rgba(231,76,60,0.25);
}

.order-available {
  text-align: center;
  font-size: 12px;
  color: #4a4a5a;
}

.order-available strong {
  color: #8a8a9a;
}

/* ========== ACTIVE POSITIONS TABLE ========== */

.margin-positions-card {
  margin-top: 1px;
}

.positions-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.positions-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: #e0e0e8;
  margin: 0;
}

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

.pos-tab-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 6px;
  color: #5a5a6a;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 14px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: 'Inter', -apple-system, sans-serif;
}

.pos-tab-btn:hover {
  border-color: rgba(255,255,255,0.12);
  color: #8a8a9a;
}

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

.positions-table-wrap {
  overflow-x: auto;
}

.positions-table {
  width: 100%;
  border-collapse: collapse;
}

.positions-table thead th {
  font-size: 10px;
  font-weight: 600;
  color: #4a4a5a;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 10px 16px;
  text-align: left;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  white-space: nowrap;
}

.positions-table tbody tr {
  transition: background 0.15s;
}

.positions-table tbody tr:hover {
  background: rgba(255,255,255,0.02);
}

.positions-table tbody td {
  font-size: 13px;
  color: #b0b0c0;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.pos-pair {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pos-pair-name {
  font-weight: 600;
  color: #e0e0e8;
}

.pos-leverage {
  font-size: 10px;
  font-weight: 700;
  color: #5cb8e6;
  background: rgba(92,184,230,0.1);
  padding: 2px 6px;
  border-radius: 4px;
}

.pos-side {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.pos-side.long {
  color: #00c087;
  background: rgba(0,192,135,0.1);
}

.pos-side.short {
  color: #e74c3c;
  background: rgba(231,76,60,0.1);
}

td.warning {
  color: #f0b90b !important;
}

.pos-pnl {
  font-weight: 600;
}

.pos-pnl.positive {
  color: #00c087;
}

.pos-pnl.negative {
  color: #e74c3c;
}

.pos-actions {
  display: flex;
  gap: 6px;
}

.pos-action-btn {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 6px;
  color: #8a8a9a;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  cursor: pointer;
  transition: all 0.15s;
}

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

.pos-action-btn.close {
  color: #e74c3c;
  border-color: rgba(231,76,60,0.2);
}

.pos-action-btn.close:hover {
  background: rgba(231,76,60,0.1);
}

/* ========== RESPONSIVE ========== */

@media (max-width: 1200px) {
  .margin-top-grid {
    grid-template-columns: 1fr 280px;
  }

  .margin-order-card {
    grid-column: 1 / -1;
  }
}

@media (max-width: 768px) {
  .margin-top-grid {
    grid-template-columns: 1fr;
  }

  .margin-info-bar {
    padding: 12px 16px;
    gap: 0;
  }

  .margin-info-item {
    padding: 0 16px;
  }

  .positions-header {
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
  }

  .positions-table thead th,
  .positions-table tbody td {
    padding: 10px 12px;
    font-size: 12px;
  }
}
