/* Select styles */
.select {
  @apply flex flex-col gap-1;

  &[data-invalid="true"],
  &[aria-invalid="true"] {
    [data-slot="description"] {
      @apply hidden;
    }
  }

  [data-slot="label"] {
    @apply w-fit;
  }
}

.select__trigger {
  @apply relative isolate inline-flex min-h-9 rounded-field border bg-field px-3 py-2 text-sm text-field-foreground shadow-field outline-none select-none no-highlight;

  /**
   * Transitions
   * CRITICAL: motion-reduce must be AFTER transition for correct override specificity
   */
  transition:
    background-color 150ms var(--ease-smooth),
    border-color 150ms var(--ease-smooth),
    box-shadow 150ms var(--ease-out);
  @apply motion-reduce:transition-none;

  /* Cursor */
  cursor: var(--cursor-interactive);

  border-width: var(--border-width-field);
  border-color: var(--field-border);

  /* Add inline-end padding when indicator is present */
  &:has(.select__indicator) {
    @apply pe-7;
  }

  /* Hover state */
  @media (hover: hover) {
    &:hover,
    &[data-hovered="true"] {
      @apply bg-field-hover;
      border-color: var(--field-border-hover);
    }
  }

  /* Focus visible state */
  &:focus-visible:not(:focus),
  &[data-focus-visible="true"] {
    @apply status-focused;
    border-color: var(--field-border-focus);
    background-color: var(--field-focus);
  }

  /* Focus state */
  &:focus,
  &[data-focus="true"] {
  }

  /* Invalid state */
  .select[data-invalid="true"] &,
  .select[aria-invalid="true"] & {
    @apply status-invalid-field;
    background-color: var(--field-focus);
  }

  /* Disabled state */
  &:disabled,
  &[data-disabled="true"],
  &[aria-disabled="true"] {
    @apply status-disabled;
  }
}

/* Variant property definitions */
.select--primary {
  /* Default styles */
}

.select--secondary .select__trigger {
  @apply shadow-none;
  background-color: var(--select-trigger-bg);

  --select-trigger-bg: var(--default);
  --select-trigger-bg-hover: var(--default-hover);
  --select-trigger-bg-focus: var(--default);

  @media (hover: hover) {
    &:hover,
    &[data-hovered="true"] {
      background-color: var(--select-trigger-bg-hover);
    }
  }

  &:focus-visible:not(:focus),
  &[data-focus-visible="true"] {
    background-color: var(--select-trigger-bg-focus);
  }

  &:focus,
  &[data-focus="true"] {
  }

  .select[data-invalid="true"] &,
  .select[aria-invalid="true"] & {
    background-color: var(--select-trigger-bg-focus);
  }
}

.select__value {
  @apply flex-1 text-start text-base wrap-break-word text-current sm:text-sm;

  &[data-placeholder="true"] {
    @apply text-field-placeholder;
  }

  /* Removes the list-box-item indicator element from the select value*/
  [data-slot="list-box-item-indicator"] {
    @apply hidden;
  }
}

.select__indicator {
  @apply absolute inset-y-0 end-2 my-auto flex shrink-0 items-center justify-center text-field-placeholder transition duration-150;

  &[data-open="true"] {
    @apply rotate-180;
  }

  &[data-slot="select-default-indicator"] {
    @apply size-4;
  }
}

/* Similar to popover content styles */
.select__popover {
  @apply min-w-(--trigger-width) origin-(--trigger-anchor-point) scroll-py-1 overflow-y-auto overscroll-contain bg-overlay p-0 text-sm scrollbar;
  border-radius: min(32px, var(--radius-3xl));
  box-shadow: var(--shadow-overlay);

  /* Focus state */
  &:focus-visible:not(:focus),
  &[data-focus-visible="true"] {
    @apply outline-none;
  }

  /* Entering animations */
  &[data-entering="true"] {
    @apply animate-in duration-150 ease-smooth fade-in-0 zoom-in-95;

    /* Placement-specific translations */
    &[data-placement="top"] {
      @apply slide-in-from-bottom-1;
    }

    &[data-placement="bottom"] {
      @apply slide-in-from-top-1;
    }

    &[data-placement="left"] {
      @apply slide-in-from-right-1;
    }

    &[data-placement="right"] {
      @apply slide-in-from-left-1;
    }
  }

  /* Exiting animations */
  &[data-exiting="true"] {
    @apply animate-out duration-100 ease-smooth zoom-out-95 fade-out;
  }

  &[data-exiting="true"],
  &[data-entering="true"] {
    @apply transition-[opacity,transform] will-change-[opacity,transform];
  }

  /* Arrow styling */
  & [data-slot="popover-overlay-arrow"] {
    fill: var(--overlay);
  }

  /* Arrow rotation based on placement */
  &[data-placement="bottom"] [data-slot="popover-overlay-arrow"] {
    rotate: 180deg;
  }

  &[data-placement="left"] [data-slot="popover-overlay-arrow"] {
    rotate: -90deg;
  }

  &[data-placement="right"] [data-slot="popover-overlay-arrow"] {
    rotate: 90deg;
  }

  /* Listbox styles */
  [data-slot="list-box"] {
    @apply p-1.5 outline-none;
  }

  [data-slot="list-box-item"] {
    @apply px-2.5;
  }

  /* As the popover closes fast in single-select mode, the default item indicator transition is not even visible - so we disable it only for single-select */
  [data-slot="list-box"]:not([aria-multiselectable="true"]) [data-slot="list-box-item-indicator"],
  [data-slot="list-box"]:not([aria-multiselectable="true"])
    [data-slot="list-box-item-indicator"]
    [data-slot="list-box-item-indicator--checkmark"] {
    @apply transition-none;
  }
}

/* Full width modifier */
.select--full-width {
  @apply w-full;
}

.select__trigger--full-width {
  @apply w-full;
}
