/**
 * @file
 * Enhanced AJAX loading overlay styles for Valia forms.
 * Provides accessible and performant loading states with smooth animations.
 */

/* Base loading state */
form.ajax-form-processing {
  position: relative;
  transition: opacity 0.2s ease-in-out;
  isolation: isolate; /* Creates stacking context for better z-index management */
  
  /* Delay pointer-events blocking to allow form submission */
  animation: block-interactions 0.1s ease-out 0.1s forwards;
}

@keyframes block-interactions {
  from {
    pointer-events: auto;
  }
  to {
    pointer-events: none;
  }
}

/* Loading overlay background */
form.ajax-form-processing::before {
  content: '';
  position: absolute;
  inset: 0; /* Modern shorthand for top/right/bottom/left: 0 */
  background: rgba(255, 255, 255, 0.02);
  backdrop-filter: blur(1px) saturate(1.05);
  border-radius: var(--radius-lg, 12px);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none; /* Ensure overlay doesn't block clicks initially */
  animation: overlay-fade-in 0.3s ease-out 0.05s forwards;
}

/* Loading spinner icon */
form.ajax-form-processing::after {
  content: 'sync';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'Material Symbols Sharp', 'Material Icons', sans-serif;
  font-size: clamp(2rem, 4vw, 3rem); /* Responsive sizing */
  color: var(--brand-primary, #8B5CF6);
  z-index: 1000;
  opacity: 0;
  animation: 
    spinner-fade-in 0.3s ease-out 0.1s forwards,
    spin-loading 1.2s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  
  /* Ensure proper font rendering */
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 48;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Enhanced animations */
@keyframes overlay-fade-in {
  from {
    opacity: 0;
    backdrop-filter: blur(0px) saturate(1);
  }
  to {
    opacity: 1;
    backdrop-filter: blur(1px) saturate(1.05);
  }
}

@keyframes spinner-fade-in {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.8);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

@keyframes spin-loading {
  0% {
    transform: translate(-50%, -50%) rotate(0deg);
  }
  100% {
    transform: translate(-50%, -50%) rotate(-360deg);
  }
}

/* Enhanced states for different form types */
form.ajax-form-processing[data-drupal-selector*="payment"] {
  /* Payment forms get slightly different styling */
  &::before {
    background: rgba(248, 250, 252, 0.03);
    border: 1px solid rgba(139, 92, 246, 0.05);
  }
  
  &::after {
    color: var(--brand-primary, #8B5CF6);
    filter: drop-shadow(0 2px 8px rgba(139, 92, 246, 0.3));
  }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
  form.ajax-form-processing::before,
  form.ajax-form-processing::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
  
  form.ajax-form-processing::after {
    animation-name: spinner-fade-in !important;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  form.ajax-form-processing::before {
    background: rgba(255, 255, 255, 0.98);
    border: 2px solid currentColor;
  }
  
  form.ajax-form-processing::after {
    color: #000;
    font-weight: 700;
  }
}

/* Dark theme support */
@media (prefers-color-scheme: dark) {
  form.ajax-form-processing::before {
    background: rgba(17, 24, 39, 0.02);
  }
  
  form.ajax-form-processing::after {
    color: var(--brand-primary-light, #A78BFA);
  }
}

/* Mobile optimizations */
@media (max-width: 768px) {
  form.ajax-form-processing::after {
    font-size: 2.2rem;
  }
}

/* Focus management during loading */
form.ajax-form-processing :focus {
  outline: none !important;
  box-shadow: none !important;
}

/* Disabled element styling during loading */
form.ajax-form-processing input:disabled,
form.ajax-form-processing select:disabled,
form.ajax-form-processing textarea:disabled,
form.ajax-form-processing button:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transition: opacity 0.2s ease-in-out;
}

/* Screen reader only content for loading announcements */
.sr-only,
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Form Loading State */
form.loading, .section-loading {
  position: relative;
  pointer-events: none;
}

form.loading::before, .section-loading::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(2px);
  border-radius: 8px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
}

form.loading::after, .section-loading::after {
  content: 'sync';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'Material Symbols Sharp';
  font-size: 2rem;
  color: var(--brand-primary, #8B5CF6);
  z-index: 11;
  animation: spin-loading 1s linear infinite;
}