/**
 * Enhanced Form Validation Styles
 * Comprehensive styling for real-time form validation with accessibility
 */

/* Form Validation Base Styles */
.form-validation-enhanced {
  position: relative;
}

.field-wrapper {
  position: relative;
  margin-bottom: 1.5rem;
  transition: all 0.2s ease-in-out;
}

.form-field {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 2px solid #e2e8f0;
  border-radius: 0.5rem;
  font-size: 1rem;
  line-height: 1.5;
  transition: all 0.2s ease-in-out;
  background-color: #ffffff;
  color: #1a202c;
}

.form-field:focus {
  outline: none;
  border-color: #3182ce;
  box-shadow: 0 0 0 3px rgba(49, 130, 206, 0.1);
  background-color: #ffffff;
}

/* Validation States */
.field-wrapper.field-validating .form-field {
  border-color: #ed8936;
  background-color: #fffbf0;
}

.field-wrapper.field-error .form-field {
  border-color: #e53e3e;
  background-color: #fef5f5;
  box-shadow: 0 0 0 3px rgba(229, 62, 62, 0.1);
}

.field-wrapper.field-success .form-field {
  border-color: #38a169;
  background-color: #f0fff4;
  box-shadow: 0 0 0 3px rgba(56, 161, 105, 0.1);
}

.form-field.invalid {
  animation: shake 0.5s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* Validation Messages */
.field-validation {
  min-height: 1.25rem;
  margin-top: 0.5rem;
  font-size: 0.875rem;
  line-height: 1.25rem;
}

.error-message {
  color: #e53e3e;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0;
  font-weight: 500;
}

.error-message::before {
  content: "⚠";
  font-size: 1rem;
  flex-shrink: 0;
}

.success-message {
  color: #38a169;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0;
  font-weight: 500;
}

.success-message::before {
  content: "✓";
  font-size: 1rem;
  flex-shrink: 0;
}

/* Success Indicator */
.field-success {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  z-index: 10;
  transition: all 0.2s ease-in-out;
}

.field-success.hidden {
  opacity: 0;
  transform: translateY(-50%) scale(0.8);
}

/* Loading States */
.field-wrapper.field-validating::after {
  content: "";
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1rem;
  height: 1rem;
  border: 2px solid #e2e8f0;
  border-top: 2px solid #3182ce;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  z-index: 10;
}

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

/* Form Submit Button States */
.form-validation-enhanced button[type="submit"],
.form-validation-enhanced input[type="submit"] {
  transition: all 0.2s ease-in-out;
  position: relative;
  overflow: hidden;
}

.form-validation-enhanced button[type="submit"]:disabled,
.form-validation-enhanced input[type="submit"]:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.form-validation-enhanced button[type="submit"]:disabled:hover,
.form-validation-enhanced input[type="submit"]:disabled:hover {
  transform: none;
  box-shadow: none;
}

/* Progressive Enhancement Indicators */
.field-wrapper.progressive-validation .form-field {
  border-left: 4px solid transparent;
  transition: border-left-color 0.2s ease-in-out;
}

.field-wrapper.progressive-validation.field-touched .form-field {
  border-left-color: #ed8936;
}

.field-wrapper.progressive-validation.field-validated.field-success .form-field {
  border-left-color: #38a169;
}

.field-wrapper.progressive-validation.field-validated.field-error .form-field {
  border-left-color: #e53e3e;
}

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

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
  .form-field {
    border-width: 3px;
  }
  
  .field-wrapper.field-error .form-field {
    border-color: #000;
    background-color: #fff;
  }
  
  .field-wrapper.field-success .form-field {
    border-color: #000;
    background-color: #fff;
  }
  
  .error-message {
    color: #000;
    font-weight: 700;
  }
  
  .success-message {
    color: #000;
    font-weight: 700;
  }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
  .form-field,
  .field-wrapper,
  .field-success {
    transition: none;
  }
  
  .form-field.invalid {
    animation: none;
  }
  
  .field-wrapper.field-validating::after {
    animation: none;
  }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
  .form-field {
    background-color: #2d3748;
    color: #ffffff;
    border-color: #4a5568;
  }
  
  .form-field:focus {
    border-color: #63b3ed;
    background-color: #2d3748;
  }
  
  .field-wrapper.field-error .form-field {
    background-color: #3d2525;
    border-color: #fc8181;
  }
  
  .field-wrapper.field-success .form-field {
    background-color: #25402e;
    border-color: #68d391;
  }
  
  .field-wrapper.field-validating .form-field {
    background-color: #3d3425;
    border-color: #f6ad55;
  }
  
  .error-message {
    color: #fc8181;
  }
  
  .success-message {
    color: #68d391;
  }
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
  .field-wrapper {
    margin-bottom: 1.25rem;
  }
  
  .form-field {
    padding: 1rem;
    font-size: 16px; /* Prevents zoom on iOS */
  }
  
  .field-validation {
    font-size: 0.875rem;
  }
  
  .field-success {
    right: 1rem;
  }
  
  .field-wrapper.field-validating::after {
    right: 1rem;
  }
}

/* Form Progress Indicator */
.form-progress {
  margin-bottom: 2rem;
  background-color: #f7fafc;
  border-radius: 0.5rem;
  padding: 1rem;
  border: 1px solid #e2e8f0;
}

.form-progress-bar {
  width: 100%;
  height: 0.5rem;
  background-color: #e2e8f0;
  border-radius: 0.25rem;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

.form-progress-fill {
  height: 100%;
  background-color: #3182ce;
  border-radius: 0.25rem;
  transition: width 0.3s ease-in-out;
  width: 0%;
}

.form-progress-text {
  font-size: 0.875rem;
  color: #4a5568;
  text-align: center;
}

/* Auto-save Indicator */
.auto-save-indicator {
  position: fixed;
  top: 1rem;
  right: 1rem;
  background-color: #4299e1;
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 0.25rem;
  font-size: 0.875rem;
  z-index: 1000;
  opacity: 0;
  transform: translateY(-1rem);
  transition: all 0.3s ease-in-out;
}

.auto-save-indicator.visible {
  opacity: 1;
  transform: translateY(0);
}

.auto-save-indicator.success {
  background-color: #38a169;
}

.auto-save-indicator.error {
  background-color: #e53e3e;
}

/* Field Dependencies */
.field-wrapper.field-dependent {
  opacity: 0.6;
  pointer-events: none;
  transition: all 0.3s ease-in-out;
}

.field-wrapper.field-dependent.enabled {
  opacity: 1;
  pointer-events: auto;
}

/* Validation Summary */
.validation-summary {
  background-color: #fef5f5;
  border: 1px solid #fed7d7;
  color: #c53030;
  padding: 1rem;
  border-radius: 0.5rem;
  margin-bottom: 1.5rem;
}

.validation-summary.success {
  background-color: #f0fff4;
  border-color: #c6f6d5;
  color: #2f855a;
}

.validation-summary h3 {
  margin: 0 0 0.5rem 0;
  font-size: 1rem;
  font-weight: 600;
}

.validation-summary ul {
  margin: 0;
  padding-left: 1.5rem;
}

.validation-summary li {
  margin-bottom: 0.25rem;
}

/* Custom Field Types */
.field-wrapper.field-type-password {
  position: relative;
}

.password-toggle {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: #4a5568;
  cursor: pointer;
  padding: 0.25rem;
  z-index: 10;
}

.password-toggle:hover {
  color: #2d3748;
}

/* File Upload Validation */
.field-wrapper.field-type-file .form-field {
  padding: 0.5rem;
  cursor: pointer;
}

.file-upload-info {
  margin-top: 0.5rem;
  font-size: 0.875rem;
  color: #4a5568;
}

.file-upload-error {
  color: #e53e3e;
  font-weight: 500;
}

/* Multi-step Form Support */
.form-step {
  display: none;
}

.form-step.active {
  display: block;
  animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateX(1rem); }
  to { opacity: 1; transform: translateX(0); }
}

.form-step-navigation {
  margin-top: 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.form-step-navigation button {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 0.375rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease-in-out;
}

.form-step-navigation .btn-secondary {
  background-color: #e2e8f0;
  color: #4a5568;
}

.form-step-navigation .btn-secondary:hover {
  background-color: #cbd5e0;
}

.form-step-navigation .btn-primary {
  background-color: #3182ce;
  color: white;
}

.form-step-navigation .btn-primary:hover {
  background-color: #2c5aa0;
}

/* Validation Tooltip */
.validation-tooltip {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  background-color: #1a202c;
  color: white;
  padding: 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
  opacity: 0;
  transform: translateY(0.5rem);
  transition: all 0.2s ease-in-out;
  pointer-events: none;
  z-index: 20;
}

.validation-tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 1rem;
  border: 0.25rem solid transparent;
  border-top-color: #1a202c;
}

.field-wrapper:hover .validation-tooltip,
.form-field:focus + .validation-tooltip {
  opacity: 1;
  transform: translateY(0);
}

/* Print Styles */
@media print {
  .field-validation,
  .field-success,
  .validation-tooltip,
  .auto-save-indicator {
    display: none !important;
  }
  
  .form-field {
    border: 1px solid #000 !important;
    background: white !important;
  }
}