/**
 * Custom Searchable Region Dropdown - CSS
 * File: custom-region-dropdown.css
 * Place in: /wp-content/themes/your-theme/assets/css/
 */

/**
 * Custom Searchable Region Dropdown - CSS
 * File: custom-region-dropdown.css
 * Place in: /wp-content/themes/your-theme/assets/css/
 */

/* ========================================
   Hide Default WooCommerce Region Dropdown
   ======================================== */

select#pa_region,
select[name="attribute_pa_region"] {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    height: 0 !important;
    width: 0 !important;
    position: absolute !important;
}

.variations tr:has(select#pa_region),
.variations tr:has(select[name="attribute_pa_region"]) {
    display: none !important;
}

/* Fallback for browsers without :has() support */
.variations select#pa_region {
    display: none !important;
}

.variations label[for="pa_region"] {
    display: none !important;
}

.variations .value:has(select#pa_region) {
    display: none !important;
}

/* ========================================
   Custom Dropdown Container
   ======================================== */

.custom-region-dropdown-wrapper {
    margin-bottom: 20px;
    width: auto;
    max-width: 100%;
    position: relative;
}

.custom-region-dropdown-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 600;
    color: #333;
    margin-bottom: 10px;
}

.custom-region-dropdown-label svg {
    color: #666;
}

/* ========================================
   Select Container
   ======================================== */

.custom-select-container {
    position: relative;
    width: auto;
    max-width: 250px;
    display: inline-block;
}

/* ========================================
   Select Trigger (Main Button)
   ======================================== */

.custom-select-trigger {
    width: auto;
  min-width: auto;  
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 16px;
    background-color: #ffffff;
    border: 1px solid #ddd;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    min-height: auto;
    white-space: nowrap;
}

.custom-select-trigger:hover {
    border-color: #000;
}

.custom-select-trigger.active {
    border-color: #000;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
}

.custom-select-value {
    font-size: 14px;
    color: #999;
    flex: 1;
}

.custom-select-value::before {
    content: attr(data-placeholder);
}

.custom-select-value:not([data-placeholder]) {
    color: #000;
    font-weight: 500;
}

.custom-select-value:not([data-placeholder])::before {
    content: none;
}

.custom-select-arrow {
    margin-left: 8px;
    color: #666;
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.custom-select-trigger.active .custom-select-arrow {
    transform: rotate(180deg);
}

/* ========================================
   Dropdown Panel
   ======================================== */

.custom-select-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    width: 100%;
    min-width: 300px;
    background-color: #ffffff;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1), 
                0 2px 4px rgba(0, 0, 0, 0.06);
    z-index: 9999;
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
    max-height: 380px;
    display: flex;
    flex-direction: column;
}

.custom-select-dropdown.show {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
}

/* ========================================
   Search Input
   ======================================== */

.custom-select-search {
    display: flex;
    align-items: center;
    padding: 0px 16px !important;
    border-bottom: 1px solid #f0f0f0;
    background-color: #fafafa;
    border-radius: 10px 10px 0 0;
    gap: 10px;
    flex-shrink: 0;
}

.search-icon {
    color: #999;
    flex-shrink: 0;
}

.custom-search-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 14px;
    color: #333;
    padding: 4px 0;
  line-height:30px;
}

.custom-search-input::placeholder {
    color: #999;
}

/* ========================================
   Options List
   ======================================== */

.custom-select-options {
    overflow-y: auto;
    max-height: 280px;
    padding: 8px 0;
    flex: 1;
}

/* Custom scrollbar */
.custom-select-options::-webkit-scrollbar {
    width: 8px;
}

.custom-select-options::-webkit-scrollbar-track {
    background: #f5f5f5;
    border-radius: 0 10px 10px 0;
}

.custom-select-options::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

.custom-select-options::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

/* ========================================
   Individual Options
   ======================================== */

.custom-select-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    cursor: pointer;
    transition: background-color 0.15s ease;
    user-select: none;
}

.custom-select-option:hover {
    background-color: #f5f5f5;
}

.custom-select-option.selected {
    background-color: #f0f0f0;
}

.custom-select-option.hidden {
    display: none;
}

.option-text {
    font-size: 14px;
    color: #333;
    flex: 1;
}

.custom-select-option.selected .option-text {
    color: #000;
    font-weight: 600;
}

.option-checkmark {
    color: #000;
    flex-shrink: 0;
    margin-left: 8px;
}

.custom-select-option:not(.selected) .option-checkmark {
    display: none;
}

/* ========================================
   No Results Message
   ======================================== */

.no-results {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: #999;
}

.no-results svg {
    margin-bottom: 12px;
    opacity: 0.5;
}

.no-results p {
    margin: 0;
    font-size: 14px;
}

/* ========================================
   Loading State
   ======================================== */

.custom-select-container.loading .custom-select-trigger {
    opacity: 0.6;
    pointer-events: none;
}

.custom-select-container.loading::after {
    content: '';
    position: absolute;
    right: 50px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #333;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    0% { transform: translateY(-50%) rotate(0deg); }
    100% { transform: translateY(-50%) rotate(360deg); }
}

/* ========================================
   Dynamic Region Display (for icon box)
   ======================================== */

.dynamic-selected-region {
    font-weight: 700;
    color: #000;
    transition: color 0.2s ease;
}

.dynamic-selected-region.no-region {
    color: #999;
    font-style: italic;
    font-weight: 400;
}

.dynamic-selected-region.has-region {
    color: #000;
}

/* ========================================
   Responsive Design
   ======================================== */

@media (max-width: 768px) {
    .custom-select-trigger {
        padding: 5px 14px;
    }
    
    .custom-select-option {
        padding: 10px 14px;
    }
    
    .custom-select-search {
        padding: 10px 14px;
    }
    
    .custom-select-dropdown {
        max-height: 320px;
    }
    
    .custom-select-options {
        max-height: 220px;
    }
}

@media (max-width: 480px) {
    .custom-region-dropdown-wrapper {
        margin-bottom: 15px;
    }
    
    .custom-select-trigger {
        padding: 3px 12px;
        min-height: auto;
    }
    
    .custom-select-dropdown {
        max-height: 280px;
    }
    
    .custom-select-options {
        max-height: 180px;
    }
}

/* ========================================
   Accessibility
   ======================================== */

.custom-select-trigger:focus {
    outline: 2px solid #000;
    outline-offset: 2px;
}

.custom-select-option:focus {
    background-color: #f0f0f0;
    outline: none;
}

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

/* ========================================
   Integration with Existing Bricks Styles
   ======================================== */

/* Match your existing grid layout */
#brxe-kbadqc .custom-region-dropdown-wrapper {
    grid-column: span 2;
}

@media (min-width: 768px) {
    #brxe-kbadqc .custom-region-dropdown-wrapper {
        grid-column: span 1;
    }
}

/* Match your icon box styling for region display */
#brxe-owxkpi .dynamic-selected-region {
    font-weight: inherit;
}

/* ========================================
   Animation Classes
   ======================================== */

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

.custom-select-dropdown.show {
    animation: fadeIn 0.2s ease;
}

/* ========================================
   Print Styles
   ======================================== */

@media print {
    .custom-select-dropdown {
        display: none !important;
    }
}