/**
 * SVGaze - Custom Dropdown Component
 * Styled dropdown with icon support and theme colors
 */

/* === Dropdown Container === */
.custom-dropdown {
  position: relative;
  display: inline-block;
  min-width: 180px;
  max-width: 280px;
  z-index: 1;
}

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

/* === Dropdown Trigger Button === */
.dropdown-trigger {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  width: 100%;
  padding: 10px 32px 10px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--card);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: var(--line-height-normal);
  text-align: left;
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
  min-height: 40px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dropdown-trigger:hover {
  border-color: var(--border-hover);
}

.dropdown-trigger:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* Dropdown arrow icon */
.dropdown-trigger::after {
  content: '';
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="%236b7280"><path d="M4 6l4 4 4-4H4z"/></svg>');
  background-repeat: no-repeat;
  background-position: center;
  background-size: 16px;
  transition: transform var(--transition-fast);
  pointer-events: none;
}

.custom-dropdown.is-open .dropdown-trigger::after {
  transform: translateY(-50%) rotate(180deg);
}

/* === Dropdown Menu === */
.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 100%;
  width: max-content;
  max-width: 320px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  list-style: none;
  margin: 0;
  padding: var(--space-xs) 0;
}

.custom-dropdown.is-open .dropdown-menu {
  display: block;
  animation: dropdownSlideIn 0.2s ease-out;
}

@keyframes dropdownSlideIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* === Dropdown Menu Items === */
.dropdown-menu [role="option"] {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  color: var(--text-primary);
  font-size: var(--font-size-base);
  cursor: pointer;
  transition: all var(--transition-fast);
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  outline: none;
  user-select: none;
}

.dropdown-menu [role="option"]:hover {
  background: var(--bg);
  color: var(--primary);
}

.dropdown-menu [role="option"]:focus {
  background: var(--primary-light);
  color: var(--primary);
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

.dropdown-menu [role="option"].is-selected {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: var(--font-weight-semibold);
}

.dropdown-menu [role="option"].is-selected::before {
  content: '✓';
  margin-right: var(--space-xs);
  font-weight: var(--font-weight-bold);
}

/* === Dropdown Item Icon === */
.dropdown-item-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: currentColor;
  opacity: 0.9;
}

.dropdown-item-icon svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Ensure SVG colors inherit from parent */
.dropdown-item-icon svg *[fill]:not([fill="none"]) {
  fill: currentColor !important;
}

.dropdown-item-icon svg *[stroke]:not([stroke="none"]) {
  stroke: currentColor !important;
}

/* Dark theme explicit color */
[data-theme="dark"] .dropdown-item-icon {
  color: var(--text-primary);
}

/* === Scrollbar Styling === */
.dropdown-menu::-webkit-scrollbar {
  width: 8px;
}

.dropdown-menu::-webkit-scrollbar-track {
  background: transparent;
}

.dropdown-menu::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.dropdown-menu::-webkit-scrollbar-thumb:hover {
  background: var(--border-hover);
}

/* === Responsive === */
@media (max-width: 640px) {
  .custom-dropdown {
    max-width: 180px;
    min-width: 120px;
  }

  .dropdown-menu {
    max-height: 240px;
  }

  .dropdown-item-icon {
    width: 16px;
    height: 16px;
  }
}
