/*
 * FRECUENCIAS - resultado animado
 * Al buscar, el panel se despliega, un camión recorre la ruta y "deja" el destino y la frecuencia.
 * El estado base de cada pieza es el FINAL de la animación; las animaciones solo corren bajo
 * .frec-corriendo (por eso con "reducir movimiento" el resultado aparece directo, sin animar).
 */
#frecuenciaForm {
  --frec-dur: 2.2s;                                  /* duración del viaje del camión */
  --frec-ease: cubic-bezier(.45, .05, .25, 1);
  --frec-azul: var(--accent-color, #163E6D);
  --frec-rojo: #CF1920;
  --frec-camion-ancho: 64px;
}

/* ---------- Aviso / validación ---------- */
.frec-aviso {
  margin-top: 1rem;
  font-family: 'Montserrat', sans-serif;
  font-size: .9rem;
  color: var(--frec-rojo);
}
.frec-aviso[hidden] { display: none; }
#frecuenciaForm .form-select.frec-sacudir {
  border-color: var(--frec-rojo);
  animation: frec-sacudir .4s ease;
}
@keyframes frec-sacudir {
  20%, 60% { transform: translateX(-5px); }
  40%, 80% { transform: translateX(5px); }
}

/* ---------- Panel: se despliega en altura (no aparece de golpe) ---------- */
.frec-resultado {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows .6s cubic-bezier(.2, .8, .2, 1);
  font-family: 'Montserrat', sans-serif;
}
.frec-resultado.frec-abierto { grid-template-rows: 1fr; }
.frec-resultado-inner { min-height: 0; overflow: hidden; }

.frec-tarjeta {
  margin-top: 1.5rem;
  padding: 1.15rem 1.35rem 1.25rem;
  border: 1px solid rgba(22, 62, 109, .09);
  border-radius: 1rem;
  background: linear-gradient(180deg, #f7f9fc, #eef3f9);
}

/* ---------- Origen / destino ---------- */
.frec-etiquetas {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: .6rem;
}
.frec-parada {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  max-width: 47%;
}
.frec-parada small,
.frec-detalle small {
  font-size: .66rem;
  font-weight: 600;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: #7a8b9e;
}
.frec-parada strong {
  font-size: 1.05rem;
  line-height: 1.2;
  color: var(--frec-azul);
}
.frec-hasta { align-items: flex-end; text-align: right; }
.frec-hasta strong { color: var(--frec-rojo); }

/* ---------- Ruta y camión ---------- */
.frec-camino {
  position: relative;
  height: 42px;
}
.frec-via,
.frec-estela {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  border-radius: 2px;
}
.frec-via {                                          /* línea de la ruta, punteada */
  right: 0;
  background: repeating-linear-gradient(90deg, #c3cedb 0 12px, transparent 12px 20px);
}
.frec-estela {                                       /* tramo ya recorrido */
  width: 100%;
  background: linear-gradient(90deg, rgba(22, 62, 109, .12), var(--frec-azul));
}
.frec-pin {
  position: absolute;
  right: 0;
  bottom: 3px;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--frec-rojo);
  transform-origin: 50% 100%;
  filter: drop-shadow(0 2px 2px rgba(207, 25, 32, .3));
}
.frec-camion {
  position: absolute;
  left: calc(100% - var(--frec-camion-ancho) - 22px);
  bottom: 1px;
  width: var(--frec-camion-ancho);
  height: 36px;
  overflow: visible;
}
.frec-rueda {
  transform-box: fill-box;
  transform-origin: center;
}

/* ---------- Frecuencia ---------- */
.frec-detalle {
  display: flex;
  align-items: center;
  gap: .8rem;
  margin-top: 1.05rem;
  padding-top: 1.05rem;
  border-top: 1px dashed rgba(22, 62, 109, .2);
}
.frec-detalle > i {
  display: grid;
  place-items: center;
  flex: none;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 8px rgba(22, 62, 109, .12);
  font-size: 1.15rem;
  color: var(--frec-rojo);
}
.frec-detalle strong {
  display: block;
  font-size: 1.1rem;
  color: #172a28;
}

/* ---------- Animación (línea de tiempo) ----------
   0 s ........ aparece el origen y arranca el camión
   dur ........ llega: cae el pin y el nombre del destino
   dur + .3 s . se revela la frecuencia                          */
.frec-corriendo .frec-desde   { animation: frec-aparecer .5s ease both; }
.frec-corriendo .frec-estela  { animation: frec-recorrer var(--frec-dur) var(--frec-ease) .2s both; }
.frec-corriendo .frec-via     { animation: frec-ruta var(--frec-dur) var(--frec-ease) .2s both; }
.frec-corriendo .frec-camion  { animation: frec-avanzar var(--frec-dur) var(--frec-ease) .2s both; }
.frec-corriendo .frec-cuerpo  { animation: frec-vaiven .3s ease-in-out .2s 7 alternate; }
.frec-corriendo .frec-rueda   { animation: frec-rodar var(--frec-dur) var(--frec-ease) .2s both; }
.frec-corriendo .frec-pin     { animation: frec-pin .6s cubic-bezier(.3, 1.6, .5, 1) calc(var(--frec-dur) - .05s) both; }
.frec-corriendo .frec-hasta   { animation: frec-soltar .55s cubic-bezier(.3, 1.5, .5, 1) calc(var(--frec-dur) + .05s) both; }
.frec-corriendo .frec-detalle { animation: frec-aparecer .6s ease calc(var(--frec-dur) + .35s) both; }

@keyframes frec-aparecer {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
@keyframes frec-avanzar {
  from { left: 0; }
  to   { left: calc(100% - var(--frec-camion-ancho) - 22px); }
}
@keyframes frec-recorrer {
  from { width: 0; }
  to   { width: 100%; }
}
@keyframes frec-ruta {                               /* los guiones "corren" hacia atrás */
  from { background-position: 0 0; }
  to   { background-position: -160px 0; }
}
@keyframes frec-rodar {
  to { transform: rotate(1080deg); }
}
@keyframes frec-vaiven {
  from { transform: translateY(0); }
  to   { transform: translateY(-.8px); }
}
@keyframes frec-pin {
  0%   { opacity: 0; transform: translateY(-14px) scale(.4); }
  60%  { opacity: 1; transform: translateY(0) scale(1.15); }
  100% { opacity: 1; transform: none; }
}
@keyframes frec-soltar {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: none; }
}

@media (max-width: 575.98px) {
  .frec-tarjeta { padding: 1rem 1rem 1.1rem; }
  .frec-parada strong { font-size: .95rem; }
}

@media (prefers-reduced-motion: reduce) {
  .frec-resultado { transition: none; }
  .frec-corriendo * { animation: none !important; }
}
