/* ==========================================================================
   NEXUS PRIME | Institutional Multi-Asset Algorithmic Trading Terminal
   Modern FinTech High-Density Architecture: CSS Grid, Modern Dialogs, Canvas
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Design Tokens & Quantitative Variables
   -------------------------------------------------------------------------- */
:root {
  /* Surface Layers */
  --term-bg-root: #060910;
  --term-bg-panel: #0b101c;
  --term-bg-subtle: #101728;
  --term-bg-hover: #151e33;
  --term-bg-input: #080c16;

  /* Borders */
  --term-border: rgba(255, 255, 255, 0.07);
  --term-border-hover: rgba(255, 255, 255, 0.15);
  --term-border-cyan: rgba(6, 182, 212, 0.3);

  /* Tactical Chroma */
  --color-emerald: #10b981;
  --color-emerald-glow: rgba(16, 185, 129, 0.2);
  --color-emerald-bg: rgba(16, 185, 129, 0.1);

  --color-rose: #f43f5e;
  --color-rose-glow: rgba(244, 63, 94, 0.2);
  --color-rose-bg: rgba(244, 63, 94, 0.1);

  --color-cyan: #06b6d4;
  --color-cyan-glow: rgba(6, 182, 212, 0.25);

  --color-gold: #f59e0b;
  --color-gold-glow: rgba(245, 158, 11, 0.2);

  /* Typography */
  --font-mono: 'JetBrains Mono', monospace;
  --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;

  --text-white: #f8fafc;
  --text-sub: #cbd5e1;
  --text-muted: #64748b;
  --text-dim: #334155;

  /* Fluid Scales */
  --text-xs: 0.72rem;
  --text-sm: 0.82rem;
  --text-base: 0.95rem;
  --text-lg: 1.15rem;
  --text-xl: 1.4rem;
  --text-2xl: 1.8rem;

  /* Layout Heights */
  --topbar-h: 56px;
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-full: 9999px;
  --transition-fast: 0.15s cubic-bezier(0.16, 1, 0.3, 1);
}

/* --------------------------------------------------------------------------
   2. Reset & High-Density Terminal Core
   -------------------------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  background-color: var(--term-bg-root);
  color: var(--text-white);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

.terminal-body {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

img {
  max-width: 100%;
  display: block;
}

button, input {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  border: none;
  background: none;
  outline: none;
}

button {
  cursor: pointer;
  transition: all var(--transition-fast);
}

button:focus-visible, input:focus-visible {
  outline: 2px solid var(--color-cyan);
  outline-offset: 1px;
}

/* --------------------------------------------------------------------------
   3. Top Institutional Ticker Header
   -------------------------------------------------------------------------- */
.terminal-topbar {
  height: var(--topbar-h);
  background: var(--term-bg-panel);
  border-bottom: 1px solid var(--term-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  flex-shrink: 0;
  z-index: 100;
}

.terminal-logo-crest {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-xs);
  background: rgba(6, 182, 212, 0.1);
  border: 1px solid var(--term-border-cyan);
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-title {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  display: block;
  line-height: 1.1;
}

.brand-sub {
  font-size: 0.62rem;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  display: block;
}

.status-indicator-pill {
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.2);
  border-radius: var(--radius-full);
  padding: 2px 8px;
}

.pulse-emerald {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-emerald);
  box-shadow: 0 0 8px var(--color-emerald);
  animation: pulse-glow 1.5s infinite;
}

@keyframes pulse-glow {
  0% { transform: scale(0.9); opacity: 0.6; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.6; }
}

/* Ticker Marquee Strip */
.ticker-marquee {
  overflow-x: auto;
  white-space: nowrap;
}

.ticker-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 3px 8px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.ticker-item:hover, .ticker-item.active {
  background: var(--term-bg-subtle);
}

.ticker-sym {
  color: var(--text-muted);
}

.trader-thumb {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--term-border-hover);
}

.btn-terminal-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-xs);
  background: var(--term-bg-subtle);
  border: 1px solid var(--term-border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.btn-terminal-icon:hover {
  color: var(--text-white);
  border-color: var(--term-border-hover);
}

/* --------------------------------------------------------------------------
   4. Main 3-Pane Trading Workbench Grid
   -------------------------------------------------------------------------- */
.terminal-workbench {
  flex: 1;
  display: grid;
  grid-template-columns: 240px 1fr 340px;
  min-height: 0;
  overflow: hidden;
}

@media (max-width: 1200px) {
  .terminal-workbench {
    grid-template-columns: 200px 1fr 320px;
  }
}

@media (max-width: 960px) {
  .terminal-workbench {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }
  .workbench-watchlist { display: none; }
}

/* Common Panel Header */
.panel-header {
  padding: 0.65rem 0.85rem;
  background: var(--term-bg-panel);
  border-bottom: 1px solid var(--term-border);
  letter-spacing: 0.05em;
}

.panel-title {
  color: var(--text-sub);
  font-weight: 700;
}

/* --------------------------------------------------------------------------
   5. Column 1: Watchlist & Risk Intelligence
   -------------------------------------------------------------------------- */
.workbench-watchlist {
  background: var(--term-bg-panel);
  border-right: 1px solid var(--term-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.watchlist-items {
  display: flex;
  flex-direction: column;
}

.watchlist-row {
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid var(--term-border);
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.watchlist-row:hover {
  background: var(--term-bg-subtle);
}

.watchlist-row.active {
  background: rgba(6, 182, 212, 0.06);
  border-left: 3px solid var(--color-cyan);
}

.risk-telemetry-box {
  background: var(--term-bg-subtle);
  border-top: 1px solid var(--term-border);
}

.margin-track {
  height: 4px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.margin-fill {
  height: 100%;
  background: var(--color-cyan);
  border-radius: var(--radius-full);
}

/* --------------------------------------------------------------------------
   6. Column 2: Center Stage (Candlestick Chart & Positions)
   -------------------------------------------------------------------------- */
.workbench-center {
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-right: 1px solid var(--term-border);
  background: var(--term-bg-root);
}

.chart-action-bar {
  background: var(--term-bg-panel);
  border-bottom: 1px solid var(--term-border);
  padding: 0.5rem 1rem;
}

.active-symbol-title {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-white);
}

.badge-perpetual {
  font-size: 0.62rem;
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  color: var(--text-muted);
}

.chart-stat-pill {
  padding: 2px 8px;
  border-radius: var(--radius-xs);
  background: rgba(255, 255, 255, 0.02);
}

.tf-btn, .ind-btn {
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: var(--radius-xs);
  color: var(--text-muted);
  border: 1px solid transparent;
}

.tf-btn:hover, .ind-btn:hover {
  color: var(--text-white);
  background: var(--term-bg-subtle);
}

.tf-btn.active, .ind-btn.active {
  background: var(--term-bg-subtle);
  color: var(--color-cyan);
  border-color: var(--term-border-cyan);
  font-weight: 700;
}

/* Chart Canvas Viewport */
.chart-viewport {
  flex: 1;
  position: relative;
  min-height: 280px;
  background: radial-gradient(circle at 50% 50%, rgba(11, 16, 28, 0.8) 0%, var(--term-bg-root) 100%);
}

#candleCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.chart-hover-inspect {
  position: absolute;
  top: 10px;
  left: 12px;
  background: rgba(6, 9, 16, 0.85);
  backdrop-filter: blur(8px);
  padding: 4px 10px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--term-border);
  color: var(--text-muted);
  pointer-events: none;
}

/* Bottom Positions Dock */
.workbench-bottom-dock {
  height: 200px;
  background: var(--term-bg-panel);
  border-top: 1px solid var(--term-border);
  display: flex;
  flex-direction: column;
}

.dock-header {
  padding: 0.45rem 1rem;
  border-bottom: 1px solid var(--term-border);
}

.dock-tab-btn {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  padding: 2px 4px;
  position: relative;
}

.dock-tab-btn.active {
  color: var(--text-white);
}

.dock-tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 0;
  width: 100%;
  height: 2px;
  background: var(--color-cyan);
}

.dock-table-container {
  flex: 1;
  overflow-y: auto;
}

.terminal-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.terminal-table th {
  padding: 0.45rem 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
  border-bottom: 1px solid var(--term-border);
  background: var(--term-bg-subtle);
  position: sticky;
  top: 0;
}

.terminal-table td {
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--term-border);
}

.btn-close-pos {
  background: rgba(244, 63, 94, 0.12);
  border: 1px solid rgba(244, 63, 94, 0.3);
  color: var(--color-rose);
  padding: 2px 8px;
  border-radius: var(--radius-xs);
}

.btn-close-pos:hover {
  background: var(--color-rose);
  color: #fff;
}

/* --------------------------------------------------------------------------
   7. Column 3: Order Book DOM & Execution Ticket
   -------------------------------------------------------------------------- */
.workbench-execution {
  background: var(--term-bg-panel);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

/* Order Book DOM */
.orderbook-panel {
  border-bottom: 1px solid var(--term-border);
}

.orderbook-table-wrap {
  padding: 0.5rem 0.75rem;
  display: flex;
  flex-direction: column;
}

.ob-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  padding: 2px 4px;
  position: relative;
  font-size: 0.72rem;
}

.ob-row span {
  position: relative;
  z-index: 2;
}

.ob-row .size, .ob-row .total {
  text-align: right;
  color: var(--text-sub);
}

.depth-bar {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  z-index: 1;
  opacity: 0.18;
}

.ask-bar { background: var(--color-rose); }
.bid-bar { background: var(--color-emerald); }

.border-y {
  border-top: 1px solid var(--term-border);
  border-bottom: 1px solid var(--term-border);
}

/* Execution Ticket Form */
.execution-ticket-panel {
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
}

.order-side-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}

.side-btn {
  padding: 0.55rem;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 700;
  border-radius: var(--radius-xs);
  border: 1px solid var(--term-border);
  color: var(--text-muted);
}

.btn-buy.active {
  background: var(--color-emerald);
  color: #000;
  border-color: var(--color-emerald);
  box-shadow: 0 0 12px var(--color-emerald-glow);
}

.btn-sell.active {
  background: var(--color-rose);
  color: #fff;
  border-color: var(--color-rose);
  box-shadow: 0 0 12px var(--color-rose-glow);
}

.type-btn {
  font-size: 0.68rem;
  padding: 2px 8px;
  border-radius: var(--radius-xs);
  background: var(--term-bg-subtle);
  color: var(--text-muted);
}

.type-btn.active {
  color: var(--text-white);
  border: 1px solid var(--term-border-hover);
}

.input-with-addon {
  display: flex;
  align-items: center;
  background: var(--term-bg-input);
  border: 1px solid var(--term-border);
  border-radius: var(--radius-xs);
  padding: 0.4rem 0.65rem;
}

.input-with-addon:focus-within {
  border-color: var(--color-cyan);
}

.ticket-input {
  flex: 1;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-white);
}

.leverage-range {
  width: 100%;
  accent-color: var(--color-cyan);
}

.btn-execute {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: all var(--transition-fast);
}

.btn-execute-buy {
  background: var(--color-emerald);
  color: #000;
}

.btn-execute-buy:hover {
  background: #34d399;
  box-shadow: 0 4px 16px var(--color-emerald-glow);
}

.btn-execute-sell {
  background: var(--color-rose);
  color: #fff;
}

.btn-execute-sell:hover {
  background: #fb7185;
  box-shadow: 0 4px 16px var(--color-rose-glow);
}

/* --------------------------------------------------------------------------
   8. Top-Layer Dialogs (Modern Web Standard)
   -------------------------------------------------------------------------- */
dialog.terminal-modal {
  border: none;
  background: transparent;
  color: var(--text-white);
  max-width: 100vw;
  max-height: 100vh;
  margin: auto;
  padding: 0;
  transition: opacity 0.25s ease, transform 0.25s ease, overlay 0.25s ease allow-discrete, display 0.25s ease allow-discrete;
  opacity: 0;
  transform: scale(0.96);
}

dialog.terminal-modal[open] {
  opacity: 1;
  transform: scale(1);
}

@starting-style {
  dialog.terminal-modal[open] {
    opacity: 0;
    transform: scale(0.96);
  }
}

dialog.terminal-modal::backdrop {
  background: rgba(3, 5, 10, 0.8);
  backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 0.25s ease, overlay 0.25s ease allow-discrete, display 0.25s ease allow-discrete;
}

dialog.terminal-modal[open]::backdrop {
  opacity: 1;
}

@starting-style {
  dialog.terminal-modal[open]::backdrop {
    opacity: 0;
  }
}

.modal-inner {
  background: var(--term-bg-panel);
  border: 1px solid var(--term-border-cyan);
  border-radius: var(--radius-sm);
  padding: 1.75rem;
  width: 100%;
  max-width: 440px;
  position: relative;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  font-size: 1.4rem;
  color: var(--text-muted);
}

.modal-close:hover {
  color: var(--text-white);
}

.vault-thumb {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  margin: 0 auto;
  border: 1px solid var(--term-border);
}

/* --------------------------------------------------------------------------
   9. Buttons & Utilities
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  border-radius: var(--radius-xs);
  font-size: var(--text-xs);
  font-weight: 700;
}

.btn-cyan {
  background: var(--color-cyan);
  color: #000;
}

.btn-cyan:hover {
  background: #22d3ee;
  box-shadow: 0 0 14px var(--color-cyan-glow);
}

.btn-outline {
  border: 1px solid var(--term-border);
  color: var(--text-sub);
}

.btn-outline:hover {
  background: var(--term-bg-subtle);
  color: var(--text-white);
}

.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-align { display: flex; align-items: center; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.gap-6 { gap: 1.5rem; }

.text-white { color: var(--text-white); }
.text-muted { color: var(--text-muted); }
.text-emerald { color: var(--color-emerald); }
.text-rose { color: var(--color-rose); }
.text-cyan { color: var(--color-cyan); }
.text-gold { color: var(--color-gold); }

.font-mono { font-family: var(--font-mono); }
.font-bold { font-weight: 700; }

.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }

.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.mt-auto { margin-top: auto; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.p-2 { padding: 0.5rem; }
.p-3 { padding: 0.75rem; }
.py-1 { padding-top: 0.25rem; padding-bottom: 0.25rem; }
.py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.px-2 { padding-left: 0.5rem; padding-right: 0.5rem; }
.my-1 { margin-top: 0.25rem; margin-bottom: 0.25rem; }
.border { border: 1px solid var(--term-border); }
.border-b { border-bottom: 1px solid var(--term-border); }
.rounded { border-radius: var(--radius-xs); }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.full-width { width: 100%; }
.block { display: block; }
.inline { display: inline-block; }
.ml-1 { margin-left: 0.25rem; }

.icon-xs { width: 13px; height: 13px; }
.icon-sm { width: 16px; height: 16px; }

@media (max-width: 768px) {
  .hide-mobile { display: none !important; }
}

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