:root {
  --fondo: #0d1117;
  --panel: #151b24;
  --panel-borde: #232c39;
  --texto: #e6edf3;
  --sutil: #8b949e;
  --acento: #d4a12a;
  --sube: #3fb950;
  --baja: #f85149;
  --alto: #f85149;
  --tibio: #d29922;
  --bien: #3fb950;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--fondo);
  color: var(--texto);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body.centrado {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
}

/* ------------------------------------------------------------------ barra */
.barra {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-borde);
}
.marca { font-weight: 650; letter-spacing: .2px; display: flex; align-items: center; gap: 8px; }
.punto { width: 8px; height: 8px; border-radius: 50%; background: var(--sutil); }
.punto.vivo { background: var(--sube); box-shadow: 0 0 8px var(--sube); }
.punto.alto { background: var(--alto); box-shadow: 0 0 8px var(--alto); }

.barra nav { display: flex; gap: 4px; margin-right: auto; flex-wrap: wrap; }
.barra nav a {
  color: var(--sutil); text-decoration: none;
  padding: 6px 12px; border-radius: 6px;
}
.barra nav a:hover { background: #1d2530; color: var(--texto); }
.barra nav a.activo { background: #1d2530; color: var(--texto); }

.usuario { display: flex; align-items: center; gap: 12px; }
.usuario .correo { color: var(--sutil); font-size: 13px; text-decoration: none; }
.usuario .correo:hover { color: var(--texto); text-decoration: underline; }
.etiqueta {
  font-size: 11px; text-transform: uppercase; letter-spacing: .6px;
  padding: 3px 8px; border-radius: 4px; font-weight: 600;
}
.modo-paper { background: #1f3a5f; color: #79c0ff; }
.modo-live { background: #4a1d1d; color: #ff9492; }
.modo-backtest { background: #2d2a1f; color: #e3b341; }

button, .enlace {
  font: inherit; cursor: pointer;
  background: #21262d; color: var(--texto);
  border: 1px solid var(--panel-borde);
  padding: 8px 14px; border-radius: 6px;
}
button:hover { background: #2a313a; }
.enlace { background: none; border: none; color: var(--sutil); padding: 4px 8px; }
.enlace:hover { color: var(--texto); background: none; text-decoration: underline; }
button.principal { background: var(--acento); color: #1a1204; border-color: var(--acento); font-weight: 600; }
button.principal:hover { filter: brightness(1.1); }
button.peligro { background: #6b1f1f; border-color: #8b2a2a; color: #ffd7d5; font-weight: 600; }
button.peligro:hover { background: #822626; }

/* ------------------------------------------------------------------ avisos */
.aviso { margin: 0; padding: 10px 20px; font-size: 13px; border-bottom: 1px solid var(--panel-borde); }
.aviso.alto { background: #3d1618; color: #ffb3b0; }
.aviso.tibio { background: #3a2d10; color: #f0d086; }
.aviso.bien { background: #12331d; color: #8fdba1; }

main { padding: 20px; max-width: 1400px; margin: 0 auto; }

/* ------------------------------------------------------------------ cifras */
.cifras {
  display: grid; gap: 12px; margin-bottom: 20px;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}
.cifra {
  background: var(--panel); border: 1px solid var(--panel-borde);
  border-radius: 10px; padding: 14px 16px;
  display: flex; flex-direction: column; gap: 2px;
}
.rotulo { color: var(--sutil); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.valor { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.sub { font-size: 12px; color: var(--sutil); font-variant-numeric: tabular-nums; }
.sube { color: var(--sube); }
.baja { color: var(--baja); }

/* ------------------------------------------------------------------ paneles */
.panel {
  background: var(--panel); border: 1px solid var(--panel-borde);
  border-radius: 10px; padding: 16px; margin-bottom: 20px;
}
.panel h2 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }
.panel h2 .sutil { font-weight: 400; }
.sutil { color: var(--sutil); font-size: 13px; }
.vacio { padding: 20px 0; text-align: center; }
.columnas { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }

canvas { width: 100%; display: block; }

/* ------------------------------------------------------------------ tablas */
.panel { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; font-weight: 500; color: var(--sutil);
  padding: 8px 10px; border-bottom: 1px solid var(--panel-borde);
  white-space: nowrap; font-size: 12px;
}
td { padding: 8px 10px; border-bottom: 1px solid #1b222c; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tr.atenuada td { opacity: .62; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.recorte { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
table.compacta td { border: none; padding: 5px 10px; }

.lado { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 4px; }
.lado.buy { background: #123021; color: var(--sube); }
.lado.sell { background: #3d1618; color: var(--baja); }

.estado { font-size: 12px; padding: 2px 8px; border-radius: 4px; background: #21262d; color: var(--sutil); }
.estado.filled { background: #123021; color: var(--sube); }
.estado.rejected { background: #3d1618; color: var(--baja); }
.estado.pending { background: #3a2d10; color: var(--tibio); }

.freno { font-size: 12px; background: #2d2320; color: #e0a37a; padding: 2px 8px; border-radius: 4px; }
.chip { font-size: 11px; background: #1d2530; color: var(--sutil); padding: 1px 6px; border-radius: 4px; margin-left: 4px; }

.estados { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.estado-item { display: flex; flex-direction: column; gap: 6px; }
.pastilla { font-size: 13px; padding: 4px 10px; border-radius: 6px; display: inline-block; width: fit-content; }
.pastilla.bien { background: #123021; color: var(--sube); }
.pastilla.alto { background: #3d1618; color: var(--baja); }
.pastilla.tibio { background: #3a2d10; color: var(--tibio); }
.pastilla.neutro { background: #21262d; color: var(--sutil); }

/* ------------------------------------------------------------------ ingreso */
.tarjeta.ingreso {
  background: var(--panel); border: 1px solid var(--panel-borde);
  border-radius: 12px; padding: 32px; width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: 6px;
}
.ingreso h1 { margin: 0; font-size: 20px; }
.ingreso .sutil { margin: 0 0 16px; }
.ingreso label { font-size: 13px; color: var(--sutil); margin-top: 10px; }
.ingreso input {
  font: inherit; background: #0d1117; color: var(--texto);
  border: 1px solid var(--panel-borde); border-radius: 6px; padding: 10px 12px;
}
.ingreso input:focus { outline: 2px solid var(--acento); outline-offset: -1px; }
.ingreso button { margin-top: 18px; padding: 11px; }
.ingreso .pie { margin: 14px 0 0; font-size: 12px; text-align: center; }
.ingreso .aviso { margin: 8px 0; border-radius: 6px; border: none; padding: 10px 12px; }

footer { padding: 16px 20px; color: var(--sutil); font-size: 12px; text-align: center; }

@media (max-width: 640px) {
  .barra { gap: 12px; }
  .usuario .correo { display: none; }
  main { padding: 12px; }
}

/* =======================================================================
   MOVIMIENTO
   En un panel que vigila dinero la animación tiene que informar, no adornar.
   Todo lo de acá abajo o señala un cambio, o suaviza una transición brusca.
   Se desactiva entero si el sistema pide movimiento reducido.
   ======================================================================= */

@keyframes aparecer {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

@keyframes latir {
  0%, 100% { box-shadow: 0 0 0 0 currentColor; opacity: 1; }
  50%      { box-shadow: 0 0 0 4px transparent; opacity: .55; }
}

/* Destello al cambiar un número entre recargas: es la señal más útil del panel. */
@keyframes destello-verde {
  0%   { background: rgba(63,185,80,0);   }
  18%  { background: rgba(63,185,80,.28); }
  100% { background: rgba(63,185,80,0);   }
}
@keyframes destello-rojo {
  0%   { background: rgba(248,81,73,0);   }
  18%  { background: rgba(248,81,73,.28); }
  100% { background: rgba(248,81,73,0);   }
}
@keyframes destello-neutro {
  0%   { background: rgba(212,161,42,0);   }
  18%  { background: rgba(212,161,42,.22); }
  100% { background: rgba(212,161,42,0);   }
}

.destello-sube { animation: destello-verde 1.4s ease-out; border-radius: 4px; }
.destello-baja { animation: destello-rojo  1.4s ease-out; border-radius: 4px; }
.destello      { animation: destello-neutro 1.4s ease-out; border-radius: 4px; }

/* Entrada escalonada de las tarjetas: da orden de lectura sin marear. */
.cifras .cifra { animation: aparecer .34s ease-out both; }
.cifras .cifra:nth-child(1) { animation-delay: .00s; }
.cifras .cifra:nth-child(2) { animation-delay: .04s; }
.cifras .cifra:nth-child(3) { animation-delay: .08s; }
.cifras .cifra:nth-child(4) { animation-delay: .12s; }
.cifras .cifra:nth-child(5) { animation-delay: .16s; }
main > .panel, main > .columnas { animation: aparecer .34s ease-out both; animation-delay: .18s; }

/* El punto de estado late sólo cuando el bot está operativo. */
.punto.vivo { animation: latir 2.4s ease-in-out infinite; color: var(--sube); }
.punto.alto { animation: latir 1s   ease-in-out infinite; color: var(--alto); }

/* Barra fina de progreso hacia el refresco automatico: evita que la recarga
   aparezca de la nada. */
#refresco {
  position: fixed; top: 0; left: 0; height: 2px; width: 100%;
  background: linear-gradient(90deg, var(--acento), #f0c75a);
  transform: scaleX(0); transform-origin: left;
  z-index: 50; opacity: .75;
}

/* Realce de tarjetas y filas. */
.cifra {
  transition: border-color .18s ease, transform .18s ease;
  position: relative; overflow: hidden;
}
.cifra::after {
  content: ""; position: absolute; inset: 0 auto auto 0;
  width: 100%; height: 2px;
  background: linear-gradient(90deg, var(--acento), transparent);
  opacity: 0; transition: opacity .18s ease;
}
.cifra:hover { border-color: #33404f; transform: translateY(-1px); }
.cifra:hover::after { opacity: .6; }

.panel { transition: border-color .18s ease; }
tbody tr { transition: background .12s ease; }
tbody tr:hover { background: #1a2130; }

/* Subrayado que se despliega en la pestaña activa. */
.barra nav a { position: relative; transition: color .16s ease, background .16s ease; }
.barra nav a::after {
  content: ""; position: absolute; left: 12px; right: 12px; bottom: 2px;
  height: 2px; background: var(--acento);
  transform: scaleX(0); transform-origin: center;
  transition: transform .22s cubic-bezier(.4, 0, .2, 1);
}
.barra nav a.activo::after { transform: scaleX(1); }

button { transition: background .15s ease, transform .08s ease, filter .15s ease; }
button:active { transform: translateY(1px); }
button:focus-visible, .ingreso input:focus-visible, .barra nav a:focus-visible {
  outline: 2px solid var(--acento); outline-offset: 2px;
}

.pastilla, .lado, .estado, .freno { transition: filter .15s ease; }

/* La tarjeta de ingreso entra sola. */
.tarjeta.ingreso { animation: aparecer .3s ease-out both; }

/* Respeto por quien pide menos movimiento: se apaga todo, sin excepciones. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
  #refresco { display: none; }
}


/* ------------------------------------------------------ estado del motor --
   Sin esto el panel muestra "0 operaciones" y no hay forma de distinguir un
   bot trabajando en silencio de uno caído. Para una estrategia que señala
   una vez al día, esa diferencia es todo. */
.panel.motor { border-left: 3px solid var(--sutil); }
.panel.motor-vivo { border-left-color: var(--sube); }
.panel.motor-mudo { border-left-color: var(--alto); }

.motor-cabecera { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.motor-cabecera h2 { margin: 0; }
.motor-detalle { margin-left: auto; }

.latido { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.latido.ok { background: var(--sube); color: var(--sube); animation: latir 2.4s ease-in-out infinite; }
.latido.mal { background: var(--alto); color: var(--alto); animation: latir 1s ease-in-out infinite; }

.motor-explica { margin: 12px 0 0; line-height: 1.6; }
.motor-explica a { color: var(--acento); }

.motivos { margin-top: 14px; }
.motivos-lista { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.chip-motivo {
  font-size: 12px; background: #1d2530; color: var(--sutil);
  padding: 3px 9px; border-radius: 5px;
}
.chip-motivo b { color: var(--texto); margin-left: 3px; }
