/*
  TraderScreener — Momentum Terminal
  Intent: terminal de day trading nocturna, densa, pero cálida y cómoda de
  mirar por horas. Carbón cálido + ámbar/cobre como único acento (mismo color
  que una luz de halt en el piso de bolsa). Verde/rojo solo para dirección de
  precio, nunca decorativo.
*/

:root {
  /* Superficies — carbón cálido, no azul-negro frío */
  --bg-canvas: #15110d;
  --bg-surface-1: #1c1712;
  --bg-surface-2: #241e17;
  --bg-surface-3: #2c2419;
  --bg-control: #110d09;

  /* Bordes — susurran, no gritan */
  --border-subtle: rgba(255, 232, 205, 0.06);
  --border-default: rgba(255, 232, 205, 0.10);
  --border-emphasis: rgba(224, 164, 88, 0.32);
  --border-focus: rgba(224, 164, 88, 0.55);

  /* Texto — blanco hueso, no blanco puro */
  --text-primary: #f3ede2;
  --text-secondary: #b9ae9d;
  --text-tertiary: #8c8172;
  --text-muted: #5c5448;

  /* Acento único: ámbar cobre envejecido */
  --accent: #e0a458;
  --accent-strong: #f0bd7a;
  --accent-dim: rgba(224, 164, 88, 0.13);

  /* Semántico: subida/bajada, atenuados, no neón */
  --up: #4cae8c;
  --up-strong: #74d1af;
  --up-dim: rgba(76, 174, 140, 0.13);
  --down: #e0665a;
  --down-strong: #f28e83;
  --down-dim: rgba(224, 102, 90, 0.13);

  /* Halt — mismo ámbar, ligeramente más saturado (beacon) */
  --halt: #e8a33d;
  --halt-dim: rgba(232, 163, 61, 0.16);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  --font-ui: 'IBM Plex Sans', system-ui, sans-serif;
  --font-data: 'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 14px;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar / ticker tape ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface-1);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  white-space: nowrap;
}
.brand-mark { color: var(--accent); font-size: 18px; }
.brand-name {
  font-family: var(--font-data);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.08em;
}
.brand-tag {
  color: var(--text-tertiary);
  font-size: 11px;
  letter-spacing: 0.04em;
}

.tape {
  flex: 1;
  overflow: hidden;
  border-left: 1px solid var(--border-subtle);
  border-right: 1px solid var(--border-subtle);
  padding: 0 var(--space-4);
  mask-image: linear-gradient(90deg, transparent, black 24px, black calc(100% - 24px), transparent);
}
.tape-track {
  display: flex;
  gap: var(--space-6);
  white-space: nowrap;
  animation: scroll-tape 110s linear infinite;
  width: max-content;
}
.tape:hover .tape-track {
  animation-play-state: paused;
}
@keyframes scroll-tape {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}
.tape-item {
  font-family: var(--font-data);
  font-size: 12.5px;
  display: inline-flex;
  gap: var(--space-2);
  align-items: baseline;
}
.tape-item .label { color: var(--text-tertiary); }
.tape-item .price { color: var(--text-primary); font-weight: 500; }
.tape-item .chg.up { color: var(--up-strong); }
.tape-item .chg.down { color: var(--down-strong); }
.tape-item.muted { color: var(--text-muted); }

.session {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  white-space: nowrap;
}
.session-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-muted);
}
.session-dot.open { background: var(--up-strong); box-shadow: 0 0 6px var(--up); }
.session-dot.closed { background: var(--down-strong); }
.session-label { font-size: 12px; color: var(--text-secondary); }
.session-clock { font-family: var(--font-data); font-size: 12px; color: var(--text-tertiary); }

/* Acceso discreto al panel privado — a propósito casi invisible */
.discreet-link {
  color: var(--bg-surface-3);
  text-decoration: none;
  font-size: 14px;
  padding: 0 4px;
  cursor: default;
}
.discreet-link:hover { color: var(--text-muted); cursor: pointer; }

/* ---------- Grid layout ---------- */

.grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-5);
  padding: var(--space-5);
  align-content: start;
}
.panel.wide { grid-column: span 3 / span 3; }

@media (max-width: 1100px) {
  .grid { grid-template-columns: 1fr; }
  .panel.wide { grid-column: span 1 / span 1; }
}

.panel {
  background: var(--bg-surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border-subtle);
}
.panel-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-primary);
}
.panel-head h2 .subtle {
  text-transform: none;
  font-weight: 400;
  color: var(--text-tertiary);
  letter-spacing: normal;
}
.count {
  font-family: var(--font-data);
  font-size: 11px;
  color: var(--text-tertiary);
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  padding: 1px 8px;
}

.panel-head-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.filter-trigger {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 3px 10px;
  cursor: pointer;
  transition: border-color 120ms ease, color 120ms ease;
}
.filter-trigger:hover {
  color: var(--text-primary);
  border-color: var(--border-emphasis);
}
.filter-trigger.active {
  color: var(--accent-strong);
  border-color: var(--border-emphasis);
  background: var(--accent-dim);
}

/* ---------- Tables ---------- */

.table-wrap {
  overflow-y: auto;
  max-height: 340px;
}
table { width: 100%; border-collapse: collapse; }
thead th {
  position: sticky; top: 0;
  background: var(--bg-surface-1);
  text-align: left;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  padding: var(--space-2) var(--space-2);
  border-bottom: 1px solid var(--border-default);
}
thead th:not(:first-child), tbody td:not(:first-child) { text-align: right; }
tbody td {
  font-family: var(--font-data);
  font-size: 12.5px;
  padding: var(--space-2);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}
tbody tr { cursor: pointer; transition: background 120ms ease; }
tbody tr:hover { background: var(--bg-surface-2); }
tbody td.symbol {
  color: var(--text-primary);
  font-weight: 600;
  text-align: left;
}
.hod-badge {
  display: inline-block;
  margin-left: var(--space-2);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--accent-strong);
  background: var(--accent-dim);
  border: 1px solid var(--border-emphasis);
  border-radius: 4px;
  padding: 1px 4px;
  vertical-align: middle;
}
.up { color: var(--up-strong); }
.down { color: var(--down-strong); }
.halt-reason {
  color: var(--halt);
  background: var(--halt-dim);
  border: 1px solid rgba(232, 163, 61, 0.3);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 11px;
}

.empty {
  display: none;
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
  padding: var(--space-5) 0;
}
.empty.visible { display: block; }

/* ---------- Momentum Leaders (ranking por apariciones) ---------- */

.leaders-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-3);
}
@media (max-width: 900px) {
  .leaders-grid { grid-template-columns: repeat(2, 1fr); }
}

.leader-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: var(--bg-control);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  cursor: pointer;
  transition: border-color 120ms ease;
}
.leader-card:hover { border-color: var(--border-emphasis); }

.leader-rank {
  font-family: var(--font-data);
  font-size: 11px;
  color: var(--text-muted);
  width: 16px;
  flex-shrink: 0;
}

.leader-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }

.leader-top-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
}
.leader-symbol {
  font-family: var(--font-data);
  font-weight: 700;
  font-size: 13px;
  color: var(--text-primary);
}
.leader-badge {
  margin-left: 4px;
  font-size: 11px;
  cursor: help;
}
.leader-count {
  font-family: var(--font-data);
  font-size: 11px;
  color: var(--accent-strong);
  background: var(--accent-dim);
  border-radius: 999px;
  padding: 1px 7px;
  flex-shrink: 0;
}

.leader-bar-track {
  height: 4px;
  border-radius: 999px;
  background: var(--bg-surface-3);
  overflow: hidden;
}
.leader-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
}

/* Pulso ámbar: mismo lenguaje visual para HOD nuevo y halts nuevos */
@keyframes pulse-row {
  0% { background: var(--accent-dim); }
  100% { background: transparent; }
}
tr.pulse { animation: pulse-row 1.6s ease-out; }

/* Símbolo cotizando bajo su VWAP de sesión — atenuado para que el ojo
   priorice lo que sí está sobre VWAP sin tener que leer cada fila. */
tr.below-vwap { opacity: 0.5; }
tr.below-vwap:hover { opacity: 0.85; }

/* ---------- Drawer (Quote Info + Chart) ---------- */

.drawer-overlay {
  position: fixed; inset: 0;
  background: rgba(10, 8, 6, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
  z-index: 20;
}
.drawer-overlay.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(440px, 92vw);
  background: var(--bg-surface-1);
  border-left: 1px solid var(--border-default);
  transform: translateX(100%);
  transition: transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
  z-index: 21;
  display: flex;
  flex-direction: column;
  padding: var(--space-5);
  gap: var(--space-4);
  overflow-y: auto;
}
.drawer.open { transform: translateX(0); }

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}
.drawer-symbol {
  font-family: var(--font-data);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.drawer-price-row {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  margin-top: var(--space-1);
}
.drawer-price { font-family: var(--font-data); font-size: 24px; font-weight: 600; }
.drawer-change { font-family: var(--font-data); font-size: 13px; }
.drawer-close {
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  width: 28px; height: 28px;
  cursor: pointer;
}
.drawer-close:hover { color: var(--text-primary); border-color: var(--border-default); }

.drawer-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-3);
}
.stat {
  background: var(--bg-control);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-label { font-size: 10px; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.03em; }
.stat-value { font-family: var(--font-data); font-size: 13px; color: var(--text-primary); }

.chart-container {
  flex: none;
  height: 260px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.news-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.news-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}
.news-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.news-item {
  display: block;
  background: var(--bg-control);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  text-decoration: none;
  transition: border-color 120ms ease;
}
.news-item:hover { border-color: var(--border-emphasis); }
.news-headline {
  font-size: 12.5px;
  color: var(--text-primary);
  line-height: 1.4;
}
.news-meta {
  margin-top: 4px;
  font-family: var(--font-data);
  font-size: 10.5px;
  color: var(--text-tertiary);
}

.sound-toggle {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 3px 10px;
  cursor: pointer;
  transition: border-color 120ms ease, color 120ms ease;
}
.sound-toggle:hover { color: var(--text-primary); border-color: var(--border-emphasis); }
.sound-toggle.active {
  color: var(--accent-strong);
  border-color: var(--border-emphasis);
  background: var(--accent-dim);
}

/* ---------- Modal (Filtro Momentum Stock) ---------- */

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(10, 8, 6, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
  z-index: 30;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }

.modal {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -48%);
  width: min(480px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg-surface-1);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
  z-index: 31;
}
.modal.open {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
}
.modal-head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}
.modal-head h3 .subtle {
  font-weight: 400;
  color: var(--text-tertiary);
  font-size: 12px;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.field-row label {
  font-size: 12.5px;
  color: var(--text-secondary);
  flex-shrink: 0;
}
.field-pair {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.field-tag {
  font-size: 10.5px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.field-pair input[type="number"] {
  width: 120px;
  background: var(--bg-control);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-data);
  font-size: 12px;
  padding: 6px 6px;
  outline: none;
  transition: border-color 120ms ease;
  -moz-appearance: textfield;
}
/* Ocultar flechas nativas del <input type=number> — le comían ~20px al
   ancho disponible y cortaban números grandes como floats (30000000). */
.field-pair input[type="number"]::-webkit-outer-spin-button,
.field-pair input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.field-pair input[type="number"]:focus {
  border-color: var(--border-focus);
}

.toggle-row label:first-child { flex: 1; }

.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.switch-slider {
  position: absolute;
  inset: 0;
  background: var(--bg-control);
  border: 1px solid var(--border-default);
  border-radius: 999px;
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease;
}
.switch-slider::before {
  content: "";
  position: absolute;
  width: 16px; height: 16px;
  left: 2px; top: 2px;
  background: var(--text-tertiary);
  border-radius: 50%;
  transition: transform 150ms ease, background 150ms ease;
}
.switch input:checked + .switch-slider {
  background: var(--accent-dim);
  border-color: var(--border-emphasis);
}
.switch input:checked + .switch-slider::before {
  transform: translateX(18px);
  background: var(--accent-strong);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px solid var(--border-subtle);
}
.btn {
  font-family: var(--font-ui);
  font-size: 12.5px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: opacity 120ms ease;
}
.btn:hover { opacity: 0.85; }
.btn-danger {
  background: transparent;
  color: var(--down-strong);
  border-color: rgba(224, 102, 90, 0.3);
}
.btn-muted {
  background: var(--bg-surface-2);
  color: var(--text-secondary);
  border-color: var(--border-subtle);
}
.btn-primary {
  background: var(--accent);
  color: var(--bg-canvas);
  font-weight: 600;
}

/* Scrollbars discretos */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-surface-3); border-radius: 8px; }

/* Perfil de candidatas en Momentum Leaders (solo visual) */
.leaders-profile {
  display: inline-flex;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.lp-btn {
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 11px;
  background: var(--bg-surface-2);
  color: var(--text-secondary);
  border: 0;
  border-right: 1px solid var(--border-subtle);
  cursor: pointer;
}
.lp-btn:last-child { border-right: 0; }
.lp-btn:hover { color: var(--text-primary); }
.lp-btn.active {
  background: var(--accent-dim);
  color: var(--accent-strong);
  font-weight: 600;
}
.leaders-profile-info {
  font-family: var(--font-data);
  font-size: 11px;
  color: var(--text-tertiary);
}

@media (max-width: 720px) {
  #panel-leaders .panel-head { flex-wrap: wrap; row-gap: var(--space-2); }
  #panel-leaders .panel-head-actions { flex-wrap: wrap; width: 100%; }
  #panel-leaders .leaders-profile-info { order: 3; flex-basis: 100%; }
}
