/* =========================================================
   SERVICIOS · el viaje de tu visita (lo completa y anima js/anim/viaje.js)
   Un ciclo dura --T: el pedido sale de tu equipo por el arco hasta el servidor y
   la respuesta vuelve cruzando las siete cabeceras de seguridad, que se encienden
   al pasar. Corre --n veces cuando la tarjeta aparece (y una más con "Volver a
   medir"); después queda quieta, con las cabeceras encendidas.
   El JS dibuja el arco según el tamaño (puntos --x0..--x3 / --y0..--y3).
   ========================================================= */

@property --p { syntax: "<number>"; inherits: false; initial-value: 0; }

.tv {
  --T: 4.2s;
  --n: 3;
  --tv-ok: #8EE3B5;
  margin: 0 0 22px; padding: 20px 24px 18px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
:root[data-theme="light"] .tv { --tv-ok: #0B7A4B; }
.no-js .tv { display: none; }

.tv__head { display: flex; align-items: center; gap: 14px; margin: 0 0 6px; }
.tv__live {
  display: inline-flex; align-items: center; gap: 7px; min-height: 32px; /* el alto del botón: que no salte al aparecer */
  font: 500 .7rem var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--tv-ok);
}
.tv__live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.tv.is-running .tv__live::before { animation: tv-blink 1.4s ease-in-out infinite; }
.tv__title { font-size: 1.075rem; font-weight: 600; color: var(--text); }
.tv__again {
  margin-left: auto; height: 32px; padding: 0 12px; border-radius: 8px; cursor: pointer;
  font: 500 .75rem var(--mono); color: var(--muted); background: transparent; border: 1px solid var(--border-strong);
  transition: color .2s, border-color .2s, opacity .2s;
}
.tv__again:hover { color: var(--text); border-color: var(--violet); }
.tv__again[aria-disabled="true"] { opacity: .45; cursor: progress; }

/* Esquema: tu equipo ── arco ── servidor */
.tv__map { display: flex; align-items: flex-end; padding: 6px 0; }
.tv__node { flex: none; width: 150px; display: flex; flex-direction: column; align-items: center; gap: 3px; text-align: center; }
.tv__box {
  position: relative; display: grid; place-items: center; width: 58px; height: 58px; margin-bottom: 6px;
  border-radius: 14px; border: 1px solid var(--border-strong); background: rgba(155, 107, 255, .06);
}
.tv__box::after { content: ""; position: absolute; inset: -1px; border-radius: inherit; border: 1px solid var(--violet); opacity: 0; }
.tv.is-running .tv__node--edge .tv__box::after { animation: tv-ping var(--T) calc(var(--T) * .3) var(--n); }
.tv.is-running .tv__node--you .tv__box::after { border-color: var(--tv-ok); animation: tv-ping var(--T) calc(var(--T) * .75) var(--n); }
.tv__icon { width: 26px; height: 26px; fill: none; stroke: var(--violet); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.tv__icon--phone { display: none; }
.tv__node b { font-size: .95rem; font-weight: 600; color: var(--text); }
.tv__node small { font: .74rem var(--mono); color: var(--muted); }

.tv__wire { position: relative; flex: 1; height: 168px; }
.tv__arc { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.tv__arc path { fill: none; stroke: var(--border-strong); stroke-width: 1.2; stroke-dasharray: 4 6; }
.tv__km {
  position: absolute; left: var(--ax); top: var(--ay); transform: translate(-50%, -100%); padding-bottom: 7px;
  font: 500 .72rem var(--mono); color: var(--muted); white-space: nowrap;
}
.tv__km:empty { display: none; }

/* Escudos sobre el arco, con la sigla de cada cabecera */
.tv__shield { position: absolute; left: var(--sx); top: var(--sy); width: 20px; height: 20px; margin: -10px 0 0 -10px; color: var(--muted); }
.tv__shield svg { display: block; width: 100%; height: 100%; fill: var(--surface); stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; }
.tv__shield i {
  position: absolute; left: 50%; top: calc(100% + 5px); transform: translateX(-50%);
  font: normal 500 .6rem/1 var(--mono); color: var(--tv-ok); white-space: nowrap; opacity: 0;
}
.tv--nolabels .tv__shield i { display: none; }
.tv.is-running .tv__shield { animation: tv-hit var(--T) var(--t) var(--n); }
.tv.is-running .tv__shield i { animation: tv-label var(--T) var(--t) var(--n); }
.tv.is-done .tv__shield { color: var(--tv-ok); }
.tv.is-done .tv__shield i { opacity: 1; }
/* Si una cabecera no llegó, su escudo queda apagado y tachado */
.tv .tv__shield.is-off { color: var(--muted); opacity: .45; animation: none; }
.tv .tv__shield.is-off i { color: var(--muted); text-decoration: line-through; animation: none; }

/* Paquetes: recorren la curva de Bézier del arco según --p (0 = tu equipo, 1 = el servidor) */
.tv__packet {
  position: absolute; left: -5px; top: -5px; width: 10px; height: 10px; border-radius: 50%; opacity: 0;
  transform: translate(
    calc((1 - var(--p)) * (1 - var(--p)) * (1 - var(--p)) * var(--x0) + 3 * (1 - var(--p)) * (1 - var(--p)) * var(--p) * var(--x1) + 3 * (1 - var(--p)) * var(--p) * var(--p) * var(--x2) + var(--p) * var(--p) * var(--p) * var(--x3)),
    calc((1 - var(--p)) * (1 - var(--p)) * (1 - var(--p)) * var(--y0) + 3 * (1 - var(--p)) * (1 - var(--p)) * var(--p) * var(--y1) + 3 * (1 - var(--p)) * var(--p) * var(--p) * var(--y2) + var(--p) * var(--p) * var(--p) * var(--y3)));
}
.tv__packet--req { background: var(--violet); box-shadow: 0 0 0 3px rgba(155, 107, 255, .2), 0 0 18px rgba(155, 107, 255, .9); }
.tv__packet--res { background: var(--tv-ok); box-shadow: 0 0 0 3px rgba(142, 227, 181, .2), 0 0 18px rgba(142, 227, 181, .9); }
.tv.is-running .tv__packet--req { animation: tv-req var(--T) linear var(--n) both; }
.tv.is-running .tv__packet--res { animation: tv-res var(--T) linear var(--n) both; }

.tv__tag {
  position: absolute; left: var(--ax); top: calc(var(--y0) + 30px); transform: translateX(-50%);
  font: 500 .74rem var(--mono); white-space: nowrap; opacity: 0;
}
.tv__tag--req { color: var(--violet); }
.tv__tag--res { color: var(--tv-ok); }
.tv.is-running .tv__tag--req { animation: tv-tag-req var(--T) var(--n); }
.tv.is-running .tv__tag--res { animation: tv-tag-res var(--T) var(--n); }

/* Datos medidos */
.tv__stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 10px 0 0; padding-top: 14px; border-top: 1px solid var(--border); }
.tv__stats div { display: flex; flex-direction: column; gap: 3px; }
.tv__stats dt { font: .68rem var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.tv__stats dd { margin: 0; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }

@keyframes tv-req { 0% { --p: 0; opacity: 0; } 3% { opacity: 1; } 30% { --p: 1; opacity: 1; } 33%, 100% { --p: 1; opacity: 0; } }
@keyframes tv-res { 0%, 40% { --p: 1; opacity: 0; } 43% { opacity: 1; } 75% { --p: 0; opacity: 1; } 78%, 100% { --p: 0; opacity: 0; } }
@keyframes tv-tag-req { 0%, 2% { opacity: 0; } 6%, 28% { opacity: 1; } 33%, 100% { opacity: 0; } }
@keyframes tv-tag-res { 0%, 42% { opacity: 0; } 46%, 72% { opacity: 1; } 78%, 100% { opacity: 0; } }
@keyframes tv-ping { 0% { opacity: .9; transform: scale(1); } 22%, 100% { opacity: 0; transform: scale(1.4); } }
@keyframes tv-hit {
  0% { color: var(--tv-ok); transform: scale(1.3); filter: drop-shadow(0 0 6px rgba(142, 227, 181, .9)); }
  18% { color: var(--tv-ok); transform: scale(1); filter: none; }
  55% { color: var(--tv-ok); }
  100% { color: var(--muted); }
}
@keyframes tv-label { 0% { opacity: 0; } 8%, 55% { opacity: 1; } 100% { opacity: .25; } }
@keyframes tv-blink { 50% { opacity: .3; } }

/* Celular: el esquema va de arriba abajo y el arco se curva hacia la izquierda */
@media (max-width: 640px) {
  .tv { padding: 18px 16px 14px; }
  .tv__head { flex-wrap: wrap; gap: 8px 12px; }
  .tv__title { order: 3; flex-basis: 100%; }
  .tv__map { flex-direction: column; align-items: center; }
  .tv__node { width: auto; }
  .tv__wire { flex: none; align-self: stretch; height: 270px; }
  .tv__km { transform: translate(-100%, -50%); padding: 0 16px 0 0; }
  .tv__shield i { left: calc(100% + 7px); top: 50%; transform: translateY(-50%); }
  .tv__tag { left: auto; right: 0; transform: none; }
  .tv__tag--req { top: 4px; }
  .tv__tag--res { top: auto; bottom: 4px; }
  .tv__icon--laptop { display: none; }
  .tv__icon--phone { display: block; }
  .tv__stats { grid-template-columns: 1fr 1fr; }
}

/* Movimiento reducido: el esquema queda quieto, con las cabeceras encendidas */
@media (prefers-reduced-motion: reduce) {
  .tv__packet, .tv__tag { display: none; }
  .tv__shield, .tv__shield i, .tv__box::after, .tv__live::before { animation: none !important; }
}
