/* Select2 Fixes for Funeral Membership Form */

/* CRITICAL Z-INDEX FIXES */
.select2-container--open {
  z-index: 999999 !important;
}

.select2-container--open .select2-dropdown {
  z-index: 999999 !important;
}

.select2-container--open .select2-results__options {
  z-index: 999999 !important;
}

/* Ensure dropdown appears above everything */
.select2-dropdown {
  z-index: 999999 !important;
  position: absolute !important;
}

/* Fix for step containers */
.step .select2-container--open {
  z-index: 999999 !important;
}

/* Fix for form rows */
.form-row .field-group .select2-container--open {
  z-index: 999999 !important;
}

/* Ensure proper stacking context */
.membership-form-container {
  position: relative;
  z-index: 1;
}

#afsf-form .step {
  position: relative;
  z-index: 1;
}

/* Fix for any potential overflow issues */
.select2-container {
  overflow: visible !important;
}

.select2-container--open {
  overflow: visible !important;
}

/* Ensure form elements don't interfere with dropdown */
.form-row {
  position: relative;
  z-index: 1;
}

.field-group {
  position: relative;
  z-index: 1;
}

/* CRITICAL: Ensure field-group has proper positioning for Select2 dropdown */
.field-group {
  position: relative !important;
  z-index: 1;
}

.field-group .select2-container {
  position: relative !important;
  z-index: 1;
}

.field-group .select2-container--open {
  z-index: 999999 !important;
}

/* REMOVED: Manual positioning that was causing the issue */
/* Let Select2 handle its own positioning naturally */

/* Select2 Custom Styling for AAHO Design */
.select2-container {
  width: 100% !important;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  position: relative !important;
  z-index: 1;
}

/* Match exact form input styling */
.select2-container--default .select2-selection--single {
  background: #ffffff !important;
  border: 2px solid #e1e8ed !important;
  border-radius: 8px !important;
  height: 48px !important;
  display: flex !important;
  align-items: center !important;
  transition: all 0.3s ease !important;
  cursor: pointer !important;
  position: relative !important;
  box-sizing: border-box !important;
  padding: 0 !important;
  margin: 0 !important;
}

/* Hover state */
.select2-container--default .select2-selection--single:hover {
  border-color: #4a90e2 !important;
  box-shadow: 0 2px 8px rgba(74, 144, 226, 0.15) !important;
}

/* Focus state */
.select2-container--default.select2-container--focus
  .select2-selection--single {
  border-color: #2c5aa0 !important;
  box-shadow: 0 0 0 4px rgba(44, 90, 160, 0.15) !important;
  outline: none !important;
}

/* Text rendering */
.select2-container--default
  .select2-selection--single
  .select2-selection__rendered {
  color: #333333 !important;
  font-size: 15px !important;
  font-weight: 500 !important;
  padding: 12px 16px !important;
  line-height: 1.4 !important;
  width: 100% !important;
  box-sizing: border-box !important;
  padding-right: 40px !important;
}

/* Placeholder styling */
.select2-container--default
  .select2-selection--single
  .select2-selection__placeholder {
  color: #999999 !important;
  font-style: italic !important;
}

/* Arrow styling */
.select2-container--default
  .select2-selection--single
  .select2-selection__arrow {
  height: 100% !important;
  width: 30px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  position: absolute !important;
  right: 8px !important;
  top: 0 !important;
}

.select2-container--default
  .select2-selection--single
  .select2-selection__arrow::after {
  content: "▼" !important;
  font-size: 12px !important;
  color: #666666 !important;
  transition: all 0.3s ease !important;
}

.select2-container--default.select2-container--open
  .select2-selection--single
  .select2-selection__arrow::after {
  transform: rotate(180deg) !important;
  color: #2c5aa0 !important;
}

/* Clear button */
.select2-container--default
  .select2-selection--single
  .select2-selection__clear {
  color: #999999 !important;
  font-size: 16px !important;
  font-weight: bold !important;
  margin-right: 30px !important;
  transition: color 0.3s ease !important;
  position: absolute !important;
  right: 35px !important;
  top: 50% !important;
  transform: translateY(-50%) !important;
  cursor: pointer !important;
}

.select2-container--default
  .select2-selection--single
  .select2-selection__clear:hover {
  color: #dc3545 !important;
}

/* Dropdown styling - REMOVED manual positioning */
.select2-dropdown {
  background: #ffffff !important;
  border: 2px solid #e1e8ed !important;
  border-radius: 8px !important;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15) !important;
  overflow: hidden !important;
  z-index: 999999 !important;
  margin-top: 4px !important;
  position: absolute !important;
  max-height: 200px !important;
  overflow-y: auto !important;
}

/* Search field in dropdown */
.select2-container--default .select2-search--dropdown .select2-search__field {
  border: 2px solid #e1e8ed !important;
  border-radius: 6px !important;
  padding: 10px 12px !important;
  font-size: 14px !important;
  color: #333333 !important;
  background: #f8fafc !important;
  transition: all 0.3s ease !important;
  margin: 8px !important;
  width: calc(100% - 16px) !important;
  box-sizing: border-box !important;
}

.select2-container--default
  .select2-search--dropdown
  .select2-search__field:focus {
  outline: none !important;
  border-color: #2c5aa0 !important;
  background: #ffffff !important;
  box-shadow: 0 0 0 3px rgba(44, 90, 160, 0.1) !important;
}

/* Dropdown options */
.select2-container--default .select2-results__option {
  padding: 12px 16px !important;
  font-size: 15px !important;
  color: #333333 !important;
  transition: all 0.2s ease !important;
  border-bottom: 1px solid #f0f0f0 !important;
  cursor: pointer !important;
}

.select2-container--default .select2-results__option:hover {
  background: #e8f0f8 !important;
  color: #2c5aa0 !important;
}

.select2-container--default
  .select2-results__option--highlighted[aria-selected] {
  background: linear-gradient(135deg, #2c5aa0, #4a90e2) !important;
  color: #ffffff !important;
}

.select2-container--default .select2-results__option[aria-selected="true"] {
  background: #f0f8ff !important;
  color: #2c5aa0 !important;
  font-weight: 600 !important;
}

.select2-container--default
  .select2-results__option[aria-selected="true"]:hover {
  background: #e8f0f8 !important;
  color: #2c5aa0 !important;
}

/* Loading state */
.select2-container--default
  .select2-selection--single.select2-selection--loading {
  opacity: 0.7 !important;
  pointer-events: none !important;
}

.select2-container--default
  .select2-selection--single.select2-selection--loading::after {
  content: "" !important;
  position: absolute !important;
  top: 50% !important;
  right: 40px !important;
  transform: translateY(-50%) !important;
  width: 16px !important;
  height: 16px !important;
  border: 2px solid #e1e8ed !important;
  border-top: 2px solid #2c5aa0 !important;
  border-radius: 50% !important;
  animation: spin 1s linear infinite !important;
}

/* Error state */
.select2-container--default .select2-selection--single.error {
  border-color: #dc3545 !important;
  box-shadow: 0 0 0 4px rgba(220, 53, 69, 0.15) !important;
}

.select2-container--default .select2-selection--single.error:focus {
  border-color: #dc3545 !important;
  box-shadow: 0 0 0 4px rgba(220, 53, 69, 0.2) !important;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .select2-container--default .select2-selection--single {
    height: 44px !important;
  }

  .select2-container--default
    .select2-selection--single
    .select2-selection__rendered {
    padding: 10px 14px !important;
    font-size: 14px !important;
  }

  .select2-container--default .select2-results__option {
    padding: 10px 14px !important;
    font-size: 14px !important;
  }

  .select2-dropdown {
    max-height: 200px !important;
  }
}

/* Accessibility improvements */
.select2-container--default .select2-selection--single:focus-visible {
  outline: 2px solid #2c5aa0 !important;
  outline-offset: 2px !important;
}

.select2-dropdown:focus-within {
  outline: 2px solid #2c5aa0 !important;
  outline-offset: 2px !important;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .select2-container--default .select2-selection--single {
    border-width: 3px !important;
  }

  .select2-container--default
    .select2-results__option--highlighted[aria-selected] {
    border: 2px solid #000000 !important;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .select2-container--default .select2-selection--single,
  .select2-container--default .select2-results__option,
  .select2-container--default
    .select2-selection--single
    .select2-selection__arrow::after {
    transition: none !important;
  }
}

/* Ensure Select2 matches other form elements exactly */
.field-group .select2-container {
  margin-bottom: 0 !important;
}

.field-group .select2-container--default .select2-selection--single {
  height: 48px !important;
  border: 2px solid #e1e8ed !important;
  border-radius: 8px !important;
  background: #ffffff !important;
}

/* Match the exact styling of other form inputs */
#afsf-form .select2-container--default .select2-selection--single {
  border: 2px solid #e1e8ed !important;
  border-radius: 8px !important;
  background: #ffffff !important;
  transition: all 0.3s ease !important;
  height: 48px !important;
  display: flex !important;
  align-items: center !important;
}

#afsf-form .select2-container--default .select2-selection--single:hover {
  border-color: #4a90e2 !important;
  box-shadow: 0 2px 8px rgba(74, 144, 226, 0.15) !important;
}

#afsf-form
  .select2-container--default.select2-container--focus
  .select2-selection--single {
  border-color: #2c5aa0 !important;
  box-shadow: 0 0 0 4px rgba(44, 90, 160, 0.15) !important;
  outline: none !important;
}

#afsf-form
  .select2-container--default
  .select2-selection--single
  .select2-selection__rendered {
  color: #333333 !important;
  font-size: 15px !important;
  font-weight: 500 !important;
  padding: 12px 16px !important;
  line-height: 1.4 !important;
}

#afsf-form
  .select2-container--default
  .select2-selection--single
  .select2-selection__placeholder {
  color: #999999 !important;
  font-style: italic !important;
}

/* Additional Select2 styling to match form elements exactly */
.select2-container {
  margin-bottom: 0 !important;
}

/* Ensure Select2 has the same spacing as other form elements */
.form-row .field-group .select2-container {
  flex: 1 !important;
  margin-bottom: 0 !important;
}

/* Match the exact height and padding of other form inputs */
#afsf-form .select2-container--default .select2-selection--single {
  height: 48px !important;
  padding: 0 !important;
  border: 2px solid #e1e8ed !important;
  border-radius: 8px !important;
  background: #ffffff !important;
  transition: all 0.3s ease !important;
  display: flex !important;
  align-items: center !important;
  box-sizing: border-box !important;
}

/* Ensure the dropdown arrow is positioned correctly */
#afsf-form
  .select2-container--default
  .select2-selection--single
  .select2-selection__arrow {
  position: absolute !important;
  right: 8px !important;
  top: 50% !important;
  transform: translateY(-50%) !important;
  width: 20px !important;
  height: 20px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

/* Ensure the text is positioned correctly */
#afsf-form
  .select2-container--default
  .select2-selection--single
  .select2-selection__rendered {
  padding: 12px 16px !important;
  padding-right: 40px !important;
  width: 100% !important;
  box-sizing: border-box !important;
  line-height: 1.4 !important;
}

/* Ensure the clear button is positioned correctly */
#afsf-form
  .select2-container--default
  .select2-selection--single
  .select2-selection__clear {
  position: absolute !important;
  right: 35px !important;
  top: 50% !important;
  transform: translateY(-50%) !important;
  font-size: 16px !important;
  color: #999999 !important;
  cursor: pointer !important;
  transition: color 0.3s ease !important;
}

#afsf-form
  .select2-container--default
  .select2-selection--single
  .select2-selection__clear:hover {
  color: #dc3545 !important;
}

/* Ensure the dropdown matches the form styling */
#afsf-form .select2-dropdown {
  border: 2px solid #e1e8ed !important;
  border-radius: 8px !important;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15) !important;
  margin-top: 4px !important;
  background: #ffffff !important;
  z-index: 999999 !important;
  position: absolute !important;
}

/* Fix z-index for all Select2 dropdowns */
.select2-dropdown {
  z-index: 999999 !important;
  position: absolute !important;
}

.select2-container--open .select2-dropdown {
  z-index: 999999 !important;
}

/* Ensure Select2 container has proper positioning */
.select2-container {
  position: relative !important;
  z-index: 1;
}

.select2-container--open {
  z-index: 999999 !important;
}

/* Fix positioning for form rows with Select2 */
.form-row .field-group .select2-container {
  position: relative !important;
  z-index: 1;
}

.form-row .field-group .select2-container--open {
  z-index: 999999 !important;
}

/* Ensure dropdown appears above all other elements */
.select2-results__options {
  z-index: 999999 !important;
}

/* Fix for step containers */
.step .select2-container--open {
  z-index: 999999 !important;
}

/* Additional z-index fixes */
.select2-container--default .select2-selection--single {
  position: relative;
  z-index: 1;
}

.select2-container--default.select2-container--open .select2-selection--single {
  z-index: 999999 !important;
}

/* Ensure proper stacking context for form elements */
.membership-form-container {
  position: relative;
  z-index: 1;
}

#afsf-form .step {
  position: relative;
  z-index: 1;
}

/* Force dropdown to appear above everything */
.select2-container--open {
  z-index: 999999 !important;
}

.select2-container--open .select2-dropdown {
  z-index: 999999 !important;
}

/* Fix for any potential overflow issues */
.select2-container {
  overflow: visible !important;
}

.select2-container--open {
  overflow: visible !important;
}

/* Ensure form elements don't interfere with dropdown */
.form-row {
  position: relative;
  z-index: 1;
}

.field-group {
  position: relative;
  z-index: 1;
}
