.custom-dropdown {
  position: relative;
  min-width: 0;
}

.custom-dropdown--sort {
  min-width: 12.5rem;
}

.custom-dropdown__trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  width: 100%;
  min-height: 44px;
  padding: 0.4rem 0.75rem 0.4rem 0.9rem;
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  background: var(--c-surface);
  color: var(--c-text);
  font: inherit;
  font-size: 16px;
  line-height: var(--lh-snug);
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

.custom-dropdown__label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-dropdown__chevron {
  flex-shrink: 0;
  color: var(--c-text-secondary);
  transition: transform var(--duration-ui) var(--ease-out);
}

.custom-dropdown.is-open {
  z-index: var(--z-dropdown);
}

.custom-dropdown.is-open .custom-dropdown__chevron {
  transform: rotate(180deg);
}

.custom-dropdown__trigger:focus-visible {
  outline: none;
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px rgba(var(--c-accent-rgb), 0.22);
}

.custom-dropdown.is-open .custom-dropdown__trigger {
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px rgba(var(--c-accent-rgb), 0.18);
}

.custom-dropdown__menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  left: 0;
  z-index: var(--z-dropdown);
  margin: 0;
  padding: var(--sp-1);
  list-style: none;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
  max-height: min(16rem, calc(100dvh - 8rem));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translate3d(0, -6px, 0);
  transition: opacity var(--duration-ui) var(--ease-out),
    transform var(--duration-ui) var(--ease-out),
    visibility var(--duration-ui) var(--ease-out);
}

.custom-dropdown.is-open .custom-dropdown__menu {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translate3d(0, 0, 0);
}

.custom-dropdown__option {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 44px;
  padding: 0.45rem 0.75rem;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--c-text);
  font: inherit;
  font-size: 16px;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--t-fast), color var(--t-fast);
}

.custom-dropdown__option.is-selected {
  background: var(--c-accent);
  color: var(--c-text-inverse);
  font-weight: var(--fw-semibold);
}

.custom-dropdown__option.is-selected:hover,
.custom-dropdown__option.is-selected:focus-visible {
  background: var(--c-accent-dark);
  color: var(--c-text-inverse);
}

@media (hover: hover) {
  .custom-dropdown__trigger:hover {
    border-color: var(--c-accent);
  }

  .custom-dropdown__option:hover,
  .custom-dropdown__option:focus-visible {
    background: var(--c-accent-bg);
    color: var(--c-accent-dark);
  }

  .custom-dropdown__option.is-selected:hover,
  .custom-dropdown__option.is-selected:focus-visible {
    background: var(--c-accent-dark);
    color: var(--c-text-inverse);
  }
}

@media (prefers-reduced-motion: reduce) {
  .custom-dropdown__trigger,
  .custom-dropdown__chevron,
  .custom-dropdown__menu,
  .custom-dropdown__option {
    transition: none;
    transform: none;
  }
}

@media (max-width: 899px) {
  .custom-dropdown--sort {
    min-width: 0;
    width: 100%;
  }
}
