/**
 * Select2 Custom Styling for DompetTracker
 * Modern, clean aesthetics with full responsiveness
 */

/* Container */
.select2-container {
  box-sizing: border-box;
  display: inline-block;
  margin: 0;
  position: relative;
  vertical-align: middle;
  width: 100% !important;
}

/* Selection Field */
.select2-container .select2-selection--single {
  box-sizing: border-box;
  cursor: pointer;
  display: block;
  height: 42px;
  user-select: none;
  -webkit-user-select: none;
  background-color: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: #111827;
  transition: all 0.2s ease-in-out;
}

/* Hover State */
.select2-container .select2-selection--single:hover {
  border-color: #9ca3af;
}

/* Focus State */
.select2-container.select2-container--focus .select2-selection--single,
.select2-container--open .select2-selection--single {
  border-color: #059669;
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.1);
  outline: none;
}

/* Rendered Text */
.select2-container--default
  .select2-selection--single
  .select2-selection__rendered {
  color: #111827;
  line-height: 1.5rem;
  padding-left: 0;
  padding-right: 1.5rem;
}

/* Placeholder */
.select2-container--default
  .select2-selection--single
  .select2-selection__placeholder {
  color: #9ca3af;
}

/* Clear Button */
.select2-container--default
  .select2-selection--single
  .select2-selection__clear {
  color: #9ca3af;
  cursor: pointer;
  float: right;
  font-weight: 500;
  margin-right: 1.25rem;
  font-size: 1.125rem;
  line-height: 1.5rem;
  transition: color 0.15s ease;
}

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

/* Arrow Indicator */
.select2-container--default
  .select2-selection--single
  .select2-selection__arrow {
  height: 40px;
  position: absolute;
  right: 0.5rem;
  top: 0;
  width: 1.5rem;
}

.select2-container--default
  .select2-selection--single
  .select2-selection__arrow
  b {
  border-color: #6b7280 transparent transparent transparent;
  border-style: solid;
  border-width: 5px 5px 0 5px;
  height: 0;
  left: 50%;
  margin-left: -5px;
  margin-top: -2px;
  position: absolute;
  top: 50%;
  width: 0;
  transition: border-color 0.15s ease;
}

.select2-container--default.select2-container--open
  .select2-selection--single
  .select2-selection__arrow
  b {
  border-color: transparent transparent #6b7280 transparent;
  border-width: 0 5px 5px 5px;
}

/* Dropdown Menu */
.select2-container--default .select2-dropdown {
  background-color: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  box-shadow:
    0 10px 15px -3px rgba(0, 0, 0, 0.1),
    0 4px 6px -2px rgba(0, 0, 0, 0.05);
  margin-top: 0.25rem;
  overflow: hidden;
  z-index: 1050;
}

/* Search Field in Dropdown */
.select2-container--default .select2-search--dropdown .select2-search__field {
  background-color: #f9fafb;
  border: 1px solid #d1d5db;
  border-radius: 0.375rem;
  color: #111827;
  font-size: 0.875rem;
  padding: 0.5rem 0.75rem;
  width: 100%;
  transition: all 0.15s ease;
}

.select2-container--default
  .select2-search--dropdown
  .select2-search__field:focus {
  border-color: #059669;
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.1);
  outline: none;
}

/* Search Icon Placeholder */
.select2-container--default .select2-search--dropdown::before {
  content: "🔍";
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0.4;
  font-size: 0.875rem;
  pointer-events: none;
}

/* Results List */
.select2-container--default .select2-results > .select2-results__options {
  max-height: 280px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #d1d5db transparent;
}

.select2-container--default
  .select2-results
  > .select2-results__options::-webkit-scrollbar {
  width: 6px;
}

.select2-container--default
  .select2-results
  > .select2-results__options::-webkit-scrollbar-track {
  background: transparent;
}

.select2-container--default
  .select2-results
  > .select2-results__options::-webkit-scrollbar-thumb {
  background-color: #d1d5db;
  border-radius: 3px;
}

/* Individual Result Item */
.select2-container--default .select2-results__option {
  color: #374151;
  cursor: pointer;
  font-size: 0.875rem;
  line-height: 1.25rem;
  padding: 0.625rem 0.875rem;
  transition: all 0.15s ease;
  border-bottom: 1px solid #f3f4f6;
}

.select2-container--default .select2-results__option:last-child {
  border-bottom: none;
}

/* Hover State */
.select2-container--default
  .select2-results__option--highlighted[aria-selected] {
  background-color: #ecfdf5;
  color: #059669;
}

/* Selected State */
.select2-container--default .select2-results__option[aria-selected="true"] {
  background-color: #d1fae5;
  color: #047857;
  font-weight: 500;
}

.select2-option-row {
  align-items: center;
  display: flex;
  gap: 0.5rem;
  min-width: 0;
  width: 100%;
}

.select2-option-icon {
  flex: 0 0 auto;
  font-size: 1rem;
  line-height: 1;
}

.select2-option-text {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.select2-option-chip {
  flex: 0 0 auto;
  font-size: 0.68rem;
  padding: 0.125rem 0.375rem;
}

.select2-highlight {
  background: #fef3c7;
  border-radius: 0.2rem;
  color: #92400e;
  font-weight: 700;
  padding: 0 0.125rem;
}

/* Disabled State */
.select2-container--default
  .select2-results__option.select2-results__option--disabled {
  color: #9ca3af;
  cursor: not-allowed;
  background-color: #f9fafb;
}

/* Loading State */
.select2-container--default .select2-results__option.loading-results {
  color: #6b7280;
  font-style: italic;
  text-align: center;
  padding: 1rem;
}

/* No Results Message */
.select2-container--default .select2-results__message {
  color: #6b7280;
  font-size: 0.875rem;
  padding: 0.75rem;
  text-align: center;
  background-color: #f9fafb;
  border-radius: 0.375rem;
  margin: 0.5rem;
}

/* Optgroup Styling */
.select2-container--default .select2-results__group {
  color: #6b7280;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.025em;
  padding: 0.5rem 0.875rem;
  text-transform: uppercase;
  background-color: #f9fafb;
  border-bottom: 1px solid #e5e7eb;
}

/* Option within Optgroup */
.select2-container--default
  .select2-results__options--nested
  .select2-results__option {
  padding-left: 1.5rem;
}

/* Responsive Adjustments */
@media (max-width: 640px) {
  .select2-container .select2-selection--single {
    height: 44px;
    font-size: 16px; /* Prevents zoom on iOS */
    padding: 0.625rem 0.75rem;
  }

  .select2-container .select2-selection--single .select2-selection__arrow {
    height: 42px;
  }

  .select2-container--default .select2-results__option {
    padding: 0.75rem 1rem;
    font-size: 16px;
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .select2-container--default .select2-dropdown {
    border-radius: 0.75rem;
    margin-top: 0.5rem;
  }

  .select2-container--default .select2-search--dropdown .select2-search__field {
    font-size: 16px;
    padding: 0.75rem 1rem;
  }
}

/* Touch Device Optimizations */
@media (hover: none) and (pointer: coarse) {
  .select2-container .select2-selection--single {
    min-height: 44px;
  }

  .select2-container--default .select2-results__option {
    min-height: 44px;
    padding-top: 0.875rem;
    padding-bottom: 0.875rem;
  }
}

/* Dark Mode Support (if needed in future) */
@media (prefers-color-scheme: dark) {
  /* Can be implemented when dark mode is added to the app */
}

/* Animation for dropdown opening */
.select2-container--open .select2-dropdown {
  animation: select2-dropdown-fade-in 0.15s ease-out;
}

@keyframes select2-dropdown-fade-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Focus visible for accessibility */
.select2-container *:focus-visible {
  outline: 2px solid #059669;
  outline-offset: 2px;
}

/* Print styles */
@media print {
  .select2-container {
    display: none;
  }
}
