// GiftFlow Select Search (inherits --gfh-* from .giftflow-dashboard-view)
.giftflow-select-search {
  position: relative;
  width: 100%;
  font-family: inherit;

  &__trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: 44px;
    padding: 0.75rem;
    background: var(--gfh-bg, #fff);
    border: 1px solid var(--gfh-line-strong, #c3c4c7);
    border-radius: var(--gfh-radius-sm, 6px);
    cursor: pointer;
    transition:
      border-color var(--gfh-dur, 0.2s) var(--gfh-ease, ease),
      box-shadow var(--gfh-dur, 0.2s) var(--gfh-ease, ease);
    outline: none;
    box-sizing: border-box;

    &:hover {
      border-color: var(--gfh-text-muted, #646970);
    }

    &:focus {
      border-color: var(--gfh-theme, #2271b1);
      box-shadow: 0 0 0 1px var(--gfh-theme, #2271b1);
    }
  }

  &__value {
    flex: 1;
    display: flex;
    align-items: center;
    min-width: 0;
  }

  &__value-text {
    color: var(--gfh-text, #1d2327);
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  &__placeholder {
    color: var(--gfh-text-muted, #646970);
    font-size: 0.875rem;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  &__indicators {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
  }

  &__clear {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    background: none;
    border: none;
    border-radius: 50%;
    color: var(--gfh-text-muted, #646970);
    cursor: pointer;
    transition: background var(--gfh-dur, 0.2s) var(--gfh-ease, ease), color var(--gfh-dur, 0.2s) var(--gfh-ease, ease);

    &:hover {
      background: var(--gfh-bg-soft, #f6f7f7);
      color: var(--gfh-text, #1d2327);
    }

    &:focus {
      outline: none;
      background: var(--gfh-bg-soft, #f6f7f7);
      color: var(--gfh-text, #1d2327);
    }
  }

  &__arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gfh-text-muted, #646970);
    transition: transform var(--gfh-dur, 0.2s) var(--gfh-ease, ease);
  }

  &__dropdown {
    position: fixed;
    z-index: 100001;
    background: var(--gfh-bg, #fff);
    border: 1px solid var(--gfh-line, #dcdcde);
    border-radius: var(--gfh-radius-sm, 6px);
    box-shadow: var(--gfh-shade-hover, 0 8px 24px rgba(0, 0, 0, 0.1));
    overflow: hidden;
    animation: giftflow-select-search-dropdown 0.2s ease-out;
    max-height: 300px;
    min-width: 200px;
  }

  &__search {
    position: relative;
    padding: 0.75rem;
    border-bottom: 1px solid var(--gfh-line, #dcdcde);
    background: var(--gfh-bg-soft, #f6f7f7);
  }

  &__search-icon {
    position: absolute;
    left: 1.25rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gfh-text-muted, #646970);
    pointer-events: none;
  }

  &__search-input {
    width: 100%;
    padding: 0.5rem 0.5rem 0.5rem 2.5rem !important;
    background: var(--gfh-bg, #fff);
    border: 1px solid var(--gfh-line-strong, #c3c4c7);
    border-radius: var(--gfh-radius-sm, 6px);
    font-size: 0.875rem;
    color: var(--gfh-text, #1d2327);
    outline: none;
    transition: border-color var(--gfh-dur, 0.2s) var(--gfh-ease, ease), box-shadow var(--gfh-dur, 0.2s) var(--gfh-ease, ease);

    &:focus {
      border-color: var(--gfh-theme, #2271b1);
      box-shadow: 0 0 0 1px var(--gfh-theme, #2271b1);
    }

    &::placeholder {
      color: var(--gfh-text-muted, #646970);
    }
  }

  &__options {
    max-height: 200px;
    overflow-y: auto;
    padding: 0.25rem 0;

    // Custom scrollbar
    &::-webkit-scrollbar {
      width: 6px;
    }

    &::-webkit-scrollbar-track {
      background: var(--gfh-bg-muted, #f0f0f1);
    }

    &::-webkit-scrollbar-thumb {
      background: var(--gfh-line-strong, #c3c4c7);
      border-radius: 3px;
    }

    &::-webkit-scrollbar-thumb:hover {
      background: var(--gfh-text-muted, #646970);
    }
  }

  &__option {
    display: flex;
    flex-direction: column;
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: background-color var(--gfh-dur, 0.2s) var(--gfh-ease, ease);
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    box-sizing: border-box;
    border-bottom: solid 1px var(--gfh-line, #dcdcde);

    &:hover,
    &--highlighted {
      background: var(--gfh-bg-soft, #f6f7f7);
    }

    &--selected {
      background: color-mix(in srgb, var(--gfh-theme, #2271b1) 12%, var(--gfh-bg, #fff));
      color: var(--gfh-theme, #2271b1);
      font-weight: 600;

      .giftflow-select-search__option-label {
        color: var(--gfh-theme, #2271b1);
      }
    }
  }

  &__option-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gfh-text, #1d2327);
    line-height: 1.4;
    margin-bottom: 0.125rem;
  }

  &__option-description {
    font-size: 0.75rem;
    color: var(--gfh-text-muted, #646970);
    line-height: 1.3;
  }

  &__loading {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    color: var(--gfh-text-muted, #646970);
    font-size: 0.875rem;
    justify-content: center;
  }

  &__spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--gfh-line, #dcdcde);
    border-top: 2px solid var(--gfh-theme, #2271b1);
    border-radius: 50%;
    animation: giftflow-select-search-spin 1s linear infinite;
  }

  &__no-options {
    padding: 1rem;
    text-align: center;
    color: var(--gfh-text-muted, #646970);
    font-size: 0.875rem;
    font-style: italic;
  }

  &__error-message {
    margin-top: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: #fcf0f1;
    border: 1px solid #f0b0b5;
    border-radius: var(--gfh-radius-sm, 6px);
    color: #d63638;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.4;
  }

  // States
  &--disabled {
    .giftflow-select-search__trigger {
      background: var(--gfh-bg-muted, #f0f0f1);
      color: var(--gfh-text-muted, #646970);
      cursor: not-allowed;
      border-color: var(--gfh-line, #dcdcde);

      &:hover,
      &:focus {
        border-color: var(--gfh-line, #dcdcde);
        box-shadow: none;
      }
    }

    .giftflow-select-search__value-text,
    .giftflow-select-search__placeholder {
      color: var(--gfh-text-muted, #646970);
    }

    .giftflow-select-search__arrow {
      color: var(--gfh-line-strong, #c3c4c7);
    }
  }

  &--error {
    .giftflow-select-search__trigger {
      border-color: #d63638;

      &:hover {
        border-color: #b32d2e;
      }

      &:focus {
        border-color: #d63638;
        box-shadow: 0 0 0 1px #d63638;
      }
    }
  }

  // When dropdown is open
  &.giftflow-select-search--open {
    .giftflow-select-search__arrow {
      transform: rotate(180deg);
    }
  }
}

// Animations
@keyframes giftflow-select-search-dropdown {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes giftflow-select-search-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

// Responsive design
@media (max-width: 768px) {
  .giftflow-select-search {
    &__trigger {
      min-height: 40px;
      padding: 0.625rem 0.875rem;
    }

    &__value-text,
    &__placeholder {
      font-size: 0.8rem;
    }

    &__search {
      padding: 0.625rem;
    }

    &__search-input {
      padding: 0.5rem 0.5rem 0.5rem 2.25rem;
      font-size: 0.8rem;
    }

    &__option {
      padding: 0.625rem 0.875rem;
    }

    &__option-label {
      font-size: 0.8rem;
    }

    &__option-description {
      font-size: 0.7rem;
    }

    &__loading {
      padding: 0.875rem;
      font-size: 0.8rem;
    }

    &__no-options {
      padding: 0.875rem;
      font-size: 0.8rem;
    }
  }
}

@media (max-width: 480px) {
  .giftflow-select-search {
    &__trigger {
      min-height: 36px;
      padding: 0.5rem 0.75rem;
    }

    &__value-text,
    &__placeholder {
      font-size: 0.75rem;
    }

    &__search {
      padding: 0.5rem;
    }

    &__search-input {
      padding: 0.375rem 0.375rem 0.375rem 2rem;
      font-size: 0.75rem;
    }

    &__option {
      padding: 0.5rem 0.75rem;
    }

    &__option-label {
      font-size: 0.75rem;
    }

    &__option-description {
      font-size: 0.65rem;
    }

    &__loading {
      padding: 0.75rem;
      font-size: 0.75rem;
    }

    &__no-options {
      padding: 0.75rem;
      font-size: 0.75rem;
    }
  }
}
