/**
 * @file
 * Custom styling for Select2 dropdowns in registration form.
 * Matches the modern registration form design.
 */

/* Select2 Container Styling - Updated to match form inputs */
.select2-container--default .select2-selection--single {
  height: auto;
  min-height: 48px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  background: #ffffff;
  transition: all 0.3s ease;
}

.select2-container--default .select2-selection--single:hover {
  border-color: #cbd5e0;
}

.select2-container--default.select2-container--focus .select2-selection--single,
.select2-container--default.select2-container--open .select2-selection--single {
  border-color: #0133a0;
  box-shadow: 0 0 0 4px rgba(1, 51, 160, 0.1);
  outline: none;
}

/* Selected Value Styling */
.select2-container--default .select2-selection--single .select2-selection__rendered {
  color: #1e293b;
  line-height: 1.5;
  padding-left: 0;
  font-size: 15px;
  font-weight: 400;
}

.select2-container--default .select2-selection--single .select2-selection__placeholder {
  color: #94a3b8;
  font-size: 15px;
}

/* Arrow Icon - Updated to match phone field design */
.select2-container--default .select2-selection--single .select2-selection__arrow {
  height: 100%;
  right: 12px;
  top: 0;
  display: flex;
  align-items: center;
}

.select2-container--default .select2-selection--single .select2-selection__arrow b {
  border-color: #64748b transparent transparent transparent;
  border-width: 6px 5px 0 5px;
  margin-left: -5px;
  margin-top: 0;
  transition: all 0.2s ease;
}

.select2-container--default.select2-container--open .select2-selection--single .select2-selection__arrow b {
  border-color: transparent transparent #0133a0 transparent;
  border-width: 0 5px 6px 5px;
  transform: rotate(180deg);
}

/* Dropdown Styling - Updated to match phone field */
.select2-container--default .select2-dropdown {
  border: 2px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  margin-top: 4px;
  overflow: hidden;
  padding: 0;
}

/* Search Box */
.select2-container--default .select2-search--dropdown {
  padding: 8px;
  background: #ffffff;
  border-bottom: 1px solid #e2e8f0;
  margin: 0;
}

.select2-container--default .select2-search--dropdown .select2-search__field {
  border: 2px solid #e2e8f0;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
  outline: none;
  transition: all 0.2s ease;
  width: 100%;
  margin: 0;
  box-sizing: border-box;
}

.select2-container--default .select2-search--dropdown .select2-search__field:focus {
  border-color: #0133a0;
  box-shadow: 0 0 0 3px rgba(1, 51, 160, 0.1);
}

/* Results List - Updated to match phone field */
.select2-container--default .select2-results__options {
  max-height: 250px;
  overflow-y: auto;
  padding: 4px 0;
  margin: 0;
}

.select2-container--default .select2-results__option {
  padding: 8px 12px;
  font-size: 14px;
  color: #334155;
  transition: all 0.2s ease;
  cursor: pointer;
  margin: 0;
  line-height: 1.4;
}

.select2-container--default .select2-results__option:hover,
.select2-container--default .select2-results__option--highlighted[aria-selected] {
  background-color: #f8fafc;
  color: #334155;
}

.select2-container--default .select2-results__option.select2-results__option--highlighted {
  background: #ebf8ff;
  color: #0133a0;
  font-weight: 500;
}

.select2-container--default .select2-results__option[aria-selected="true"] {
  background-color: #dbeafe;
  color: #0133a0;
  font-weight: 600;
}

.select2-container--default .select2-results__option[aria-selected="true"]:hover {
  background-color: #bfdbfe;
  color: #0133a0;
}

/* No Results Message */
.select2-container--default .select2-results__option--disabled {
  color: #a0aec0;
  font-style: italic;
}

/* Loading Message */
.select2-container--default .select2-results__message {
  color: #718096;
  padding: 12px 16px;
  font-size: 14px;
}

/* Clear Button (when allowClear is true) */
.select2-container--default .select2-selection--single .select2-selection__clear {
  color: #718096;
  cursor: pointer;
  float: right;
  font-size: 18px;
  font-weight: bold;
  margin-right: 10px;
  line-height: 27px;
  transition: color 0.2s ease;
}

.select2-container--default .select2-selection--single .select2-selection__clear:hover {
  color: #e53e3e;
}

/* Scrollbar Styling for Results - Updated to match phone field */
.select2-container--default .select2-results__options::-webkit-scrollbar {
  width: 8px;
}

.select2-container--default .select2-results__options::-webkit-scrollbar-track {
  background: #f8fafc;
  border-radius: 4px;
}

.select2-container--default .select2-results__options::-webkit-scrollbar-thumb {
  background: #cbd5e0;
  border-radius: 4px;
  transition: background 0.2s ease;
}

.select2-container--default .select2-results__options::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Error State (for Drupal form errors) - Updated colors */
.form-item--error .select2-container--default .select2-selection--single,
.form-item--error .select2-container--default .select2-selection--multiple {
  border-color: #ef4444 !important;
  background: #fef2f2 !important;
}

.form-item--error .select2-container--default.select2-container--focus .select2-selection--single,
.form-item--error .select2-container--default.select2-container--focus .select2-selection--multiple,
.form-item--error .select2-container--default.select2-container--open .select2-selection--single,
.form-item--error .select2-container--default.select2-container--open .select2-selection--multiple {
  border-color: #ef4444 !important;
  box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.1) !important;
}

/* Disabled State */
.select2-container--default .select2-selection--single.select2-selection--disabled {
  background-color: #f1f5f9;
  cursor: not-allowed;
  opacity: 0.6;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
  .select2-container--default .select2-selection--single {
    height: 44px;
  }
  
  .select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 44px;
    font-size: 14px;
  }
  
  .select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 44px;
  }
  
  .select2-container--default .select2-results__option {
    padding: 10px 14px;
  }
  
  .select2-container--default .select2-dropdown {
    max-height: 250px;
  }
}

/* Z-index for proper layering */
/* Hide the original select element when Select2 is initialized */
.select2-hidden-accessible,
select.select2-hidden-accessible,
select[class*="select2-hidden-accessible"] {
  position: absolute !important;
  width: 1px !important;
  height: 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;
  visibility: hidden !important;
  display: none !important;
}

/* Additional hiding for select elements that should be hidden */
select.searchable-select.select2-hidden-accessible,
select[data-once="select2-init"].select2-hidden-accessible {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
}

.select2-container {
  z-index: 999;
  width: 100% !important;
  max-width: 100%;
  box-sizing: border-box;
}

.select2-dropdown {
  z-index: 9999;
  box-sizing: border-box;
}

/* Animation for dropdown opening */
.select2-container--default.select2-container--open .select2-dropdown {
  animation: slideDown 0.2s ease;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================
   MULTI-SELECT STYLES
   ============================================ */

/* Multi-Select Container - Updated to match form design */
.select2-container--default .select2-selection--multiple {
  min-height: 48px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 8px 10px;
  background: #ffffff;
  transition: all 0.3s ease;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 0;
}

.select2-container--default .select2-selection--multiple:hover {
  border-color: #cbd5e0;
}

.select2-container--default.select2-container--focus .select2-selection--multiple,
.select2-container--default.select2-container--open .select2-selection--multiple {
  border-color: #0133a0;
  box-shadow: 0 0 0 4px rgba(1, 51, 160, 0.1);
  outline: none;
}

/* Selected Items (Tags/Chips) */
.select2-container--default .select2-selection--multiple .select2-selection__choice {
  background: linear-gradient(135deg, #015dd1 0%, #0133a0 100%);
  border: none;
  border-radius: 6px;
  color: #ffffff;
  padding: 8px 10px 8px 14px; /* top right bottom left - more padding on left, less on right for X button */
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 10px; /* Space between text and X button */
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(1, 93, 209, 0.15);
  flex-direction: row; /* Ensure horizontal layout */
}

.select2-container--default .select2-selection--multiple .select2-selection__choice:hover {
  background: linear-gradient(135deg, #0133a0 0%, #012a80 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 6px rgba(1, 93, 209, 0.2);
}

/* Remove Button for Selected Items */
.select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
  color: rgba(255, 255, 255, 0.9);
  font-size: 18px;
  font-weight: bold;
  margin: 0;
  padding: 0;
  order: 2; /* Remove button comes after text */
  cursor: pointer;
  border: none;
  background: none;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex-shrink: 0; /* Don't shrink the X button */
  position: absolute;
  top: 8px;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover {
  color: #ffffff;
  background-color: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
}

/* Choice Display Text */
.select2-container--default .select2-selection--multiple .select2-selection__choice__display {
  cursor: default;
  padding: 0;
  order: 1; /* Display text comes first */
  flex: 0 1 auto; /* Don't grow, can shrink, auto width */
}

/* Search Input in Multi-Select */
.select2-container--default .select2-selection--multiple .select2-search--inline {
  margin: 0;
  padding: 0;
  min-width: 100px; /* Ensure search field has minimum space */
  line-height: 1;
}

.select2-container--default .select2-selection--multiple .select2-search--inline .select2-search__field {
  border: none;
  font-size: 14px;
  color: #2d3748;
  padding: 6px 2px;
  margin: 0;
  outline: none;
  min-width: 100px;
  background: transparent;
  line-height: 1.4;
  height: auto;
}

.select2-container--default .select2-selection--multiple .select2-search--inline .select2-search__field::placeholder {
  color: #a0aec0;
  font-size: 14px;
}

/* Multi-Select Dropdown Options */
.select2-container--default .select2-results__option--selectable {
  position: relative;
  padding-left: 15px;
}

/* Checkbox styling for multi-select items */
.select2-container--default.select2-container--open .select2-selection--multiple .select2-results__option--selectable::before {
  content: '';
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  border: 2px solid #cbd5e0;
  border-radius: 4px;
  background: #ffffff;
  transition: all 0.2s ease;
}

.select2-container--default .select2-results__option[aria-selected="true"]::before {
  background: #015dd1;
  border-color: #015dd1;
  background-image: url('data:image/svg+xml;charset=UTF-8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12"><path fill="%23ffffff" d="M10.28 2.28L4.5 8.06 1.72 5.28a.75.75 0 0 0-1.06 1.06l3.25 3.25a.75.75 0 0 0 1.06 0l6.34-6.34a.75.75 0 0 0-1.06-1.06z"/></svg>');
  background-position: center;
  background-repeat: no-repeat;
}

/* Empty State for Multi-Select */
.select2-container--default .select2-selection--multiple.select2-selection--empty {
  min-height: 48px;
}

/* Disabled State for Multi-Select */
.select2-container--default .select2-selection--multiple.select2-selection--disabled {
  background-color: #edf2f7;
  cursor: not-allowed;
  opacity: 0.6;
}

.select2-container--default .select2-selection--multiple.select2-selection--disabled .select2-selection__choice {
  background: #cbd5e0;
  color: #718096;
}

.select2-container--default .select2-selection--multiple.select2-selection--disabled .select2-selection__choice__remove {
  display: none;
}


/* Mobile Responsiveness for Multi-Select */
@media (max-width: 768px) {
  .select2-container--default .select2-selection--multiple {
    min-height: 44px;
    padding: 8px 10px;
    gap: 6px;
  }
  
  .select2-container--default .select2-selection--multiple .select2-selection__choice {
    font-size: 12px;
    padding: 6px 8px 6px 12px;
    gap: 8px;
  }
  
  .select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
    width: 16px;
    height: 16px;
    font-size: 16px;
  }
  
  .select2-container--default .select2-selection--multiple .select2-search--inline .select2-search__field {
    font-size: 13px;
    min-width: 80px;
    padding: 6px 4px;
  }
  
  .select2-container--default .select2-selection--multiple .select2-selection__rendered {
    gap: 6px;
  }
}

/* Improved Multi-Select Dropdown */
.select2-container--default[dir="ltr"] .select2-selection--multiple .select2-selection__choice {
  float: none;
  margin: 2px 0; /* Small vertical margin for tag rows */
}

/* Ensure proper list rendering */
.select2-container--default .select2-selection--multiple .select2-selection__rendered {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 0;
  margin: 0;
  width: 100%;
  list-style: none;
}

/* Ensure each list item (tag) displays properly */
.select2-container--default .select2-selection--multiple .select2-selection__rendered > li {
  display: inline-flex;
  align-items: center;
}

/* Better spacing for multiple selections */
.select2-container--default .select2-selection--multiple:has(.select2-selection__choice) {
  padding: 10px 12px;
}

/* Placeholder styling when items are selected */
.select2-container--default .select2-selection--multiple:has(.select2-selection__choice) .select2-search__field::placeholder {
  font-size: 13px;
}

