/* ═══════════════════════════════════════════════════════════════════════════
   CUSTOM SELECT COMPONENT - Pastel Punk Style
   ═══════════════════════════════════════════════════════════════════════════

   Custom dropdowns with chunky borders and hard shadows.
   Consistent with global theme system.
   ═══════════════════════════════════════════════════════════════════════════ */

.custom-select {
  position: relative;
  width: 100%;
}

.custom-select.is-dropdown-open {
  z-index: 12;
}

.custom-select__trigger {
  appearance: none;
  width: 100%;
  padding: 12px 40px 12px 16px;
  border: var(--border-width) solid var(--color-ink);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #fffefb 0%, #fff4ed 100%);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition:
    transform 220ms cubic-bezier(0.34, 1.56, 0.64, 1),
    box-shadow 200ms cubic-bezier(0.34, 1.56, 0.64, 1),
    background 180ms ease,
    border-color 180ms ease;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
  color: var(--color-ink);
  position: relative;
}

.custom-select__trigger:hover {
  transform: translate(-2px, -2px);
  box-shadow: var(--shadow-md);
  background: rgba(255, 159, 243, 0.08);
  border-color: var(--color-surface);
}

.custom-select__trigger:focus {
  outline: none;
  border-color: var(--color-surface);
  box-shadow: var(--shadow-md);
  transform: translate(-1px, -1px);
}

.custom-select__trigger:active {
  animation: triggerBounce 260ms cubic-bezier(0.68, -0.8, 0.265, 1.8);
}

@keyframes triggerBounce {
  0% { transform: translate(0, 0) scale(1); }
  40% { transform: translate(0, 0) scale(0.95); }
  70% { transform: translate(0, 0) scale(1.02); }
  100% { transform: translate(0, 0) scale(1); }
}

.custom-select__trigger.is-open {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-bottom-color: var(--color-surface);
  background: white;
}

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

.custom-select__arrow {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.7rem;
  color: var(--color-surface);
  transition:
    transform 420ms cubic-bezier(0.34, 1.56, 0.64, 1),
    color 200ms cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}

.custom-select__trigger:hover .custom-select__arrow {
  color: var(--color-ink);
  transform: translateY(-50%) scale(1.25);
}

.custom-select__trigger.is-open .custom-select__arrow {
  transform: translateY(-50%) rotate(180deg) scale(1.1);
}

/* ───────────────────────────────────────────────────────────────────────── */
/* DROPDOWN MENU
/* ───────────────────────────────────────────────────────────────────────── */

.custom-select__dropdown {
  position: fixed;
  inset: auto;
  top: var(--custom-select-top, 0px);
  left: var(--custom-select-left, 0px);
  width: min(var(--custom-select-width, 320px), calc(100vw - 24px));
  max-height: min(360px, var(--custom-select-max-height, calc(100vh - var(--custom-select-top, 0px) - 24px)));
  background: white;
  opacity: 0;
  border: var(--border-width) solid var(--color-ink);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: none;
  pointer-events: none;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  transform: translateY(-8px) scale(0.96);
  transition:
    opacity 200ms cubic-bezier(0.4, 0, 0.2, 1),
    transform 280ms cubic-bezier(0.34, 1.56, 0.64, 1),
    box-shadow 220ms ease;
  z-index: var(--z-popover, 9999);
  padding: 8px 0;
}

.custom-select__dropdown:popover-open,
.custom-select__dropdown.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
  box-shadow:
    0 12px 30px rgba(0, 0, 0, 0.2),
    4px 4px 0 rgba(0, 0, 0, 0.2);
}

.custom-select__dropdown::backdrop {
  background: transparent;
}

@supports not (popover: auto) {
  .custom-select__dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    width: 100%;
    transform: translateY(0);
    opacity: 0;
  }

  .custom-select__dropdown:not(.is-open) {
    display: none;
  }

  .custom-select__dropdown.is-open {
    display: block;
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .custom-select__dropdown,
  .custom-select__dropdown:popover-open,
  .custom-select__option,
  .custom-select__trigger {
    transition-duration: 0ms;
  }
}

.custom-select__option {
  appearance: none;
  width: 100%;
  padding: 12px 16px;
  border: none;
  background: white;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition:
    background 180ms cubic-bezier(0.34, 1.56, 0.64, 1),
    padding 220ms cubic-bezier(0.34, 1.56, 0.64, 1),
    transform 200ms cubic-bezier(0.34, 1.56, 0.64, 1);
  text-align: left;
  color: var(--color-ink);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.custom-select__option::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--color-surface);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 280ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.custom-select__option:hover {
  background: rgba(255, 159, 243, 0.12);
  padding-left: 24px;
  transform: translateX(2px);
}

.custom-select__option:hover::before {
  transform: scaleX(1);
}

.custom-select__option:active {
  background: rgba(255, 159, 243, 0.18);
  animation: optionBounce 240ms cubic-bezier(0.68, -0.8, 0.265, 1.8);
}

@keyframes optionBounce {
  0% { transform: scale(1); }
  35% { transform: scale(0.94); }
  65% { transform: scale(1.03); }
  100% { transform: scale(1); }
}

.custom-select__option.is-selected {
  background: rgba(255, 159, 243, 0.12);
  font-weight: 700;
  padding-left: 20px;
}

.custom-select__option.is-selected::before {
  transform: scaleX(1);
}

.custom-select__option-label {
  flex: 1;
}

.custom-select__option-desc {
  font-size: 0.8rem;
  color: var(--color-muted);
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}

/* Custom scrollbar for dropdown */
.custom-select__dropdown::-webkit-scrollbar {
  width: 8px;
}

.custom-select__dropdown::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.03);
}

.custom-select__dropdown::-webkit-scrollbar-thumb {
  background: var(--color-surface);
  border-radius: 4px;
  transition: background 200ms ease;
}

.custom-select__dropdown::-webkit-scrollbar-thumb:hover {
  background: var(--color-surface-alt);
}

/* ───────────────────────────────────────────────────────────────────────── */
/* STAGGER ANIMATION FOR OPTIONS - Whimsical spring physics
/* ───────────────────────────────────────────────────────────────────────── */

.custom-select__dropdown.is-open .custom-select__option {
  animation: optionSpringIn 420ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.custom-select__dropdown.is-open .custom-select__option:nth-child(1) { animation-delay: 50ms; }
.custom-select__dropdown.is-open .custom-select__option:nth-child(2) { animation-delay: 80ms; }
.custom-select__dropdown.is-open .custom-select__option:nth-child(3) { animation-delay: 110ms; }
.custom-select__dropdown.is-open .custom-select__option:nth-child(4) { animation-delay: 140ms; }
.custom-select__dropdown.is-open .custom-select__option:nth-child(5) { animation-delay: 170ms; }
.custom-select__dropdown.is-open .custom-select__option:nth-child(6) { animation-delay: 200ms; }
.custom-select__dropdown.is-open .custom-select__option:nth-child(7) { animation-delay: 230ms; }
.custom-select__dropdown.is-open .custom-select__option:nth-child(8) { animation-delay: 260ms; }
.custom-select__dropdown.is-open .custom-select__option:nth-child(9) { animation-delay: 290ms; }
.custom-select__dropdown.is-open .custom-select__option:nth-child(10) { animation-delay: 320ms; }

@keyframes optionSpringIn {
  0% {
    opacity: 0;
    transform: translateX(-16px) scale(0.96);
  }
  60% {
    transform: translateX(2px) scale(1.01);
  }
  100% {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}
