/* Custom Country Dropdown CSS */
/* Specifically for Country Selection (Nationality/Residence) */

.js-country-container,
.country-select-container {
    position: relative !important; /* Fix Stacking Context */
    width: 100%;
    z-index: 1001; /* Ensure container is above other elements */
    overflow: visible !important;
}

.js-country-trigger,
.country-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 15px;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 0.25rem;
    cursor: pointer;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    position: relative;
    z-index: 1002; /* Trigger above container */
    color: var(--text-primary);
}

.js-country-trigger:hover,
.country-select-trigger:hover {
    border-color: var(--primary-color);
}

.js-country-trigger .selected-flag,
.country-select-trigger .selected-flag {
    width: 24px;
    height: 16px;
    margin-left: 10px;
    object-fit: cover;
}

.js-country-dropdown,
.country-select-dropdown {
    position: absolute !important;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 9999 !important; /* Maximum Z-Index */
    background: #ffffff !important; /* Use shorthand to override all bg properties */
    background-color: #ffffff !important;
    opacity: 1 !important;
    border: 1px solid var(--border-color);
    border-radius: 0.25rem;
    box-shadow: var(--card-shadow);
    max-height: 300px;
    overflow-y: auto;
    display: none;
}

.js-country-dropdown.show,
.country-select-dropdown.show {
    display: block !important;
}

.country-option {
    display: flex;
    align-items: center;
    padding: 8px 15px;
    cursor: pointer;
    transition: background-color 0.15s;
    color: var(--text-primary);
}

.country-option:hover {
    background-color: var(--bg-surface-secondary);
}

.country-option img {
    width: 24px;
    height: 16px;
    margin-left: 10px;
    object-fit: cover;
}

.country-option .country-name {
    flex-grow: 1;
}

.country-option .country-code {
    color: var(--text-secondary);
    font-size: 0.9em;
}

/* FIX: Prevent dropdown clipping - Mandatory Overrides */
.js-country-container,
.country-select-container,
.auth-section,
.auth-wrapper,
.login-section,
.container,
.row,
.card,
.login-card,
.auth-card,
.hero-section,
.auth-hero-section {
    overflow: visible !important;
}

/* Ensure dropdown always on top when moved to body */
body > .js-country-dropdown,
body > .country-select-dropdown {
    z-index: 2147483647 !important; /* Max signed 32-bit integer */
    background: #ffffff !important;
    border: 1px solid var(--border-color) !important;
    box-shadow: var(--card-shadow-hover) !important;
    opacity: 1 !important;
    visibility: visible !important;
    color: var(--text-primary) !important;
}

/* Dark Mode Support */
[data-bs-theme='dark'] .js-country-dropdown,
[data-bs-theme='dark'] .country-select-dropdown,
[data-bs-theme='dark'] body > .js-country-dropdown,
[data-bs-theme='dark'] body > .country-select-dropdown {
    background-color: #1e293b !important;
    background: #1e293b !important;
    border-color: #334155 !important;
    color: #ecf0f1 !important;
}

[data-bs-theme='dark'] .country-option:hover {
    background-color: #334155 !important;
}


/* Mobile Specific Fixes */
@media (max-width: 991px) {
    .js-country-dropdown,
    .country-select-dropdown {
        background: #ffffff !important;
        background-color: #ffffff !important;
        opacity: 1 !important;
        /* z-index handled by container */
        max-height: 60vh !important;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    /* CRITICAL: Ensure the open container is above subsequent containers on mobile */
    .js-country-container.is-open,
    .country-select-container.is-open {
        z-index: 2147483647 !important;
    }

    [data-bs-theme='dark'] .js-country-dropdown,
    [data-bs-theme='dark'] .country-select-dropdown {
        background: #1e293b !important;
        background-color: #1e293b !important;
    }
}


/* Handle Stacking Context on Open */
.js-country-container.is-open,
.country-select-container.is-open {
    z-index: 10000 !important; /* Ensure active container is on top of everything */
}
