/**
 * Select2 Custom Styling for Modern Weather App
 * Overrides default Select2 styles to match the modern design system
 */

/* ============================================
   GLOBAL TEXT COLOR FIX
   ============================================ */

/* Force visible text color on all Select2 elements */
.select2-container,
.select2-dropdown,
.select2-results,
.select2-results__option,
.select2-search__field {
  color: #212529 !important;
}

/* Ensure dropdown options have proper text color */
.select2-nav-dropdown .select2-results__option {
  color: #212529 !important;
}

.select2-nav-dropdown .select2-results__option--highlighted[aria-selected] {
  color: #212529 !important;
}

.select2-nav-dropdown .select2-results__option[aria-selected="true"] {
  color: white !important;
}

/* ============================================
   SELECT2 CONTAINER & SELECTION
   ============================================ */

/* Main container */
.select2-container {
  font-family: var(--font-primary);
  font-size: var(--text-base);
}

/* Selection box (the main visible element) */
.select2-container--default .select2-selection--single {
  background-color: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius-md);
  padding: var(--space-1-5) var(--space-2);
  height: auto;
  min-height: 44px; /* Touch-friendly */
  transition: var(--transition-normal);
  outline: none;
}

/* Selection box hover state */
.select2-container--default .select2-selection--single:hover {
  background-color: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.4);
}

/* Selection box focus state */
.select2-container--default.select2-container--focus .select2-selection--single,
.select2-container--default.select2-container--open .select2-selection--single {
  border-color: var(--primary-blue);
  box-shadow: 0 0 0 4px rgba(74, 144, 226, 0.1);
  background-color: rgba(255, 255, 255, 0.3);
}

/* Selected text */
.select2-container--default
  .select2-selection--single
  .select2-selection__rendered {
  color: white;
  line-height: normal;
  padding: 0;
  font-weight: var(--font-medium);
  text-shadow: var(--text-shadow-sm);
}

/* Placeholder text */
.select2-container--default
  .select2-selection--single
  .select2-selection__placeholder {
  color: rgba(255, 255, 255, 0.9);
  font-weight: var(--font-regular);
}

/* Arrow indicator */
.select2-container--default
  .select2-selection--single
  .select2-selection__arrow {
  height: 100%;
  right: var(--space-2);
  top: 0;
}

.select2-container--default
  .select2-selection--single
  .select2-selection__arrow
  b {
  border-color: white transparent transparent transparent;
  border-width: 6px 5px 0 5px;
  margin-left: -5px;
  margin-top: -3px;
}

.select2-container--default.select2-container--open
  .select2-selection--single
  .select2-selection__arrow
  b {
  border-color: transparent transparent white transparent;
  border-width: 0 5px 6px 5px;
}

/* ============================================
   SELECT2 DROPDOWN
   ============================================ */

/* Dropdown container */
.select2-dropdown {
  background-color: white;
  border: 1px solid #dee2e6;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  color: #212529;
}

/* Modern dropdown class */
.select2-modern-dropdown {
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xl);
  animation: fadeInSlideDown var(--duration-medium) var(--ease-out);
}

@keyframes fadeInSlideDown {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Search box */
.select2-search--dropdown {
  padding: var(--space-2);
  background-color: var(--gray-50);
  border-bottom: 1px solid var(--border-light);
}

.select2-search--dropdown .select2-search__field {
  background-color: white;
  border: 2px solid #dee2e6;
  border-radius: var(--radius-sm);
  padding: var(--space-1-5) var(--space-2);
  font-family: var(--font-primary);
  font-size: var(--text-sm);
  color: #212529 !important;
  outline: none;
  transition: var(--transition-normal);
  width: 100%;
}

.select2-search--dropdown .select2-search__field:focus {
  border-color: var(--primary-blue);
  box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
}

/* Results container */
.select2-results {
  max-height: 320px;
  overflow-y: auto;
}

/* Custom scrollbar for results */
.select2-results::-webkit-scrollbar {
  width: 8px;
}

.select2-results::-webkit-scrollbar-track {
  background: var(--gray-50);
}

.select2-results::-webkit-scrollbar-thumb {
  background: var(--gray-300);
  border-radius: var(--radius-full);
}

.select2-results::-webkit-scrollbar-thumb:hover {
  background: var(--gray-400);
}

/* Results list */
.select2-results__options {
  padding: var(--space-1);
}

/* Individual result item */
.select2-results__option {
  padding: var(--space-2) var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  color: #212529 !important;
  cursor: pointer;
  transition: var(--transition-fast);
  margin-bottom: var(--space-0-5);
  background-color: transparent;
}

/* Result item hover state */
.select2-results__option--highlighted[aria-selected] {
  background-color: #f8f9fa;
  color: #212529 !important;
}

/* Result item selected state */
.select2-results__option[aria-selected="true"] {
  background-color: var(--primary-blue);

  font-weight: var(--font-medium);
}

.select2-results__option[aria-selected="true"]:hover {
  background-color: var(--primary-blue-dark);
}

/* No results message */
.select2-results__message {
  padding: var(--space-3) var(--space-2);
  text-align: center;
  color: #6c757d !important;
  font-size: var(--text-sm);
}

/* ============================================
   NAVIGATION SELECT2 STYLING
   ============================================ */

/* Navigation select elements */
.nav-select {
  min-width: auto;
  margin: 0;
  border: none;
  background: transparent;
}

/* Navigation select container */
.navbar .select2-container {
  margin: 0;
}

/* Navigation selection box - styled like nav links */
.select2-nav-dropdown ~ .select2-container--default .select2-selection--single,
.navbar .select2-container--default .select2-selection--single {
  background-color: transparent;
  border: none;
  color: #6c757d;
  padding: 8px 16px;
  min-height: auto;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  transition: all 200ms ease;
}

.navbar .select2-container--default .select2-selection--single:hover {
  background-color: #f8f9fa;
  color: #212529;
  border: none;
}

.navbar
  .select2-container--default.select2-container--focus
  .select2-selection--single,
.navbar
  .select2-container--default.select2-container--open
  .select2-selection--single {
  background-color: #f8f9fa;
  color: #212529;
  border: none;
  box-shadow: none;
  outline: 2px solid #4a90e2;
  outline-offset: 2px;
}

.navbar
  .select2-container--default
  .select2-selection--single
  .select2-selection__rendered {
  color: inherit;
  text-shadow: none;
  padding: 0;
  line-height: normal;
  font-weight: 500;
}

.navbar
  .select2-container--default
  .select2-selection--single
  .select2-selection__placeholder {
  color: #6c757d;
  font-weight: 500;
}

/* Arrow styled like dropdown toggle */
.navbar
  .select2-container--default
  .select2-selection--single
  .select2-selection__arrow {
  height: 100%;
  right: 16px;
  width: auto;
}

.navbar
  .select2-container--default
  .select2-selection--single
  .select2-selection__arrow
  b {
  border-color: currentColor transparent transparent transparent;
  border-width: 4px 4px 0 4px;
  margin-left: 4px;
  margin-top: -2px;
  transition: transform 200ms ease;
}

.navbar
  .select2-container--default.select2-container--open
  .select2-selection--single
  .select2-selection__arrow
  b {
  border-color: transparent transparent currentColor transparent;
  border-width: 0 4px 4px 4px;
  transform: rotate(0deg);
}


/* ============================================
   WEATHER CARD SELECT2 STYLING
   ============================================ */

/* Weather card city selector */
.weather-card .select2-container {
  width: 100% !important;
  margin-bottom: var(--space-4);
}

.weather-card .select2-container--default .select2-selection--single {
  background-color: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.weather-card .select2-container--default .select2-selection--single:hover {
  background-color: rgba(255, 255, 255, 0.3);
}

/* ============================================
   RESPONSIVE BEHAVIOR
   ============================================ */

/* Mobile optimizations */
@media (max-width: 767px) {
  /* Larger touch targets on mobile */
  .select2-container--default .select2-selection--single {
    min-height: 48px;
    padding: var(--space-2);
  }

  /* Full width on mobile */
  .nav-select,
  .navbar .select2-container {
    width: 100%;
    margin: 4px 0;
  }

  /* Mobile nav select styling - like mobile nav links */
  .navbar .select2-container--default .select2-selection--single {
    padding: 16px 24px;
    font-size: 16px;
    text-align: left;
  }

  .navbar
    .select2-container--default
    .select2-selection--single
    .select2-selection__arrow {
    right: 24px;
  }

  /* Adjust dropdown height for mobile */
  .select2-results {
    max-height: 240px;
  }

  /* Larger text on mobile for readability */
  .select2-results__option {
    padding: var(--space-2-5) var(--space-2);
    font-size: var(--text-base);
    min-height: 48px; /* Touch-friendly */
    display: flex;
    align-items: center;
  }

  /* Larger search input on mobile */
  .select2-search--dropdown .select2-search__field {
    font-size: var(--text-base);
    padding: var(--space-2);
    min-height: 48px;
  }

  /* Mobile dropdown positioning */
  .select2-mobile .select2-dropdown {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    width: 90vw !important;
    max-width: 400px;
    max-height: 70vh;
    z-index: var(--z-modal);
  }

  /* Mobile dropdown backdrop */
  .select2-container--open ~ .select2-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: calc(var(--z-modal) - 1);
  }

  /* Prevent body scroll when dropdown is open on mobile */
  body.select2-mobile-open {
    overflow: hidden;
  }
}

/* Tablet adjustments */
@media (min-width: 768px) and (max-width: 1023px) {
  .nav-select,
  .navbar .select2-container {
    min-width: auto;
  }

  .navbar .select2-container--default .select2-selection--single {
    padding: 8px 12px;
    font-size: 13px;
  }

  .navbar
    .select2-container--default
    .select2-selection--single
    .select2-selection__arrow {
    right: 12px;
  }
}

/* Desktop adjustments */
@media (min-width: 1024px) {
  .nav-select,
  .navbar .select2-container {
    min-width: 160px;
  }

  /* Enable horizontal scrolling for long lists on desktop */
  .select2-results {
    max-height: 360px;
  }
}

/* ============================================
   ACCESSIBILITY ENHANCEMENTS
   ============================================ */

/* Focus visible for keyboard navigation */
.select2-container--default .select2-selection--single:focus,
.select2-container--default .select2-selection--single:focus-visible {
  outline: 2px solid var(--primary-blue);
  outline-offset: 2px;
  border-color: var(--primary-blue);
}

.select2-results__option:focus,
.select2-results__option:focus-visible {
  outline: 2px solid var(--primary-blue);
  outline-offset: -2px;
  background-color: var(--gray-50);
}

/* Ensure focus is visible when navigating with keyboard */
.select2-container--default.select2-container--focus
  .select2-selection--single {
  outline: 2px solid var(--primary-blue);
  outline-offset: 2px;
}

/* Screen reader only text */
.select2-keyboard-help,
.sr-only,
.visually-hidden {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* Skip to content for keyboard users */
.select2-skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--primary-blue);
  color: white;
  padding: var(--space-2);
  text-decoration: none;
  border-radius: var(--radius-sm);
  z-index: var(--z-tooltip);
}

.select2-skip-link:focus {
  top: 0;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .select2-container--default .select2-selection--single {
    border-width: 2px;
    border-color: currentColor;
  }

  .select2-results__option[aria-selected="true"] {
    border: 2px solid var(--primary-blue);
    background-color: var(--primary-blue);
  }

  .select2-container--default .select2-selection--single:focus,
  .select2-container--default .select2-selection--single:focus-visible {
    outline-width: 3px;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .select2-modern-dropdown {
    animation: none;
  }

  .select2-results__option,
  .select2-container--default .select2-selection--single {
    transition: none;
  }

  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Force text color in all dropdown states */
.select2-dropdown .select2-results__option,
.select2-dropdown .select2-results__option span {
  color: inherit;
}

.select2-dropdown .select2-results__option[aria-selected="true"],
.select2-dropdown .select2-results__option[aria-selected="true"] span {
  color: white !important;
}

/* Improve visibility of selected option */
.select2-results__option[aria-selected="true"]::before {
  content: "✓ ";
  font-weight: var(--font-bold);
  margin-right: var(--space-1);
}

/* Focus indicator for dropdown items */
.select2-results__option[aria-selected]:focus {
  box-shadow: inset 0 0 0 2px var(--primary-blue);
}

/* Keyboard navigation hint */
.select2-dropdown::after {
  content: "";
  display: block;
  height: 0;
  overflow: hidden;
}

/* Ensure dropdown is announced to screen readers */
.select2-dropdown[aria-hidden="false"] {
  visibility: visible;
}

.select2-dropdown[aria-hidden="true"] {
  visibility: hidden;
}

/* ============================================
   LOADING STATE
   ============================================ */

.select2-container--default .select2-results__option--loading {
  padding: var(--space-3) var(--space-2);
  text-align: center;
  color: var(--text-secondary);
  font-style: italic;
}

/* ============================================
   DISABLED STATE
   ============================================ */

.select2-container--default.select2-container--disabled
  .select2-selection--single {
  background-color: var(--gray-100);
  border-color: var(--border-light);
  cursor: not-allowed;
  opacity: 0.6;
}

.select2-container--default.select2-container--disabled
  .select2-selection--single
  .select2-selection__rendered {
  color: var(--text-tertiary);
}
