/* Progressive native-select enhancement. The original select remains the
   fallback and form control; only the JS-enhanced wrapper hides it visually. */
:root,
.themed-select,
.themed-select__popover {
  --themed-select-surface: var(--theme-surface-bg, var(--color-bg-card, #ffffff));
  --themed-select-surface-raised: var(--theme-surface-bg, var(--color-bg-card, #ffffff));
  --themed-select-text: var(--theme-text-primary, var(--color-text-primary, #263238));
  --themed-select-muted: var(--color-text-secondary, #667085);
  --themed-select-border: var(--color-border, #cbd5e1);
  --themed-select-hover: var(--color-bg-secondary, #f1f5f9);
  --themed-select-selected: var(--color-bg-tertiary, #e8edf2);
  --themed-select-accent: var(--theme-accent, var(--theme-primary, #475569));
  --themed-select-danger: var(--color-danger, #a4312b);
}

@supports (color: color-mix(in srgb, black, white)) {
  :root,
  .themed-select,
  .themed-select__popover {
    --themed-select-surface-raised: color-mix(in srgb, var(--theme-surface-bg, var(--color-bg-card, #ffffff)) 96%, #ffffff);
    --themed-select-muted: color-mix(in srgb, var(--theme-text-primary, var(--color-text-primary, #263238)) 68%, var(--theme-surface-bg, var(--color-bg-card, #ffffff)));
    --themed-select-border: color-mix(in srgb, var(--theme-text-primary, var(--color-text-primary, #263238)) 18%, var(--theme-surface-bg, var(--color-bg-card, #ffffff)));
    --themed-select-hover: color-mix(in srgb, var(--theme-accent, var(--theme-primary, #475569)) 8%, var(--theme-surface-bg, var(--color-bg-card, #ffffff)));
    --themed-select-selected: color-mix(in srgb, var(--theme-accent, var(--theme-primary, #475569)) 15%, var(--theme-surface-bg, var(--color-bg-card, #ffffff)));
  }
}

/* Beauty storefront & Beauty admin derive all colors from active theme variables
   so BoundMerchantDesign custom palettes and all 4 presets render natively. */
body[data-storefront-style="beauty"],
body[data-storefront-style="beauty"] .themed-select,
body[data-storefront-style="beauty"] .themed-select__popover,
body.admin-body.admin-beauty-theme,
body.admin-body.admin-beauty-theme .themed-select,
body.admin-body.admin-beauty-theme .themed-select__popover {
  --themed-select-surface: var(--theme-surface-bg, var(--atelier-paper, var(--color-bg-card, #ffffff)));
  --themed-select-surface-raised: var(--theme-surface-bg, var(--atelier-paper, var(--color-bg-card, #ffffff)));
  --themed-select-text: var(--theme-text-primary, var(--atelier-ink, var(--color-text-primary, #263238)));
  --themed-select-accent: var(--theme-accent, var(--atelier-action, var(--theme-primary, #475569)));
  --themed-select-border: var(--atelier-line, var(--color-border, #cbd5e1));
  --themed-select-danger: var(--color-danger, #a4312b);
}

@supports (color: color-mix(in srgb, black, white)) {
  body[data-storefront-style="beauty"],
  body[data-storefront-style="beauty"] .themed-select,
  body[data-storefront-style="beauty"] .themed-select__popover,
  body.admin-body.admin-beauty-theme,
  body.admin-body.admin-beauty-theme .themed-select,
  body.admin-body.admin-beauty-theme .themed-select__popover {
    --themed-select-surface-raised: color-mix(in srgb, var(--themed-select-surface) 97%, #ffffff);
    --themed-select-muted: color-mix(in srgb, var(--themed-select-text) 68%, var(--themed-select-surface));
    --themed-select-border: var(--atelier-line, color-mix(in srgb, var(--themed-select-text) 20%, var(--themed-select-surface)));
    --themed-select-hover: color-mix(in srgb, var(--themed-select-accent) 9%, var(--themed-select-surface));
    --themed-select-selected: color-mix(in srgb, var(--themed-select-accent) 16%, var(--themed-select-surface));
  }
}

.themed-select {
  position: relative;
  display: block;
  width: 100%;
  min-width: 0;
  color: var(--themed-select-text);
  font-family: var(--font-family-primary, inherit);
}

.themed-select[hidden] {
  display: none !important;
}

/* JS-off fallback for all ordinary native selects, including controls the
   enhancer intentionally leaves alone. Keep option lists native/keyboardable. */
select:not(.themed-select__native):not([multiple]):not([size]:not([size="1"]):not([size="0"])) {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  box-sizing: border-box;
  padding: 10px 38px 10px 12px;
  border: 1px solid var(--themed-select-border);
  border-radius: 8px;
  background-color: var(--themed-select-surface);
  color: var(--themed-select-text);
  font-family: var(--font-family-primary, inherit);
  font-size: 16px;
  line-height: 1.4;
  appearance: auto;
  -webkit-appearance: menulist;
}

select[multiple],
select[size]:not([size="1"]):not([size="0"]) {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 9rem;
  height: auto;
  box-sizing: border-box;
  padding: 6px;
  border: 1px solid var(--themed-select-border);
  border-radius: 8px;
  background-color: var(--themed-select-surface);
  color: var(--themed-select-text);
  font-family: var(--font-family-primary, inherit);
  font-size: 16px;
  line-height: 1.4;
  appearance: auto;
  -webkit-appearance: listbox;
  overflow: auto;
}

select[multiple] option:checked,
select[size]:not([size="1"]):not([size="0"]) option:checked {
  background-color: var(--themed-select-selected);
  color: var(--themed-select-text);
}

select[multiple] option:disabled,
select[size]:not([size="1"]):not([size="0"]) option:disabled {
  color: var(--themed-select-muted);
}

/* Native fallback: keep the browser's own picker and keyboard behavior when
   JavaScript is unavailable or enhancement has not completed. */
.themed-select:not([data-enhanced="true"]) .themed-select__native:not([multiple]):not([size]:not([size="1"]):not([size="0"])) {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  box-sizing: border-box;
  padding: 10px 38px 10px 12px;
  border: 1px solid var(--themed-select-border);
  border-radius: 8px;
  background-color: var(--themed-select-surface);
  color: var(--themed-select-text);
  font: inherit;
  font-size: 16px;
  line-height: 1.4;
  appearance: auto;
  -webkit-appearance: menulist;
}

.themed-select .themed-select__native[multiple],
.themed-select .themed-select__native[size]:not([size="1"]):not([size="0"]) {
  display: block !important;
  width: 100%;
  box-sizing: border-box;
  min-height: 9rem;
  height: auto;
  padding: 6px;
  border: 1px solid var(--themed-select-border);
  border-radius: 8px;
  background-color: var(--themed-select-surface);
  color: var(--themed-select-text);
  font-size: 16px;
  appearance: auto;
  -webkit-appearance: listbox;
}

.themed-select[data-enhanced="true"] .themed-select__native:not([multiple]):not([size]:not([size="1"]):not([size="0"])) {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
  border: 0 !important;
  pointer-events: none !important;
}

.themed-select__trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  box-sizing: border-box;
  padding: 10px 12px;
  border: 1px solid var(--themed-select-border);
  border-radius: 8px;
  background: var(--themed-select-surface);
  color: var(--themed-select-text);
  font: inherit;
  font-size: 16px;
  line-height: 1.4;
  text-align: start;
  cursor: pointer;
  transition: background-color 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.themed-select__trigger:hover:not(:disabled) {
  border-color: var(--themed-select-accent);
  background: var(--themed-select-hover);
}

.themed-select__trigger:focus-visible,
.themed-select__search:focus-visible,
.themed-select__option:focus-visible {
  outline: 3px solid var(--themed-select-accent);
  outline-offset: 2px;
}

.themed-select__value {
  display: block;
  min-width: 0;
  overflow: hidden;
  color: inherit;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.themed-select__value:empty::before {
  content: attr(data-placeholder);
  color: var(--themed-select-muted);
}

.themed-select__chevron {
  display: block;
  flex: 0 0 12px;
  width: 12px;
  height: 12px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  color: var(--themed-select-muted);
  transform: rotate(45deg) translateY(-2px);
  transition: transform 140ms ease;
}

.themed-select[data-open="true"] .themed-select__chevron,
.themed-select__trigger[aria-expanded="true"] .themed-select__chevron {
  transform: rotate(225deg) translate(-2px, -1px);
}

.themed-select__trigger:disabled,
.themed-select[data-disabled="true"] .themed-select__trigger {
  cursor: not-allowed;
  opacity: 0.62;
}

.themed-select[data-invalid="true"] .themed-select__trigger,
.themed-select[data-invalid="true"] .themed-select__native {
  border-color: var(--themed-select-danger);
}

.themed-select__popover {
  position: fixed;
  z-index: 10050;
  display: flex;
  flex-direction: column;
  width: min(24rem, calc(100vw - 24px));
  max-width: calc(100vw - 24px);
  max-height: min(50vh, 24rem);
  padding: 6px;
  overflow: hidden;
  border: 1px solid var(--themed-select-border);
  border-radius: 10px;
  background: var(--themed-select-surface-raised);
  color: var(--themed-select-text);
  box-shadow: 0 14px 36px rgb(28 25 23 / 20%);
}

.themed-select__popover[hidden],
.themed-select__search[hidden],
.themed-select__empty[hidden],
.themed-select__error[hidden] {
  display: none !important;
}

.themed-select__search {
  flex: 0 0 auto;
  width: 100%;
  min-height: 44px;
  box-sizing: border-box;
  margin-bottom: 6px;
  padding: 9px 11px;
  border: 1px solid var(--themed-select-border);
  border-radius: 7px;
  background: var(--themed-select-surface);
  color: var(--themed-select-text);
  font: inherit;
  font-size: 16px;
}

.themed-select__listbox {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  max-height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-color: var(--themed-select-border) transparent;
  scrollbar-width: thin;
}

.themed-select__option {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 44px;
  box-sizing: border-box;
  padding: 9px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--themed-select-text);
  font: inherit;
  font-size: 16px;
  line-height: 1.35;
  text-align: start;
  overflow-wrap: anywhere;
  cursor: pointer;
}

.themed-select__option[aria-selected="true"] {
  background: var(--themed-select-selected);
  font-weight: 650;
}

.themed-select__option[data-active="true"] {
  background: var(--themed-select-hover);
}

.themed-select__option[aria-selected="true"]::after {
  content: "✓";
  flex: 0 0 auto;
  margin-inline-start: auto;
  padding-inline-start: 10px;
  color: var(--themed-select-accent);
  font-weight: 700;
}

.themed-select__option[aria-disabled="true"] {
  color: var(--themed-select-muted);
  cursor: not-allowed;
  opacity: 0.65;
}

.themed-select__group {
  padding: 8px 10px 4px;
  color: var(--themed-select-muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.themed-select__empty {
  padding: 12px 10px;
  color: var(--themed-select-muted);
  font-size: 14px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.themed-select__error:not([hidden]) {
  display: block;
  margin-top: 5px;
  color: var(--themed-select-danger);
  font-size: 0.875rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.themed-select[data-disabled="true"] .themed-select__native {
  cursor: not-allowed;
  opacity: 0.62;
}

@media (prefers-reduced-motion: reduce) {
  .themed-select__trigger,
  .themed-select__chevron {
    transition: none;
  }
}

@media (forced-colors: active) {
  .themed-select__trigger,
  .themed-select__search,
  .themed-select__popover {
    border: 1px solid ButtonText;
  }

  .themed-select__trigger:focus-visible,
  .themed-select__search:focus-visible,
  .themed-select__option:focus-visible {
    outline-color: Highlight;
  }

  .themed-select__option[aria-selected="true"],
  .themed-select__option[data-active="true"] {
    background: Highlight;
    color: HighlightText;
  }
}
