/* ============================================================================
   MARDIN TRADE — PORTAL DESIGN SYSTEM (UNIFIED WITH ARENA PRO)
   ============================================================================ */

html body #page-trade {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: radial-gradient(120% 80% at 50% 0%, #101d2c 0%, #090a0f 55%, #07080c 100%) !important;
  color: #f8fafc;
  font-family: var(--font-sans, "Inter", system-ui, -apple-system, sans-serif);
  overflow: hidden;
  display: none;
}
body.page-trade .cosmic-starfield {
  display: none !important;
}
html body #page-trade.active {
  display: block !important;
}

html body #page-trade .tr-scroll-container {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  box-sizing: border-box;
}

html body #page-trade .tr-scroll-inner {
  position: relative;
  min-height: 100%;
  padding: calc(18px + env(safe-area-inset-top, 0px)) 16px calc(228px + env(safe-area-inset-bottom, 0px)) !important;
  box-sizing: border-box;
}

/* Scrolling Starfield (anchored to .tr-scroll-inner so every star scrolls 1:1 with page content) */
html body #page-trade .tr-scroll-stars {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}
html body #page-trade .tr-star {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
}
html body #page-trade .tr-scroll-inner > *:not(.tr-scroll-stars) {
  position: relative;
  z-index: 2;
}

/* 1. Top-Center Online Indicator */
html body #page-trade .tr-top-online {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 4px 0 12px;
}
html body #page-trade .tr-presence {
  height: 28px;
  padding: 0 14px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 800;
  color: #f1f5f9;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.09);
}
html body #page-trade .tr-presence i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 10px #22c55e;
}

/* 2. Sub-Header Row: (!) Info on Left + Wallet Balance on Right */
html body #page-trade .tr-subbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 14px;
  gap: 12px;
}
html body #page-trade .tr-info-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #252836 0%, #171923 100%);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #f8fafc;
  font-size: 17px;
  font-weight: 900;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  cursor: pointer;
  transition: transform 0.14s ease;
}
html body #page-trade .tr-info-btn:active {
  transform: scale(0.92);
}
html body #page-trade .tr-wallet {
  height: 40px;
  padding: 0 16px 0 10px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(135deg, #1b2234 0%, #111522 100%);
  border: 1px solid rgba(56, 189, 248, 0.35);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}
html body #page-trade .tr-not-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
}
html body #page-trade .tr-wallet strong {
  font-size: 15px;
  font-weight: 900;
  color: #ffffff;
  font-variant-numeric: tabular-nums;
}

/* 3. Graphical Cyberpunk Trade Banner */
html body #page-trade .tr-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  width: 100%;
  height: 60px;
  margin: 0 0 12px;
  padding: 0 14px 0 20px;
  border-radius: 22px;
  background: radial-gradient(90% 160% at 65% 50%, rgba(16, 185, 129, 0.25) 0%, transparent 65%), linear-gradient(95deg, #071921 0%, #0b2938 48%, #0e3b4e 100%);
  border: 1px solid rgba(56, 189, 248, 0.38);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55), 0 0 24px rgba(16, 185, 129, 0.16), inset 0 1px 0 rgba(255, 255, 255, 0.15);
  overflow: hidden;
  cursor: pointer;
}
html body #page-trade .tr-banner strong {
  font-size: 19px;
  font-weight: 900;
  color: #ffffff;
  letter-spacing: 0.02em;
  z-index: 2;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
}
html body #page-trade .tr-skyline {
  position: absolute;
  left: 26%;
  right: 24%;
  bottom: 0;
  top: 4px;
  opacity: 0.92;
  display: flex;
  align-items: flex-end;
  pointer-events: none;
}
html body #page-trade .tr-skyline svg {
  width: 100%;
  height: 92%;
  filter: drop-shadow(0 0 8px rgba(16, 185, 129, 0.65));
}
html body #page-trade .tr-banner-pill {
  position: relative;
  z-index: 2;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  color: #ffffff;
  background: linear-gradient(90deg, #10b981 0%, #06b6d4 100%);
  border: 1px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 0 18px rgba(16, 185, 129, 0.5);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}
html body #page-trade .tr-banner-pill.crashed {
  background: linear-gradient(90deg, #e11d48 0%, #f43f5e 100%);
  box-shadow: 0 0 18px rgba(244, 63, 94, 0.55);
}

/* 4. History Multiplier Pills */
html body #page-trade .tr-history-strip {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  padding: 2px 0 12px;
  scrollbar-width: none;
}
html body #page-trade .tr-history-strip::-webkit-scrollbar {
  display: none;
}
html body #page-trade .tr-hist-pill {
  flex: 0 0 auto;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #cbd5e1;
  cursor: pointer;
}
html body #page-trade .tr-hist-pill.high {
  background: rgba(16, 185, 129, 0.16);
  border-color: rgba(16, 185, 129, 0.42);
  color: #4ade80;
}
html body #page-trade .tr-hist-pill.moon {
  background: rgba(250, 204, 21, 0.18);
  border-color: rgba(250, 204, 21, 0.5);
  color: #fde047;
}
html body #page-trade .tr-hist-pill.low {
  background: rgba(244, 63, 94, 0.14);
  border-color: rgba(244, 63, 94, 0.35);
  color: #fb7185;
}

/* 5. Main Trade Chart Card */
html body #page-trade .tr-chart-card {
  padding: 12px 12px 14px;
  border-radius: 26px;
  background: linear-gradient(180deg, #161822 0%, #0f1017 100%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
html body #page-trade .tr-chart-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 6px 10px;
}
html body #page-trade .tr-mult-wrap {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
html body #page-trade .tr-mult-val {
  font-size: 28px;
  font-weight: 900;
  color: #4ade80;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 18px rgba(74, 222, 128, 0.35);
  line-height: 1;
}
html body #page-trade .tr-mult-val.down {
  color: #fb7185;
  text-shadow: 0 0 18px rgba(251, 113, 133, 0.35);
}
html body #page-trade .tr-mult-val.waiting {
  color: #38bdf8;
  text-shadow: 0 0 18px rgba(56, 189, 248, 0.35);
}
html body #page-trade .tr-pnl-badge {
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: rgba(255, 255, 255, 0.07);
  color: #e2e8f0;
}
html body #page-trade .tr-pnl-badge.pos {
  background: rgba(34, 197, 94, 0.2);
  color: #4ade80;
}
html body #page-trade .tr-pnl-badge.neg {
  background: rgba(244, 63, 94, 0.2);
  color: #fb7185;
}
html body #page-trade .tr-phase-pill {
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  background: rgba(34, 197, 94, 0.14);
  border: 1px solid rgba(34, 197, 94, 0.35);
  color: #4ade80;
  font-variant-numeric: tabular-nums;
}
html body #page-trade .tr-phase-pill.waiting {
  background: rgba(56, 189, 248, 0.14);
  border-color: rgba(56, 189, 248, 0.35);
  color: #38bdf8;
}
html body #page-trade .tr-phase-pill.crashed {
  background: rgba(244, 63, 94, 0.18);
  border-color: rgba(244, 63, 94, 0.45);
  color: #fb7185;
}

html body #page-trade .tr-canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 11;
  border-radius: 18px;
  overflow: hidden;
  background: #0b0d14;
  border: 1px solid rgba(255, 255, 255, 0.07);
}
html body #page-trade #tr-canvas {
  width: 100%;
  height: 100%;
  display: block;
}
html body #page-trade .tr-position-bar {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 8px;
  margin-top: 10px;
}
html body #page-trade .tr-pos-stat {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 14px;
  padding: 9px 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
}
html body #page-trade .tr-pos-stat span {
  font-size: 10.5px;
  font-weight: 700;
  color: #94a3b8;
}
html body #page-trade .tr-pos-stat strong {
  font-size: 15px;
  font-weight: 900;
  color: #f8fafc;
  font-variant-numeric: tabular-nums;
}
html body #page-trade .tr-pos-stat.tr-pos-pnl strong {
  font-size: 20px;
  font-weight: 900;
  letter-spacing: -0.01em;
}
html body #page-trade .tr-pos-stat.tr-pos-pnl strong.pos {
  color: #4ade80;
  text-shadow: 0 0 14px rgba(74, 222, 128, 0.35);
}
html body #page-trade .tr-pos-stat.tr-pos-pnl strong.neg {
  color: #fb7185;
  text-shadow: 0 0 14px rgba(251, 113, 133, 0.35);
}

/* 6. Live Traders List */
html body #page-trade .tr-traders-section {
  margin-top: 22px;
}
html body #page-trade .tr-traders-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 4px 10px;
}
html body #page-trade .tr-traders-heading h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
  color: #f1f5f9;
}
html body #page-trade .tr-traders-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}
html body #page-trade .tr-trader-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
}
html body #page-trade .tr-trader-card.me {
  border-color: rgba(56, 189, 248, 0.45);
  background: rgba(56, 189, 248, 0.08);
}
html body #page-trade .tr-trader-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
html body #page-trade .tr-trader-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0ea5e9 0%, #10b981 100%);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 900;
  color: #fff;
  flex-shrink: 0;
}
html body #page-trade .tr-trader-name {
  font-size: 13.5px;
  font-weight: 800;
  color: #f8fafc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
html body #page-trade .tr-trader-stake {
  font-size: 11.5px;
  font-weight: 700;
  color: #94a3b8;
  font-variant-numeric: tabular-nums;
}
html body #page-trade .tr-trader-right {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
html body #page-trade .tr-trader-val {
  font-size: 13.5px;
  font-weight: 900;
  color: #f8fafc;
}
html body #page-trade .tr-trader-pnl {
  font-size: 11.5px;
  font-weight: 800;
}
html body #page-trade .tr-trader-pnl.pos { color: #4ade80; }
html body #page-trade .tr-trader-pnl.neg { color: #fb7185; }

html body #page-trade .tr-message {
  text-align: center;
  font-size: 12.5px;
  font-weight: 700;
  color: #94a3b8;
  min-height: 18px;
  margin: 10px 0 0;
}

/* 7. Bottom Fixed Portal Controls */
html body #page-trade .tr-controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, rgba(11, 13, 20, 0.92) 0%, #090a0f 100%);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-radius: 26px 26px 0 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
html body #page-trade .tr-entry-row {
  display: grid;
  grid-template-columns: 40px repeat(5, 1fr);
  gap: 5px;
}
html body #page-trade .tr-edit {
  display: grid;
  place-items: center;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(180deg, #252836 0%, #171923 100%);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #f8fafc;
  font-size: 15px;
  cursor: pointer;
}
html body #page-trade button.tr-quick {
  height: 38px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: #f8fafc;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.15s ease, background 0.15s ease;
}
html body #page-trade button.tr-quick.selected {
  background: rgba(56, 189, 248, 0.22);
  border-color: #38bdf8;
  color: #ffffff;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.35);
}
html body #page-trade button.tr-quick:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
html body #page-trade .tr-action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
html body #page-trade .tr-btn-buy {
  height: 46px;
  border-radius: 15px;
  border: 1px solid rgba(74, 222, 128, 0.45);
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #ffffff;
  font-size: 14px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(16, 185, 129, 0.35);
}
html body #page-trade .tr-btn-sell {
  height: 46px;
  border-radius: 15px;
  border: 1px solid rgba(250, 204, 21, 0.55);
  background: linear-gradient(135deg, #f59e0b 0%, #ea580c 100%);
  color: #ffffff;
  font-size: 14px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(245, 158, 11, 0.38);
}
html body #page-trade .tr-btn-buy:disabled,
html body #page-trade .tr-btn-sell:disabled {
  opacity: 0.38;
  box-shadow: none;
  cursor: not-allowed;
}
html body #page-trade .tr-portal-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: 18px;
  background: rgba(10, 11, 16, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
html body #page-trade .tr-portal-back-btn {
  width: 100%;
  height: 40px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(180deg, rgba(16, 185, 129, 0.22) 0%, rgba(6, 182, 212, 0.12) 100%);
  border: 1px solid rgba(56, 189, 248, 0.38);
  color: #e0f2fe;
  font-size: 13.5px;
  font-weight: 800;
  cursor: pointer;
}

/* 8. Bottom Sheet Modal */
html body #page-trade .tr-sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
html body #page-trade .tr-sheet-overlay[hidden] {
  display: none !important;
}
html body #page-trade .tr-sheet {
  width: 100%;
  max-width: 480px;
  background: #141620;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 26px 26px 0 0;
  padding: 16px 20px calc(24px + env(safe-area-inset-bottom, 0px));
  position: relative;
  color: #f8fafc;
}
html body #page-trade .tr-sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.22);
  margin: 0 auto 12px;
}
html body #page-trade .tr-sheet-close {
  position: absolute;
  top: 14px;
  right: 16px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}
html body #page-trade .tr-sheet h2 {
  margin: 0 0 10px;
  font-size: 18px;
  font-weight: 900;
}
html body #page-trade .tr-sheet p {
  margin: 0 0 10px;
  font-size: 13px;
  line-height: 1.55;
  color: #cbd5e1;
}
html body #page-trade .tr-sheet input {
  width: 100%;
  box-sizing: border-box;
  height: 44px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: #0b0d14;
  color: #fff;
  padding: 0 12px;
  font-size: 16px;
  font-weight: 800;
  margin: 8px 0 12px;
}
html body #page-trade .tr-sheet code {
  display: block;
  word-break: break-all;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.4);
  font-size: 11px;
  color: #38bdf8;
  margin-bottom: 10px;
}
html body #page-trade .tr-primary {
  width: 100%;
  height: 46px;
  border-radius: 14px;
  border: 0;
  background: linear-gradient(135deg, #10b981 0%, #0ea5e9 100%);
  color: #fff;
  font-size: 14px;
  font-weight: 900;
  cursor: pointer;
}
