/* Form Handler Styles - Enhanced */
:root {
  --primary-color: #30d5c8;
  --error-color: #e74c3c;
  --success-color: #2ecc71;
  --warning-color: #f39c12;
  --text-color: #2c3e50;
  --border-color: #e0e0e0;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
  --transition-base: all 0.2s ease-in-out;
  --radius-sm: 0.25rem;
  --radius-md: 0.375rem;
  --focus-ring: 0 0 0 3px rgba(48, 213, 200, 0.25);
}

/* Base Styles */
.form-group {
  margin-bottom: 1.75rem;
  position: relative;
  transition: var(--transition-base);
}

/* Improved focus styles for better accessibility */
:focus-visible {
  outline: 3px solid var(--primary-color);
  outline-offset: 2px;
  box-shadow: var(--focus-ring);
}

/* Hide outline for mouse users but keep for keyboard navigation */
:focus:not(:focus-visible) {
  outline: none;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #333;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"],
input[type="date"],
input[type="time"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
    line-height: 1.5;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    background-color: #fff;
    color: #333;
}

/* Focus States */
input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: #30d5c8;
    box-shadow: 0 0 0 3px rgba(48, 213, 200, 0.2);
}

/* Enhanced Error States */
input.error,
select.error,
textarea.error,
.form-group.has-error input:not([type="checkbox"], [type="radio"]),
.form-group.has-error select,
.form-group.has-error textarea {
  border-color: var(--error-color);
  padding-right: 2.75rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23e74c3c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'%3E%3C/circle%3E%3Cline x1='12' y1='8' x2='12' y2='12'%3E%3C/line%3E%3Cline x1='12' y1='16' x2='12.01' y2='16'%3E%3C/line%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 1.25rem;
  animation: shake 0.5s cubic-bezier(.36,.07,.19,.97) both;
  backface-visibility: hidden;
  transform: translate3d(0, 0, 0);
}

/* Shake animation for invalid fields */
@keyframes shake {
  10%, 90% { transform: translate3d(-1px, 0, 0); }
  20%, 80% { transform: translate3d(2px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
  40%, 60% { transform: translate3d(4px, 0, 0); }
}

/* Success state for validated fields */
input.success,
select.success,
textarea.success,
.form-group.has-success input:not([type="checkbox"], [type="radio"]),
.form-group.has-success select,
.form-group.has-success textarea {
  border-color: var(--success-color);
  padding-right: 2.75rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%232ecc71' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 11.08V12a10 10 0 1 1-5.93-9.14'%3E%3C/path%3E%3Cpolyline points='22 4 12 14.01 9 11.01'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 1.25rem;
  transition: var(--transition-base);
}

/* Validating state */
input.validating,
select.validating,
textarea.validating {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23f39c12' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='12' y1='2' x2='12' y2='6'%3E%3C/line%3E%3Cline x1='12' y1='18' x2='12' y2='22'%3E%3C/line%3E%3Cline x1='4.93' y1='4.93' x2='7.76' y2='7.76'%3E%3C/line%3E%3Cline x1='16.24' y1='16.24' x2='19.07' y2='19.07'%3E%3C/line%3E%3Cline x1='2' y1='12' x2='6' y2='12'%3E%3C/line%3E%3Cline x1='18' y1='12' x2='22' y2='12'%3E%3C/line%3E%3Cline x1='4.93' y1='19.07' x2='7.76' y2='16.24'%3E%3C/line%3E%3Cline x1='16.24' y1='7.76' x2='19.07' y2='4.93'%3E%3C/line%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 1.25rem;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% { opacity: 0.6; }
  50% { opacity: 1; }
  100% { opacity: 0.6; }
}

/* Enhanced Error Messages */
.error-message {
  display: block;
  margin-top: 0.5rem;
  font-size: 0.875rem;
  color: var(--error-color);
  line-height: 1.4;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: all 0.3s ease-in-out;
  transform: translateY(-10px);
  will-change: max-height, opacity, transform;
}

/* Animate error message in */
.error-enter {
  display: block;
  max-height: 0;
  opacity: 0;
  transform: translateY(-10px);
}

.error-enter-active {
  max-height: 100px;
  opacity: 1;
  transform: translateY(0);
}

/* Animate error message out */
.error-exit {
  max-height: 100px;
  opacity: 1;
  transform: translateY(0);
}

.error-exit-active {
  max-height: 0;
  opacity: 0;
  transform: translateY(-10px);
}

.error-message::before {
    content: '';
    display: inline-block;
    width: 1em;
    height: 1em;
    margin-right: 0.5em;
    vertical-align: middle;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23e74c3c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'%3E%3C/circle%3E%3Cline x1='12' y1='8' x2='12' y2='12'%3E%3C/line%3E%3Cline x1='12' y1='16' x2='12.01' y2='16'%3E%3C/line%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
}

/* Success State */
input.success,
select.success,
textarea.success {
    border-color: #2ecc71;
    padding-right: 2.5rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%232ecc71' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 11.08V12a10 10 0 1 1-5.93-9.14'%3E%3C/path%3E%3Cpolyline points='22 4 12 14.01 9 11.01'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1.25rem;
}

/* Form Messages */
.form-message {
    padding: 1rem;
    margin-bottom: 1.5rem;
    border-radius: 4px;
    font-size: 0.9375rem;
    line-height: 1.5;
    position: relative;
    padding-left: 3rem;
}

.form-message::before {
    content: '';
    position: absolute;
    left: 1rem;
    top: 1rem;
    width: 1.5rem;
    height: 1.5rem;
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
}

.form-message-success {
    background-color: #e8f8f5;
    color: #27ae60;
    border-left: 4px solid #2ecc71;
}

.form-message-success::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%232ecc71' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 11.08V12a10 10 0 1 1-5.93-9.14'%3E%3C/path%3E%3Cpolyline points='22 4 12 14.01 9 11.01'%3E%3C/polyline%3E%3C/svg%3E");
}

.form-message-error {
    background-color: #fdf0ef;
    color: #e74c3c;
    border-left: 4px solid #e74c3c;
}

.form-message-error::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23e74c3c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'%3E%3C/circle%3E%3Cline x1='12' y1='8' x2='12' y2='12'%3E%3C/line%3E%3Cline x1='12' y1='16' x2='12.01' y2='16'%3E%3C/line%3E%3C/svg%3E");
}

.form-message-warning {
    background-color: #fef9e7;
    color: #f39c12;
    border-left: 4px solid #f1c40f;
}

.form-message-warning::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23f39c12' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z'%3E%3C/path%3E%3Cline x1='12' y1='9' x2='12' y2='13'%3E%3C/line%3E%3Cline x1='12' y1='17' x2='12.01' y2='17'%3E%3C/line%3E%3C/svg%3E");
}

/* Enhanced Loading Spinner */
.form-spinner {
  display: inline-block;
  width: 1.5rem;
  height: 1.5rem;
  margin-left: 0.75rem;
  vertical-align: middle;
  opacity: 0;
  transition: opacity 0.2s ease-in-out;
  position: relative;
}

.form-spinner.visible {
  opacity: 1;
}

/* Modern spinner animation */
.form-spinner .spinner {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  animation: rotate 1.4s linear infinite;
  transform-origin: center;
}

.form-spinner .path {
  stroke: currentColor;
  stroke-linecap: round;
  animation: dash 1.4s ease-in-out infinite;
  stroke-dasharray: 80, 200;
  stroke-dashoffset: 0;
}

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

@keyframes dash {
  0% {
    stroke-dasharray: 1, 200;
    stroke-dashoffset: 0;
  }
  50% {
    stroke-dasharray: 89, 200;
    stroke-dashoffset: -35;
  }
  100% {
    stroke-dasharray: 89, 200;
    stroke-dashoffset: -124;
  }
}

.form-spinner .spinner {
    animation: rotate 1.4s linear infinite;
    width: 100%;
    height: 100%;
}

.form-spinner .path {
    stroke: currentColor;
    stroke-linecap: round;
    animation: dash 1.4s ease-in-out infinite;
}

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

@keyframes dash {
    0% {
        stroke-dasharray: 1, 150;
        stroke-dashoffset: 0;
    }
    50% {
        stroke-dasharray: 90, 150;
        stroke-dashoffset: -35;
    }
    100% {
        stroke-dasharray: 90, 150;
        stroke-dashoffset: -124;
    }
}

/* Enhanced Form States */
[data-state="submitting"],
[data-state="loading"] {
  position: relative;
  pointer-events: none;
}

[data-state="submitting"]::after,
[data-state="loading"]::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.8);
  z-index: 10;
  border-radius: var(--radius-md);
  opacity: 0;
  transition: opacity 0.3s ease;
}

[data-state="submitting"] .form-spinner,
[data-state="loading"] .form-spinner {
  display: inline-block;
  opacity: 1;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 20;
  color: var(--primary-color);
  width: 2.5rem;
  height: 2.5rem;
  margin: 0;
}

/* Focus management for better accessibility */
[tabindex="-1"]:focus:not(:focus-visible) {
  outline: 0 !important;
}

/* Print styles */
@media print {
  .form-spinner,
  .error-message::before,
  [data-state]::after {
    display: none !important;
  }
  
  [data-state] {
    opacity: 1 !important;
    pointer-events: auto !important;
  }
}

/* Enhanced Honeypot Field */
.form-hidden,
[data-honeypot="true"] {
  position: absolute !important;
  height: 1px !important;
  width: 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;
  opacity: 0 !important;
  pointer-events: none !important;
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  
  .error-message,
  .form-spinner,
  [data-state]::after {
    transition: none !important;
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  :root {
    --text-color: #f5f5f5;
    --border-color: #444;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
  }
  
  input,
  select,
  textarea {
    background-color: #2d2d2d;
    color: var(--text-color);
    border-color: #444;
  }
  
  input:focus,
  select:focus,
  textarea:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(48, 213, 200, 0.5);
  }
}
/* End of form handler styles */

/* Print styles are handled in the main styles */
