/* ── Component: TradingSettings modal, TradeCard ──
 * Class prefix: trading-
 */

/* ── Trading Settings Modal ─────────────────────────────────────────────────── */

.trading-overlay {
  position: fixed;
  inset: 0;
  z-index: 400;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

.trading-modal {
  background: var(--color-surface, #1a1a2e);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  width: min(560px, 92vw);
  max-height: 85vh;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
}

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

.trading-modal-header h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-text-primary, #f0f0f0);
}

.trading-modal-close {
  background: none;
  border: none;
  color: var(--color-text-secondary, #888);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 10px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: background 0.15s;
}

.trading-modal-close:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--color-text-primary, #f0f0f0);
}

.trading-modal-body {
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ── Mode Banner ──────────────────────────────────────────────────────────── */

.trading-mode-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.85rem;
  letter-spacing: 0.5px;
}

.trading-mode-banner.paper {
  background: rgba(5, 150, 105, 0.12);
  border: 1px solid rgba(5, 150, 105, 0.3);
  color: #34D399;
}

.trading-mode-banner.live {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #F87171;
}

.trading-mode-banner.disconnected {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--color-text-secondary, #888);
}

.trading-mode-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.trading-mode-banner.paper .trading-mode-dot { background: #34D399; }
.trading-mode-banner.live .trading-mode-dot { background: #F87171; animation: pulse-dot 1.5s infinite; }
.trading-mode-banner.disconnected .trading-mode-dot { background: #666; }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Section styles ───────────────────────────────────────────────────────── */

.trading-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.trading-section-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--color-text-secondary, #888);
  margin: 0;
}

/* ── Mode toggle ──────────────────────────────────────────────────────────── */

.trading-mode-toggle {
  display: flex;
  gap: 8px;
}

.trading-mode-btn {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--color-text-secondary, #888);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.trading-mode-btn:hover {
  background: rgba(255, 255, 255, 0.06);
}

.trading-mode-btn.active-paper {
  background: rgba(5, 150, 105, 0.15);
  border-color: rgba(5, 150, 105, 0.4);
  color: #34D399;
}

.trading-mode-btn.active-live {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
  color: #F87171;
}

/* ── Credentials form ─────────────────────────────────────────────────────── */

.trading-credentials {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.trading-input-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.trading-input-group label {
  font-size: 0.75rem;
  color: var(--color-text-secondary, #888);
  font-weight: 500;
}

.trading-input {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--color-text-primary, #f0f0f0);
  font-family: 'JetBrains Mono', monospace;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s;
}

.trading-input:focus {
  border-color: rgba(5, 150, 105, 0.5);
}

.trading-input::placeholder {
  color: rgba(255, 255, 255, 0.5);
}

.trading-btn-row {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.trading-btn {
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  font-size: 0.875rem;
  min-height: 44px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.trading-btn-primary {
  background: rgba(5, 150, 105, 0.2);
  color: #34D399;
  border: 1px solid rgba(5, 150, 105, 0.3);
}

.trading-btn-primary:hover {
  background: rgba(5, 150, 105, 0.3);
}

.trading-btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--color-text-secondary, #888);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.trading-btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
}

.trading-btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #F87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.trading-btn-danger:hover {
  background: rgba(239, 68, 68, 0.25);
}

.trading-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.trading-status-msg {
  font-size: 0.75rem;
  padding: 6px 10px;
  border-radius: 6px;
  margin-top: 4px;
}

.trading-status-msg.success {
  background: rgba(5, 150, 105, 0.1);
  color: #34D399;
}

.trading-status-msg.error {
  background: rgba(239, 68, 68, 0.1);
  color: #F87171;
}

/* ── Capital rules form ───────────────────────────────────────────────────── */

.trading-rules {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.trading-rules .trading-input-group {
  gap: 3px;
}

.trading-rules .trading-input {
  padding: 6px 10px;
  font-size: 0.8rem;
}

.trading-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  grid-column: 1 / -1;
  padding: 4px 0;
}

.trading-toggle-row label {
  font-size: 0.8rem;
  color: var(--color-text-secondary, #888);
}

.trading-toggle {
  position: relative;
  width: 36px;
  height: 20px;
  appearance: none;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s;
  border: none;
}

.trading-toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #666;
  transition: all 0.2s;
}

.trading-toggle:checked {
  background: rgba(5, 150, 105, 0.4);
}

.trading-toggle:checked::after {
  left: 18px;
  background: #34D399;
}

/* ── Watchlist ────────────────────────────────────────────────────────────── */

.trading-watchlist {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.trading-watchlist-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 32px;
}

.trading-watchlist-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: rgba(5, 150, 105, 0.12);
  border: 1px solid rgba(5, 150, 105, 0.25);
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #34D399;
  font-family: 'JetBrains Mono', monospace;
}

.trading-watchlist-chip button {
  background: none;
  border: none;
  color: rgba(52, 211, 153, 0.6);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0;
  line-height: 1;
}

.trading-watchlist-chip button:hover {
  color: #F87171;
}

.trading-watchlist-input-row {
  display: flex;
  gap: 6px;
}

.trading-watchlist-input-row .trading-input {
  flex: 1;
  text-transform: uppercase;
}

/* ── Live mode warning ────────────────────────────────────────────────────── */

.trading-live-warning {
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: 10px;
  padding: 12px 16px;
  color: #F87171;
  font-size: 0.8rem;
  line-height: 1.5;
}

.trading-live-warning strong {
  display: block;
  margin-bottom: 4px;
}

/* ── Workspace mode banner (persistent) ───────────────────────────────────── */

.workspace-trading-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: opacity 0.15s;
}

.workspace-trading-banner:hover {
  opacity: 0.85;
}

.workspace-trading-banner.paper {
  background: rgba(5, 150, 105, 0.12);
  border: 1px solid rgba(5, 150, 105, 0.25);
  color: #34D399;
}

.workspace-trading-banner.live {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.25);
  color: #F87171;
}

/* ── Trade Card ───────────────────────────────────────────────────────────── */

.trade-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 16px;
  margin: 8px 0;
}

.trade-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.trade-card-symbol {
  font-size: 1.1rem;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  color: var(--color-text-primary, #f0f0f0);
}

.trade-card-direction {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.trade-card-direction.buy {
  background: rgba(5, 150, 105, 0.2);
  color: #34D399;
}

.trade-card-direction.sell {
  background: rgba(239, 68, 68, 0.2);
  color: #F87171;
}

.trade-card-conviction {
  margin-left: auto;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.trade-card-conviction.high {
  background: rgba(5, 150, 105, 0.15);
  color: #34D399;
}

.trade-card-conviction.medium {
  background: rgba(234, 179, 8, 0.15);
  color: #FBBF24;
}

.trade-card-conviction.low {
  background: rgba(255, 255, 255, 0.06);
  color: var(--color-text-secondary, #888);
}

.trade-card-prices {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.trade-card-price {
  text-align: center;
}

.trade-card-price-label {
  font-size: 0.65rem;
  color: var(--color-text-secondary, #888);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.trade-card-price-value {
  font-size: 0.9rem;
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
  color: var(--color-text-primary, #f0f0f0);
}

.trade-card-price-pct {
  font-size: 0.65rem;
  margin-top: 1px;
}

.trade-card-price-pct.positive { color: #34D399; }
.trade-card-price-pct.negative { color: #F87171; }

.trade-card-details {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--color-text-secondary, #888);
}

.trade-card-catalyst {
  line-height: 1.4;
}

.trade-card-risks {
  list-style: none;
  padding: 0;
  margin: 0;
}

.trade-card-risks li {
  padding-left: 12px;
  position: relative;
  line-height: 1.4;
}

.trade-card-risks li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 8px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #F87171;
}

.trade-card-meta {
  display: flex;
  gap: 16px;
  margin-top: 4px;
  font-size: 0.72rem;
  color: var(--color-text-secondary, #888);
}

/* ── Paused banner ────────────────────────────────────────────────────────── */

.trading-paused-banner {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: 10px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.trading-paused-text {
  color: #F87171;
  font-size: 0.8rem;
  font-weight: 500;
}

/* ── Tab bar ──────────────────────────────────────────────────────────────── */

.trading-tab-bar {
  display: flex;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin: -20px -24px 16px;
  padding: 0 24px;
}

.trading-tab {
  padding: 12px 20px;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--color-text-secondary, #888);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.trading-tab:hover {
  color: var(--color-text-primary, #f0f0f0);
}

.trading-tab.active {
  color: var(--color-text-primary, #f0f0f0);
  border-bottom-color: #F59E0B;
}

/* ── Crypto status banner ────────────────────────────────────────────────── */

.crypto-status-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 500;
}

.crypto-status-banner.active {
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.25);
  color: #34D399;
}

.crypto-status-banner.active .trading-mode-dot { background: #34D399; }

.crypto-status-banner.inactive {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.25);
  color: #F87171;
}

.crypto-status-banner.inactive .trading-mode-dot { background: #F87171; animation: pulse-dot 1.5s infinite; }

.crypto-status-banner.loading {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--color-text-secondary, #888);
}

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

/* ── Touch targets + bottom sheet ── */
@media (hover: none) and (pointer: coarse) {
  .trading-toggle {
    width: 44px;
    height: 26px;
    border-radius: 13px;
  }

  .trading-toggle::after {
    width: 22px;
    height: 22px;
  }

  .trading-toggle:checked::after {
    left: 20px;
  }
}

/* ── Tablet (≤ 768px): bottom sheet ── */
@media (max-width: 768px) {
  .trading-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .trading-modal {
    border-radius: 16px 16px 0 0;
    max-height: 92vh;
    max-height: 92dvh;
    width: 100%;
    max-width: 100%;
  }

  .trading-modal-body {
    padding-bottom: calc(20px + var(--safe-bottom, 0px));
  }
}

/* ── Small phones (≤ 480px) ── */
@media (max-width: 480px) {
  .trading-overlay {
    align-items: flex-end;
  }

  .trading-modal {
    border-radius: 16px 16px 0 0;
    max-height: 94vh;
    max-height: 94dvh;
  }

  .trading-modal-body {
    padding-bottom: calc(20px + var(--safe-bottom, 0px));
  }

  /* Trade card: readable font sizes on small screens */
  .trade-card-price-label {
    font-size: 0.7rem;
  }

  .trade-card-direction {
    font-size: 0.75rem;
  }

  .trade-card-conviction {
    font-size: 0.7rem;
  }

  .trade-card-price-pct {
    font-size: 0.7rem;
  }

  /* Trade card price grid: 2x2 on phones */
  .trade-card-prices {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }
}
