:root {
  --bg-root: #0b0f19;
  --bg-surface: #131826;
  --bg-panel: #181f30;
  --bg-elevated: #1f293d;
  --border: #263147;
  --border-light: #33415c;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --green: #00d084;
  --green-hover: #00e693;
  --green-dim: rgba(0, 208, 132, 0.14);
  --red: #ff4757;
  --red-hover: #ff5e6c;
  --red-dim: rgba(255, 71, 87, 0.14);
  --blue: #3b82f6;
  --amber: #f59e0b;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  background: var(--bg-root);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; border: none; outline: none; }
input, select, textarea {
  font-family: inherit;
  background: var(--bg-root);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--blue); outline: none; }

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-amber { color: var(--amber); }
.text-muted { color: var(--text-secondary); }
.hidden { display: none !important; }

/* Topbar */
.topbar {
  height: 58px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 40;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 0.04em;
  color: var(--text-primary);
  cursor: pointer;
  flex-shrink: 0;
}
.brand-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--green-dim);
  color: var(--green);
  border: 1px solid rgba(0, 208, 132, 0.35);
}
.nav-links { display: flex; align-items: center; gap: 4px; }
.nav-btn {
  background: transparent;
  color: var(--text-secondary);
  padding: 7px 11px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 13px;
  transition: all 0.15s;
  white-space: nowrap;
}
.nav-btn:hover, .nav-btn.active { color: var(--text-primary); background: var(--bg-elevated); }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.account-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.account-pill .mode-tag {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--green-dim);
  color: var(--green);
}
.account-pill .bal-val { font-weight: 700; font-size: 13.5px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13px;
  transition: all 0.15s;
}
.btn-primary { background: var(--green); color: #051b11; }
.btn-primary:hover { background: var(--green-hover); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: var(--red-hover); }
.btn-secondary { background: var(--bg-elevated); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--border-light); }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Containers & Cards */
.container { max-width: 1220px; margin: 0 auto; padding: 26px 16px; }
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card-title { font-size: 16px; font-weight: 700; margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.stat-label { font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.stat-value { font-size: 22px; font-weight: 700; }

/* Page Prose & Sections */
.page-header { margin-bottom: 22px; }
.page-header h1 { font-size: 28px; font-weight: 800; margin-bottom: 8px; letter-spacing: -0.01em; }
.page-header p { color: var(--text-secondary); font-size: 15px; max-width: 760px; }
.section-stack { display: flex; flex-direction: column; gap: 18px; }
.prose-list { list-style: none; display: flex; flex-direction: column; gap: 8px; color: var(--text-secondary); }
.prose-list li::before { content: "✓ "; color: var(--green); font-weight: 700; }

/* Tables */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-secondary); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
tr:hover td { background: rgba(255, 255, 255, 0.02); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.badge-green { background: var(--green-dim); color: var(--green); }
.badge-red { background: var(--red-dim); color: var(--red); }
.badge-amber { background: rgba(245, 158, 11, 0.16); color: #fbbf24; }
.badge-blue { background: rgba(59, 130, 246, 0.16); color: #60a5fa; }

/* Desktop Trading Terminal Layout */
.terminal-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 310px;
  grid-template-rows: 1fr;
  height: calc(100vh - 58px);
  min-height: 600px;
  background: var(--bg-root);
}
.terminal-sidebar {
  grid-column: 1;
  grid-row: 1;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.terminal-chart-area {
  grid-column: 2;
  grid-row: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--bg-root);
  overflow: hidden;
}
.chart-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}
.chart-canvas-wrap {
  flex: 1;
  position: relative;
  min-height: 280px;
}
#tradingCanvas { width: 100%; height: 100%; display: block; cursor: crosshair; }

.terminal-panel {
  grid-column: 3;
  grid-row: 1;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  overflow-y: auto;
}

.asset-list { flex: 1; overflow-y: auto; padding: 6px; }
.asset-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  margin-bottom: 4px;
}
.asset-item:hover { background: var(--bg-panel); }
.asset-item.active { background: var(--bg-elevated); border-color: var(--blue); }

.trade-btn-up {
  background: var(--green);
  color: #041d11;
  font-weight: 800;
  font-size: 15px;
  padding: 14px;
  border-radius: var(--radius-sm);
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.trade-btn-up:hover { background: var(--green-hover); }
.trade-btn-down {
  background: var(--red);
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  padding: 14px;
  border-radius: var(--radius-sm);
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.trade-btn-down:hover { background: var(--red-hover); }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 5px 9px;
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
}
.chip.active, .chip:hover { background: var(--bg-elevated); color: var(--text-primary); border-color: var(--blue); }

/* Hero & Footer */
.hero {
  padding: 64px 16px 48px;
  text-align: center;
  background: radial-gradient(circle at top center, rgba(0, 208, 132, 0.14), transparent 62%);
}
.hero h1 { font-size: 42px; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 14px; line-height: 1.15; }
.hero p { max-width: 700px; margin: 0 auto 24px; color: var(--text-secondary); font-size: 16px; }

.footer {
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  padding: 36px 16px 28px;
  margin-top: 52px;
}
.footer-grid { max-width: 1220px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 24px; }
.footer h4 { font-size: 13px; margin-bottom: 10px; color: var(--text-primary); }
.footer a { display: block; color: var(--text-secondary); font-size: 12.5px; margin-bottom: 7px; cursor: pointer; }
.footer-bottom {
  max-width: 1220px; margin: 22px auto 0; padding-top: 16px;
  border-top: 1px solid var(--border); display: flex; justify-content: space-between;
  flex-wrap: wrap; gap: 8px; font-size: 12px; color: var(--text-muted);
}

/* Modals & Toasts */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 15, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}
.modal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  width: 100%;
  max-width: 440px;
  padding: 22px;
  box-shadow: var(--shadow);
  max-height: 90vh;
  overflow-y: auto;
}
.toast-container {
  position: fixed;
  bottom: 72px;
  right: 16px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-left: 4px solid var(--blue);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  box-shadow: var(--shadow);
  min-width: 240px;
  max-width: 340px;
}
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }

/* Mobile Bottom Nav */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 58px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  z-index: 50;
  justify-content: space-around;
  align-items: center;
  padding: 0 4px;
}




@media screen and (max-width: 900px) {
  html, body {
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .topbar {
    height: auto;
    min-height: 52px;
    padding: 8px 12px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .brand { font-size: 16px; }
  .nav-links {
    order: 3;
    width: 100%;
    display: flex;
    overflow-x: auto;
    gap: 4px;
    padding-top: 4px;
    border-top: 1px solid var(--border);
    scrollbar-width: none;
  }
  .nav-links::-webkit-scrollbar { display: none; }
  .nav-btn { padding: 6px 10px; font-size: 12.5px; }
  .account-pill { padding: 4px 8px; }
  .account-pill .bal-val { font-size: 13px; }

  .grid-2, .grid-3, .grid-4, .footer-grid { grid-template-columns: 1fr; }
  .container { padding: 16px 12px; }
  .hero { padding: 36px 12px 28px; }
  .hero h1 { font-size: 26px; }

  /* Quotex-style Mobile Trading Terminal: Full Chart + Thumb-Ready Side-by-Side UP/DOWN */
  .terminal-shell {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: auto;
  }
  .terminal-chart-area {
    order: 1;
    width: 100%;
    height: 310px;
  }
  .chart-toolbar {
    padding: 6px 10px;
    gap: 6px;
  }
  .chart-toolbar .chip-row {
    overflow-x: auto;
    flex-wrap: nowrap;
    max-width: 100%;
  }
  .terminal-panel {
    order: 2;
    border-left: none;
    border-top: 1px solid var(--border);
    padding: 12px;
    gap: 10px;
    overflow: visible;
  }
  /* Make UP & DOWN buttons side-by-side right in the thumb zone */
  .terminal-panel > div:has(#tradeUpBtn) {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  .trade-btn-up, .trade-btn-down {
    padding: 15px 12px;
    font-size: 15px;
    justify-content: center;
    gap: 8px;
  }
  .terminal-sidebar {
    order: 3;
    max-height: 280px;
    border-right: none;
    border-top: 1px solid var(--border);
  }
}
