/* --------------------------------

File#: 1_custom-select
Title: Custom Select
Descr: Custom Select Control
Usage: codyhouse.co/license

-------------------------------- */
:root {
  /* --default variation only 👇 */
  --select-icon-size: 16px;
  --select-icon-right-margin: 0.75rem;
  /* icon margin right */
  --select-text-icon-gap: 0.25rem;
  /* gap between text and icon */
}
@media (min-width: 64rem) {
  :root {
    --select-icon-right-margin: 1.125rem;
    --select-text-icon-gap: 0.375rem;
  }
}

.select {
  position: relative;
}

.select__input {
  width: 100%;
  height: 100%;
  padding-right: calc(var(--select-icon-size) + var(--select-icon-right-margin) + var(--select-text-icon-gap)) !important;
  user-select: none;
}

.select__icon {
  width: var(--select-icon-size);
  height: var(--select-icon-size);
  pointer-events: none;
  position: absolute;
  right: var(--select-icon-right-margin);
  top: 50%;
  transform: translateY(-50%);
}

/* --custom-dropdown */
:root {
  --select-dropdown-gap: 4px;
  /* distance between select control and custom dropdown */
}

.select__button {
  /* created in JS - custom select control */
  width: 100%;
}

.select__button[aria-expanded=true] {
  /* custom select control if dropdown = visible */
}

.select__dropdown {
  /* created in JS - custom select dropdown */
  position: absolute;
  left: 0;
  top: 100%;
  min-width: 200px;
  max-height: 1px; /* updated in JS */
  @apply bg-floor-light;
  @apply shadow-inner-md;
  @apply py-1 lg:py-1.5 px-0;
  @apply rounded;
  @apply z-5;
  margin-top: var(--select-dropdown-gap);
  margin-bottom: var(--select-dropdown-gap);
  overflow: auto;
  /* use rem units */
  @apply text-base;
  visibility: hidden;
  opacity: 0;
  transition: visibility 0s 0.2s, opacity 0.2s;
}

.select__dropdown--right {
  /* change dropdown position based on the available space */
  right: 0;
  left: auto;
}

.select__dropdown--up {
  bottom: 100%;
  top: auto;
}

.select__button[aria-expanded=true] + .select__dropdown {
  visibility: visible;
  opacity: 1;
  transition: visibility 0s, opacity 0.2s;
}

/* custom <optgroup> list - include all <option>s if no <optgroup> available  */
.select__list {
  list-style: none !important;
}

.select__list:not(:first-of-type) {
  @apply pt-1.5 lg:pt-2;
}

.select__list:not(:last-of-type) {
  @apply border-b border-contrast-higher/10;
  @apply pb-1.5 lg:pb-2;
}

.select__item {
  /* single item inside .select__list */
  display: flex;
  align-items: center;
  @apply py-1.5 lg:py-2 px-3 lg:px-5;
  @apply text-contrast-high;
  width: 100%;
  text-align: left;
  /* truncate text */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.select__item--optgroup {
  /* custom <optgroup> label */
  @apply text-xs;
  @apply text-contrast-medium;
}

.select__item--option {
  /* custom <option> label */
  cursor: pointer;
  transition: 0.2s;
}
.select__item--option:hover {
  @apply bg-contrast-higher/7;
}
.select__item--option:focus {
  outline: none;
  @apply bg-primary/15;
}
.select__item--option[aria-selected=true] {
  /* selected option */
  @apply bg-primary text-white;
  position: relative;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
.select__item--option[aria-selected=true]::after {
  /* check icon next to the selected language */
  content: "";
  display: block;
  height: 1em;
  width: 1em;
  margin-left: auto;
  background-color: currentColor;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpolyline stroke-width='2' stroke='%23ffffff' fill='none' stroke-linecap='round' stroke-linejoin='round' points='1,9 5,13 15,3 '/%3E%3C/svg%3E");mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpolyline stroke-width='2' stroke='%23ffffff' fill='none' stroke-linecap='round' stroke-linejoin='round' points='1,9 5,13 15,3 '/%3E%3C/svg%3E");
}
.select__item--option[aria-selected=true]:focus {
  box-shadow: inset 0 0 0 2px hsl(var(--color-primary-dark));
}
.select__item--option[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}