/**
 * Form Animations & States
 * Warszawski Klub Junto - Registration System
 *
 * Accessibility-compliant animations (respects prefers-reduced-motion)
 * WCAG 2.1 AA compliant colors and focus states
 */

/* ============================================================================
   SUCCESS CHECKMARK ANIMATION
   ============================================================================ */

@keyframes checkmark-pop {
  0% {
    transform: scale(0) rotate(-45deg);
    opacity: 0;
  }
  50% {
    transform: scale(1.2) rotate(-5deg);
  }
  100% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
}

.success-checkmark svg {
  animation: checkmark-pop 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* ============================================================================
   LOADING SPINNER (for submit button)
   ============================================================================ */

@keyframes spinner-rotate {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.loading-spinner {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spinner-rotate 0.8s linear infinite;
}

/* ============================================================================
   BUTTON STATES
   ============================================================================ */

#submit-button {
  position: relative;
  overflow: hidden;
}

#submit-button:disabled {
  cursor: not-allowed;
}

#submit-button:not(:disabled):active {
  transform: scale(0.98);
}

/* Ripple effect on click (optional enhancement) */
@keyframes ripple {
  0% {
    transform: scale(0);
    opacity: 1;
  }
  100% {
    transform: scale(4);
    opacity: 0;
  }
}

#submit-button::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(0);
  transition: transform 0.5s, opacity 0.5s;
}

#submit-button:active:not(:disabled)::before {
  animation: ripple 0.6s ease-out;
}

/* ============================================================================
   MESSAGE ANIMATIONS (success/error)
   ============================================================================ */

@keyframes slide-in-down {
  0% {
    transform: translateY(-20px);
    opacity: 0;
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

#success-message:not(.hidden),
#error-message:not(.hidden) {
  animation: slide-in-down 0.4s ease-out;
}

/* ============================================================================
   FIELD ERROR STATES
   ============================================================================ */

@keyframes shake {
  0%, 100% {
    transform: translateX(0);
  }
  10%, 30%, 50%, 70%, 90% {
    transform: translateX(-5px);
  }
  20%, 40%, 60%, 80% {
    transform: translateX(5px);
  }
}

input[aria-invalid="true"],
textarea[aria-invalid="true"],
select[aria-invalid="true"] {
  animation: shake 0.5s ease-in-out;
}

.error-message:not(.hidden) {
  animation: slide-in-down 0.3s ease-out;
}

/* ============================================================================
   FOCUS STATES (Enhanced for keyboard navigation)
   ============================================================================ */

input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid #D97706; /* amber */
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(217, 119, 6, 0.2);
}

/* Checkbox focus (larger target) */
input[type="checkbox"]:focus-visible {
  outline: 3px solid #D97706;
  outline-offset: 4px;
}

/* ============================================================================
   HOVER STATES (Accessible contrast)
   ============================================================================ */

label:has(input[type="checkbox"]):hover {
  background-color: rgba(248, 245, 242, 0.8); /* paper with opacity */
}

/* ============================================================================
   TRANSITIONS (Smooth state changes)
   ============================================================================ */

input,
textarea,
select,
button {
  transition: border-color 0.2s ease,
              box-shadow 0.2s ease,
              background-color 0.2s ease,
              transform 0.1s ease;
}

/* ============================================================================
   REDUCED MOTION (Accessibility)
   ============================================================================ */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  html {
    scroll-behavior: auto;
  }
}

/* ============================================================================
   MOBILE OPTIMIZATIONS
   ============================================================================ */

@media (max-width: 640px) {
  /* Larger touch targets on mobile */
  input,
  textarea,
  select,
  button {
    min-height: 48px; /* WCAG 2.1 AA minimum touch target */
  }

  /* Prevent zoom on focus (iOS) */
  input,
  textarea,
  select {
    font-size: 16px; /* iOS won't zoom if >= 16px */
  }
}

/* ============================================================================
   PRINT STYLES (Hide interactive elements)
   ============================================================================ */

@media print {
  #registration-form,
  #success-message,
  #error-message {
    display: none;
  }
}

/* ============================================================================
   HIGH CONTRAST MODE (Windows High Contrast)
   ============================================================================ */

@media (prefers-contrast: high) {
  input,
  textarea,
  select {
    border-width: 2px;
  }

  button {
    border: 2px solid currentColor;
  }

  input[aria-invalid="true"],
  textarea[aria-invalid="true"],
  select[aria-invalid="true"] {
    border-width: 3px;
  }
}

/* ============================================================================
   DARK MODE (Future enhancement)
   ============================================================================ */

@media (prefers-color-scheme: dark) {
  /* Placeholder for future dark mode support */
  /* Currently respecting the "Intellectual Minimalism" light theme */
}

/* ============================================================================
   UTILITY CLASSES
   ============================================================================ */

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

.sr-only-focusable:focus {
  position: static;
  width: auto;
  height: auto;
  padding: inherit;
  margin: inherit;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* ============================================================================
   FORM FIELD SPACING (Consistent rhythm)
   ============================================================================ */

.form-field + .form-field {
  margin-top: 1.5rem; /* 24px */
}

@media (min-width: 768px) {
  .form-field + .form-field {
    margin-top: 2rem; /* 32px on larger screens */
  }
}
