/**
 * Branded Select Dropdown Component
 *
 * Replaces native <select> dropdown menus with brand-consistent
 * custom dropdown overlays. Only styles the OPEN state - closed
 * state styling is handled by existing form CSS.
 *
 * Target Elements:
 * - .category-select (category levels 1-6)
 * - #ba-modal-country (billing modal)
 * - #country (settings page)
 * - #invoice-language-select, #invoice-status-filter, #invoice-date-filter, #invoice-items-select
 * - #default-size (preferences)
 * - #feedback-category (help section)
 * - #contact-category (support page)
 *
 * @version 1.0.0
 * @date 2025-12-30
 */

/* ============================================
   BRANDED SELECT - WRAPPER STYLES
   ============================================ */

/* Wrapper added around the original select */
.branded-select-wrapper {
    position: relative;
    display: inline-block;
    width: 100%;
}

/* When dropdown is open, add visual indicator to wrapper */
.branded-select-wrapper.is-open {
    z-index: 9999;
}

/* ============================================
   BRANDED SELECT - DROPDOWN MENU
   ============================================ */

/* The custom dropdown menu - portaled to body */
.branded-select-menu {
    position: absolute;
    background: white;
    border: 2px solid var(--spark-orange);
    border-top: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    box-shadow: 0 12px 32px rgba(58, 53, 44, 0.25);
    z-index: 999999;
    max-height: 280px;
    overflow-y: auto;
    overflow-x: hidden;
    display: none;
    -webkit-overflow-scrolling: touch;
}

/* When menu is portaled to body */
.branded-select-menu.is-portaled {
    position: absolute;
    /* top/left/width set by JavaScript */
}

/* Menu open state */
.branded-select-menu.is-open {
    display: block;
    animation: brandedSelectSlideIn 0.2s ease-out;
}

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

/* ============================================
   BRANDED SELECT - MENU ITEMS
   ============================================ */

.branded-select-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    cursor: pointer;
    transition: background-color var(--transition-fast);
    border-bottom: 1px solid var(--light-taupe);
    min-height: 44px;
    font-family: var(--font-primary);
    font-size: var(--font-size-input);
    color: var(--charcoal);
}

.branded-select-item:last-child {
    border-bottom: none;
}

.branded-select-item:hover {
    background-color: var(--soft-beige);
}

.branded-select-item:active {
    background-color: var(--light-taupe);
}

/* Selected item state */
.branded-select-item.is-selected {
    background-color: rgba(255, 107, 53, 0.08);
}

.branded-select-item.is-selected:hover {
    background-color: rgba(255, 107, 53, 0.12);
}

/* Disabled/placeholder items */
.branded-select-item.is-disabled {
    color: var(--warm-gray);
    cursor: not-allowed;
    font-style: italic;
}

.branded-select-item.is-disabled:hover {
    background-color: transparent;
}

/* ============================================
   BRANDED SELECT - SELECTION INDICATOR
   ============================================ */

.branded-select-check {
    width: 20px;
    height: 20px;
    border: 2px solid var(--light-taupe);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition-fast);
    background: white;
}

.branded-select-item.is-selected .branded-select-check {
    background: var(--spark-orange);
    border-color: var(--spark-orange);
    color: white;
}

.branded-select-check svg {
    width: 12px;
    height: 12px;
    opacity: 0;
    transform: scale(0.5);
    transition: all var(--transition-fast);
}

.branded-select-item.is-selected .branded-select-check svg {
    opacity: 1;
    transform: scale(1);
}

/* ============================================
   BRANDED SELECT - ITEM CONTENT
   ============================================ */

.branded-select-item-text {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: var(--font-size-caption);
}

.branded-select-item.is-selected .branded-select-item-text {
    color: var(--spark-orange);
    font-weight: 500;
}

/* ============================================
   BRANDED SELECT - SINGLE-SELECT TEXT-ONLY STYLING
   For single-select dropdowns, hide checkmarks and use text styling only
   ============================================ */

/* Hide checkmark for single-select menus */
.branded-select-menu[data-single-select="true"] .branded-select-check {
    display: none;
}

/* Adjust item padding when no checkmark */
.branded-select-menu[data-single-select="true"] .branded-select-item {
    gap: 0;
}

/* Selected state uses bold orange text only */
.branded-select-menu[data-single-select="true"] .branded-select-item.is-selected {
    background-color: rgba(255, 107, 53, 0.06);
}

.branded-select-menu[data-single-select="true"] .branded-select-item.is-selected .branded-select-item-text {
    color: var(--spark-orange);
    font-weight: 600;
}

/* ============================================
   BRANDED SELECT - SCROLLBAR STYLING
   ============================================ */

.branded-select-menu::-webkit-scrollbar {
    width: 6px;
}

.branded-select-menu::-webkit-scrollbar-track {
    background: var(--soft-beige);
    border-radius: 3px;
    margin-bottom: 10px;
}

.branded-select-menu::-webkit-scrollbar-thumb {
    background: var(--medium-taupe);
    border-radius: 3px;
}

.branded-select-menu::-webkit-scrollbar-thumb:hover {
    background: var(--warm-gray);
}

/* ============================================
   BRANDED SELECT - TRIGGER STYLING (OPEN STATE)
   When the select is open, style the trigger
   ============================================ */

/* Native select when branded dropdown is open */
.branded-select-wrapper.is-open select,
.branded-select-wrapper.is-open .category-select,
.branded-select-wrapper.is-open .form-input,
.branded-select-wrapper.is-open .contact-form-select {
    border-color: var(--spark-orange);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    box-shadow: none;
    outline: none;
}

/* ============================================
   BRANDED SELECT - ACCESSIBILITY
   ============================================ */

/* Focus ring for keyboard navigation - only show on actual keyboard nav, not programmatic focus */
.branded-select-item:focus {
    outline: none;
}

.branded-select-item:focus-visible {
    background-color: var(--soft-beige);
}

/* Screen reader only text */
.branded-select-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ============================================
   BRANDED SELECT - RESPONSIVE ADJUSTMENTS
   ============================================ */

/* Smaller sizing on smaller screens */
@media (max-width: 768px) {
    .branded-select-item {
        min-height: 40px;
        padding: var(--space-xsm) var(--space-sm);
        gap: var(--space-xsm);
        font-size: var(--font-size-body-sm);
    }

    .branded-select-check {
        width: 18px;
        height: 18px;
    }

    .branded-select-check svg {
        width: 10px;
        height: 10px;
    }

    .branded-select-menu {
        max-height: 240px;
    }
}

@media (max-width: 480px) {
    .branded-select-item {
        min-height: 36px;
        padding: var(--space-xsm) var(--space-sm);
        gap: var(--space-xsm);
        font-size: var(--font-size-small);
    }

    .branded-select-check {
        width: 16px;
        height: 16px;
    }

    .branded-select-check svg {
        width: 9px;
        height: 9px;
    }

    .branded-select-menu {
        max-height: 200px;
    }
}

/* ============================================
   BRANDED SELECT - REDUCED MOTION
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    .branded-select-menu.is-open {
        animation: none;
    }

    .branded-select-check svg,
    .branded-select-item {
        transition: none;
    }
}

/* ============================================
   CONTEXT-SPECIFIC ADJUSTMENTS
   Each dropdown may need slight tweaks
   ============================================ */

/* Category selects - slightly smaller padding */
.branded-select-menu[data-context="category"] .branded-select-item {
    min-height: 40px;
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--font-size-caption);
}

/* Invoice filters - compact layout */
.branded-select-menu[data-context="invoice-filter"] .branded-select-item {
    min-height: 38px;
    padding: var(--space-xs) var(--space-sm);
}

/* Modal context - ensure proper layering above modal */
.branded-select-menu[data-context="modal"] {
    z-index: 1000000;
}

/* Settings context - match form styling */
.branded-select-menu[data-context="settings"] .branded-select-item {
    font-family: var(--font-primary);
}

/* Support page context */
.branded-select-menu[data-context="support"] .branded-select-item {
    font-family: var(--font-primary);
}
