/**
 * Select, NativeSelect, and Combobox styles
 * @countermeasure/web-components/primitives/select
 */

/* ==========================================================================
   Custom Select
   ========================================================================== */

.cmm-select {
  position: relative;
  display: inline-block;
  width: 100%;
}

.cmm-select--disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Trigger Button */

.cmm-select__trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 2.5rem;
  padding: 0.5rem 0.75rem;
  background-color: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  color: hsl(var(--foreground));
  font-size: 0.875rem;
  line-height: 1.5;
  cursor: pointer;
  transition: border-color var(--transition-fast),
    box-shadow var(--transition-fast);
  gap: 0.5rem;
  text-align: left;
}

.cmm-select__trigger:hover {
  border-color: hsl(var(--ring));
}

.cmm-select__trigger:focus-visible {
  outline: 2px solid hsl(var(--focus-ring));
  outline-offset: 2px;
}

.cmm-select__trigger--open {
  border-color: hsl(var(--ring));
}

/* Sizes */

.cmm-select--sm .cmm-select__trigger {
  min-height: 2rem;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
}

.cmm-select--lg .cmm-select__trigger {
  min-height: 3rem;
  padding: 0.625rem 1rem;
  font-size: 1rem;
}

/* Value & Placeholder */

.cmm-select__value {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cmm-select__placeholder {
  color: hsl(var(--muted-foreground));
}

/* Chevron */

.cmm-select__chevron {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  transition: transform var(--transition-fast);
  color: hsl(var(--muted-foreground));
}

.cmm-select__trigger--open .cmm-select__chevron {
  transform: rotate(180deg);
}

/* Dropdown Panel */

.cmm-select__dropdown {
  position: absolute;
  left: 0;
  right: 0;
  z-index: var(--z-dropdown);
  background-color: hsl(var(--popover));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  max-height: 16rem;
  overflow-y: auto;
  padding: 0.25rem;
}

.cmm-select__dropdown--below {
  top: calc(100% + 4px);
}

.cmm-select__dropdown--above {
  bottom: calc(100% + 4px);
}

/* Search Input */

.cmm-select__search-wrap {
  padding: 0.25rem;
  position: sticky;
  top: 0;
  background-color: hsl(var(--popover));
}

.cmm-select__search {
  width: 100%;
  padding: 0.375rem 0.5rem;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-sm);
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  font-size: 0.875rem;
  outline: none;
}

.cmm-select__search:focus {
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 2px hsl(var(--focus-ring) / 0.2);
}

/* Options */

.cmm-select__option {
  display: flex;
  align-items: center;
  padding: 0.375rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  color: hsl(var(--foreground));
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.cmm-select__option:hover {
  background-color: hsl(var(--accent));
}

.cmm-select__option--selected {
  background-color: hsl(var(--accent));
  font-weight: 500;
}

.cmm-select__option--highlighted {
  background-color: hsl(var(--accent));
  outline: 2px solid hsl(var(--focus-ring));
  outline-offset: -2px;
}

.cmm-select__option--disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Group Header */

.cmm-select__group-header {
  padding: 0.375rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: hsl(var(--muted-foreground));
  text-transform: uppercase;
  letter-spacing: 0.05em;
  pointer-events: none;
}

/* ==========================================================================
   Native Select
   ========================================================================== */

.cmm-native-select {
  position: relative;
  display: inline-block;
  width: 100%;
}

.cmm-native-select--disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.cmm-native-select__select {
  display: block;
  width: 100%;
  min-height: 2.5rem;
  padding: 0.5rem 2rem 0.5rem 0.75rem;
  appearance: none;
  background-color: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  color: hsl(var(--foreground));
  font-size: 0.875rem;
  line-height: 1.5;
  cursor: pointer;
  transition: border-color var(--transition-fast),
    box-shadow var(--transition-fast);
}

.cmm-native-select__select:hover {
  border-color: hsl(var(--ring));
}

.cmm-native-select__select:focus-visible {
  outline: 2px solid hsl(var(--focus-ring));
  outline-offset: 2px;
}

.cmm-native-select__chevron {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  pointer-events: none;
  color: hsl(var(--muted-foreground));
}

/* ==========================================================================
   Combobox
   ========================================================================== */

.cmm-combobox {
  position: relative;
  display: inline-block;
  width: 100%;
}

.cmm-combobox--disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.cmm-combobox__input {
  display: block;
  width: 100%;
  min-height: 2.5rem;
  padding: 0.5rem 0.75rem;
  background-color: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  color: hsl(var(--foreground));
  font-size: 0.875rem;
  line-height: 1.5;
  transition: border-color var(--transition-fast),
    box-shadow var(--transition-fast);
}

.cmm-combobox__input:hover {
  border-color: hsl(var(--ring));
}

.cmm-combobox__input:focus {
  outline: 2px solid hsl(var(--focus-ring));
  outline-offset: 2px;
  border-color: hsl(var(--ring));
}

.cmm-combobox__input::placeholder {
  color: hsl(var(--muted-foreground));
}

/* Combobox Dropdown */

.cmm-combobox__dropdown {
  position: absolute;
  left: 0;
  right: 0;
  z-index: var(--z-dropdown);
  background-color: hsl(var(--popover));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  max-height: 16rem;
  overflow-y: auto;
  padding: 0.25rem;
}

.cmm-combobox__dropdown--below {
  top: calc(100% + 4px);
}

.cmm-combobox__dropdown--above {
  bottom: calc(100% + 4px);
}

/* Combobox Options */

.cmm-combobox__option {
  display: flex;
  align-items: center;
  padding: 0.375rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  color: hsl(var(--foreground));
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.cmm-combobox__option:hover {
  background-color: hsl(var(--accent));
}

.cmm-combobox__option--selected {
  background-color: hsl(var(--accent));
  font-weight: 500;
}

.cmm-combobox__option--highlighted {
  background-color: hsl(var(--accent));
  outline: 2px solid hsl(var(--focus-ring));
  outline-offset: -2px;
}

.cmm-combobox__option--disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Create Option */

.cmm-combobox__create {
  color: hsl(var(--primary));
  font-style: italic;
}
