/* ============================================
   Trading Arena — Global Styles
   Dark trading terminal aesthetic
   ============================================ */

:root {
  --bg: #0d0f14;
  --bg2: #13161e;
  --bg3: #1a1e28;
  --border: #252935;
  --text: #e8eaf0;
  --text2: #8b92a8;
  --text3: #555d72;
  --green: #00d084;
  --green-dim: rgba(0, 208, 132, 0.12);
  --red: #ff4d6a;
  --red-dim: rgba(255, 77, 106, 0.12);
  --blue: #4f8ef7;
  --blue-dim: rgba(79, 142, 247, 0.12);
  --gold: #f5a623;
  --gold-dim: rgba(245, 166, 35, 0.12);
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* ---- LOGIN PAGE ---- */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 0%, #1a2040 0%, var(--bg) 70%);
}

.login-container {
  width: 100%;
  max-width: 400px;
  padding: 24px;
}

.login-logo {
  text-align: center;
  margin-bottom: 40px;
}
.logo-icon { font-size: 48px; display: block; margin-bottom: 12px; }
.login-logo h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.5px; }
.login-logo p { color: var(--text2); margin-top: 4px; }

.login-form {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
}

/* ---- FORMS ---- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; color: var(--text2); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
.form-group input, .form-group select {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s;
  font-family: var(--font);
}
.form-group input:focus, .form-group select:focus { border-color: var(--blue); }
.form-group select option { background: var(--bg3); }

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  padding: 10px 18px;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  font-family: var(--font);
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { opacity: 0.9; }
.btn-success { background: var(--green); color: #000; }
.btn-success:hover { opacity: 0.9; }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { opacity: 0.9; }
.btn-ghost { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { border-color: var(--text3); }
.btn-full { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ---- ERRORS / ALERTS ---- */
.error-msg { color: var(--red); font-size: 13px; padding: 8px 12px; background: var(--red-dim); border-radius: var(--radius); margin-bottom: 12px; }
.success-msg { color: var(--green); font-size: 13px; padding: 8px 12px; background: var(--green-dim); border-radius: var(--radius); margin-bottom: 12px; }
.hidden { display: none !important; }

/* ---- LAYOUT ---- */
.app-layout { display: flex; flex-direction: column; min-height: 100vh; }

/* ---- NAVBAR ---- */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.nav-brand span { font-size: 20px; }
.nav-right { display: flex; align-items: center; gap: 16px; }
.nav-user { color: var(--text2); font-size: 13px; }
.nav-user strong { color: var(--text); }

/* ---- PRICE TICKER ---- */
.price-ticker {
  display: flex;
  gap: 24px;
  align-items: center;
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
  padding: 8px 24px;
  overflow-x: auto;
}
.ticker-item { display: flex; flex-direction: column; align-items: center; min-width: 80px; }
.ticker-symbol { font-size: 10px; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: 1px; }
.ticker-price { font-size: 15px; font-weight: 600; font-family: var(--mono); color: var(--text); }
.ticker-price.up { color: var(--green); }
.ticker-price.down { color: var(--red); }

/* ---- MAIN CONTENT ---- */
.main-content { flex: 1; padding: 24px; max-width: 1400px; margin: 0 auto; width: 100%; }

/* ---- CARDS ---- */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
}
.card-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text2); margin-bottom: 16px; }

/* ---- STATS ROW ---- */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 16px 20px; }
.stat-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text2); margin-bottom: 6px; }
.stat-value { font-size: 24px; font-weight: 700; font-family: var(--mono); }
.stat-value.green { color: var(--green); }
.stat-value.red { color: var(--red); }
.stat-value.blue { color: var(--blue); }

/* ---- TRADE FORM ---- */
.trade-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.direction-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.direction-btn { padding: 14px; font-size: 16px; font-weight: 700; border: 2px solid transparent; border-radius: var(--radius); cursor: pointer; background: var(--bg3); color: var(--text2); transition: all 0.15s; }
.direction-btn.long.active { background: var(--green-dim); border-color: var(--green); color: var(--green); }
.direction-btn.short.active { background: var(--red-dim); border-color: var(--red); color: var(--red); }
.direction-btn:hover { border-color: var(--border); }
.current-price-display { font-family: var(--mono); font-size: 20px; font-weight: 700; color: var(--blue); text-align: center; padding: 12px; background: var(--blue-dim); border-radius: var(--radius); margin-bottom: 16px; }

/* ---- TABLES ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th { text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text2); padding: 10px 12px; border-bottom: 1px solid var(--border); }
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border); color: var(--text); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--bg3); }
.mono { font-family: var(--mono); }
.pnl-pos { color: var(--green); font-weight: 600; font-family: var(--mono); }
.pnl-neg { color: var(--red); font-weight: 600; font-family: var(--mono); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.badge-long { background: var(--green-dim); color: var(--green); }
.badge-short { background: var(--red-dim); color: var(--red); }
.badge-open { background: var(--blue-dim); color: var(--blue); }
.badge-closed { background: var(--bg3); color: var(--text2); }
.badge-stopped { background: var(--red-dim); color: var(--red); }
.badge-tp { background: var(--gold-dim); color: var(--gold); }

/* ---- LEADERBOARD ---- */
.leaderboard-table .rank-1 td { background: rgba(245, 166, 35, 0.05); }
.rank-badge { font-size: 16px; }

/* ---- TABS ---- */
.tabs { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.tab-btn { padding: 10px 16px; background: none; border: none; color: var(--text2); font-size: 14px; font-weight: 500; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; transition: all 0.15s; font-family: var(--font); }
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--blue); border-bottom-color: var(--blue); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ---- MODAL ---- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.7); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal { background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 28px; width: 100%; max-width: 440px; }
.modal-title { font-size: 16px; font-weight: 700; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ---- EMPTY STATE ---- */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text2); }
.empty-state p { font-size: 15px; }
.empty-state span { font-size: 40px; display: block; margin-bottom: 12px; }

/* ---- LIVE DOT ---- */
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); display: inline-block; animation: pulse 2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* ---- RESPONSIVE ---- */
@media (max-width: 640px) {
  .main-content { padding: 16px; }
  .trade-form-grid { grid-template-columns: 1fr; }
  .stats-row { grid-template-columns: 1fr 1fr; }
}

/* ============================================
   TRADER FULL-SCREEN CHART LAYOUT
   ============================================ */

body.trader-view {
  overflow: hidden;
  height: 100vh;
}

body.trader-view .app-layout {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Stats Strip */
.stats-strip {
  display: flex;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.strip-stat {
  flex: 1;
  padding: 8px 16px;
  border-right: 1px solid var(--border);
}
.strip-stat:last-child { border-right: none; }
.strip-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text2);
  margin-bottom: 2px;
}
.strip-value {
  font-size: 15px;
  font-weight: 700;
  font-family: var(--mono);
  color: var(--text);
}
.strip-value.green { color: var(--green); }
.strip-value.red   { color: var(--red); }
.strip-value.blue  { color: var(--blue); }

/* Main Trading Layout */
.trading-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Chart Area */
.chart-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-right: 1px solid var(--border);
}

.chart-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sym-tabs, .tf-tabs { display: flex; gap: 3px; }

.sym-tab, .tf-tab {
  padding: 3px 10px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text2);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.12s;
  white-space: nowrap;
}
.sym-tab:hover, .tf-tab:hover { color: var(--text); border-color: var(--text3); }
.sym-tab.active { background: var(--blue-dim); border-color: var(--blue); color: var(--blue); }
.tf-tab.active  { background: rgba(255,255,255,0.06); border-color: var(--text3); color: var(--text); }

.tf-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

.chart-cur-price {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
}

#chart {
  flex: 1;
  min-height: 350px;
  position: relative;
}

/* Order Sidebar */
.order-sidebar {
  width: 264px;
  min-width: 264px;
  display: flex;
  flex-direction: column;
  background: var(--bg2);
  overflow-y: auto;
}
.order-section {
  padding: 14px;
  flex: 1;
}
.order-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text2);
  margin-bottom: 10px;
}
.order-sym-display {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 10px;
}
.order-sym-display span:first-child {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}
.order-sym-price {
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 600;
  color: var(--blue);
}

.lbl-opt {
  color: var(--text3);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  font-size: 11px;
}

.point-value-hint {
  text-align: center;
  font-size: 11px;
  color: var(--text3);
  margin-top: 8px;
  font-family: var(--mono);
}

/* Positions Panel */
.positions-panel {
  flex-shrink: 0;
  height: 220px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.pos-tabs {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding: 0 12px;
  background: var(--bg2);
  flex-shrink: 0;
}
.pos-tab {
  padding: 7px 14px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--font);
  margin-bottom: -1px;
  transition: all 0.12s;
}
.pos-tab:hover { color: var(--text); }
.pos-tab.active { color: var(--blue); border-bottom-color: var(--blue); }
.pos-tab-refresh {
  margin-left: auto;
  font-size: 14px;
  padding: 3px 8px;
}

.pos-content { display: none; flex: 1; overflow-y: auto; }
.pos-content.active { display: block; }

.empty-state-sm {
  text-align: center;
  padding: 20px;
  color: var(--text2);
  font-size: 13px;
}
.empty-state-sm span { font-size: 22px; display: block; margin-bottom: 6px; }

/* Chart drag handle (mobile resize) */
.chart-drag-handle {
  display: none;
  text-align: center;
  padding: 4px 0;
  cursor: row-resize;
  color: var(--text3);
  font-size: 14px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  user-select: none;
  flex-shrink: 0;
}

/* ============================================
   MOBILE — must be at end to override desktop
   ============================================ */
@media (max-width: 768px) {
  /* Unlock the fixed viewport so everything scrolls */
  body.trader-view { overflow: auto !important; height: auto !important; }
  body.trader-view .app-layout { height: auto !important; overflow: visible !important; }
  body.trader-view .trading-layout { overflow: visible !important; min-height: 0 !important; }

  /* Navbar */
  .navbar { padding: 0 12px; }
  .nav-user { display: none; }
  .nav-right { gap: 8px; }
  .nav-brand { font-size: 14px; }

  /* Price ticker */
  .price-ticker { gap: 0; padding: 6px 0; }
  .ticker-item { min-width: 25vw; padding: 0 8px; border-right: 1px solid var(--border); }
  .ticker-item:last-child { border-right: none; }
  .ticker-price { font-size: 13px; }

  /* Stats strip */
  .stats-strip { overflow-x: auto; }
  .strip-stat { min-width: 80px; padding: 6px 10px; }
  .strip-label { font-size: 9px; }
  .strip-value { font-size: 13px; }

  /* Stack chart above order form */
  .trading-layout { flex-direction: column !important; flex: none !important; }

  /* Chart */
  .chart-area { border-right: none; border-bottom: 1px solid var(--border); height: 220px !important; flex: none !important; }
  #chart { min-height: 0 !important; height: 220px !important; }
  .chart-toolbar { overflow-x: auto; gap: 6px; padding: 6px 8px; }
  .chart-cur-price { font-size: 14px; }

  /* Order form full width */
  .order-sidebar { width: 100% !important; min-width: 0 !important; overflow-y: visible !important; height: auto !important; }
  .order-section { padding: 12px; }
  .direction-btn { padding: 16px; font-size: 15px; }

  /* Positions panel */
  .positions-panel { height: auto !important; max-height: 280px; overflow: hidden; }
  .pos-content.active { display: block; overflow-y: auto; max-height: 220px; }

  /* Show drag handle on mobile */
  .chart-drag-handle { display: block; }

  /* Fix balance/stats overflow */
  .strip-stat { overflow: hidden; }
  .strip-value { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* Admin */
  .tabs { overflow-x: auto; flex-wrap: nowrap; }
  .tab-btn { white-space: nowrap; padding: 10px 12px; font-size: 13px; }
  .card { padding: 14px; }
  .modal { max-width: calc(100vw - 32px); padding: 20px; }
}
