/* Dashboard de paper trading.
   Los colores vienen de la paleta validada: azul serie 1 para el capital,
   rojo/verde de estado sólo para signo de resultado, siempre acompañados de
   texto o icono para que el color nunca cargue el significado solo. */

*, *::before, *::after { box-sizing: border-box; }

.viz-root {
  color-scheme: light;
  --surface-1:      #fcfcfb;
  --page:           #f9f9f7;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;

  --series-1:       #2a78d6;

  /* Ganancia/pérdida usan los slots CATEGÓRICOS verde y rojo, no los colores
     de estado: esos están reservados para el estado del sistema (detenido,
     error) y no deben impersonar un dato.

     El par verde↔rojo es la convención financiera, pero para deuteranopia su
     separación queda en la banda 6–8, que sólo es admisible con un segundo
     canal de significado. Acá hay tres: la barra va por encima o por debajo
     del cero, el número lleva signo explícito y el tooltip dice "Ganadora" o
     "Perdedora". El color nunca decide solo. */
  --gain:           #008300;
  --gain-text:      #006300;   /* paso más oscuro: contraste de TEXTO */
  --loss:           #e34948;
  --loss-text:      #c0322f;

  /* Estado del sistema, no de los datos. */
  --status-good:    #0ca30c;
  --status-critical:#d03b3b;
  --warning:        #fab219;

  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .viz-root {
    color-scheme: dark;
    --surface-1:      #1a1a19;
    --page:           #0d0d0d;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --baseline:       #383835;
    --series-1:       #3987e5;
    --gain:           #008300;
    --gain-text:      #4bb34b;
    --loss:           #e66767;
    --loss-text:      #e66767;
    --status-critical:#d03b3b;
  }
}
:root[data-theme="dark"] .viz-root {
  color-scheme: dark;
  --surface-1:      #1a1a19;
  --page:           #0d0d0d;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --gridline:       #2c2c2a;
  --baseline:       #383835;
  --series-1:       #3987e5;
  --gain:           #008300;
  --gain-text:      #4bb34b;
  --loss:           #e66767;
  --loss-text:      #e66767;
  --status-critical:#d03b3b;
}

html, body { margin: 0; padding: 0; }

body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* El fondo se declara acá con el mismo valor que --page para que el área
     fuera del contenedor no quede blanca en modo oscuro. Las variables viven
     en .viz-root y `body` no puede leerlas. */
  background: #f9f9f7;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) body { background: #0d0d0d; }
}
:root[data-theme="dark"] body { background: #0d0d0d; }

.viz-root {
  background: var(--page);
  /* Sin esto el texto hereda el color por defecto del navegador (negro) y en
     modo oscuro queda ilegible sobre el fondo oscuro: sólo se verían bien los
     elementos que declaran su propio color. */
  color: var(--text-primary);
  min-height: 100vh;
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

/* ---------------------------------------------------------------- cabecera */
.topbar {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 18px;
}
.topbar h1 { margin: 0; font-size: 1.5rem; letter-spacing: -0.02em; }
.sub, .muted { color: var(--text-secondary); margin: 4px 0 0; font-size: 0.875rem; }
.muted { color: var(--text-muted); }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.badge {
  font-size: 0.75rem; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--baseline); color: var(--text-secondary);
  white-space: nowrap;
}
.badge.live   { border-color: var(--status-good);     color: var(--status-good); }
.badge.halted { border-color: var(--status-critical); color: var(--status-critical); }

.bot-select {
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--baseline); border-radius: 8px;
  padding: 6px 10px; font-size: 0.82rem; font-family: inherit; cursor: pointer;
  max-width: 240px;
}
.bot-select:hover { border-color: var(--text-secondary); }

/* Visible para lectores de pantalla, oculto visualmente. */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.ghost-btn {
  background: transparent; border: 1px solid var(--baseline); color: var(--text-secondary);
  border-radius: 8px; width: 34px; height: 34px; cursor: pointer; font-size: 1rem;
}
.ghost-btn:hover { border-color: var(--text-secondary); }

.notice {
  background: var(--surface-1); border: 1px solid var(--gridline);
  border-left: 3px solid var(--warning);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 20px;
  font-size: 0.85rem; color: var(--text-secondary); line-height: 1.5;
}
.notice strong { color: var(--text-primary); }

/* ------------------------------------------------------------------ tarjetas */
.card {
  background: var(--surface-1); border: 1px solid var(--gridline);
  border-radius: var(--radius); padding: 18px; margin-bottom: 18px;
}
.card-head { margin-bottom: 14px; }
.card h2 { margin: 0; font-size: 1rem; font-weight: 600; letter-spacing: -0.01em; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }

/* --------------------------------------------------------------------- KPIs */
.tiles {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px; margin-bottom: 18px;
}
.tile {
  background: var(--surface-1); border: 1px solid var(--gridline);
  border-radius: var(--radius); padding: 14px 16px;
}
.tile .label {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); margin-bottom: 6px;
}
.tile .value {
  font-size: 1.6rem; font-weight: 600; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums; line-height: 1.1;
}
.tile .hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }
/* El signo también va en el texto, para que el color no sea el único canal. */
.pos { color: var(--gain-text); }
.neg { color: var(--loss-text); }

/* ------------------------------------------------------------------ gráficos */
.chart { margin: 0; width: 100%; overflow-x: auto; }
.chart svg { display: block; width: 100%; height: auto; }
.grid line   { stroke: var(--gridline); stroke-width: 1; }
.axis line, .axis path { stroke: var(--baseline); stroke-width: 1; }
.axis text   { fill: var(--text-muted); font-size: 11px; }
.series-line { fill: none; stroke: var(--series-1); stroke-width: 2;
               stroke-linejoin: round; stroke-linecap: round; }
.series-area { fill: var(--series-1); opacity: 0.10; }
.baseline-ref { stroke: var(--baseline); stroke-width: 1; stroke-dasharray: 3 3; }
.hover-line  { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; }
.marker      { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }

/* ------------------------------------------------------------------- tablas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--gridline); }
th { color: var(--text-muted); font-weight: 500; font-size: 0.75rem;
     text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: color-mix(in srgb, var(--text-primary) 4%, transparent); }

.pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 0.72rem; border: 1px solid var(--baseline); color: var(--text-secondary);
}
.pill.long  { border-color: var(--series-1); color: var(--series-1); }
.pill.short { border-color: var(--loss-text); color: var(--loss-text); }

/* -------------------------------------------------------------- vacío / pie */
.empty { text-align: left; }
.empty h2 { font-size: 1.05rem; margin-bottom: 10px; }
.empty p { color: var(--text-secondary); font-size: 0.9rem; line-height: 1.6; margin: 0 0 10px; }
.empty-facts {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px; margin: 18px 0 0; padding-top: 16px; border-top: 1px solid var(--gridline);
}
.empty-facts div { margin: 0; }
.empty-facts dt {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); margin-bottom: 4px;
}
.empty-facts dd { margin: 0; font-size: 0.95rem; font-weight: 600;
                  font-variant-numeric: tabular-nums; }

.foot {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 26px; font-size: 0.78rem; color: var(--text-muted);
}
.foot a { color: var(--text-secondary); }

.hidden { display: none !important; }

.tooltip {
  position: fixed; pointer-events: none; opacity: 0;
  background: var(--surface-1); border: 1px solid var(--baseline);
  border-radius: 8px; padding: 8px 10px; font-size: 0.78rem;
  color: var(--text-primary); box-shadow: 0 4px 14px rgba(0,0,0,.14);
  transition: opacity .1s; z-index: 20; max-width: 240px;
  font-variant-numeric: tabular-nums;
}
.tooltip.on { opacity: 1; }
.tooltip .t-row { display: flex; justify-content: space-between; gap: 14px; }
.tooltip .t-head { color: var(--text-muted); font-size: 0.72rem; margin-bottom: 4px; }

/* ------------------------------------------------------- modal de operación */
.modal {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.55); padding: 20px;
}
.modal-box {
  background: var(--surface-1); border: 1px solid var(--gridline);
  border-radius: var(--radius); width: min(980px, 100%);
  max-height: 92vh; overflow-y: auto; padding: 18px;
  box-shadow: 0 18px 50px rgba(0,0,0,.32);
}
.modal-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 14px;
}
.modal-head h2 { margin: 0; font-size: 1.05rem; }

tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:focus-visible { outline: 2px solid var(--series-1); outline-offset: -2px; }

/* Velas: el color distingue dirección, pero el cuerpo alcista/bajista también
   se lee por la posición de apertura y cierre, así que no depende del color. */
.candle-up   { fill: var(--gain);   stroke: var(--gain); }
.candle-down { fill: var(--loss);   stroke: var(--loss); }
.wick        { stroke-width: 1; }

/* Zonas de riesgo y objetivo: sólo se pintan mientras la posición está abierta. */
.zone-risk   { fill: var(--loss); opacity: 0.13; }
.zone-target { fill: var(--gain); opacity: 0.13; }
.level-stop   { stroke: var(--loss); stroke-width: 1.5; stroke-dasharray: 5 3; }
.level-target { stroke: var(--gain); stroke-width: 1.5; stroke-dasharray: 5 3; }
.level-entry  { stroke: var(--series-1); stroke-width: 1.5; }
.level-label  { font-size: 10px; fill: var(--text-secondary); }
.marker-entry { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }
.marker-exit  { stroke: var(--surface-1); stroke-width: 2; }

.legend {
  display: flex; flex-wrap: wrap; gap: 14px; margin: 12px 0 4px;
  font-size: 0.78rem; color: var(--text-secondary);
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

.detail {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px 18px; margin: 16px 0 0; padding-top: 14px;
  border-top: 1px solid var(--gridline);
}
.detail div { margin: 0; }
.detail dt {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); margin-bottom: 3px;
}
.detail dd { margin: 0; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
