/* =========================================
   CUSTOM SELECT DROPDOWN - ATOMIC LAB THEME
   ========================================= */

/* Hide the original select when custom styling is active */
.custom-select-wrapper {
  position: relative;
  display: inline-block;
  width: 100%;
}

.custom-select-wrapper .original-select {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  z-index: -1;
}

/* Custom select button */
.custom-select-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--color-surface-primary);
  border: 1px solid var(--color-surface-tertiary);
  border-radius: var(--radius-md);
  color: var(--color-text-primary);
  font-family: var(--font-secondary);
  font-size: var(--font-size-sm);
  font-weight: var(--font-regular);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
  box-shadow: var(--shadow-sm);
  min-height: 2.75rem;
  box-sizing: border-box;
}

.custom-select-button:hover {
  background: var(--color-surface-secondary);
  border-color: var(--color-brand-primary);
  box-shadow: 0 0 0 1px var(--color-brand-primary), var(--shadow-md);
  transform: translateY(-1px);
}

.custom-select-button:focus,
.custom-select-button.active {
  background: var(--color-surface-secondary);
  border-color: var(--color-brand-primary);
  box-shadow: 0 0 0 2px var(--color-brand-primary), var(--shadow-lg);
  outline: none;
}

.custom-select-button.disabled {
  background: var(--color-surface-primary);
  border-color: var(--color-surface-tertiary);
  color: var(--color-text-disabled);
  cursor: not-allowed;
  opacity: 0.6;
}

/* Select text */
.custom-select-text {
  flex: 1;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.custom-select-text.placeholder {
  color: var(--color-text-secondary);
  font-style: italic;
}

/* Dropdown arrow */
.custom-select-arrow {
  width: 1rem;
  height: 1rem;
  margin-left: 0.5rem;
  transition: transform var(--duration-fast) var(--ease-out);
  flex-shrink: 0;
}

.custom-select-arrow svg {
  width: 100%;
  height: 100%;
  stroke: var(--color-text-secondary);
  transition: stroke var(--duration-fast) var(--ease-out);
}

.custom-select-button:hover .custom-select-arrow svg {
  stroke: var(--color-brand-primary);
}

.custom-select-button.active .custom-select-arrow {
  transform: rotate(180deg);
}

.custom-select-button.active .custom-select-arrow svg {
  stroke: var(--color-brand-primary);
}

/* Dropdown menu */
.custom-select-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--color-surface-primary);
  border: 1px solid var(--color-brand-primary);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xl);
  z-index: var(--z-dropdown);
  max-height: 300px;
  overflow-y: auto;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all var(--duration-fast) var(--ease-out);
  margin-top: 0.25rem;
}

.custom-select-dropdown.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* Dropdown options */
.custom-option {
  padding: 0.75rem 1rem;
  color: var(--color-text-primary);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
  border-bottom: 1px solid var(--color-surface-tertiary);
  position: relative;
  display: flex;
  align-items: center;
  font-family: var(--font-secondary);
  font-size: var(--font-size-sm);
  line-height: 1.5;
}

.custom-option:last-child {
  border-bottom: none;
}

.custom-option:hover {
  background: var(--color-surface-hover);
  color: var(--color-brand-primary);
}

.custom-option:focus {
  background: var(--color-surface-hover);
  color: var(--color-brand-primary);
  outline: 2px solid var(--color-brand-primary);
  outline-offset: -2px;
}

.custom-option.selected {
  background: var(--color-brand-primary);
  color: var(--color-text-on-brand);
  font-weight: var(--font-medium);
}

.custom-option.placeholder {
  color: var(--color-text-secondary);
  font-style: italic;
}

/* Category-specific styling */
.custom-option[data-category*="alkali"]:not(.placeholder) {
  border-left: 3px solid var(--color-alkali);
  background: linear-gradient(90deg, rgba(255, 23, 68, 0.1) 0%, transparent 5%);
}

.custom-option[data-category*="alkaline"]:not(.placeholder) {
  border-left: 3px solid var(--color-alkaline);
  background: linear-gradient(90deg, rgba(255, 107, 0, 0.1) 0%, transparent 5%);
}

.custom-option[data-category*="transition"]:not(.placeholder) {
  border-left: 3px solid var(--color-transition);
  background: linear-gradient(90deg, rgba(0, 188, 212, 0.1) 0%, transparent 5%);
}

.custom-option[data-category*="noble"]:not(.placeholder) {
  border-left: 3px solid var(--color-brand-secondary);
  background: linear-gradient(90deg, rgba(189, 0, 255, 0.1) 0%, transparent 5%);
}

.custom-option[data-category*="halogen"]:not(.placeholder) {
  border-left: 3px solid var(--color-brand-tertiary);
  background: linear-gradient(90deg, rgba(0, 255, 136, 0.1) 0%, transparent 5%);
}

.custom-option[data-category*="lanthanide"]:not(.placeholder),
.custom-option[data-category*="actinide"]:not(.placeholder) {
  border-left: 3px solid var(--color-brand-accent);
  background: linear-gradient(90deg, rgba(255, 107, 0, 0.1) 0%, transparent 5%);
}

/* Scrollbar styling for dropdown */
.custom-select-dropdown::-webkit-scrollbar {
  width: 6px;
}

.custom-select-dropdown::-webkit-scrollbar-track {
  background: var(--color-surface-secondary);
  border-radius: var(--radius-sm);
}

.custom-select-dropdown::-webkit-scrollbar-thumb {
  background: var(--color-surface-tertiary);
  border-radius: var(--radius-sm);
}

.custom-select-dropdown::-webkit-scrollbar-thumb:hover {
  background: var(--color-brand-primary);
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .custom-select-button {
    padding: 0.875rem 1.125rem;
    min-height: 3rem;
    font-size: var(--font-size-base);
  }
  
  .custom-option {
    padding: 1rem 1.25rem;
    font-size: var(--font-size-base);
  }
  
  .custom-select-dropdown {
    max-height: 250px;
  }
}

/* Accessibility enhancements */
@media (prefers-reduced-motion: reduce) {
  .custom-select-button,
  .custom-select-arrow,
  .custom-select-dropdown,
  .custom-option {
    transition: none;
  }
  
  .custom-select-button:hover {
    transform: none;
  }
}

/* High contrast mode */
@media (prefers-contrast: high) {
  .custom-select-button {
    border-width: 2px;
  }
  
  .custom-select-button:focus,
  .custom-select-button.active {
    box-shadow: 0 0 0 3px var(--color-brand-primary);
  }
  
  .custom-option {
    border-bottom-width: 2px;
  }
  
  .custom-option:focus {
    outline-width: 3px;
  }
}

/* Dark theme specific adjustments */
.dark-theme .custom-select-button,
[data-theme="dark"] .custom-select-button {
  background: var(--color-surface-primary);
  border-color: var(--color-surface-tertiary);
  color: var(--color-text-primary);
}

.dark-theme .custom-select-dropdown,
[data-theme="dark"] .custom-select-dropdown {
  background: var(--color-surface-primary);
  border-color: var(--color-brand-primary);
}

.dark-theme .custom-option,
[data-theme="dark"] .custom-option {
  background: transparent;
  color: var(--color-text-primary);
  border-color: var(--color-surface-tertiary);
}

/* Animation classes */
.custom-select-fade-in {
  animation: customSelectFadeIn var(--duration-fast) var(--ease-out);
}

.custom-select-fade-out {
  animation: customSelectFadeOut var(--duration-fast) var(--ease-out);
}

@keyframes customSelectFadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes customSelectFadeOut {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-10px);
  }
}

/* Loading state */
.custom-select-button.loading {
  opacity: 0.7;
  pointer-events: none;
}

.custom-select-button.loading .custom-select-arrow {
  animation: customSelectSpin 1s linear infinite;
}

@keyframes customSelectSpin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}