/* Phone Input with Country Code Selector */

.phone-input-wrapper {
    display: flex;
    align-items: stretch;
    position: relative;
    width: 100%;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 15px;
    overflow: visible; /* Changed from hidden to visible for dropdown */
    background: transparent;
    transition: all 0.3s ease;
}

.phone-input-wrapper:focus-within {
    border-color: #8A42FF;
    box-shadow: 0 0 0 2px rgba(138, 66, 255, 0.1);
}

/* Country Code Selector Button */
.country-code-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 16px;
    background: rgba(0, 0, 0, 0.03);
    border: none;
    border-right: 1px solid rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 110px;
    height: 58px;
    border-top-left-radius: 15px;
    border-bottom-left-radius: 15px;
}

.country-code-selector:hover {
    background: rgba(0, 0, 0, 0.05);
}

.country-code-selector:focus {
    outline: none;
    background: rgba(138, 66, 255, 0.05);
}

.country-code-selector:active {
    background: rgba(138, 66, 255, 0.08);
}

/* Flag Icon - Now handles images */
.flag-icon {
    min-width: 28px;
    height: 20px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.flag-image {
    width: 24px;
    height: auto;
    border-radius: 2px;
    display: inline-block;
    vertical-align: middle;
}

.flag-fallback {
    font-size: 12px;
    font-weight: 600;
    color: rgba(0, 0, 0, 0.6);
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 6px;
    border-radius: 3px;
    display: inline-block;
}

.dial-code {
    font-size: 16px;
    font-weight: 500;
    color: rgba(0, 0, 0, 0.7);
    font-family: 'Gordita', sans-serif;
}

.dropdown-arrow {
    font-size: 10px;
    color: rgba(0, 0, 0, 0.4);
    transition: transform 0.2s ease;
}

.country-code-selector.active .dropdown-arrow {
    transform: rotate(180deg);
}

/* Phone Number Input */
.phone-number-input {
    flex: 1;
    border: none !important;
    padding: 0 20px;
    font-size: 18px;
    color: rgba(0, 0, 0, 0.7);
    background: transparent;
    height: 58px;
    font-family: 'Gordita', sans-serif;
    border-top-right-radius: 15px;
    border-bottom-right-radius: 15px;
}

.phone-number-input:focus {
    outline: none;
}

.phone-number-input::placeholder {
    color: rgba(0, 0, 0, 0.4);
}

/* Country Dropdown */
.country-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    width: 100%;
    max-width: 380px;
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    z-index: 9999 !important; /* Force high z-index */
    overflow: hidden;
    animation: slideDown 0.2s ease;
    display: none; /* Hidden by default */
}

.country-dropdown[style*="display: block"],
.country-dropdown:not([style*="display: none"]) {
    display: block !important;
}

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

/* Country Search */
.country-search-wrapper {
    padding: 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    background: #f8f9fa;
}

.country-search-input {
    width: 100%;
    padding: 10px 15px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 10px;
    font-size: 15px;
    font-family: 'Gordita', sans-serif;
    background: #fff;
    transition: all 0.2s ease;
}

.country-search-input:focus {
    outline: none;
    border-color: #8A42FF;
    box-shadow: 0 0 0 2px rgba(138, 66, 255, 0.1);
}

.country-search-input::placeholder {
    color: rgba(0, 0, 0, 0.4);
}

/* Country List */
.country-list {
    max-height: 280px;
    overflow-y: auto;
    overflow-x: hidden;
}

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

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

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

.country-list::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* Country Item */
.country-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

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

.country-item:hover {
    background: rgba(138, 66, 255, 0.05);
}

.country-item.selected {
    background: rgba(138, 66, 255, 0.1);
}

.country-item .flag-icon {
    flex-shrink: 0;
}

.country-item .country-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
}

.country-item .country-name {
    font-size: 15px;
    font-weight: 500;
    color: rgba(0, 0, 0, 0.8);
    font-family: 'Gordita', sans-serif;
}

.country-item .country-dial-code {
    font-size: 14px;
    color: rgba(0, 0, 0, 0.5);
    font-family: 'Gordita', sans-serif;
    margin-left: auto;
    font-weight: 500;
}

/* No Results */
.no-results {
    padding: 20px;
    text-align: center;
    color: rgba(0, 0, 0, 0.5);
    font-size: 14px;
    font-style: italic;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .phone-input-wrapper,
    .phone-number-input {
        height: 52px;
    }

    .country-code-selector {
        min-width: 95px;
        padding: 0 12px;
        gap: 6px;
        height: 52px;
    }

    .flag-image {
        width: 20px;
    }

    .dial-code {
        font-size: 14px;
    }

    .phone-number-input {
        font-size: 16px;
        padding: 0 15px;
    }

    .country-dropdown {
        max-width: 100%;
    }

    .country-item {
        padding: 10px 12px;
    }

    .country-item .country-name {
        font-size: 14px;
    }

    .country-item .country-dial-code {
        font-size: 13px;
    }
}

/* Validation States */
.phone-input-wrapper.is-valid {
    border-color: #10b981;
}

.phone-input-wrapper.is-invalid {
    border-color: #ef4444;
}

.phone-input-wrapper.is-valid:focus-within {
    border-color: #10b981;
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.1);
}

.phone-input-wrapper.is-invalid:focus-within {
    border-color: #ef4444;
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.1);
}

/* Loading State */
.country-list.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100px;
}

.country-list.loading::before {
    content: '';
    width: 24px;
    height: 24px;
    border: 3px solid rgba(138, 66, 255, 0.2);
    border-top-color: #8A42FF;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Accessibility */
.country-item:focus,
.country-code-selector:focus {
    outline: 2px solid #8A42FF;
    outline-offset: -2px;
}

/* Ensure dropdown stays visible above other elements */
.input-group-meta {
    position: relative;
    z-index: 1;
}

.input-group-meta:has(.country-dropdown[style*="display: block"]) {
    z-index: 10000 !important;
}

/* Override any parent z-index that might be blocking */
.phone-input-wrapper,
.country-dropdown {
    isolation: isolate;
}

/* Flag loading placeholder */
.flag-icon img.flag-image {
    background: rgba(0, 0, 0, 0.03);
}

/* Debug helper - remove after testing */
.country-dropdown.debug-visible {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
}
