/* ==========================================================
   AgencyOS - Shared Dropdown Components

   Consolidated custom dropdown styles from public-booking.css
   and portal-calendar-modals.css.

   Eliminates ~280 lines of duplication.
   ========================================================== */

/* ========================================
   CUSTOM DROPDOWN CONTAINER
   ======================================== */

/**
 * Custom dropdown wrapper
 * Contains button and menu
 */
.custom-dropdown {
  position: relative;
  display: inline-block;
}

/* Full width dropdown when inside a field */
.field .custom-dropdown {
  display: block;
  width: 100%;
}

/* ========================================
   DROPDOWN BUTTON
   ======================================== */

/**
 * Dropdown trigger button
 * Pill-shaped button with icon/avatar support
 * Reduced padding to allow larger icons/avatars and text
 */
.custom-dropdown-btn {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: 6px 12px;
  background: var(--c-white);
  border: 1px solid var(--c-gray-400);
  border-radius: var(--radius-pill);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  color: var(--c-gray-700);
  cursor: pointer;
  transition: var(--transition-base);
  white-space: nowrap;
  text-align: left;
  min-height: 40px;
}

/* Full width button when dropdown is inside a field */
.field .custom-dropdown-btn {
  width: 100%;
  justify-content: space-between;
}

.custom-dropdown-btn:hover {
  background: var(--c-gray-50);
  border-color: var(--c-gray-400);
}

.custom-dropdown-btn:focus {
  outline: none;
  border-color: var(--c-accent);
  box-shadow: var(--shadow-focus);
}

/* Dropdown button with brand styling */
.custom-dropdown-btn--brand {
  background: var(--c-brand);
  border-color: var(--c-brand);
  color: var(--c-white);
}

.custom-dropdown-btn--brand:hover {
  background: var(--c-mid);
  border-color: var(--c-mid);
}

/* Dropdown button variants */
.custom-dropdown-btn--small {
  padding: 4px 12px;
  font-size: var(--font-size-xs);
}

.custom-dropdown-btn--large {
  padding: 10px 20px;
  font-size: var(--font-size-base);
}

/* ========================================
   DROPDOWN ICON/AVATAR
   ======================================== */

/**
 * Icon or avatar in dropdown button
 * Larger sizes for better visibility with reduced padding
 */
.custom-dropdown-icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.custom-dropdown-icon i {
  font-size: 20px;
}

.custom-dropdown-icon--circle {
  border-radius: var(--radius-circle);
}

.custom-dropdown-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-circle);
  object-fit: cover;
  flex-shrink: 0;
}

/* Text label in dropdown button */
.custom-dropdown-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ========================================
   DROPDOWN CARET/ARROW
   ======================================== */

/**
 * Caret/arrow indicator
 * Rotates when dropdown is open
 */
.custom-dropdown-caret {
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  transition: transform 0.2s ease;
  flex-shrink: 0;
  margin-left: auto;
}

.custom-dropdown.open .custom-dropdown-caret,
.custom-dropdown-btn[aria-expanded="true"] .custom-dropdown-caret {
  transform: rotate(180deg);
}

/* Alternative: SVG arrow */
.custom-dropdown-arrow {
  width: 16px;
  height: 16px;
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.custom-dropdown.open .custom-dropdown-arrow,
.custom-dropdown-btn[aria-expanded="true"] .custom-dropdown-arrow {
  transform: rotate(180deg);
}

/* ========================================
   DROPDOWN MENU
   ======================================== */

/**
 * Dropdown menu container
 * Hidden by default, shown when .open class added
 * Auto-scrolls if content exceeds max-height to prevent overflow
 * Note: max-height is set dynamically by JavaScript to fit within modals
 */
.custom-dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 200px;
  max-height: 300px; /* Default max-height, overridden by JS in modals */
  overflow-y: auto;
  background: var(--c-white);
  border: 1px solid var(--c-gray-200);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-dropdown);
  display: none;
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  list-style: none;
  padding: 8px;
  margin: 0;
}

/* Full width menu when dropdown is inside a field */
.field .custom-dropdown-menu {
  left: 0;
  right: 0;
  min-width: 100%;
}

/* Show dropdown menu */
.custom-dropdown.open .custom-dropdown-menu,
.custom-dropdown-menu.open,
.custom-dropdown-menu[aria-hidden="false"] {
  display: block;
  opacity: 1;
  transform: translateY(0);
  animation: slideDown 0.2s ease-out;
}

/* Dropdown menu positioned to the left */
.custom-dropdown-menu--left {
  right: auto;
  left: 0;
}

/* Dropdown menu full width */
.custom-dropdown-menu--full {
  left: 0;
  right: 0;
  min-width: 100%;
}

/* Dropdown menu with max height and scroll */
.custom-dropdown-menu--scrollable {
  max-height: 300px;
  overflow-y: auto;
}

/* ========================================
   DROPDOWN MENU ITEMS
   ======================================== */

/**
 * Individual dropdown menu item
 * Reduced padding to allow larger icons/avatars and text
 */
.custom-dropdown-item,
.custom-dropdown-menu li,
.custom-dropdown-menu li button {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: 6px 12px;
  color: var(--c-gray-700);
  text-decoration: none;
  cursor: pointer;
  transition: var(--transition-fast);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-normal);
  font-family: inherit;
  border-radius: var(--radius-sm);
  list-style: none;
}

.custom-dropdown-item:hover,
.custom-dropdown-menu li:hover,
.custom-dropdown-menu li button:hover {
  background: var(--c-accent);
  color: #fff;
}

.custom-dropdown-item:focus {
  outline: none;
  background: var(--c-gray-100);
}

.custom-dropdown-item:active {
  background: var(--c-gray-200);
}

/* Dropdown item with icon */
.custom-dropdown-item-icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  color: var(--c-brand);
  font-size: 20px;
}

.custom-dropdown-item:hover .custom-dropdown-item-icon {
  color: #fff;
}

/* All icons inside dropdown menus are brand colored */
.custom-dropdown-menu i,
.custom-dropdown-menu .fa-solid,
.custom-dropdown-menu .fa-regular,
.custom-dropdown-menu .fa-light {
  color: var(--c-brand);
  font-size: 20px;
}

/* Icons turn white on hover */
.custom-dropdown-menu li:hover i,
.custom-dropdown-menu li button:hover i,
.custom-dropdown-item:hover i {
  color: #fff;
}

/* Icon in dropdown button (selected state) */
.custom-dropdown-btn .custom-dropdown-icon,
.custom-dropdown-btn .custom-dropdown-item-icon {
  color: var(--c-brand);
}

/* Icons inside dropdown button */
.custom-dropdown-btn i {
  color: var(--c-brand);
}

/* Dropdown item with avatar */
.custom-dropdown-item-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-circle);
  object-fit: cover;
  flex-shrink: 0;
}

/* Dropdown item variants */
.custom-dropdown-item--danger {
  color: var(--c-error);
}

.custom-dropdown-item--danger:hover {
  background: var(--c-error-light);
  color: var(--c-error-dark);
}

.custom-dropdown-item--selected {
  background: var(--c-gray-100);
  color: var(--c-brand);
  font-weight: var(--font-weight-medium);
}

.custom-dropdown-item--disabled {
  color: var(--c-gray-400);
  cursor: not-allowed;
  pointer-events: none;
}

/* ========================================
   DROPDOWN DIVIDER
   ======================================== */

/**
 * Divider between dropdown sections
 */
.custom-dropdown-divider {
  height: 1px;
  background: var(--c-gray-200);
  margin: 4px 0;
}

/* ========================================
   DROPDOWN HEADER
   ======================================== */

/**
 * Section header in dropdown
 */
.custom-dropdown-header {
  padding: 8px 16px;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  color: var(--c-gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ========================================
   DROPDOWN TEXT CONTENT
   ======================================== */

/**
 * Text content wrapper for multi-line items
 */
.custom-dropdown-item-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.custom-dropdown-item-title {
  font-weight: var(--font-weight-medium);
  color: var(--c-gray-900);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.custom-dropdown-item:hover .custom-dropdown-item-title {
  color: #fff;
}

.custom-dropdown-item-subtitle {
  font-size: var(--font-size-xs);
  color: var(--c-gray-500);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.custom-dropdown-item:hover .custom-dropdown-item-subtitle {
  color: rgba(255, 255, 255, 0.9);
}

/* ========================================
   SCROLLBAR STYLING
   ======================================== */

.custom-dropdown-menu::-webkit-scrollbar,
.custom-dropdown-menu--scrollable::-webkit-scrollbar {
  width: 6px;
}

.custom-dropdown-menu::-webkit-scrollbar-track,
.custom-dropdown-menu--scrollable::-webkit-scrollbar-track {
  background: var(--c-gray-100);
  border-radius: var(--radius-sm);
}

.custom-dropdown-menu::-webkit-scrollbar-thumb,
.custom-dropdown-menu--scrollable::-webkit-scrollbar-thumb {
  background: var(--c-gray-400);
  border-radius: var(--radius-sm);
}

.custom-dropdown-menu::-webkit-scrollbar-thumb:hover,
.custom-dropdown-menu--scrollable::-webkit-scrollbar-thumb:hover {
  background: var(--c-gray-500);
}

/* ========================================
   MODAL DROPDOWN CONSTRAINTS
   ======================================== */

/**
 * Constrain dropdowns inside modals to prevent overflow
 * Uses a smaller max-height to stay within modal body
 */
.modal-body .custom-dropdown-menu {
  max-height: 200px;
  overflow-y: auto;
}

/* Even smaller on mobile to account for smaller modal heights */
@media (max-width: 768px) {
  .modal-body .custom-dropdown-menu {
    max-height: 150px;
  }
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */

@media (max-width: 480px) {
  .custom-dropdown-menu {
    min-width: 180px;
  }

  .custom-dropdown-item,
  .custom-dropdown-menu li,
  .custom-dropdown-menu li button {
    padding: 8px 12px;
    font-size: var(--font-size-base);
  }
}
