/*! =============================================================================
 *  © 2026 Renzo Núñez · RonBStudio — "Perú Elige 2026 · Segunda Vuelta".
 *  Todos los derechos reservados. Código propietario: queda prohibida su copia,
 *  redistribución, ingeniería inversa o uso no autorizado, total o parcial.
 *  https://www.ronbstudio.com
 * ============================================================================= */
/* =============================================================================
 *  Proyecto      : Perú Elige 2026 — Segunda Vuelta
 *  Archivo       : timeline-scrubber.css
 *  Descripción   : Slider de tiempo full-width (rebobinar el conteo). Echa el
 *                  mismo fondo en degradé de las tarjetas (mapa/evolución) y la
 *                  paleta de "llama" de la barra Conteo ONPE para el relleno.
 *                  El tooltip usa el mismo navy que el gráfico de evolución; la
 *                  manija es neutra (no usa colores de candidato).
 *
 *                  El relleno es un gradiente POSICIONAL (termómetro) recortado
 *                  con clip-path a la fracción `--tls-pct` que escribe el JS —
 *                  responsivo sin depender de anchos en px.
 *
 *  Convenciones BEM. Colores en custom properties locales (sin hex sueltos).
 *  Autor         : Renzo Núñez · RonBStudio
 *  Versión       : 0.1.16
 * ===========================================================================*/

.tl-scrub {
  /* Paleta de LLAMA del avance del conteo (echo de progreso-onpe). Son colores
     del PROGRESO, no de candidatos. */
  --tls-flame-0:   rgb( 60,  60,  70);
  --tls-flame-20:  rgb( 60, 130, 240);
  --tls-flame-38:  rgb(200, 220, 255);
  --tls-flame-55:  rgb(255, 220,  80);
  --tls-flame-75:  rgb(255, 140,  50);
  --tls-flame-100: rgb(225,  60,  35);

  /* Acentos de UI (no son colores de candidato). */
  --tls-live:      rgb( 22, 163,  74);   /* verde "en vivo" */
  --tls-live-soft: rgba(22, 163,  74, 0.12);
  --tls-live-edge: rgba(22, 163,  74, 0.50);
  --tls-hist:      rgb( 99, 102, 241);   /* indigo "modo histórico" */
  --tls-hist-edge: rgba(99, 102, 241, 0.45);
  --tls-tip-bg:    rgb( 30,  58, 138);   /* navy (igual que el tooltip del gráfico) */
  --tls-handle-ring: rgba(71, 85, 105, 0.95);  /* slate neutro */

  --tls-track-h: 12px;
  --tls-handle:  20px;
  --tls-pct:     0%;          /* lo escribe el JS (relleno + manija + tooltip) */

  box-sizing: border-box;
  max-width: 980px;
  margin: var(--sp-4, 1.25rem) auto 0;
  padding: var(--sp-3, 0.75rem) var(--sp-4, 1rem);
  background:
    radial-gradient(
      ellipse at top left,
      var(--c-mv-mapa-radial-from) 0%,
      var(--c-mv-mapa-radial-mid)  60%,
      transparent 100%
    ),
    var(--c-mv-bg-card, #ffffff);
  border: 1px solid var(--c-mv-card-border, #e2e8f0);
  border-radius: var(--c-card-radius, 16px);
  box-shadow: var(--c-card-shadow, 0 1px 3px rgba(15, 23, 42, 0.06));
  font-family: var(--font-mono, ui-monospace, monospace);
}

/* ---------- Cabecera: título + indicador/botón VIVO ---------- */

.tl-scrub__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2, 0.5rem);
  margin-bottom: 0.55rem;
}

.tl-scrub__title {
  font-size: var(--fs-xs, 0.72rem);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--c-mv-ink-muted, #64748b);
}
.tl-scrub__title::before { content: '\25C0\00A0'; opacity: 0.5; }  /* ◀ */

/* En histórico, el título muestra el momento rebobinado (fecha + % real): se
   lee normal (no mayúsculas) y en el índigo del modo histórico. */
.tl-scrub--historical .tl-scrub__title {
  text-transform: none;
  color: var(--tls-hist);
  font-weight: var(--fw-semibold, 600);
}

.tl-scrub__live {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: inherit;
  font-size: var(--fs-xs, 0.72rem);
  font-weight: var(--fw-semibold, 600);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--c-mv-ink-muted, #64748b);
  background: transparent;
  border: 1px solid var(--c-mv-card-border, #e2e8f0);
  border-radius: var(--radius-pill, 999px);
  padding: 3px 11px;
  cursor: default;
  transition: color 150ms ease, background 150ms ease, border-color 150ms ease;
}
.tl-scrub__live::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--tls-live);
  box-shadow: 0 0 6px var(--tls-live);
}
/* En histórico el botón se vuelve accionable (volver a vivo) y el punto late. */
.tl-scrub--historical .tl-scrub__live {
  cursor: pointer;
  color: var(--tls-live);
  border-color: var(--tls-live-edge);
  background: var(--tls-live-soft);
}
.tl-scrub--historical .tl-scrub__live::before {
  animation: tls-pulse-dot 1.4s ease-in-out infinite;
}

/* ---------- Track + relleno + manija + tooltip ---------- */

.tl-scrub__track {
  position: relative;
  height: var(--tls-track-h);
  border-radius: var(--radius-pill, 999px);
  background: var(--c-mv-border-soft, #e2e8f0);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.10);
  cursor: pointer;
  touch-action: none;             /* el arrastre horizontal no dispara scroll */
  /* Margen superior holgado: deja lugar para el tooltip flotante del arrastre
     (que se ancla sobre la manija) sin pisar la fila del título. */
  margin: 1.3rem 0 0.55rem;
}
.tl-scrub__track:focus-visible {
  outline: 2px solid var(--tls-flame-20);
  outline-offset: 3px;
}

.tl-scrub__fill {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(
    90deg,
    var(--tls-flame-0)     0%,
    var(--tls-flame-20)   20%,
    var(--tls-flame-38)   38%,
    var(--tls-flame-55)   55%,
    var(--tls-flame-75)   75%,
    var(--tls-flame-100) 100%
  );
  /* Recorta el gradiente posicional hasta la fracción actual. */
  clip-path: inset(0 calc(100% - var(--tls-pct)) 0 0);
  transition: clip-path 120ms ease-out;
}
.tl-scrub--dragging .tl-scrub__fill { transition: none; }

.tl-scrub__handle {
  position: absolute;
  top: 50%;
  left: var(--tls-pct);
  width: var(--tls-handle);
  height: var(--tls-handle);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid var(--tls-handle-ring);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.28), 0 0 0 4px rgba(255, 255, 255, 0.55);
  cursor: grab;
  transition: left 120ms ease-out, transform 120ms ease-out, border-color 150ms ease;
}
.tl-scrub--dragging .tl-scrub__handle {
  transition: none;
  transform: translate(-50%, -50%) scale(1.14);
  cursor: grabbing;
}
.tl-scrub--historical .tl-scrub__handle { border-color: var(--tls-hist); }

.tl-scrub__tip {
  position: absolute;
  bottom: calc(100% + 7px);
  left: var(--tls-pct);
  transform: translateX(-50%);
  white-space: nowrap;
  background: var(--tls-tip-bg);
  color: #ffffff;
  font-family: inherit;
  font-size: var(--fs-xs, 0.72rem);
  font-weight: var(--fw-semibold, 600);
  padding: 4px 9px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.28);
  pointer-events: none;
  z-index: 3;
}
.tl-scrub__tip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--tls-tip-bg);
}
.tl-scrub__tip[hidden] { display: none; }

/* ---------- Pie: etiquetas de extremos ---------- */

.tl-scrub__foot {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  color: var(--c-mv-ink-muted, #64748b);
}

/* ---------- Estado HISTÓRICO (toda la tarjeta) ---------- */

.tl-scrub--historical {
  border-color: var(--tls-hist-edge);
  box-shadow:
    0 0 0 1px var(--tls-hist-edge),
    var(--c-card-shadow, 0 1px 3px rgba(15, 23, 42, 0.06));
}

/* ---------- Estado BLOQUEADO (conteo aún por debajo del umbral) ----------
   El rebobinado no aporta hasta que haya suficiente avance. La barra queda
   atenuada y no interactiva, con el aviso en el título. El relleno sigue
   mostrando el % vivo como lectura. */
.tl-scrub--locked .tl-scrub__track {
  pointer-events: none;
  opacity: 0.5;
  cursor: default;
}
.tl-scrub--locked .tl-scrub__handle { display: none; }
.tl-scrub--locked .tl-scrub__live  { display: none; }
.tl-scrub--locked .tl-scrub__foot  { visibility: hidden; }
.tl-scrub--locked .tl-scrub__title {
  text-transform: none;
  color: var(--c-mv-ink-muted, #64748b);
}
.tl-scrub--locked .tl-scrub__title::before { content: ''; }   /* sin ◀ cuando está bloqueado */

@keyframes tls-pulse-dot {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.3; }
}

/* ===========================================================================
 *  Accesibilidad
 * =========================================================================*/

@media (prefers-reduced-motion: reduce) {
  .tl-scrub__fill,
  .tl-scrub__handle { transition: none; }
  .tl-scrub--historical .tl-scrub__live::before { animation: none; }
}

/* ===========================================================================
 *  Responsive — móvil: gutters + target táctil más grande
 * =========================================================================*/

@media (max-width: 768px) {
  .tl-scrub {
    margin: var(--sp-3, 0.75rem);
    padding: var(--sp-3, 0.75rem);
    --tls-track-h: 14px;
    --tls-handle:  24px;
  }
  .tl-scrub__title { font-size: 0.66rem; }
  .tl-scrub__foot  { font-size: 0.62rem; }
}
