/* Country Code Dropdown Styles */

.country-code-dropdown-wrapper {
    position: relative;
    flex: 0 0 auto;
    width: 100px;
    max-width: 100px;
    min-width: 100px;
    z-index: 99999 !important;
    display: block;
    isolation: isolate; /* Create new stacking context */
}

/* Trigger Button */
.country-code-trigger {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    max-width: 100px;
    height: 50px;
    padding: 10px 8px;
    border: 1.3px solid var(--quaternary-color, #E2E8F0);
    border-radius: 10px;
    background-color: rgba(255, 255, 255, 0.3);
    color: #000000;
    font-size: 13px;
    cursor: pointer;
    outline: none;
    transition: all 0.4s ease-in-out;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    box-sizing: border-box;
}

.country-code-trigger:hover {
    background-color: rgba(255, 255, 255, 0.5);
    border-color: var(--primary-color, #6366F1);
}

.country-code-trigger:focus {
    border-color: var(--primary-color, #6366F1);
    background-color: rgba(255, 255, 255, 0.5);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.country-code-trigger[aria-expanded="true"] {
    border-color: var(--primary-color, #6366F1);
    background-color: rgba(255, 255, 255, 0.5);
}

.country-code-trigger[aria-expanded="true"] .country-code-arrow {
    transform: rotate(180deg);
}

/* Flag in trigger */
.country-code-flag {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.country-code-flag img {
    width: 20px;
    height: 15px;
    object-fit: cover;
    border-radius: 2px;
    display: block;
}

/* Country code text in trigger */
.country-code-text {
    font-weight: 500;
    flex: 1;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

/* Arrow icon */
.country-code-arrow {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    transition: transform 0.2s ease-in-out;
    margin-left: auto;
}

.country-code-arrow svg {
    width: 12px;
    height: 12px;
}

/* Dropdown Container */
.country-code-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    width: 280px; /* Fixed width wider than button */
    min-width: 280px;
    background: #FFFFFF;
    border: 1px solid #E2E8F0;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 8px 20px rgba(0, 0, 0, 0.15);
    max-height: 300px;
    overflow: hidden;
    display: none !important;
    z-index: 99999 !important;
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.2s ease-in-out, transform 0.2s ease-in-out;
    visibility: hidden;
}

.country-code-dropdown.active {
    display: block !important;
    opacity: 1;
    transform: translateY(0);
    visibility: visible;
    z-index: 99999 !important;
}

/* When dropdown is active, ensure labels don't interfere */
/* This will be controlled by JavaScript adding a class to body */
body.country-dropdown-open .spectacledcoder-input-secondary .d-label {
    z-index: 0 !important;
}

/* Search Wrapper */
.country-code-search-wrapper {
    padding: 8px;
    border-bottom: 1px solid #E2E8F0;
    background: #F8FAFC;
    position: relative;
    z-index: 100000 !important;
    isolation: isolate;
}

.country-code-search {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #E2E8F0;
    border-radius: 6px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s ease-in-out;
    position: relative;
    z-index: 100000 !important;
    background: #FFFFFF !important;
}

.country-code-search:focus {
    border-color: var(--primary-color, #6366F1);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* Country List */
.country-code-list {
    list-style: none;
    margin: 0;
    padding: 4px 0;
    max-height: 240px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.country-code-list::-webkit-scrollbar {
    width: 6px;
}

.country-code-list::-webkit-scrollbar-track {
    background: #F1F5F9;
}

.country-code-list::-webkit-scrollbar-thumb {
    background: #CBD5E1;
    border-radius: 3px;
}

.country-code-list::-webkit-scrollbar-thumb:hover {
    background: #94A3B8;
}

/* Country Item */
.country-code-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    cursor: pointer;
    transition: background-color 0.15s ease-in-out;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.country-code-item:hover,
.country-code-item:focus {
    background-color: #F1F5F9;
    outline: none;
}

.country-code-item:active {
    background-color: #E2E8F0;
}

/* Flag in list item */
.country-code-item-flag {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.country-code-item-flag img {
    width: 20px;
    height: 15px;
    object-fit: cover;
    border-radius: 2px;
    display: block;
}

/* Country name in list item */
.country-code-item-name {
    flex: 1;
    font-size: 14px;
    color: #0F172A;
    font-weight: 400;
    text-align: left;
}

/* Country code in list item */
.country-code-item-code {
    font-size: 14px;
    color: #475569;
    font-weight: 500;
    flex-shrink: 0;
}

/* Mobile Responsive */
@media only screen and (max-width: 768px) {
    .country-code-dropdown-wrapper {
        width: 90px;
        max-width: 90px;
        min-width: 90px;
    }
    
    .country-code-trigger {
        padding: 8px 6px;
        font-size: 12px;
        max-width: 90px;
    }
    
    .country-code-text {
        font-size: 12px;
    }
    
    .country-code-dropdown {
        width: 260px;
        min-width: 260px;
        max-height: 250px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }
    
    .country-code-list {
        max-height: 200px;
    }
    
    .country-code-item {
        padding: 12px;
    }
    
    .country-code-item-name,
    .country-code-item-code {
        font-size: 13px;
    }
}

/* Ensure dropdown appears above other elements */
.mobile-input-wrapper {
    position: relative;
    z-index: 1;
}

.country-code-dropdown-wrapper {
    z-index: 99999 !important;
    position: relative;
}

/* Prevent text selection on trigger */
.country-code-trigger,
.country-code-item {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Accessibility improvements */
.country-code-trigger:focus-visible {
    outline: 2px solid var(--primary-color, #6366F1);
    outline-offset: 2px;
}

.country-code-item:focus-visible {
    outline: 2px solid var(--primary-color, #6366F1);
    outline-offset: -2px;
}
