/**
 * Custom Dropdown Styling (TomSelect / Choices.js replacement)
 * Single shared dropdown style for every <select> in the app (auto-applied by custom-dropdown.js).
 * Ensures dropdown lists stay within the viewport on mobile (320px, 375px, 393px, 768px).
 * Supports Light Theme (Orange accent) and Dark/Gold Theme (#111 with #D4AF37 gold).
 */

/* Visually hide original select while keeping it in DOM for model binding, validation, and form post */
.custom-select-native-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* Custom Dropdown Wrapper */
.custom-select-wrapper {
    position: relative;
    width: 100%; /* overridden by the select's inline width, copied over in JS */
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box !important;
    font-family: inherit;
    user-select: none;
}

/* Trigger Button */
.custom-select-trigger {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 8px;
    cursor: pointer;
    font-size: 16px !important; /* Prevents iOS Safari auto-zoom */
    font-weight: 500;
    text-align: left;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
    min-height: 44px; /* WCAG touch target */
    line-height: 1.4;
    background: transparent;
}

.custom-select-text {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.custom-select-arrow {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
}

.custom-select-wrapper.is-open .custom-select-arrow {
    transform: rotate(180deg);
}

/* Dropdown Menu List
   Fixed-positioned (coordinates set in JS) so it is never clipped by cards,
   tables or toolbars that use overflow:hidden. */
.custom-select-menu {
    position: fixed;
    top: 0;
    left: 0;
    box-sizing: border-box !important;
    max-height: 320px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    z-index: 2000;
    display: none;
    flex-direction: column;
    text-align: left;
}

.custom-select-wrapper.is-open .custom-select-menu {
    display: flex;
}

/* Option Items */
.custom-select-option {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    min-height: 44px; /* WCAG touch target */
    padding: 11px 14px;
    flex: 0 0 auto;
    display: block;
    align-items: center;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 22px;
}

.custom-select-option.is-disabled {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

/* ========================================================= */
/* SIZES (match Bootstrap .form-select / .form-select-sm)    */
/* ========================================================= */
.custom-select-wrapper.custom-select-md .custom-select-trigger {
    min-height: 38px;
    padding: 6px 12px !important;
    font-size: 14px !important;
}

.custom-select-wrapper.custom-select-sm .custom-select-trigger {
    min-height: 31px;
    padding: 4px 10px !important;
    font-size: 13px !important;
    border-radius: 6px !important;
}

.custom-select-wrapper.custom-select-sm .custom-select-option {
    min-height: 38px;
    padding: 8px 12px;
    font-size: 13px;
}

/* Shrinks to its content (grid page-size pickers) */
.custom-select-wrapper.custom-select-inline {
    display: inline-block;
    width: auto;
    min-width: 72px;
}

/* Borderless inline trigger (e.g. topbar / hero search fields) */
.custom-select-wrapper.custom-select-plain .custom-select-trigger {
    border-color: transparent !important;
    background: transparent !important;
    box-shadow: none !important;
    padding-left: 0 !important;
    min-height: 0;
}

/* Disabled */
.custom-select-wrapper.is-disabled .custom-select-trigger {
    cursor: not-allowed;
    opacity: 0.6;
}

/* Validation */
.custom-select-wrapper.is-invalid .custom-select-trigger {
    border-color: #dc3545 !important;
}

.custom-select-wrapper.is-invalid .custom-select-trigger:focus {
    box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.15) !important;
}

/* Bootstrap's .is-invalid ~ .invalid-feedback relies on the select being a sibling */
.custom-select-native-hidden.is-invalid ~ .invalid-feedback {
    display: block;
}

/* ========================================================= */
/* THEME 1: Light Theme with Orange Accent (Filters Card)    */
/* ========================================================= */
.custom-select-wrapper.theme-light .custom-select-trigger {
    padding: 9px 14px;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    color: #0f172a;
}

.custom-select-wrapper.theme-light .custom-select-trigger:focus,
.custom-select-wrapper.theme-light.is-open .custom-select-trigger {
    border-color: #f26419;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(242, 100, 25, 0.14);
}

.custom-select-wrapper.theme-light .custom-select-trigger.is-placeholder .custom-select-text {
    color: #64748b;
}

.custom-select-wrapper.theme-light .custom-select-arrow {
    color: #64748b;
}

.custom-select-wrapper.theme-light.is-open .custom-select-arrow {
    color: #f26419;
}

.custom-select-wrapper.theme-light .custom-select-menu {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(15, 23, 42, 0.12);
}

.custom-select-wrapper.theme-light .custom-select-option {
    color: #1e293b;
    border-bottom: 1px solid #f1f5f9;
}

.custom-select-wrapper.theme-light .custom-select-option:last-child {
    border-bottom: none;
}

.custom-select-wrapper.theme-light .custom-select-option:hover,
.custom-select-wrapper.theme-light .custom-select-option.is-highlighted {
    background: #fff3ec;
    color: #f26419;
    font-weight: 600;
}

.custom-select-wrapper.theme-light .custom-select-option.is-selected {
    background: #fff3ec;
    color: #f26419;
    font-weight: 700;
}

/* ========================================================= */
/* THEME 2: Dark Gold Theme (Luxury Private Inquiry Card)    */
/* ========================================================= */
.custom-select-wrapper.theme-dark-gold .custom-select-trigger {
    padding: 12px 16px;
    border-radius: 4px;
    border: 1px solid rgba(212, 175, 55, 0.25);
    background: #121110;
    color: #FDFBF7;
}

.custom-select-wrapper.theme-dark-gold .custom-select-trigger:focus,
.custom-select-wrapper.theme-dark-gold.is-open .custom-select-trigger {
    border-color: #D4AF37;
    box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.2);
}

.custom-select-wrapper.theme-dark-gold .custom-select-trigger.is-placeholder .custom-select-text {
    color: #A89F91;
}

.custom-select-wrapper.theme-dark-gold .custom-select-arrow {
    color: #D4AF37;
}

.custom-select-wrapper.theme-dark-gold .custom-select-menu {
    background: #111111;
    border: 1px solid rgba(212, 175, 55, 0.35);
    border-radius: 4px;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.85);
}

.custom-select-wrapper.theme-dark-gold .custom-select-option {
    color: #E5DECF;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.custom-select-wrapper.theme-dark-gold .custom-select-option:last-child {
    border-bottom: none;
}

.custom-select-wrapper.theme-dark-gold .custom-select-option:hover,
.custom-select-wrapper.theme-dark-gold .custom-select-option.is-highlighted {
    background: rgba(212, 175, 55, 0.12);
    color: #D4AF37;
    font-weight: 600;
}

.custom-select-wrapper.theme-dark-gold .custom-select-option.is-selected {
    background: rgba(212, 175, 55, 0.22);
    color: #D4AF37;
    font-weight: 700;
}

/* ========================================================= */
/* THEME 3: Dark Indigo Theme (Modern website inquiry form)     */
/* ========================================================= */
.custom-select-wrapper.theme-dark-indigo .custom-select-trigger {
    padding: 12px 16px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(15, 23, 42, 0.8);
    color: #F8FAFC;
}

.custom-select-wrapper.theme-dark-indigo .custom-select-trigger:focus,
.custom-select-wrapper.theme-dark-indigo.is-open .custom-select-trigger {
    border-color: #6366F1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.22);
}

.custom-select-wrapper.theme-dark-indigo .custom-select-trigger.is-placeholder .custom-select-text {
    color: #94A3B8;
}

.custom-select-wrapper.theme-dark-indigo .custom-select-arrow {
    color: #6366F1;
}

.custom-select-wrapper.theme-dark-indigo .custom-select-menu {
    background: #111827;
    border: 1px solid rgba(99, 102, 241, 0.35);
    border-radius: 10px;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.75);
}

.custom-select-wrapper.theme-dark-indigo .custom-select-option {
    color: #E2E8F0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.custom-select-wrapper.theme-dark-indigo .custom-select-option:last-child {
    border-bottom: none;
}

.custom-select-wrapper.theme-dark-indigo .custom-select-option:hover,
.custom-select-wrapper.theme-dark-indigo .custom-select-option.is-highlighted {
    background: rgba(99, 102, 241, 0.14);
    color: #F8FAFC;
    font-weight: 600;
}

.custom-select-wrapper.theme-dark-indigo .custom-select-option.is-selected {
    background: rgba(99, 102, 241, 0.24);
    color: #F8FAFC;
    font-weight: 700;
}

/* ========================================================= */
/* THEME 4: Dark Pink Theme (Creative website inquiry form)      */
/* ========================================================= */
.custom-select-wrapper.theme-dark-pink .custom-select-trigger {
    padding: 12px 16px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(9, 13, 22, 0.9);
    color: #F1F5F9;
}

.custom-select-wrapper.theme-dark-pink .custom-select-trigger:focus,
.custom-select-wrapper.theme-dark-pink.is-open .custom-select-trigger {
    border-color: #EC4899;
    box-shadow: 0 0 0 3px rgba(236, 72, 153, 0.22);
}

.custom-select-wrapper.theme-dark-pink .custom-select-trigger.is-placeholder .custom-select-text {
    color: #94A3B8;
}

.custom-select-wrapper.theme-dark-pink .custom-select-arrow {
    color: #EC4899;
}

.custom-select-wrapper.theme-dark-pink .custom-select-menu {
    background: #0F172A;
    border: 1px solid rgba(236, 72, 153, 0.35);
    border-radius: 12px;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.75);
}

.custom-select-wrapper.theme-dark-pink .custom-select-option {
    color: #E2E8F0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.custom-select-wrapper.theme-dark-pink .custom-select-option:last-child {
    border-bottom: none;
}

.custom-select-wrapper.theme-dark-pink .custom-select-option:hover,
.custom-select-wrapper.theme-dark-pink .custom-select-option.is-highlighted {
    background: rgba(236, 72, 153, 0.14);
    color: #F1F5F9;
    font-weight: 600;
}

.custom-select-wrapper.theme-dark-pink .custom-select-option.is-selected {
    background: rgba(236, 72, 153, 0.24);
    color: #F1F5F9;
    font-weight: 700;
}

/* ========================================================= */
/* LAYOUT HOOKS: mirror rules pgmanager.css / responsive.css */
/* apply to native selects so the wrapper behaves the same   */
/* ========================================================= */
@media (max-width: 767px) {
    .custom-select-wrapper.custom-select-md .custom-select-trigger {
        min-height: 44px; /* touch target, same as .form-select on phones */
    }

    .table-toolbar .custom-select-wrapper,
    .table-card > div:not(.table-responsive):not(.card-body) .custom-select-wrapper,
    .page-heading .custom-select-wrapper {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
    }

    #topbarCompanySwitcherWrap .custom-select-wrapper {
        width: auto !important;
        max-width: 105px !important;
        min-width: 0 !important;
    }

    #topbarCompanySwitcherWrap .custom-select-trigger {
        min-height: 36px;
        padding: 4px 6px !important;
        font-size: 11px !important;
    }
}

@media (max-width: 480px) {
    #topbarCompanySwitcherWrap .custom-select-wrapper {
        max-width: 82px !important;
    }

    #topbarCompanySwitcherWrap .custom-select-trigger {
        padding: 2px 4px !important;
        font-size: 10.5px !important;
    }
}
