/**
 * Input Validation Styling
 * Adds visual feedback for form validation states
 * 
 * Added to Metal Configurator Plugin - January 2026
 */

/* Valid field styling */
.form-control.is-valid {
  border-color: #198754;
  padding-right: calc(1.5em + 0.75rem);
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='%23198754' d='M2.3 6.73.6 4.53c-.4-1.04.46-1.4 1.1-.8l1.1 1.4 3.4-3.8c.6-.63 1.6-.27 1.2.7l-4 4.6c-.43.5-.8.4-1.1.1z'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right calc(0.375em + 0.1875rem) center;
  background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

.form-control.is-valid:focus {
  border-color: #198754;
  box-shadow: 0 0 0 0.25rem rgba(25, 135, 84, 0.25);
}

/* Invalid field styling */
.form-control.is-invalid {
  /* Use warning/amber instead of red */
  border-color: #f5c04d;
  padding-right: calc(1.5em + 0.75rem);
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' width='12' height='12' fill='none' stroke='%23f5c04d'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23f5c04d' stroke='none'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right calc(0.375em + 0.1875rem) center;
  background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

.form-control.is-invalid:focus {
  border-color: #f5c04d;
  box-shadow: 0 0 0 0.25rem rgba(245, 192, 77, 0.25);
}

/* Invalid feedback message */
.invalid-feedback {
  display: none;
  width: 100%;
  margin-top: 0.25rem;
  font-size: 0.875em;
  color: #b58100;
}

.invalid-feedback:before {
  content: "⚠ ";
  font-weight: bold;
}

.form-control.is-invalid ~ .invalid-feedback {
  display: block;
}

/* Valid feedback (optional, for success messages) */
.valid-feedback {
  display: none;
  width: 100%;
  margin-top: 0.25rem;
  font-size: 0.875em;
  color: #198754;
}

.form-control.is-valid ~ .valid-feedback {
  display: block;
}

/* Animation for feedback appearance */
@keyframes slideInFromTop {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.invalid-feedback,
.valid-feedback {
  animation: slideInFromTop 0.3s ease-out;
}

/* Enhanced focus state for better UX */
.form-control:focus {
  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

/* Styling for number inputs specifically */
input[type="number"].form-control {
  -moz-appearance: textfield;
}

input[type="number"].form-control::-webkit-outer-spin-button,
input[type="number"].form-control::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Ensure validation icons don't overlap with number spinners in browsers that show them */
input[type="number"].form-control.is-valid,
input[type="number"].form-control.is-invalid {
  padding-right: calc(1.5em + 0.75rem);
}

/* Mobile responsive adjustments */
@media (max-width: 576px) {
  .invalid-feedback,
  .valid-feedback {
    font-size: 0.8125em;
  }
}

/* Accessibility: High contrast mode support */
@media (prefers-contrast: high) {
  .form-control.is-invalid {
    border-width: 2px;
    border-color: #f5c04d;
  }
  
  .form-control.is-valid {
    border-width: 2px;
    border-color: #198754;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .invalid-feedback,
  .valid-feedback {
    animation: none;
  }
  
  .form-control:focus {
    transition: none;
  }
}

/*
  Force VALID state to always be green.
  Some flows may temporarily leave both `is-invalid` and `is-valid` on the input;
  in that case we still want the correct input to look green.
*/
.form-control.is-valid {
  border-color: #198754 !important;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='%23198754' d='M2.3 6.73.6 4.53c-.4-1.04.46-1.4 1.1-.8l1.1 1.4 3.4-3.8c.6-.63 1.6-.27 1.2.7l-4 4.6c-.43.5-.8.4-1.1.1z'/%3e%3c/svg%3e") !important;
}

.form-control.is-valid:focus {
  border-color: #198754 !important;
  box-shadow: 0 0 0 0.25rem rgba(25, 135, 84, 0.25) !important;
}

.form-control.is-valid.is-invalid {
  border-color: #198754 !important;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='%23198754' d='M2.3 6.73.6 4.53c-.4-1.04.46-1.4 1.1-.8l1.1 1.4 3.4-3.8c.6-.63 1.6-.27 1.2.7l-4 4.6c-.43.5-.8.4-1.1.1z'/%3e%3c/svg%3e") !important;
}
