/**
 * CBMExtensions CitiesDropDown2
 * Enhanced dropdown styles with mobile and RTL support
 */

/* Main dropdown container */
.cbm2-dropdown {
    position: relative;
    width: 100%;
    margin-bottom: 15px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Search container */
.cbm2-search-container {
    position: relative;
    width: 100%;
}

/* Search icon - Default LTR (English) */
.cbm2-search-icon {
    position: absolute;
    right: 12px;
    left: auto;
    top: 50%;
    transform: translateY(-50%);
    color: #9ca3af;
    pointer-events: none;
    display: flex;
    align-items: center;
    z-index: 1;
}

/* Search input - Default LTR (English) */
.cbm2-search-input {
    width: 100%;
    padding: 12px 44px 12px 16px; /* Icon space on right for LTR */
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    font-size: 15px;
    line-height: 1.5;
    color: #1f2937;
    background-color: #ffffff;
    transition: all 0.2s ease;
    box-sizing: border-box;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;

    /* Force GPU acceleration */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    will-change: transform;
}

/* Input with clear button - Default LTR (English) */
.cbm2-search-container:has(.cbm2-clear-btn) .cbm2-search-input {
    padding-right: 72px; /* Space for both icon and clear button on right */
}

/* Input states */
.cbm2-search-input:hover {
    border-color: #d1d5db;
}

.cbm2-search-input:focus {
    outline: none;
    border-color: #6b7280;
    box-shadow: 0 0 0 3px rgba(107, 114, 128, 0.1);
    background-color: #ffffff;
}

/* Clear button - Default LTR (English) */
.cbm2-clear-btn {
    position: absolute;
    right: 36px;
    left: auto;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #6b7280;
    font-size: 20px;
    line-height: 1;
    font-weight: normal;
    transition: all 0.15s ease;
    z-index: 2;
    user-select: none;
    padding: 0;
    background: transparent;
    border: none;
}

.cbm2-clear-btn:hover {
    color: #374151;
    background-color: rgba(0, 0, 0, 0.05);
    border-radius: 50%;
}

/* Dropdown list container */
.cbm2-dropdown-list {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background-color: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1),
                0 10px 10px -5px rgba(0, 0, 0, 0.04);
    z-index: 1000;
    max-height: 320px;
    overflow: hidden;

    /* Force GPU acceleration and proper rendering */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    will-change: transform, opacity;
}

/* Options list */
.cbm2-options {
    list-style: none;
    margin: 0;
    padding: 4px 0;
    max-height: 300px;
    overflow-y: auto;
    overflow-x: hidden;

    /* Force rendering context */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    -webkit-overflow-scrolling: touch;
}

/* Custom scrollbar */
.cbm2-options::-webkit-scrollbar {
    width: 6px;
}

.cbm2-options::-webkit-scrollbar-track {
    background: #f3f4f6;
    border-radius: 3px;
}

.cbm2-options::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.cbm2-options::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* Firefox scrollbar */
.cbm2-options {
    scrollbar-width: thin;
    scrollbar-color: #d1d5db #f3f4f6;
}

/* Option items */
.cbm2-option {
    padding: 10px 48px 10px 16px;
    font-size: 14px;
    line-height: 1.4;
    color: #374151;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;

    /* Ensure text is visible */
    background-color: #ffffff;
    opacity: 1;
    visibility: visible;

    /* Force rendering */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

.cbm2-option:hover,
.cbm2-option.hover {
    background-color: #f3f4f6;
    color: #111827;
}

.cbm2-option.selected {
    background-color: #f3f4f6;
    color: #111827;
    font-weight: 500;
}

.cbm2-option.selected::after {
    content: '✓';
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: #4b5563;
    font-weight: bold;
    font-size: 16px;
}

/* No results message */
.cbm2-no-results {
    padding: 16px;
    text-align: center;
    color: #9ca3af;
    font-size: 14px;
    background-color: #ffffff;
}

/* Validation states */
.field._error .cbm2-search-input,
.cbm2-search-input.invalid {
    border-color: #ef4444;
}

.field._error .cbm2-search-input:focus,
.cbm2-search-input.invalid:focus {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

/* RTL Support - Using explicit direction classes */
.cbm2-rtl .cbm2-search-icon {
    right: auto;
    left: 12px;
}

.cbm2-rtl .cbm2-search-input {
    padding: 12px 16px 12px 44px; /* Icon space on left */
    text-align: right;
    direction: rtl;
}

/* RTL with clear button for countries */
.cbm2-rtl .cbm2-search-container:has(.cbm2-clear-btn) .cbm2-search-input {
    padding-left: 72px; /* Space for icon and clear button on left */
    padding-right: 16px;
}

.cbm2-rtl .cbm2-clear-btn {
    right: auto;
    left: 36px;
}

.cbm2-rtl .cbm2-option {
    text-align: right;
    padding: 10px 16px 10px 48px;
}

.cbm2-rtl .cbm2-option.selected::after {
    right: auto;
    left: 16px;
}

/* LTR Support - Explicit classes for clarity */
.cbm2-ltr .cbm2-search-icon {
    right: 12px;
    left: auto;
}

.cbm2-ltr .cbm2-search-input {
    padding: 12px 44px 12px 16px; /* Icon space on right */
    text-align: left;
    direction: ltr;
}

/* LTR with clear button for countries */
.cbm2-ltr .cbm2-search-container:has(.cbm2-clear-btn) .cbm2-search-input {
    padding-right: 72px; /* Space for icon and clear button on right */
    padding-left: 16px;
}

.cbm2-ltr .cbm2-clear-btn {
    right: 36px;
    left: auto;
}

.cbm2-ltr .cbm2-option {
    text-align: left;
    padding: 10px 48px 10px 16px;
}

.cbm2-ltr .cbm2-option.selected::after {
    right: 16px;
    left: auto;
}

/* Mobile Optimizations */
@media (max-width: 768px) {
    .cbm2-search-input {
        font-size: 16px; /* Prevents zoom on iOS */
        border-radius: 10px;

        /* iOS specific fixes */
        -webkit-text-size-adjust: 100%;
        -webkit-tap-highlight-color: transparent;
    }

    /* LTR mobile styles */
    .cbm2-ltr .cbm2-search-input {
        padding: 14px 46px 14px 16px; /* Icon on right */
    }

    .cbm2-ltr .cbm2-search-container:has(.cbm2-clear-btn) .cbm2-search-input {
        padding-right: 76px; /* Space for both icon and clear button */
    }

    .cbm2-ltr .cbm2-clear-btn {
        right: 38px; /* Position for mobile LTR */
    }

    /* RTL mobile styles */
    .cbm2-rtl .cbm2-search-icon {
        right: auto;
        left: 12px;
    }

    .cbm2-rtl .cbm2-search-input {
        padding: 14px 16px 14px 46px; /* Icon on left for Arabic */
        text-align: right;
    }

    .cbm2-rtl .cbm2-search-container:has(.cbm2-clear-btn) .cbm2-search-input {
        padding-left: 76px; /* Space for icon and clear button on left */
        padding-right: 16px;
    }

    .cbm2-clear-btn {
        width: 24px;
        height: 24px;
        font-size: 22px;
    }

    .cbm2-rtl .cbm2-clear-btn {
        right: auto;
        left: 38px; /* Position for mobile RTL */
    }

    .cbm2-dropdown-list {
        border-radius: 10px;
        box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.15),
                    0 10px 10px -5px rgba(0, 0, 0, 0.04);
        max-height: 60vh;

        /* iOS specific fixes */
        -webkit-overflow-scrolling: touch;
        -webkit-transform: translate3d(0, 0, 0);
    }

    .cbm2-options {
        max-height: calc(60vh - 8px);

        /* Force iOS to render properly */
        -webkit-overflow-scrolling: touch;
        -webkit-transform: translate3d(0, 0, 0);
    }

    .cbm2-option {
        font-size: 15px;
        min-height: 44px;
        display: flex;
        align-items: center;

        /* iOS touch optimization */
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    }

    .cbm2-ltr .cbm2-option {
        padding: 12px 48px 12px 16px;
    }

    .cbm2-rtl .cbm2-option {
        padding: 12px 16px 12px 48px;
    }
}

/* Small mobile devices */
@media (max-width: 375px) {
    .cbm2-dropdown-list {
        max-height: 50vh;
    }

    .cbm2-options {
        max-height: calc(50vh - 8px);
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .cbm2-search-input {
        border-width: 3px;
    }

    .cbm2-dropdown-list {
        border-width: 2px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .cbm2-search-input,
    .cbm2-clear-btn,
    .cbm2-option {
        transition: none;
    }
}

/* Z-index management for checkout pages */
#checkout .cbm2-dropdown-list,
.checkout-index-index .cbm2-dropdown-list,
.onestepcheckout-wrapper .cbm2-dropdown-list,
.amcheckout-wrapper .cbm2-dropdown-list {
    z-index: 9999;
}

/* Compatibility fixes */
.field .cbm2-dropdown {
    margin-top: 5px;
}

/* Porto theme compatibility */
.porto-theme .cbm2-dropdown {
    margin-bottom: 15px;
}

/* Amasty One Step Checkout compatibility */
.amcheckout-wrapper .cbm2-dropdown {
    margin-bottom: 20px;
}

.amcheckout-wrapper .cbm2-dropdown-list {
    z-index: 10000;
}

/* Force visibility for dropdown items */
.cbm2-dropdown-list[style*="display: block"] .cbm2-option,
.cbm2-dropdown-list:not([style*="display: none"]) .cbm2-option {
    color: #374151 !important;
    opacity: 1 !important;
    visibility: visible !important;
}

/* Hide original selects that have been enhanced */
select[data-cbm2-enhanced="true"] {
    display: none !important;
    visibility: hidden !important;
    position: absolute !important;
    left: -9999px !important;
    width: 0 !important;
    height: 0 !important;
    opacity: 0 !important;
}

/* End of styles */