/* Softwaservice · sw-espera.css · esperas de toda la web (feat/esperas-sv, 06-11-2026)
   Va con assets/js/sw-espera.js. Botón que gira sin cambiar de tamaño, tarjeta de progreso abajo,
   puntos de «pensando» de la IA, nivel del micrófono. Sin animaciones con prefers-reduced-motion. */

.sw-espera-sr {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ── Botón ocupado: el contenido se oculta (no se quita: el botón no cambia de tamaño) y encima va la capa. */
.sw-espera-boton { cursor: progress !important; color: transparent !important; }
.sw-espera-boton > :not(.sw-espera-boton__capa) { visibility: hidden; }
.sw-espera-boton:disabled, .sw-espera-boton[disabled] { opacity: .9 !important; }
.sw-espera-boton__capa {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 0 10px; color: var(--sw-espera-color, currentColor); visibility: visible;
  font-size: inherit; font-weight: inherit; line-height: 1; white-space: nowrap; overflow: hidden;
  pointer-events: none; animation: sw-espera-aparece .15s ease-out;
}
.sw-espera-boton__txt { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.sw-espera-boton--solo-giro .sw-espera-boton__txt { display: none; }

/* Giro (círculo con un trozo de color) */
.sw-espera-giro {
  flex: 0 0 auto; width: 1em; height: 1em; min-width: 14px; min-height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; opacity: .9;
  animation: sw-espera-gira .75s linear infinite;
}
.sw-espera-giro--grande { width: 22px; height: 22px; border-width: 3px; color: var(--sw-espera-acento, var(--sw-brand-600, #e11d48)); }

/* Puntos de «pensando» (IA) */
.sw-espera-puntos { display: inline-flex; align-items: center; gap: 3px; flex: 0 0 auto; }
.sw-espera-puntos i {
  display: block; width: 5px; height: 5px; border-radius: 50%; background: currentColor;
  animation: sw-espera-salta 1.1s ease-in-out infinite;
}
.sw-espera-puntos i:nth-child(2) { animation-delay: .15s; }
.sw-espera-puntos i:nth-child(3) { animation-delay: .3s; }
.sw-espera-puntos--grande { gap: 5px; color: var(--sw-espera-acento, var(--sw-brand-600, #e11d48)); }
.sw-espera-puntos--grande i { width: 8px; height: 8px; }

/* Ondas (voz pasando a texto) */
.sw-espera-ondas { display: inline-flex; align-items: center; gap: 3px; height: 24px; color: var(--sw-espera-acento, var(--sw-brand-600, #e11d48)); }
.sw-espera-ondas i { display: block; width: 4px; height: 100%; border-radius: 2px; background: currentColor; transform-origin: center; animation: sw-espera-onda 1s ease-in-out infinite; }
.sw-espera-ondas i:nth-child(2) { animation-delay: .1s; } .sw-espera-ondas i:nth-child(3) { animation-delay: .2s; }
.sw-espera-ondas i:nth-child(4) { animation-delay: .3s; } .sw-espera-ondas i:nth-child(5) { animation-delay: .4s; }

/* Nivel del micrófono mientras graba */
.sw-espera-nivel { display: inline-flex; align-items: center; gap: 3px; height: 28px; vertical-align: middle; margin: 0 8px; color: var(--sw-error-500, #ef4444); }
.sw-espera-nivel i { display: block; width: 4px; height: 100%; border-radius: 2px; background: currentColor; transform: scaleY(.15); transition: transform .08s linear; }
.sw-espera-nivel--fijo i { animation: sw-espera-onda 1.2s ease-in-out infinite; }

/* ── Tarjeta de progreso: abajo a la izquierda en el ordenador (los avisos van a la derecha);
      en el móvil, a todo el ancho por encima de las barras fijas de acciones. */
.sw-espera {
  position: fixed; left: 16px; bottom: 16px; z-index: 99;
  display: flex; align-items: flex-start; gap: 14px;
  width: 380px; max-width: calc(100vw - 32px); box-sizing: border-box;
  padding: 14px 16px 14px 14px; border-radius: 14px;
  background: var(--sw-surface, #fff); color: var(--sw-text, #141413);
  border: 1px solid var(--sw-border, #dcdbd7);
  box-shadow: 0 12px 32px rgba(15, 17, 22, .14), 0 3px 8px rgba(15, 17, 22, .06);
  animation: sw-espera-sube .22s ease-out;
}
.sw-espera[hidden] { display: none; }
.sw-espera.is-saliendo { opacity: 0; transform: translateY(6px); transition: opacity .18s, transform .18s; }
.sw-espera::before {
  content: ""; position: absolute; left: 0; top: 12px; bottom: 12px; width: 3px; border-radius: 0 3px 3px 0;
  background: var(--sw-espera-acento, var(--sw-brand-600, #e11d48));
}
.sw-espera__icono { flex: 0 0 34px; height: 34px; display: grid; place-items: center; border-radius: 10px;
  background: color-mix(in oklch, var(--sw-espera-acento, #e11d48) 10%, white); }
.sw-espera__cuerpo { flex: 1; min-width: 0; }
.sw-espera__titulo { margin: 0; font-size: 15px; font-weight: 600; line-height: 1.3; }
.sw-espera__paso { margin: 2px 0 0; font-size: 14px; color: var(--sw-text-muted, #3f3f3d); line-height: 1.35; min-height: 1.35em; }
.sw-espera__nota { margin: 8px 0 0; font-size: 13px; color: var(--sw-text-subtle, #5d5d5a); line-height: 1.4; }
.sw-espera__barra { position: relative; height: 6px; margin-top: 10px; border-radius: 3px; overflow: hidden;
  background: color-mix(in oklch, var(--sw-espera-acento, #e11d48) 14%, #f4f4f3); }
.sw-espera__barra span { position: absolute; top: 0; bottom: 0; left: 0; width: 35%; border-radius: 3px;
  background: var(--sw-espera-acento, var(--sw-brand-600, #e11d48)); animation: sw-espera-barra 1.5s ease-in-out infinite; }
.sw-espera--real .sw-espera__barra span { animation: none; transition: width .3s ease-out; }
.sw-espera__cancelar {
  align-self: center; flex: 0 0 auto; min-height: 44px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--sw-border, #dcdbd7); background: var(--sw-bg, #fff); color: var(--sw-text, #141413);
  font: inherit; font-size: 13.5px; font-weight: 500; cursor: pointer;
}
.sw-espera__cancelar[hidden] { display: none; }
.sw-espera__cancelar:hover { background: var(--sw-bg-muted, #f4f4f3); }
.sw-espera__cancelar:focus-visible { outline: 2px solid var(--sw-brand-600, #e11d48); outline-offset: 2px; }

/* Sitios (sw-espera.js elige el primero que no tape el botón que la lanzó ni lo que tiene el foco). */
.sw-espera--bc { left: calc(50% - 190px); }
.sw-espera--bd { left: auto; right: 16px; }
.sw-espera--ac { bottom: auto; top: calc(var(--sw-header-h, 64px) + 12px); left: calc(50% - 190px); }
@media (max-width: 640px) {
  .sw-espera { left: 12px; right: 12px; width: auto; max-width: none;
    bottom: calc(84px + env(safe-area-inset-bottom, 0px)); flex-wrap: wrap; }
  .sw-espera--am { bottom: auto; top: calc(var(--sw-header-h, 56px) + 8px); }
  .sw-espera__cancelar { width: 100%; margin-left: 48px; width: calc(100% - 48px); }
  /* Con la tarjeta a la vista, los avisos suben por encima para no taparse. */
  html.sw-espera-activa .sw-toasts { bottom: calc(196px + env(safe-area-inset-bottom, 0px)); }
}

/* Botón «Reintentar» dentro de los avisos (SW.toast({ accion })) */
.sw-toast__accion {
  display: inline-flex; align-items: center; margin-top: 8px; min-height: 36px; padding: 0 12px;
  border: 0; border-radius: 8px; background: #fff; color: #7f1d1d; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
}
.sw-toast:not(.sw-toast--error) .sw-toast__accion { color: var(--sw-text, #141413); }
.sw-toast__accion:hover, .sw-toast__accion:focus-visible { background: #fee2e2; }
@media (pointer: coarse), (max-width: 768px) { .sw-toast__accion { min-height: 44px; } }

@keyframes sw-espera-gira { to { transform: rotate(360deg); } }
@keyframes sw-espera-salta { 0%, 80%, 100% { transform: translateY(0); opacity: .45; } 40% { transform: translateY(-4px); opacity: 1; } }
@keyframes sw-espera-onda { 0%, 100% { transform: scaleY(.3); } 50% { transform: scaleY(1); } }
@keyframes sw-espera-barra { 0% { left: -35%; } 100% { left: 100%; } }
@keyframes sw-espera-sube { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes sw-espera-aparece { from { opacity: 0; } to { opacity: 1; } }

/* Sin movimiento: nada gira ni salta; se ve el estado y el texto cambia igual. */
@media (prefers-reduced-motion: reduce) {
  .sw-espera, .sw-espera-boton__capa { animation: none; }
  .sw-espera-giro { animation: none; border-right-color: currentColor; opacity: .55; }
  .sw-espera-puntos i, .sw-espera-ondas i, .sw-espera-nivel--fijo i { animation: none; opacity: .7; transform: none; }
  .sw-espera__barra span { animation: none; left: 0; width: 100%; opacity: .45; }
  .sw-espera.is-saliendo { transition: none; }
}
