/* =====================================================================
   NovaTrade — Design tokens & core theme
   Palette: near-black trading terminal, violet brand accent, teal/coral
   for up/down (functionally meaningful, not decorative).
   Type: Space Grotesk (display) + Inter (body) + JetBrains Mono (data)
   ===================================================================== */

:root {
  --bg-primary: #0a0d13;
  --bg-surface: #12161f;
  --bg-surface-2: #191f2c;
  --bg-surface-3: #212838;
  --border-subtle: #232a3a;
  --border-strong: #333c52;
  --text-primary: #e9ebf1;
  --text-secondary: #8b92a8;
  --text-muted: #5b6478;

  --brand: #7b61ff;
  --brand-dim: #5b45d6;
  --brand-glow: rgba(123, 97, 255, 0.35);

  --up: #00d3a7;
  --up-dim: rgba(0, 211, 167, 0.14);
  --down: #ff4d6a;
  --down-dim: rgba(255, 77, 106, 0.14);
  --warn: #ffb454;

  --font-display: 'Space Grotesk', 'Inter', sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'SFMono-Regular', Menlo, monospace;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 15px;
  min-height: 100%;
}

h1, h2, h3, h4, h5, .font-display {
  font-family: var(--font-display);
  letter-spacing: -0.01em;
}

.mono, .price, .balance-figure, .ticker-item, table td.num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

a { color: var(--brand); text-decoration: none; }
a:hover { color: #9c87ff; }

::selection { background: var(--brand-glow); }

/* Focus visibility (accessibility floor) */
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

/* ---------------------------------------------------------------------
   Layout shell
   --------------------------------------------------------------------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 76px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 0;
  gap: 6px;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}

.sidebar .brand-mark {
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--brand), var(--brand-dim));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-family: var(--font-display); font-weight: 700; font-size: 18px;
  margin-bottom: 18px;
}

.sidebar .nav-icon {
  width: 46px; height: 46px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary);
  transition: background 0.15s, color 0.15s;
  position: relative;
}
.sidebar .nav-icon:hover { background: var(--bg-surface-2); color: var(--text-primary); }
.sidebar .nav-icon.active { background: var(--bg-surface-2); color: var(--brand); }
.sidebar .nav-icon.active::before {
  content: ''; position: absolute; left: -20px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 20px; background: var(--brand); border-radius: 3px;
}
.sidebar .nav-icon .badge-dot {
  position: absolute; top: 6px; right: 6px; width: 8px; height: 8px;
  background: var(--down); border-radius: 50%; border: 2px solid var(--bg-surface);
}

.main-area { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* The page content area between the topbar and the footer. This has to
   be an explicit flex column (not just a Bootstrap flex-grow-1 item) or
   .trade-workspace below it has no real height to fill, and the
   TradingView chart ends up sized ambiguously. */
.page-main { display: flex; flex-direction: column; flex: 1; min-height: 0; }

.topbar {
  height: 60px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  background: var(--bg-primary);
  position: sticky; top: 0; z-index: 20;
}

.wallet-toggle {
  display: flex; background: var(--bg-surface); border-radius: 999px; padding: 3px; gap: 2px;
  border: 1px solid var(--border-subtle);
}
.wallet-toggle button {
  border: none; background: transparent; color: var(--text-secondary);
  padding: 7px 16px; border-radius: 999px; font-size: 13px; font-weight: 600;
  font-family: var(--font-display);
  transition: background 0.15s, color 0.15s;
}
.wallet-toggle button.active.demo { background: var(--bg-surface-3); color: var(--warn); }
.wallet-toggle button.active.live { background: var(--up-dim); color: var(--up); }

.balance-figure { font-size: 15px; font-weight: 600; }

/* ---------------------------------------------------------------------
   Signature element: live ticker tape
   --------------------------------------------------------------------- */
.ticker-tape {
  overflow: hidden;
  white-space: nowrap;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  padding: 9px 0;
  position: relative;
}
.ticker-tape::before, .ticker-tape::after {
  content: ''; position: absolute; top: 0; bottom: 0; width: 60px; z-index: 2; pointer-events: none;
}
.ticker-tape::before { left: 0; background: linear-gradient(90deg, var(--bg-surface), transparent); }
.ticker-tape::after { right: 0; background: linear-gradient(270deg, var(--bg-surface), transparent); }

.ticker-track {
  display: inline-flex;
  animation: ticker-scroll 32s linear infinite;
}
.ticker-tape:hover .ticker-track { animation-play-state: paused; }

@keyframes ticker-scroll {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

.ticker-item {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 0 22px; font-size: 13px; border-right: 1px solid var(--border-subtle);
}
.ticker-item .sym { color: var(--text-secondary); font-weight: 600; }
.ticker-item .chg.up { color: var(--up); }
.ticker-item .chg.down { color: var(--down); }

/* ---------------------------------------------------------------------
   Trading workspace
   --------------------------------------------------------------------- */
.trade-workspace { display: flex; flex: 1; min-height: 0; }

.chart-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chart-header {
  display: flex; align-items: center; gap: 16px; padding: 12px 18px;
  border-bottom: 1px solid var(--border-subtle);
  position: relative;
}
.asset-picker-btn {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-surface); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md); padding: 8px 14px; color: var(--text-primary);
}
.asset-picker-btn .payout-chip {
  background: var(--up-dim); color: var(--up); font-size: 12px; font-weight: 700;
  padding: 2px 9px; border-radius: 999px; font-family: var(--font-mono);
}
.chart-canvas-wrap { flex: 1; min-height: 340px; position: relative; }
.chart-canvas-wrap canvas { display: block; width: 100%; height: 100%; }

/* Asset picker: a small dropdown on desktop, a full-height slide-in
   sheet on mobile/tablet — see the media query at the bottom of this
   file. Same markup and JS (trade-sheets.js) drive both. */
.asset-sheet {
  display: none;
  position: absolute; top: calc(100% + 8px); left: 18px;
  width: 300px; max-height: 420px; overflow-y: auto;
  background: var(--bg-surface-2); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md); z-index: 45; padding: 10px;
  box-shadow: var(--shadow-card);
}
.asset-sheet.open { display: block; }
.asset-sheet-header {
  display: none; align-items: center; justify-content: space-between;
  padding: 4px 4px 12px; font-family: var(--font-display); font-weight: 700;
  border-bottom: 1px solid var(--border-subtle); margin-bottom: 10px;
}
.asset-sheet .sheet-close {
  background: none; border: none; color: var(--text-secondary); font-size: 22px; line-height: 1;
}
.asset-group-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted);
  font-weight: 700; padding: 10px 8px 6px;
}
.asset-option {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 10px; border-radius: var(--radius-sm); color: var(--text-primary);
}
.asset-option:hover { background: var(--bg-surface-3); color: var(--text-primary); }
.asset-option.active { background: rgba(123,97,255,0.14); }
.asset-option .opt-payout { color: var(--up); font-family: var(--font-mono); font-size: 12.5px; font-weight: 700; }

.sheet-backdrop {
  display: none;
  position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 63;
}
.sheet-backdrop.open { display: block; }

.trade-panel {
  width: 340px; flex-shrink: 0;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-subtle);
  padding: 20px;
  display: flex; flex-direction: column; gap: 18px;
  overflow-y: auto;
}

.trade-panel label.field-label {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); font-weight: 600; margin-bottom: 8px; display: block;
}

.amount-input-wrap {
  display: flex; align-items: center; background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle); border-radius: var(--radius-md); overflow: hidden;
}
.amount-input-wrap span { padding: 0 12px; color: var(--text-secondary); font-family: var(--font-mono); }
.amount-input-wrap input {
  flex: 1; background: transparent; border: none; color: var(--text-primary);
  padding: 12px 12px 12px 0; font-family: var(--font-mono); font-size: 16px; font-weight: 600;
}
.amount-input-wrap input:focus { outline: none; }
.amount-quick { display: flex; gap: 6px; margin-top: 8px; }
.amount-quick button {
  flex: 1; background: var(--bg-surface-2); border: 1px solid var(--border-subtle);
  color: var(--text-secondary); border-radius: var(--radius-sm); padding: 6px 0; font-size: 12px;
}
.amount-quick button:hover { border-color: var(--brand); color: var(--text-primary); }

.duration-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.duration-grid button {
  background: var(--bg-surface-2); border: 1px solid var(--border-subtle);
  color: var(--text-secondary); border-radius: var(--radius-sm); padding: 10px 0; font-size: 13px; font-weight: 600;
}
.duration-grid button.active { border-color: var(--brand); color: var(--text-primary); background: rgba(123,97,255,0.12); }

.payout-preview {
  background: var(--bg-surface-2); border-radius: var(--radius-md); padding: 12px 14px;
  display: flex; justify-content: space-between; align-items: baseline;
  border: 1px solid var(--border-subtle);
}
.payout-preview .amt { font-family: var(--font-mono); font-size: 18px; font-weight: 700; color: var(--up); }

.btn-direction {
  display: block; width: 100%; border: none; border-radius: var(--radius-md);
  padding: 15px 0; font-family: var(--font-display); font-weight: 700; font-size: 16px;
  color: #071a15; letter-spacing: 0.01em; transition: transform 0.08s, box-shadow 0.15s;
}
.btn-direction:active { transform: scale(0.98); }
.btn-up { background: var(--up); box-shadow: 0 6px 20px rgba(0,211,167,0.25); }
.btn-up:hover { box-shadow: 0 8px 26px rgba(0,211,167,0.4); }
.btn-down { background: var(--down); color: #290812; box-shadow: 0 6px 20px rgba(255,77,106,0.25); }
.btn-down:hover { box-shadow: 0 8px 26px rgba(255,77,106,0.4); }

/* ---------------------------------------------------------------------
   Cards, tables, badges (shared across user + admin)
   --------------------------------------------------------------------- */
.card-surface {
  background: var(--bg-surface); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-card);
  overflow-x: auto; /* wide tables (e.g. admin trade settlement) scroll
                        horizontally on narrow screens instead of
                        squeezing every column unreadably thin */
}

.table-nova {
  width: 100%; border-collapse: collapse; font-size: 13.5px;
}
@media (max-width: 767px) {
  .table-nova { min-width: 640px; }
}
.table-nova th {
  text-align: left; color: var(--text-muted); font-weight: 600; text-transform: uppercase;
  font-size: 11px; letter-spacing: 0.05em; padding: 10px 14px; border-bottom: 1px solid var(--border-subtle);
}
.table-nova td { padding: 12px 14px; border-bottom: 1px solid var(--border-subtle); vertical-align: middle; }
.table-nova tbody tr:hover { background: var(--bg-surface-2); }

.badge-status {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
}
.badge-won { background: var(--up-dim); color: var(--up); }
.badge-lost { background: var(--down-dim); color: var(--down); }
.badge-active { background: rgba(123,97,255,0.14); color: var(--brand); }
.badge-pending { background: rgba(255,180,84,0.14); color: var(--warn); }

.btn-nova {
  font-family: var(--font-display); font-weight: 600; border-radius: var(--radius-sm);
  padding: 9px 18px; border: 1px solid transparent; font-size: 13.5px;
}
.btn-nova-primary { background: var(--brand); color: #fff; }
.btn-nova-primary:hover { background: var(--brand-dim); color: #fff; }
.btn-nova-outline { background: transparent; border-color: var(--border-strong); color: var(--text-primary); }
.btn-nova-outline:hover { border-color: var(--brand); color: var(--brand); }
.btn-nova-win { background: var(--up); color: #071a15; }
.btn-nova-lose { background: var(--down); color: #290812; }

.form-control-nova {
  background: var(--bg-surface-2); border: 1px solid var(--border-subtle); color: var(--text-primary);
  border-radius: var(--radius-sm); padding: 10px 12px; width: 100%;
}
.form-control-nova:focus { outline: none; border-color: var(--brand); background: var(--bg-surface-3); }

.stat-card {
  background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg);
  padding: 18px 20px;
}
.stat-card .stat-label { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-card .stat-value { font-family: var(--font-display); font-size: 26px; font-weight: 700; margin-top: 6px; }

/* ---------------------------------------------------------------------
   Auth pages
   --------------------------------------------------------------------- */
.auth-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 20% 20%, rgba(123,97,255,0.12), transparent 45%), var(--bg-primary);
  padding: 24px;
}
.auth-card { width: 100%; max-width: 400px; padding: 34px 32px; }
.auth-card .brand-row { display: flex; align-items: center; gap: 10px; margin-bottom: 26px; }

/* Countdown ring on active trade cards */
.trade-mini {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px; background: var(--bg-surface-2); border-radius: var(--radius-sm); margin-bottom: 8px;
  border: 1px solid var(--border-subtle);
}
.trade-mini .countdown { font-family: var(--font-mono); font-size: 12.5px; color: var(--warn); }

.flash-alert {
  border-radius: var(--radius-md); padding: 12px 16px; margin-bottom: 16px; font-size: 14px;
  border: 1px solid transparent;
}
.flash-success { background: var(--up-dim); color: var(--up); border-color: rgba(0,211,167,0.3); }
.flash-error { background: var(--down-dim); color: var(--down); border-color: rgba(255,77,106,0.3); }

/* ---------------------------------------------------------------------
   Mobile bottom tab bar — replaces the sidebar entirely on small
   screens. Deliberately plain links + a native <details>/<summary> for
   the overflow sheet, so it needs zero JavaScript to open, close, or
   navigate. Nothing here can be "broken" by a script failing to load.
   --------------------------------------------------------------------- */
.bottom-nav {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -4px 24px rgba(0,0,0,0.35);
}
.bottom-nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; padding: 6px 2px; color: var(--text-secondary); font-size: 10.5px; font-weight: 600;
  border-radius: var(--radius-sm); position: relative; list-style: none; cursor: pointer;
  /* Reset so <button>/<summary>-based items look identical to the <a>-based
     ones — without this, buttons keep the browser's default chrome
     (background, border, system font) and visibly don't match. */
  background: none; border: none; margin: 0; text-decoration: none;
  font-family: var(--font-body); -webkit-appearance: none; appearance: none;
}
.bottom-nav-item::-webkit-details-marker { display: none; }
.bottom-nav-item i { font-size: 21px; line-height: 1; }
.bottom-nav-item.active { color: var(--brand); }
.bottom-nav-item .badge-dot {
  position: absolute; top: 2px; right: 26%; width: 7px; height: 7px;
  background: var(--down); border-radius: 50%; border: 2px solid var(--bg-surface);
}

.bottom-nav-more[open] > summary { color: var(--brand); }
.bottom-sheet {
  position: fixed; left: 10px; right: 10px; bottom: 78px; z-index: 71;
  background: var(--bg-surface-2); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg); padding: 8px;
  box-shadow: 0 -10px 34px rgba(0,0,0,0.5);
}
.bottom-sheet a {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border-radius: var(--radius-sm); color: var(--text-primary); font-size: 14.5px; font-weight: 500;
}
.bottom-sheet a:active, .bottom-sheet a:hover { background: var(--bg-surface-3); }
.bottom-sheet a i { width: 20px; text-align: center; color: var(--text-secondary); font-size: 17px; }
.bottom-sheet .sheet-divider { height: 1px; background: var(--border-subtle); margin: 6px 4px; }

@media (max-width: 991px) {
  /* Chart takes the full-width "page" on mobile; the trading form and
     asset list move into full-height slide-in sheets (opened from this
     page's own bottom nav — Chart / Assets / Trade / History) instead
     of competing for vertical space with the chart. Active Trades stays
     in normal scroll flow directly under the chart — no sheet needed
     to see what's currently running. */
  .page-main { display: block; padding-bottom: 78px; }
  .trade-workspace { flex-direction: column; flex: none; }
  .chart-pane { flex: none; }
  .chart-canvas-wrap { flex: none; height: 320px; min-height: 320px; }

  .asset-sheet {
    position: fixed; top: 0; left: 0; bottom: 0; height: 100vh; width: 300px;
    max-height: none;
    transform: translateX(-100%); transition: transform 0.25s ease;
    border-radius: 0; z-index: 65; display: block;
  }
  .asset-sheet.open { transform: translateX(0); }
  .asset-sheet-header { display: flex; }

  .trade-panel {
    position: fixed; top: 0; right: 0; bottom: 0; height: 100vh; width: 320px;
    transform: translateX(100%); transition: transform 0.25s ease; z-index: 65;
    border-left: 1px solid var(--border-subtle);
  }
  .trade-panel.open { transform: translateX(0); }

  /* Sidebar is replaced by the site-wide bottom tab bar on every page
     except this one, which shows its own Chart/Assets/Trade/History bar. */
  .sidebar { display: none; }
  .bottom-nav { display: flex; }
}

@media (max-width: 480px) {
  .chart-canvas-wrap { height: 260px; min-height: 260px; }
  .trade-panel { width: 280px; }
  .asset-sheet { width: 260px; }
}

/* Tablet: keep the sidebar and inline trade panel (there's room), but
   still switch to the fixed chart height and stacked chart/trade-panel
   only below 991px per above — between 992-1199px nothing changes here,
   the desktop layout already fits comfortably. */
@media (min-width: 992px) and (max-width: 1199px) {
  .trade-panel { width: 300px; }
}
