/* ============================================================
   IRASIL — movimiento: transiciones, entradas y animaciones.
   Paleta IRASIL (verde oscuro + lima). Se carga después de styles.css.

   Las entradas usan fill-mode «backwards»: al terminar no queda ningún
   transform aplicado. Un transform persistente en <main>, filas o paneles
   rompería los elementos position:fixed de adentro (modal de PDF, menú
   «⋯» de acciones, menú de estado).
   ============================================================ */

:root {
  --motion-ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --motion-ease-pop: cubic-bezier(0.34, 1.56, 0.64, 1);
  --motion-fast: 0.16s;
  --motion-base: 0.32s;
  --motion-slow: 0.5s;
}

/* —— Navegación entre páginas (Chrome/Edge/Safari 18.2+) —— */
@view-transition {
  navigation: auto;
}

::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 0.2s;
  animation-timing-function: var(--motion-ease);
}

.app-header {
  view-transition-name: irasil-header;
}

.mobile-bottom-nav {
  view-transition-name: irasil-bottom-nav;
}

/* —— Keyframes —— */
@keyframes irasil-fade-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes irasil-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes irasil-row-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes irasil-pop {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes irasil-modal-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes irasil-slide-down {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes irasil-count-in {
  0% {
    opacity: 0;
    transform: scale(0.82);
  }
  60% {
    opacity: 1;
    transform: scale(1.06);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes irasil-grow-x {
  from {
    transform: scaleX(0);
  }
  to {
    transform: scaleX(1);
  }
}

@keyframes irasil-soft-pulse {
  0%,
  100% {
    opacity: 0.55;
  }
  50% {
    opacity: 1;
  }
}

@keyframes irasil-live-dot {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.4);
    opacity: 0.5;
  }
}

@keyframes irasil-shine {
  0% {
    transform: translateX(-120%);
  }
  100% {
    transform: translateX(260%);
  }
}

/* —— Entrada de página —— */
main.container,
.login-main > * {
  animation: irasil-fade-up var(--motion-base) var(--motion-ease) backwards;
}

/* Bloques de la página en cascada */
.page-stack > *,
.home-page > *,
.home-stats > *,
.home-menu > *,
.admin-summary > *,
.catalogo-lista > * {
  animation: irasil-fade-up 0.36s var(--motion-ease) backwards;
}

.page-stack > *:nth-child(1),
.home-page > *:nth-child(1),
.home-stats > *:nth-child(1),
.home-menu > *:nth-child(1),
.admin-summary > *:nth-child(1),
.catalogo-lista > *:nth-child(1) {
  animation-delay: 0.03s;
}
.page-stack > *:nth-child(2),
.home-page > *:nth-child(2),
.home-stats > *:nth-child(2),
.home-menu > *:nth-child(2),
.admin-summary > *:nth-child(2),
.catalogo-lista > *:nth-child(2) {
  animation-delay: 0.07s;
}
.page-stack > *:nth-child(3),
.home-page > *:nth-child(3),
.home-stats > *:nth-child(3),
.home-menu > *:nth-child(3),
.admin-summary > *:nth-child(3),
.catalogo-lista > *:nth-child(3) {
  animation-delay: 0.11s;
}
.page-stack > *:nth-child(4),
.home-page > *:nth-child(4),
.home-stats > *:nth-child(4),
.home-menu > *:nth-child(4),
.admin-summary > *:nth-child(4),
.catalogo-lista > *:nth-child(4) {
  animation-delay: 0.15s;
}
.page-stack > *:nth-child(5),
.home-page > *:nth-child(5),
.home-menu > *:nth-child(5),
.admin-summary > *:nth-child(5),
.catalogo-lista > *:nth-child(5) {
  animation-delay: 0.19s;
}
.page-stack > *:nth-child(n + 6),
.home-page > *:nth-child(n + 6),
.home-menu > *:nth-child(n + 6),
.admin-summary > *:nth-child(n + 6),
.catalogo-lista > *:nth-child(n + 6) {
  animation-delay: 0.23s;
}

/* Filas de tablas: cascada corta en las primeras, el resto entra junto */
.data-table tbody tr {
  animation: irasil-row-in 0.3s var(--motion-ease) backwards;
}
.data-table tbody tr:nth-child(1) { animation-delay: 0.08s; }
.data-table tbody tr:nth-child(2) { animation-delay: 0.1s; }
.data-table tbody tr:nth-child(3) { animation-delay: 0.12s; }
.data-table tbody tr:nth-child(4) { animation-delay: 0.14s; }
.data-table tbody tr:nth-child(5) { animation-delay: 0.16s; }
.data-table tbody tr:nth-child(6) { animation-delay: 0.18s; }
.data-table tbody tr:nth-child(7) { animation-delay: 0.2s; }
.data-table tbody tr:nth-child(8) { animation-delay: 0.22s; }
.data-table tbody tr:nth-child(9) { animation-delay: 0.24s; }
.data-table tbody tr:nth-child(10) { animation-delay: 0.26s; }
.data-table tbody tr:nth-child(n + 11) { animation-delay: 0.28s; }

/* Avisos: entran al cargar. El banner de home-alerts.js se rearma cada minuto. */
.alert:not(.home-alert-banner-dynamic) {
  animation: irasil-fade-up 0.34s var(--motion-ease) backwards;
}

/* —— Cabecera —— */
.app-header::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--brand-dark), var(--brand-lime) 55%, transparent);
  transform-origin: left center;
  animation: irasil-grow-x 0.7s var(--motion-ease) backwards;
  pointer-events: none;
  z-index: 1;
}

.app-brand-logo {
  transition: transform var(--motion-fast) var(--motion-ease);
}

.app-brand:hover .app-brand-logo {
  transform: scale(1.03);
}

.app-nav-link,
.app-nav-user-toggle,
.mobile-bottom-link {
  transition: background-color var(--motion-fast) ease, color var(--motion-fast) ease,
    border-color var(--motion-fast) ease, transform var(--motion-fast) ease;
}

.app-nav-link.is-active {
  box-shadow: inset 0 -2px 0 var(--brand-lime);
}

.mobile-bottom-link .mobile-bottom-icon {
  display: inline-block;
  transition: transform 0.2s var(--motion-ease-pop);
}

.mobile-bottom-link.is-active .mobile-bottom-icon {
  transform: translateY(-1px) scale(1.12);
}

.mobile-bottom-link:active .mobile-bottom-icon {
  transform: scale(0.9);
}

/* —— Menús desplegables y modal —— */
.app-nav-user-dropdown,
.row-actions-menu,
.estado-cambio-menu {
  transform-origin: top right;
  animation: irasil-pop 0.18s var(--motion-ease) backwards;
}

.estado-cambio-menu {
  transform-origin: top left;
}

body.nav-open .app-nav-right {
  animation: irasil-slide-down 0.22s var(--motion-ease) backwards;
}

.modal-overlay {
  animation: irasil-fade-in 0.2s ease backwards;
}

.modal-overlay .modal-card {
  animation: irasil-modal-in 0.26s var(--motion-ease) backwards;
}

.aviso-version-nueva {
  animation: irasil-fade-up 0.3s var(--motion-ease) backwards;
}

/* —— Inicio —— */
.home-hero-header {
  position: relative;
}

.home-hero-header::after {
  content: "";
  position: absolute;
  width: 180px;
  height: 180px;
  right: -40px;
  top: -80px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent-glow), transparent 70%);
  pointer-events: none;
  animation: irasil-soft-pulse 4.5s ease-in-out infinite;
}

.home-hero h1::after {
  content: "";
  display: block;
  width: 3.25rem;
  height: 3px;
  margin-top: 0.55rem;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand-dark), var(--brand-lime));
  transform-origin: left center;
  animation: irasil-grow-x 0.6s 0.15s var(--motion-ease) backwards;
}

.home-stat-card {
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s ease, transform 0.2s var(--motion-ease), box-shadow 0.2s ease;
}

.home-stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.home-stat-card::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 40%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.55), transparent);
  transform: translateX(-120%);
  pointer-events: none;
}

.home-stat-card:hover::after {
  animation: irasil-shine 0.9s var(--motion-ease);
}

.home-stat-count {
  display: inline-block;
  animation: irasil-count-in var(--motion-slow) 0.2s var(--motion-ease) backwards;
}

.home-card-arrow {
  transition: transform 0.2s var(--motion-ease), opacity 0.2s ease;
}

.home-card:hover .home-card-arrow {
  transform: translateX(4px);
  opacity: 1;
}

.home-card-icon {
  transition: transform 0.25s var(--motion-ease-pop), background-color 0.2s ease, border-color 0.2s ease;
}

.home-card:hover .home-card-icon {
  transform: scale(1.06);
  background-color: rgba(141, 198, 63, 0.14);
  border-color: rgba(141, 198, 63, 0.45);
}

/* —— Botones y campos —— */
.btn:active:not(:disabled) {
  transform: scale(0.98);
  transition-duration: 0.06s;
}

.btn:focus-visible,
a:focus-visible,
button:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--brand-lime);
  outline-offset: 2px;
}

input,
select,
textarea {
  transition: border-color var(--motion-fast) ease, box-shadow var(--motion-fast) ease,
    background-color var(--motion-fast) ease;
}

.data-table tbody tr {
  transition: background-color 0.15s ease;
}

.filter-chip {
  animation: irasil-pop 0.24s var(--motion-ease-pop) backwards;
}

/* —— Indicadores «en vivo» —— */
.sync-live::before,
.estado-badge.estado-en_curso::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 0.4rem;
  border-radius: 999px;
  background: currentColor;
  vertical-align: middle;
  animation: irasil-live-dot 1.6s ease-in-out infinite;
}

.sync-live::before {
  background: var(--brand-lime);
}

/* —— Login —— */
.login-shell {
  position: relative;
}

.login-shell::before {
  content: "";
  position: absolute;
  inset: -60px -40px auto;
  height: 260px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent-glow), transparent 70%);
  pointer-events: none;
  z-index: 0;
  animation: irasil-soft-pulse 5s ease-in-out infinite;
}

.login-shell > * {
  position: relative;
  z-index: 1;
}

/* —— Accesibilidad: sin movimiento si el usuario lo pide —— */
@media (prefers-reduced-motion: reduce) {
  @view-transition {
    navigation: none;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .btn:hover,
  .btn:active:not(:disabled),
  .home-card:hover,
  .home-stat-card:hover {
    transform: none !important;
  }
}

/* —— Botón «cargando» (static/js/boton-cargando.js) —— */
@keyframes irasil-spin {
  to {
    transform: rotate(360deg);
  }
}

.btn.is-loading,
.btn-sync-icon.is-loading {
  pointer-events: none;
  cursor: progress;
}

.btn.is-loading {
  opacity: 0.92;
}

.btn.is-loading::before {
  content: "";
  width: 1em;
  height: 1em;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: irasil-spin 0.7s linear infinite;
}

.btn-sync-icon.is-loading .btn-icon-sync {
  animation: irasil-spin 0.8s linear infinite;
}

/* —— Ilustraciones de pantallas vacías —— */
@keyframes irasil-bob {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-2px);
  }
}

@keyframes irasil-blink {
  0%,
  100% {
    opacity: 0.45;
  }
  50% {
    opacity: 1;
  }
}

@keyframes irasil-speed {
  0% {
    opacity: 0;
    transform: translateX(6px);
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateX(-6px);
  }
}

@keyframes irasil-sway {
  0%,
  100% {
    transform: rotate(-6deg);
  }
  50% {
    transform: rotate(6deg);
  }
}

@keyframes irasil-lid {
  0%,
  100% {
    transform: rotate(0);
  }
  50% {
    transform: rotate(-8deg);
  }
}

@keyframes irasil-draw {
  from {
    stroke-dashoffset: 100;
  }
  to {
    stroke-dashoffset: 0;
  }
}

.ilus-mover {
  animation: irasil-bob 1.6s ease-in-out infinite;
}

.ilus-sirena {
  animation: irasil-blink 0.9s ease-in-out infinite;
}

.ilus-velocidad {
  animation: irasil-speed 1.2s ease-in-out infinite;
}

.ilus-lupa {
  transform-box: fill-box;
  transform-origin: 35% 35%;
  animation: irasil-sway 3s ease-in-out infinite;
}

.ilus-tapa {
  transform-box: fill-box;
  transform-origin: 0% 100%;
  animation: irasil-lid 3s ease-in-out infinite;
}

.ilus-check {
  stroke-dasharray: 100;
  animation: irasil-draw 0.6s 0.35s var(--motion-ease) backwards;
}

/* —— Avisos flotantes —— */
@keyframes irasil-aviso-entra {
  from {
    opacity: 0;
    transform: translateX(24px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

@keyframes irasil-aviso-sale {
  to {
    opacity: 0;
    transform: translateX(24px);
  }
}

@keyframes irasil-aviso-tiempo {
  from {
    transform: scaleX(1);
  }
  to {
    transform: scaleX(0);
  }
}

.aviso-flotante {
  animation: irasil-aviso-entra 0.32s var(--motion-ease-pop) backwards;
}

.aviso-flotante.is-saliendo {
  animation: irasil-aviso-sale 0.26s var(--motion-ease) forwards;
}

.aviso-flotante-barra {
  animation: irasil-aviso-tiempo var(--aviso-duracion, 4500ms) linear forwards;
}

.aviso-flotante.is-pausado .aviso-flotante-barra {
  animation-play-state: paused;
}

/* —— Banner de Hoy —— */
.hoy-banner::before {
  animation: irasil-soft-pulse 4.5s ease-in-out infinite;
}

.hoy-banner-en-vivo .hoy-banner-dot {
  animation: irasil-live-dot 1.6s ease-in-out infinite;
}

.hoy-banner-stat dd {
  animation: irasil-count-in var(--motion-slow) 0.2s var(--motion-ease) backwards;
}

.dia-nav-btn:active {
  transform: scale(0.92);
}

/* —— Escena del ingreso: la ciudad y la ruta pasan, la ambulancia avanza en su lugar —— */
@keyframes irasil-ciudad-pasa {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

@keyframes irasil-ruta-pasa {
  from { background-position: 0 0; }
  to { background-position: -36px 0; }
}

.login-escena-ciudad {
  animation: irasil-ciudad-pasa 24s linear infinite;
}

.login-escena-ruta::before {
  animation: irasil-ruta-pasa 0.45s linear infinite;
}

.login-escena-ambulancia .ilus-mover {
  animation-duration: 0.9s;
}
