/**
 * Custom Styling for intl-tel-input Widget
 * Matches the purple gradient theme (#667eea → #764ba2)
 * Mobile-optimized with 44×44px touch targets
 * WCAG 2.1 AA compliant contrast ratios
 */

/* =================================================================
   Hide Legacy Dropdown (replaced by intl-tel-input)
   ================================================================= */

#phoneCountryCode {
    display: none !important;
}

/* =================================================================
   Base Container Styling
   ================================================================= */

.iti {
    width: 100%;
    display: block;
}

.iti__input {
    width: 100% !important;
    padding: 12px 12px 12px 60px !important;
    border: 2px solid #ddd !important;
    border-radius: 8px !important;
    font-size: 16px !important;
    transition: border-color 0.3s ease, box-shadow 0.3s ease !important;
    background-color: white !important;
    color: #2d3748 !important;
}

.iti__input:focus {
    outline: none !important;
    border-color: #667eea !important;
    box-shadow: 0 0 8px rgba(102, 126, 234, 0.3) !important;
}

/* =================================================================
   Country Dropdown Button
   ================================================================= */

.iti__selected-flag {
    position: absolute !important;
    top: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    padding: 0 12px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background-color: #f7fafc !important;
    border-right: 2px solid #ddd !important;
    border-radius: 8px 0 0 8px !important;
    cursor: pointer !important;
    transition: all 0.3s ease !important;
    min-width: 52px !important;
    /* Mobile touch target: 44×44px minimum */
    min-height: 44px !important;
}

.iti__selected-flag:hover {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
}

.iti__selected-flag:hover .iti__flag,
.iti__selected-flag:hover .iti__arrow {
    filter: brightness(0) invert(1) !important;
}

.iti__selected-flag:focus {
    outline: 2px solid #667eea !important;
    outline-offset: 2px !important;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
}

.iti__selected-flag:focus .iti__flag,
.iti__selected-flag:focus .iti__arrow {
    filter: brightness(0) invert(1) !important;
}

/* =================================================================
   Flag Icons
   ================================================================= */

.iti__flag {
    margin-right: 6px !important;
    width: 20px !important;
    height: 15px !important;
    box-shadow: 0 0 1px 0 #888 !important;
}

/* =================================================================
   Arrow Indicator
   ================================================================= */

.iti__arrow {
    margin-left: 6px !important;
    width: 0 !important;
    height: 0 !important;
    border-left: 4px solid transparent !important;
    border-right: 4px solid transparent !important;
    border-top: 5px solid #2d3748 !important;
    transition: transform 0.3s ease, border-top-color 0.3s ease !important;
}

.iti__selected-flag:hover .iti__arrow,
.iti__selected-flag:focus .iti__arrow {
    border-top-color: white !important;
}

.iti--show-flags .iti__arrow {
    transform: rotate(180deg) !important;
}

/* =================================================================
   Country Dropdown List
   ================================================================= */

.iti__country-list {
    background-color: white !important;
    border: 2px solid #667eea !important;
    border-radius: 8px !important;
    box-shadow: 0 10px 30px rgba(102, 126, 234, 0.2) !important;
    max-height: 280px !important;
    overflow-y: auto !important;
    z-index: 9999 !important;
    margin-top: 4px !important;
    padding: 0 !important;
    list-style: none !important;
}

/* Custom scrollbar for dropdown */
.iti__country-list::-webkit-scrollbar {
    width: 8px !important;
}

.iti__country-list::-webkit-scrollbar-track {
    background: #f7fafc !important;
    border-radius: 8px !important;
}

.iti__country-list::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    border-radius: 8px !important;
}

.iti__country-list::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%) !important;
}

/* =================================================================
   Search Input in Dropdown
   ================================================================= */

.iti__search-input {
    width: calc(100% - 16px) !important;
    margin: 8px !important;
    padding: 10px 12px !important;
    border: 2px solid #ddd !important;
    border-radius: 6px !important;
    font-size: 15px !important;
    transition: border-color 0.3s ease, box-shadow 0.3s ease !important;
    background-color: white !important;
    color: #2d3748 !important;
}

.iti__search-input:focus {
    outline: none !important;
    border-color: #667eea !important;
    box-shadow: 0 0 6px rgba(102, 126, 234, 0.3) !important;
}

.iti__search-input::placeholder {
    color: #a0aec0 !important;
}

/* =================================================================
   Country List Items
   ================================================================= */

.iti__country {
    padding: 10px 14px !important;
    display: flex !important;
    align-items: center !important;
    cursor: pointer !important;
    transition: background-color 0.2s ease, color 0.2s ease !important;
    color: #2d3748 !important;
    font-size: 15px !important;
    /* Mobile touch target */
    min-height: 44px !important;
}

.iti__country:hover {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: white !important;
}

.iti__country:focus {
    outline: 2px solid #667eea !important;
    outline-offset: -2px !important;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: white !important;
}

.iti__country.iti__highlight {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: white !important;
}

.iti__country.iti__active {
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%) !important;
    color: white !important;
    font-weight: 600 !important;
}

/* Country name and dial code spacing */
.iti__country-name {
    margin-right: auto !important;
    margin-left: 8px !important;
}

.iti__dial-code {
    color: inherit !important;
    margin-left: 8px !important;
}

/* =================================================================
   Divider Between Countries
   ================================================================= */

.iti__divider {
    border-bottom: 1px solid #e2e8f0 !important;
    margin: 4px 0 !important;
    padding: 0 !important;
}

/* =================================================================
   Preferred Countries Section
   ================================================================= */

.iti__preferred {
    background-color: #f7fafc !important;
}

/* =================================================================
   Mobile Responsive Adjustments
   ================================================================= */

@media (max-width: 768px) {
    .iti__input {
        padding: 14px 14px 14px 64px !important;
        font-size: 16px !important; /* Prevents iOS zoom on focus */
    }

    .iti__selected-flag {
        padding: 0 14px !important;
        min-width: 56px !important;
        min-height: 44px !important;
    }

    .iti__country-list {
        max-height: 240px !important;
        border-radius: 12px !important;
    }

    .iti__country {
        padding: 12px 16px !important;
        font-size: 16px !important;
        min-height: 44px !important;
    }

    .iti__search-input {
        padding: 12px 14px !important;
        font-size: 16px !important;
    }
}

@media (max-width: 480px) {
    .iti__input {
        padding: 16px 16px 16px 68px !important;
    }

    .iti__selected-flag {
        min-width: 60px !important;
        min-height: 48px !important;
    }

    .iti__country {
        padding: 14px 18px !important;
        min-height: 48px !important;
    }

    .iti__country-list {
        max-height: 200px !important;
    }
}

/* =================================================================
   High Contrast Mode Support (Accessibility)
   ================================================================= */

@media (prefers-contrast: high) {
    .iti__input {
        border-width: 3px !important;
    }

    .iti__selected-flag {
        border-right-width: 3px !important;
    }

    .iti__country-list {
        border-width: 3px !important;
    }

    .iti__country:focus {
        outline-width: 3px !important;
    }
}

/* =================================================================
   Reduced Motion Support (Accessibility)
   ================================================================= */

@media (prefers-reduced-motion: reduce) {
    .iti__input,
    .iti__selected-flag,
    .iti__arrow,
    .iti__country,
    .iti__search-input {
        transition: none !important;
    }
}

/* =================================================================
   Error State Styling
   ================================================================= */

.iti.iti--error .iti__input {
    border-color: #e74c3c !important;
    box-shadow: 0 0 8px rgba(231, 76, 60, 0.3) !important;
}

.iti.iti--error .iti__selected-flag {
    border-right-color: #e74c3c !important;
}

/* =================================================================
   Disabled State Styling
   ================================================================= */

.iti__input:disabled {
    background-color: #f7fafc !important;
    color: #a0aec0 !important;
    cursor: not-allowed !important;
    border-color: #e2e8f0 !important;
}

.iti__input:disabled + .iti__selected-flag {
    background-color: #e2e8f0 !important;
    cursor: not-allowed !important;
    opacity: 0.6 !important;
}

/* =================================================================
   Focus Visible for Keyboard Navigation
   ================================================================= */

.iti__selected-flag:focus-visible {
    outline: 3px solid #667eea !important;
    outline-offset: 2px !important;
}

.iti__country:focus-visible {
    outline: 3px solid #667eea !important;
    outline-offset: -3px !important;
}

.iti__search-input:focus-visible {
    outline: 3px solid #667eea !important;
    outline-offset: 2px !important;
}

/* =================================================================
   Loading State (Optional)
   ================================================================= */

.iti.iti--loading .iti__selected-flag::after {
    content: '';
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 12px;
    height: 12px;
    border: 2px solid #667eea;
    border-top-color: transparent;
    border-radius: 50%;
    animation: iti-spinner 0.6s linear infinite;
}

@keyframes iti-spinner {
    to {
        transform: translateY(-50%) rotate(360deg);
    }
}

/* =================================================================
   RTL (Right-to-Left) Support
   ================================================================= */

[dir="rtl"] .iti__input {
    padding: 12px 60px 12px 12px !important;
}

[dir="rtl"] .iti__selected-flag {
    left: auto !important;
    right: 0 !important;
    border-right: none !important;
    border-left: 2px solid #ddd !important;
    border-radius: 0 8px 8px 0 !important;
}

[dir="rtl"] .iti__flag {
    margin-right: 0 !important;
    margin-left: 6px !important;
}

[dir="rtl"] .iti__arrow {
    margin-left: 0 !important;
    margin-right: 6px !important;
}

[dir="rtl"] .iti__country-name {
    margin-right: 8px !important;
    margin-left: auto !important;
}

[dir="rtl"] .iti__dial-code {
    margin-left: 0 !important;
    margin-right: 8px !important;
}
