/* Token logos */
.token-logo {
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  vertical-align: middle;
}

.token-logo-fallback {
  border-radius: 50%;
  background: var(--bg-input);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
  vertical-align: middle;
}

/* Spot Subheader */
.spot-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 12px;
  height: 44px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  white-space: nowrap;
  -ms-overflow-style: none;
  scrollbar-width: none;
  flex-wrap: wrap;
}
.spot-header::-webkit-scrollbar { display: none; }

.spot-header__pair {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.spot-header__pair svg { width: 14px; height: 14px; color: var(--text-third); }

.spot-header__price-mobile {
  font-size: 16px;
  font-weight: 700;
  font-family: var(--font-mono);
}

.spot-header__mobile-stats {
  display: none;
}

.spot-header__stat {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 0 12px;
  border-left: 1px solid var(--border);
}

.spot-header__stat-label {
  font-size: 12px;
  color: var(--text-third);
}

.spot-header__stat-value {
  font-size: 14px;
  font-family: var(--font-mono);
  color: var(--text-primary);
}

/* Main Grid Layout */
.trading-layout {
  display: grid;
  grid-template-columns: 380px 1fr 240px 300px;
  grid-template-rows: 1fr;
  height: calc(100vh - var(--navbar-h) - 44px);
  overflow: hidden;
}

/* Chart + orders column */
.chart-orders-col {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Pairs Sidebar */
.pairs-panel {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  min-width: 200px;
  max-width: 600px;
}

.pairs-resize-handle {
  position: absolute;
  top: 0;
  right: -3px;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 10;
  background: transparent;
  transition: background var(--transition);
}

.pairs-resize-handle:hover,
.pairs-resize-handle.active {
  background: var(--accent);
  opacity: 0.5;
}

.pairs-search {
  padding: 12px;
}

.pairs-search input {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  background: var(--bg-input);
  border-radius: 8px;
}

.pairs-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.pairs-tabs button {
  flex: 1;
  padding: 10px 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-third);
  border-bottom: 2px solid transparent;
}

.pairs-tabs button:hover { color: var(--text-secondary); }
.pairs-tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

.pairs-list {
  flex: 1;
  overflow-y: auto;
}

.pairs-list__header {
  display: grid;
  grid-template-columns: 1.3fr 1fr 64px;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text-third);
  border-bottom: 1px solid var(--border);
}

.pair-row {
  display: grid;
  grid-template-columns: 1.3fr 1fr 64px;
  padding: 9px 12px;
  font-size: 16px;
  cursor: pointer;
  transition: background var(--transition);
  font-family: var(--font-mono);
  align-items: center;
}

.pair-row:hover { background: var(--bg-input); }
.pair-row.active { background: var(--bg-input); }

.pair-row__symbol {
  font-family: var(--font);
  font-weight: 500;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 5px;
}

.pair-row__price { text-align: right; font-size: 15px; }
.pair-row__change { text-align: right; font-size: 14px; }

/* Chart Panel */
.chart-panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow: hidden;
  flex: 1;
}

.chart-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
  -ms-overflow-style: none;
  scrollbar-width: none;
}
.chart-toolbar::-webkit-scrollbar { display: none; }

.chart-toolbar button {
  padding: 4px 10px;
  font-size: 12px;
  color: var(--text-secondary);
  border-radius: var(--radius);
  transition: all var(--transition);
  white-space: nowrap;
}

.chart-toolbar button:hover { color: var(--text-primary); background: var(--bg-input); }
.chart-toolbar button.active { color: var(--accent); background: rgba(240,185,11,0.1); }

/* Drawing tools sidebar */
.chart-tools-sidebar {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 4px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  border-bottom-right-radius: var(--radius);
}

.chart-tools-sidebar button {
  padding: 6px;
  color: var(--text-secondary);
  border-radius: var(--radius);
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-tools-sidebar button:hover { color: var(--text-primary); background: var(--bg-input); }
.chart-tools-sidebar button.active { color: var(--accent); background: rgba(240,185,11,0.1); }

.chart-tools-separator {
  width: 100%;
  height: 1px;
  background: var(--border);
  margin: 2px 0;
}

.chart-container {
  flex: 1;
  position: relative;
  min-height: 0;
}

/* Chart resize handles */
.chart-resize-bottom {
  position: absolute;
  bottom: -3px;
  left: 0;
  right: 0;
  height: 6px;
  cursor: ns-resize;
  z-index: 8;
}
.chart-resize-bottom:hover, .chart-resize-bottom.active { background: rgba(240,185,11,0.3); }

.chart-resize-right {
  position: absolute;
  top: 0;
  right: -3px;
  width: 6px;
  height: 100%;
  cursor: ew-resize;
  z-index: 8;
}
.chart-resize-right:hover, .chart-resize-right.active { background: rgba(240,185,11,0.3); }

/* Orders panel */
.orders-panel {
  flex-shrink: 0;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}

.orders-stub {
  padding: 16px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-third);
  font-size: 13px;
}

.orders-stub a { color: var(--accent); margin: 0 4px; }

.orders-live {
  display: flex;
  flex-direction: column;
  max-height: 200px;
}

.orders-live__tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.orders-live__tabs button {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
}

.orders-live__tabs button.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent);
}

.orders-live__body {
  flex: 1;
  overflow-y: auto;
  font-size: 12px;
}

.orders-live__row {
  display: grid;
  grid-template-columns: 50px 45px 1fr 1fr 1fr 70px;
  padding: 6px 12px;
  font-size: 12px;
  font-family: var(--font-mono);
  border-bottom: 1px solid var(--border);
}

.orders-live__row span:last-child { text-align: right; }

.orders-live__header {
  display: grid;
  grid-template-columns: 50px 45px 1fr 1fr 1fr 70px;
  padding: 6px 12px;
  font-size: 11px;
  color: var(--text-third);
  border-bottom: 1px solid var(--border);
}

.orders-live__header span:last-child { text-align: right; }

/* Order Book + Trades */
.book-trades-panel {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.book-trades-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.book-trades-tabs button {
  flex: 1;
  padding: 8px 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
}

.book-trades-tabs button.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent);
}

/* Order Book */
.orderbook {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.orderbook__header {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  padding: 6px 10px;
  font-size: 11px;
  color: var(--text-third);
  flex-shrink: 0;
  font-weight: 500;
}

.orderbook__header span:nth-child(2) { text-align: right; }
.orderbook__header span:nth-child(3) { text-align: right; }

.orderbook__asks,
.orderbook__bids {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.orderbook__asks { justify-content: flex-end; }

.orderbook__spread {
  padding: 6px 8px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-mono);
  text-align: center;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.ob-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  padding: 0 10px;
  font-size: 12px;
  font-family: var(--font-mono);
  position: relative;
  line-height: 2;
  cursor: pointer;
  transition: background 0.08s;
}

.ob-row:hover { background: var(--bg-input); }

.ob-row span { position: relative; z-index: 1; }
.ob-row span:nth-child(2) { text-align: right; }
.ob-row span:nth-child(3) { text-align: right; color: var(--text-third); font-size: 11px; }

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

.ob-row.ask .ob-row__bg { background: rgba(246,70,93,0.12); }
.ob-row.bid .ob-row__bg { background: rgba(14,203,129,0.12); }
.ob-row.ask span:first-child { color: var(--red); }
.ob-row.bid span:first-child { color: var(--green); }

.ob-row.ob-flash { animation: obFlash 0.3s ease; }
@keyframes obFlash {
  0% { background: rgba(240,185,11,0.15); }
  100% { background: transparent; }
}

.orderbook__spread {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
}

/* Recent Trades */
.recent-trades {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.recent-trades__header {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  padding: 4px 8px;
  font-size: 10px;
  color: var(--text-third);
  flex-shrink: 0;
}

.recent-trades__header span:nth-child(2),
.recent-trades__header span:nth-child(3) { text-align: right; }

.recent-trades__list {
  flex: 1;
  overflow-y: auto;
}

.trade-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  padding: 1px 8px;
  font-size: 11px;
  font-family: var(--font-mono);
  line-height: 1.8;
}

.trade-row span:nth-child(2),
.trade-row span:nth-child(3) { text-align: right; }

.trade-row.buy span:first-child { color: var(--green); }
.trade-row.sell span:first-child { color: var(--red); }

/* Trade Form Panel */
.trade-panel {
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 14px;
}

.trade-form-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.trade-form-tabs button {
  flex: 1;
  padding: 14px 0;
  font-size: 15px;
  font-weight: 700;
  border-radius: 10px;
  letter-spacing: 0.3px;
  transition: all 0.2s ease;
}

.trade-form-tabs .tab-active-buy {
  background: rgba(14,203,129,0.15);
  color: var(--green);
  border: 1.5px solid rgba(14,203,129,0.4);
}
.trade-form-tabs .tab-active-buy:hover {
  background: rgba(14,203,129,0.25);
  border-color: var(--green);
  box-shadow: 0 0 16px rgba(14,203,129,0.2);
}
.trade-form-tabs .tab-active-sell {
  background: rgba(246,70,93,0.15);
  color: var(--red);
  border: 1.5px solid rgba(246,70,93,0.4);
}
.trade-form-tabs .tab-active-sell:hover {
  background: rgba(246,70,93,0.25);
  border-color: var(--red);
  box-shadow: 0 0 16px rgba(246,70,93,0.2);
}
.trade-form-tabs .tab-inactive {
  background: rgba(14,203,129,0.06);
  color: var(--text-third);
  border: 1.5px solid transparent;
}

.trade-type-tabs {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}

.trade-type-tabs button {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-third);
  padding: 4px 0;
}

.trade-type-tabs button.active { color: var(--text-primary); }

.trade-form__balance {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.trade-form__balance span { font-family: var(--font-mono); color: var(--text-primary); }

.trade-form__field {
  margin-bottom: 10px;
}

.trade-form__field label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-third);
  margin-bottom: 4px;
}

.trade-form__input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.trade-form__input-wrap input {
  width: 100%;
  padding-right: 50px;
  text-align: right;
  font-family: var(--font-mono);
}

.trade-form__input-wrap .suffix {
  position: absolute;
  right: 10px;
  font-size: 12px;
  color: var(--text-third);
  pointer-events: none;
}

.trade-form__slider {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.trade-form__slider button {
  flex: 1;
  padding: 4px 0;
  font-size: 11px;
  background: var(--bg-input);
  border-radius: 2px;
  color: var(--text-secondary);
}

.trade-form__slider button:hover { color: var(--text-primary); }
.trade-form__slider button.active { background: var(--accent); color: #181a20; }

.trade-form__total {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.trade-form__total span { font-family: var(--font-mono); color: var(--text-primary); }

.trade-form__submit {
  margin-top: 4px;
  padding: 14px 0;
  font-size: 15px;
  font-weight: 700;
  border-radius: 10px;
  letter-spacing: 0.3px;
  transition: all 0.2s ease;
}
.trade-form__submit.btn-green {
  background: rgba(14,203,129,0.15);
  color: var(--green);
  border: 1.5px solid rgba(14,203,129,0.4);
}
.trade-form__submit.btn-green:hover {
  background: rgba(14,203,129,0.25);
  border-color: var(--green);
  box-shadow: 0 0 18px rgba(14,203,129,0.25);
  opacity: 1;
}
.trade-form__submit.btn-red {
  background: rgba(246,70,93,0.15);
  color: var(--red);
  border: 1.5px solid rgba(246,70,93,0.4);
}
.trade-form__submit.btn-red:hover {
  background: rgba(246,70,93,0.25);
  border-color: var(--red);
  box-shadow: 0 0 18px rgba(246,70,93,0.25);
  opacity: 1;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 24px;
  font-size: 14px;
  color: var(--text-primary);
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
  z-index: 9999;
  display: none;
  animation: slideUp 0.3s ease;
}

.toast.show { display: block; }

@keyframes slideUp {
  from { transform: translateX(-50%) translateY(20px); opacity: 0; }
  to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* ===== MOBILE PAIR SELECTOR MODAL ===== */
.pair-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90%;
  max-width: 380px;
  height: 70vh;
  max-height: 500px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 16px 56px rgba(0,0,0,.6);
  z-index: 2000;
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.pair-modal.open { display: flex; animation: popupSlide 0.2s ease; }
@keyframes popupSlide { from { opacity: 0; transform: translate(-50%, -45%); } to { opacity: 1; transform: translate(-50%, -50%); } }

/* Backdrop */
.pair-modal.open::before {
  content: '';
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: -1;
}

.pair-modal__header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

.pair-modal__search {
  flex: 1;
  padding: 10px 12px;
  font-size: 14px;
  border-radius: 8px;
}

.pair-modal__close {
  padding: 8px;
  color: var(--text-secondary);
}

.pair-modal__list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.pair-modal__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}

.pair-modal__item:active { background: var(--bg-tertiary); }
.pair-modal__item.active { background: var(--bg-tertiary); }

.pair-modal__item-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.pair-modal__item-symbol {
  font-size: 15px;
  font-weight: 600;
}

.pair-modal__item-name {
  font-size: 12px;
  color: var(--text-third);
}

.pair-modal__item-right {
  text-align: right;
}

.pair-modal__item-price {
  font-size: 14px;
  font-family: var(--font-mono);
  font-weight: 500;
}

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

/* Tablet: hide pairs sidebar */
@media (max-width: 1200px) {
  .trading-layout {
    grid-template-columns: 1fr 240px 280px;
  }
}

/* Small tablet: hide trade form */
@media (max-width: 900px) {
  .trading-layout {
    grid-template-columns: 1fr 220px;
  }
  .trade-panel { display: none; }
}

/* ===== MOBILE ===== */
@media (max-width: 768px) {
  /* Header redesign for mobile */
  .spot-header {
    padding: 8px 12px;
    gap: 8px;
    height: auto;
    min-height: 44px;
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .spot-header__pair {
    font-size: 15px;
    flex-shrink: 0;
  }

  .spot-header__price-mobile {
    margin-left: 10px;
  }

  .spot-header__mobile-stats {
    display: flex;
    width: 100%;
    gap: 12px;
    font-size: 11px;
    font-family: var(--font-mono);
    padding-top: 2px;
    padding-bottom: 2px;
    overflow-x: auto;
    white-space: nowrap;
  }

  /* Layout: chart on top, trade form below, scrollable */
  .trading-layout {
    display: flex;
    flex-direction: column;
    height: auto;
    overflow-y: auto;
    padding-bottom: 70px;
  }

  .chart-orders-col {
    flex: none;
    min-height: 0;
  }

  .chart-panel {
    border-right: none;
    flex: none;
    height: 300px;
  }

  .orders-stub { display: none; }

  /* Hide book/trades by default on mobile — shown via bottom tabs */
  .book-trades-panel {
    display: none;
    flex: 1;
    min-height: 300px;
    border-right: none;
  }

  /* Hide pairs panel */
  .pairs-panel { display: none !important; }

  .trade-panel {
    display: block !important;
    padding: 12px;
    flex: none;
    overflow: visible;
    border-top: 1px solid var(--border);
  }
  .trade-panel.mobile-hidden {
    display: none !important;
  }

  /* Bottom tabs — only 3: Trade, Book, Pairs */
  .mobile-trade-tabs { height: 48px; }
  .mobile-trade-tabs button { font-size: 11px; gap: 3px; }
  .mobile-trade-tabs button svg { width: 16px; height: 16px; }

  /* Bigger trade form on mobile */
  .trade-form-tabs button {
    padding: 12px 0;
    font-size: 15px;
  }

  .trade-form__input-wrap input {
    padding: 12px;
    padding-right: 50px;
    font-size: 15px;
  }

  .trade-form__slider button {
    padding: 8px 0;
    font-size: 12px;
  }

  .trade-form__submit {
    padding: 14px 24px;
    font-size: 16px;
  }

  /* Chart toolbar scroll-friendly */
  .chart-toolbar {
    padding: 4px 8px;
    gap: 0;
  }

  .chart-toolbar button {
    padding: 6px 12px;
    font-size: 13px;
  }

  /* Order book bigger tap targets */
  .ob-row {
    line-height: 2.2;
    font-size: 12px;
  }

  .trade-row {
    line-height: 2.2;
    font-size: 12px;
  }

  /* Mobile bottom tabs */
  .mobile-trade-tabs {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border);
    z-index: 100;
    height: 52px;
  }

  .mobile-trade-tabs button {
    flex: 1;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-trade-tabs button.active { color: var(--accent); }
  .mobile-trade-tabs button svg { width: 20px; height: 20px; }

  /* Toast above bottom tabs */
  .toast {
    bottom: 68px;
  }
}

@media (min-width: 769px) {
  .mobile-trade-tabs { display: none; }
  .pair-modal { display: none !important; }
}

/* Safe area for notched phones */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  @media (max-width: 768px) {
    .mobile-trade-tabs {
      padding-bottom: env(safe-area-inset-bottom);
      height: calc(52px + env(safe-area-inset-bottom));
    }

    .trading-layout {
      height: calc(100vh - var(--navbar-h) - 80px - 52px - env(safe-area-inset-bottom));
    }

    .trade-panel {
      padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }
  }
}

/* Landscape mobile */
@media (max-width: 768px) and (orientation: landscape) {
  .spot-header {
    min-height: 36px;
    padding: 4px 12px;
  }

  .spot-header__mobile-stats { display: none; }

  .trading-layout {
    height: calc(100vh - var(--navbar-h) - 36px - 52px);
  }

  .mobile-trade-tabs {
    height: 44px;
  }
}
