/* Override intl-tel-input flag paths when build/img is missing - use CDN */
:root {
    --iti-path-flags-1x: url("https://cdn.jsdelivr.net/npm/intl-tel-input@25.3.1/build/img/flags.webp");
    --iti-path-flags-2x: url("https://cdn.jsdelivr.net/npm/intl-tel-input@25.3.1/build/img/flags@2x.webp");
    --iti-path-globe-1x: url("https://cdn.jsdelivr.net/npm/intl-tel-input@25.3.1/build/img/globe.webp");
    --iti-path-globe-2x: url("https://cdn.jsdelivr.net/npm/intl-tel-input@25.3.1/build/img/globe@2x.webp");

    /* Light theme defaults (explicit to avoid inheriting dark text on light dropdown) */
    --iti-border-color: #d0d7de;
    --iti-dropdown-bg: #ffffff;
    --iti-hover-color: rgba(215, 38, 61, 0.08); /* match site dropdown hover */
    --iti-dialcode-color: #6c757d;
    --iti-arrow-color: #495057;
}

/* Dark theme: make the dropdown readable (theme is on html, not body!) */
html[data-theme="dark"],
[data-theme="dark"] {
    --iti-border-color: rgba(255, 255, 255, 0.14);
    --iti-dropdown-bg: #141414;
    --iti-hover-color: rgba(215, 38, 61, 0.20);
    --iti-dialcode-color: rgba(255, 255, 255, 0.70);
    --iti-arrow-color: rgba(255, 255, 255, 0.80);
}

/* Keep dropdown hidden on load: library uses .iti__hide; our display:flex must not override it */
.iti--inline-dropdown .iti__dropdown-content.iti__hide {
    display: none !important;
}
/* Avoid dropdown overlapping buttons: limit height + allow opening upward. Use flex so list scrolls and last row is never clipped. */
.iti--inline-dropdown .iti__dropdown-content {
    z-index: 1060;
    display: flex;
    flex-direction: column;
    min-height: 215px !important;
    max-height: 240px !important;
    min-width: 0;
    max-width: min(360px, 92vw);
    width: max-content;
    overflow: hidden;
    background: var(--iti-dropdown-bg);
    border: 1px solid var(--iti-border-color);
    border-radius: 12px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
    color: #212529; /* force readable text in light mode */
}
/* Search (first direct child) must not shrink so list gets remaining space */
.iti--inline-dropdown .iti__dropdown-content > *:first-child {
    flex: 0 0 auto;
}
/* List: show only 3 items at a time, scroll for the rest (init 10, search can return many) */
.iti--inline-dropdown .iti__country-list {
    flex: 1 1 0;
    min-height: 145px !important;
    max-height: 145px !important;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 6px 6px 14px 6px;
    box-sizing: border-box;
}
/* When dropdown opens upward (JS adds .iti--dropup) */
.iti--dropup.iti--inline-dropdown .iti__dropdown-content {
    top: auto;
    bottom: 100%;
    margin-top: 0;
    margin-bottom: 3px;
}

/* Dark theme text (theme lives on html – body never has data-theme!) */
html[data-theme="dark"] .iti--inline-dropdown .iti__dropdown-content,
[data-theme="dark"] .iti--inline-dropdown .iti__dropdown-content {
    color: rgba(255, 255, 255, 0.92);
}
html[data-theme="dark"] .iti--inline-dropdown .iti__country-name,
[data-theme="dark"] .iti--inline-dropdown .iti__country-name,
.iti__dropdown-content.iti-dropdown--dark .iti__country-name {
    color: rgba(255, 255, 255, 0.95) !important;
}
html[data-theme="dark"] .iti--inline-dropdown .iti__dial-code,
[data-theme="dark"] .iti--inline-dropdown .iti__dial-code,
.iti__dropdown-content.iti-dropdown--dark .iti__dial-code {
    color: rgba(255, 255, 255, 0.85) !important;
}

/* Search input styling */
.iti--inline-dropdown .iti__search-input {
    background: transparent;
    border: 1px solid var(--iti-border-color);
    border-radius: 10px;
    padding: 8px 12px;
    margin: 8px;
    width: calc(100% - 16px);
    color: inherit;
    outline: none;
}
.iti--inline-dropdown .iti__search-input::placeholder {
    color: rgba(108, 117, 125, 0.95);
}
html[data-theme="dark"] .iti--inline-dropdown .iti__search-input::placeholder,
[data-theme="dark"] .iti--inline-dropdown .iti__search-input::placeholder {
    color: rgba(255, 255, 255, 0.55);
}

/* Country rows: spacing + hover + selected/highlight */
.iti--inline-dropdown .iti__country {
    border-radius: 10px;
    padding: 10px 10px;
    margin: 2px 0;
    min-width: 0;
    overflow: hidden;
}
.iti--inline-dropdown .iti__country .iti__country-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}
.iti--inline-dropdown .iti__country:hover,
.iti--inline-dropdown .iti__country.iti__highlight {
    background: var(--iti-hover-color);
}
.iti--inline-dropdown .iti__country.iti__active {
    background: rgba(215, 38, 61, 0.12);
}
/* Last row fully visible when scrolled to end */
.iti--inline-dropdown .iti__country-list > .iti__country:last-child {
    margin-bottom: 4px;
}
html[data-theme="dark"] .iti--inline-dropdown .iti__country.iti__active,
[data-theme="dark"] .iti--inline-dropdown .iti__country.iti__active {
    background: rgba(215, 38, 61, 0.26);
}

/* Dial code readability */
.iti--inline-dropdown .iti__dial-code {
    color: var(--iti-dialcode-color);
}

/* Divider color */
.iti--inline-dropdown .iti__divider {
    border-color: var(--iti-border-color) !important;
    opacity: 0.8;
}

/* Ensure dropdown is above cards/modals and not clipped */
.iti {
    z-index: 10;
}

/* Hide phone field until intl-tel-input is fully ready (flag + dial code) so user never sees plain input */
.profile-phone-wrapper.phone-input-pending {
    opacity: 0;
    visibility: hidden;
    min-height: 2.75rem;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}
.profile-phone-wrapper:not(.phone-input-pending) {
    opacity: 1;
    visibility: visible;
}
