/**
 * Phone Validation Styles
 * All World Countries Support
 * Ras Soma Theme
 */

/* Wrapper */
.phone-input-wrapper {
    position: relative;
    display: flex;
    align-items: stretch;
    background: var(--bg-white, #fff);
    border: 1px solid var(--border-light, #D4D9DD);
    border-radius: var(--radius-md, 8px);
    overflow: visible;
    transition: all 0.2s ease;
}

.phone-input-wrapper:focus-within {
    border-color: var(--primary-marine, #0D5C6D);
    box-shadow: 0 0 0 3px rgba(13, 92, 109, 0.1);
}

/* Country Selector Button */
.country-selector {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 12px 10px;
    background: var(--bg-cream, #F8F6F3);
    border: none;
    border-right: 1px solid var(--border-light, #D4D9DD);
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    min-width: 95px;
}

[dir="rtl"] .country-selector {
    border-right: none;
    border-left: 1px solid var(--border-light, #D4D9DD);
}

.country-selector:hover {
    background: var(--bg-sand, #EDE8E2);
}

.country-selector .country-flag {
    font-size: 20px;
    line-height: 1;
}

.country-selector .country-code {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-dark, #2C3E50);
    font-family: 'SF Mono', 'Monaco', monospace;
}

.country-selector .chevron {
    width: 12px;
    height: 12px;
    color: var(--text-muted, #8B9DAE);
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

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

/* Phone Input */
.phone-input-wrapper input[type="tel"],
.phone-input-wrapper input[name="phone"] {
    flex: 1;
    border: none !important;
    background: transparent !important;
    padding: 12px 15px !important;
    font-size: 15px !important;
    color: var(--text-dark, #2C3E50) !important;
    outline: none !important;
    box-shadow: none !important;
    min-width: 0;
}

.phone-input-wrapper input::placeholder {
    color: var(--text-muted, #8B9DAE);
}

/* Country Dropdown */
.country-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: auto;
    width: 320px;
    max-width: 90vw;
    background: var(--bg-white, #fff);
    border: 1px solid var(--border-light, #D4D9DD);
    border-radius: var(--radius-md, 8px);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    z-index: 99999;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    overflow: hidden;
}

[dir="rtl"] .country-dropdown {
    left: auto;
    right: 0;
}

.country-dropdown.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Search */
.country-search {
    padding: 10px;
    border-bottom: 1px solid var(--border-light, #D4D9DD);
    background: var(--bg-cream, #F8F6F3);
}

.country-search-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-light, #D4D9DD);
    border-radius: var(--radius-sm, 6px);
    font-size: 14px;
    background: var(--bg-white, #fff);
    outline: none;
    transition: border-color 0.2s ease;
}

.country-search-input:focus {
    border-color: var(--primary-marine, #0D5C6D);
}

/* Options Container */
.country-options {
    max-height: 280px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* Scrollbar */
.country-options::-webkit-scrollbar {
    width: 6px;
}

.country-options::-webkit-scrollbar-track {
    background: var(--bg-cream, #F8F6F3);
}

.country-options::-webkit-scrollbar-thumb {
    background: var(--border-medium, #BEC5CC);
    border-radius: 3px;
}

.country-options::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted, #8B9DAE);
}

/* Country Option */
.country-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    cursor: pointer;
    transition: background 0.15s ease;
    border-bottom: 1px solid var(--border-extra-light, #F0F2F5);
}

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

.country-option:hover {
    background: var(--bg-cream, #F8F6F3);
}

.country-option .country-flag {
    font-size: 20px;
    line-height: 1;
    flex-shrink: 0;
}

.country-option .country-name {
    flex: 1;
    font-size: 14px;
    color: var(--text-dark, #2C3E50);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.country-option .country-code {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted, #8B9DAE);
    font-family: 'SF Mono', 'Monaco', monospace;
    flex-shrink: 0;
}

/* Form Group Integration */
.form-group .phone-input-wrapper {
    width: 100%;
}

/* Responsive */
@media (max-width: 480px) {
    .country-dropdown {
        width: calc(100vw - 40px);
        left: 50%;
        transform: translateX(-50%) translateY(-10px);
    }
    
    .country-dropdown.active {
        transform: translateX(-50%) translateY(0);
    }
    
    .country-selector {
        min-width: 85px;
        padding: 10px 8px;
    }
    
    .country-selector .country-code {
        font-size: 12px;
    }
    
    .phone-input-wrapper input[type="tel"],
    .phone-input-wrapper input[name="phone"] {
        padding: 10px 12px !important;
        font-size: 14px !important;
    }
    
    .country-options {
        max-height: 220px;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .country-dropdown {
        background: #1a1a2e;
        border-color: #333;
    }
    
    .country-search {
        background: #16162a;
        border-color: #333;
    }
    
    .country-search-input {
        background: #1a1a2e;
        border-color: #333;
        color: #fff;
    }
    
    .country-option {
        border-color: #333;
    }
    
    .country-option:hover {
        background: #16162a;
    }
    
    .country-option .country-name {
        color: #fff;
    }
}

/* RTL Adjustments */
[dir="rtl"] .country-option {
    flex-direction: row-reverse;
}

[dir="rtl"] .country-selector {
    flex-direction: row-reverse;
}

/* Animation for smooth appearance */
@keyframes dropdownFadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.country-dropdown.active {
    animation: dropdownFadeIn 0.2s ease forwards;
}

/* Selected state */
.country-option.selected {
    background: var(--primary-marine-light, rgba(13, 92, 109, 0.1));
}

.country-option.selected .country-name {
    color: var(--primary-marine, #0D5C6D);
    font-weight: 600;
}

/* Loading state */
.phone-input-wrapper.loading::after {
    content: '';
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-light);
    border-top-color: var(--primary-marine);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Error state */
.phone-input-wrapper.error {
    border-color: var(--accent-coral, #E57373) !important;
}

.phone-input-wrapper.error:focus-within {
    box-shadow: 0 0 0 3px rgba(229, 115, 115, 0.15);
}

/* Valid state */
.phone-input-wrapper.valid {
    border-color: var(--accent-green, #4CAF50) !important;
}

.phone-input-wrapper.valid:focus-within {
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.15);
}

/* Popular countries highlight */
.country-option[data-iso="EG"],
.country-option[data-iso="SA"],
.country-option[data-iso="AE"],
.country-option[data-iso="KW"],
.country-option[data-iso="QA"],
.country-option[data-iso="OM"],
.country-option[data-iso="BH"] {
    background: linear-gradient(135deg, rgba(13, 92, 109, 0.03), transparent);
}

/* Fix for intl-tel-input library conflicts */
.iti {
    width: 100%;
}

.iti__dropdown-container {
    z-index: 99999 !important;
    pointer-events: auto !important;
}

.iti__country-list {
    max-height: 250px;
    overflow-y: auto;
    pointer-events: auto !important;
}
