/* =======================
   Custom Dropdown with Search
   Mobile-friendly country/city selector
   ======================= */

/* Wrapper for custom dropdown */
.custom-dropdown-wrapper {
  position: relative;
  width: 100%;
}

/* Trigger button that opens dropdown */
.custom-dropdown-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 52px;
  width: 100%;
  font-size: 15px;
  color: var(--text);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.custom-dropdown-trigger:hover {
  border-color: var(--primary-600);
}

.custom-dropdown-trigger:active {
  transform: scale(0.98);
}

.custom-dropdown-trigger.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.custom-dropdown-trigger.open {
  border-color: var(--primary-600);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary-600) 15%, transparent);
}

/* Selected value display */
.custom-dropdown-value {
  flex: 1;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-dropdown-value.placeholder {
  color: var(--muted);
}

/* Arrow icon */
.custom-dropdown-arrow {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  transition: transform 0.2s;
  color: var(--muted);
}

.custom-dropdown-trigger.open .custom-dropdown-arrow {
  transform: rotate(180deg);
}

/* Dropdown panel (modal-like on mobile) */
.custom-dropdown-panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
  z-index: 9999;
  max-height: 70vh;
  display: none;
  flex-direction: column;
  animation: slideUp 0.3s ease-out;
}

.custom-dropdown-panel.active {
  display: flex;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Backdrop overlay */
.custom-dropdown-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 9998;
  display: none;
  animation: fadeIn 0.3s ease-out;
}

.custom-dropdown-backdrop.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Panel header with search */
.custom-dropdown-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.custom-dropdown-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Close button */
.custom-dropdown-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--background);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--muted);
  -webkit-tap-highlight-color: transparent;
}

.custom-dropdown-close:hover {
  background: var(--border);
  color: var(--text);
}

.custom-dropdown-close:active {
  transform: scale(0.9);
}

/* Search input */
.custom-dropdown-search {
  position: relative;
}

.custom-dropdown-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--muted);
  pointer-events: none;
}

.custom-dropdown-search input {
  width: 100%;
  padding: 12px 12px 12px 40px;
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  color: var(--text);
  outline: none;
  transition: all 0.2s;
}

.custom-dropdown-search input:focus {
  border-color: var(--primary-600);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary-600) 15%, transparent);
}

.custom-dropdown-search input::placeholder {
  color: var(--muted);
}

/* Options list */
.custom-dropdown-list {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* Option item */
.custom-dropdown-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid var(--border);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.custom-dropdown-option:last-child {
  border-bottom: none;
}

.custom-dropdown-option:hover {
  background: color-mix(in srgb, var(--primary-600) 8%, transparent);
}

.custom-dropdown-option:active {
  background: color-mix(in srgb, var(--primary-600) 15%, transparent);
}

.custom-dropdown-option.selected {
  background: color-mix(in srgb, var(--primary-600) 12%, transparent);
  font-weight: 600;
}

/* First tap highlight - indicates user needs to tap again */
.custom-dropdown-option.tap-once {
  background: color-mix(in srgb, var(--primary-600) 20%, transparent);
  border-left: 4px solid var(--primary-600);
  animation: pulse 0.5s ease-in-out;
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.02);
  }
}

/* Flag emoji */
.custom-dropdown-option-flag {
  font-size: 24px;
  line-height: 1;
  flex-shrink: 0;
  width: 32px;
  text-align: center;
}

/* Option text */
.custom-dropdown-option-text {
  flex: 1;
  font-size: 15px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Check mark for selected item */
.custom-dropdown-option-check {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--primary-600);
  opacity: 0;
  transition: opacity 0.2s;
}

.custom-dropdown-option.selected .custom-dropdown-option-check {
  opacity: 1;
}

/* Empty state */
.custom-dropdown-empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

/* Hide original select */
.custom-dropdown-wrapper select {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 0;
  height: 0;
}

/* Desktop styles (larger screens) */
@media (min-width: 768px) {
  .custom-dropdown-panel {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    bottom: auto;
    border-radius: 12px;
    max-height: 400px;
    animation: slideDown 0.2s ease-out;
  }

  @keyframes slideDown {
    from {
      transform: translateY(-10px);
      opacity: 0;
    }
    to {
      transform: translateY(0);
      opacity: 1;
    }
  }

  .custom-dropdown-backdrop {
    display: none !important;
  }
}

/* Dark theme adjustments */
[data-theme="dark"] .custom-dropdown-backdrop {
  background: rgba(0, 0, 0, 0.6);
}
