/* Phone Number Field Styles for ChatWiser Signup */
/* Following ChatWiser branding guidelines and mobile-first approach */

/* Country and Phone Row Layout */
.country-phone-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

.country-phone-row .country-group {
    margin-bottom: 0;
}

.country-phone-row .phone-group {
    margin-bottom: 0;
}

/* Phone Input Container */
.phone-input-container {
    display: flex;
    border: 2px solid #e9ecef;
    border-radius: 12px;
    overflow: visible; /* Allow dropdown to be visible */
    transition: all 0.3s ease;
    background: #fff;
    position: relative;
}

/* Ensure parent containers don't hide dropdown */
.phone-group, .form-group {
    overflow: visible !important;
    position: relative;
}

.country-phone-row {
    overflow: visible !important;
}

.phone-input-container:focus-within {
    border-color: var(--blue, #007bff);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

/* Country Code Selector */
.country-code-selector {
    position: relative;
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: transparent;
    border-right: 1px solid #e9ecef;
    cursor: pointer;
    min-width: 120px;
    transition: background-color 0.2s ease;
    font-weight: 600;
}

.country-code-selector:hover {
    background: #e9ecef;
}

.selected-flag {
    font-size: 18px;
    margin-right: 8px;
    line-height: 1;
}

.selected-code {
    font-weight: 600;
    color: #495057;
    margin-right: 8px;
    font-size: 14px;
}

.dropdown-arrow {
    color: #6c757d;
    font-size: 12px;
    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: 12px 16px;
    font-size: 16px;
    background: transparent;
    outline: none;
    font-weight: 500;
}

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

.phone-number-input::placeholder {
    color: #adb5bd;
    font-weight: 400;
}

/* Country Dropdown */
.country-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff !important;
    border: 2px solid #e9ecef;
    border-top: none;
    border-radius: 0 0 12px 12px;
    max-height: 280px;
    overflow-y: auto;
    z-index: 9999 !important; /* Higher z-index to ensure visibility */
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.25) !important;
    display: none; /* Hidden by default */
    width: 100%;
    min-width: 300px; /* Ensure minimum width */
}

/* Force visibility when shown */
.country-dropdown[style*="block"] {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Custom scrollbar for dropdown */
.country-dropdown::-webkit-scrollbar {
    width: 6px;
}

.country-dropdown::-webkit-scrollbar-track {
    background: #f1f3f4;
}

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

.country-dropdown::-webkit-scrollbar-thumb:hover {
    background: #a8b2ba;
}

/* Region Headers */
.region-header {
    padding: 12px 16px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    font-weight: 700;
    font-size: 13px;
    color: #495057;
    border-bottom: 1px solid #dee2e6;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: sticky;
    top: 0;
    z-index: 1001;
}

/* Country Options */
.country-option {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: 1px solid #f8f9fa;
    background: #fff !important; /* Ensure background is visible */
}

.country-option:hover {
    background: linear-gradient(90deg, rgba(0, 123, 255, 0.05) 0%, transparent 100%) !important;
}

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

.country-option .flag {
    font-size: 16px;
    margin-right: 12px;
    width: 20px;
    flex-shrink: 0;
}

.country-option .country-name {
    flex: 1;
    font-size: 14px;
    color: #495057 !important;
    font-weight: 500;
}

.country-option .phone-code {
    font-size: 13px;
    color: #6c757d !important;
    font-weight: 600;
    margin-left: 8px;
    background: #f8f9fa !important;
    padding: 2px 6px;
    border-radius: 4px;
}

/* Country Search */
.country-search {
    padding: 12px 16px;
    border-bottom: 1px solid #e9ecef;
    background: #fff;
    position: sticky;
    top: 0;
    z-index: 1001;
}

.country-search input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s ease;
}

.country-search input:focus {
    border-color: var(--blue, #007bff);
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.1);
}

.country-search input::placeholder {
    color: #adb5bd;
    font-style: italic;
}

/* Hidden countries during search */
.country-option.hidden {
    display: none !important;
}

/* No results message */
.no-results {
    padding: 20px 16px;
    text-align: center;
    color: #6c757d;
    font-style: italic;
    background: #fff;
}

/* Ensure dropdown is above all other elements */
.country-dropdown {
    position: absolute !important;
    z-index: 99999 !important;
}

/* Field Hints */
.field-hint, .phone-format-hint {
    display: block;
    margin-top: 6px;
    font-size: 12px;
    color: #6c757d;
    font-style: italic;
    line-height: 1.4;
}

/* Error Messages */
.error-message {
    color: #dc3545;
    font-size: 12px;
    margin-top: 6px;
    display: block;
    font-weight: 500;
}

/* Optional Text */
.optional-text {
    color: #6c757d;
    font-weight: 400;
    font-size: 12px;
    margin-left: 4px;
}

/* Validation States */
.phone-input-container.valid {
    border-color: #28a745;
}

.phone-input-container.invalid {
    border-color: #dc3545;
}

.phone-input-container.valid .country-code-selector {
    border-right-color: #28a745;
}

.phone-input-container.invalid .country-code-selector {
    border-right-color: #dc3545;
}

/* High priority countries highlighting */
.country-option[data-code="AE"],
.country-option[data-code="SA"],
.country-option[data-code="QA"],
.country-option[data-code="KW"],
.country-option[data-code="BH"],
.country-option[data-code="OM"] {
    background: linear-gradient(90deg, rgba(0, 123, 255, 0.08) 0%, transparent 100%);
    border-left: 3px solid var(--blue, #007bff);
    font-weight: 600;
}

/* Animation for dropdown */
@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.country-dropdown {
    animation: slideDown 0.2s ease-out;
}

/* Focus states for accessibility */
.country-option:focus {
    outline: 2px solid var(--blue, #007bff);
    outline-offset: -2px;
    background: rgba(0, 123, 255, 0.1);
}

.country-code-selector:focus {
    outline: 2px solid var(--blue, #007bff);
    outline-offset: -2px;
}

/* Loading state */
.country-code-selector.loading::after {
    content: '';
    width: 12px;
    height: 12px;
    border: 2px solid #f3f3f4;
    border-top: 2px solid var(--blue, #007bff);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 8px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
    /* Stack country and phone vertically on mobile */
    .country-phone-row {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    .phone-input-container {
        flex-direction: column;
    }
    
    .country-code-selector {
        border-right: none;
        border-bottom: 1px solid #e9ecef;
        min-width: auto;
        justify-content: space-between;
    }
    
    .country-dropdown {
        max-height: 200px;
    }
    
    .country-option {
        padding: 14px 16px;
    }
    
    .country-option .country-name {
        font-size: 14px;
    }
    
    .region-header {
        padding: 10px 16px;
        font-size: 12px;
    }
    
    /* Larger touch targets on mobile */
    .phone-number-input {
        padding: 14px 16px;
        font-size: 16px; /* Prevent zoom on iOS */
    }
}

@media (max-width: 480px) {
    .country-phone-row {
        gap: 12px;
    }
    
    .phone-input-container {
        border-radius: 8px;
    }
    
    .country-code-selector {
        padding: 10px 12px;
    }
    
    .phone-number-input {
        padding: 12px;
    }
    
    .country-option {
        padding: 12px;
    }
    
    .country-option .country-name {
        font-size: 13px;
    }
    
    .country-option .phone-code {
        font-size: 12px;
    }
}

/* RTL Support for Arabic */
[dir="rtl"] .country-phone-row {
    direction: rtl;
}

[dir="rtl"] .phone-input-container {
    flex-direction: row-reverse;
}

[dir="rtl"] .country-code-selector {
    border-right: none;
    border-left: 1px solid #e9ecef;
}

[dir="rtl"] .selected-flag {
    margin-left: 8px;
    margin-right: 0;
}

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

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

[dir="rtl"] .country-option .flag {
    margin-left: 12px;
    margin-right: 0;
}

[dir="rtl"] .country-option .phone-code {
    margin-right: 8px;
    margin-left: 0;
}

[dir="rtl"] .country-option[data-code="AE"],
[dir="rtl"] .country-option[data-code="SA"],
[dir="rtl"] .country-option[data-code="QA"],
[dir="rtl"] .country-option[data-code="KW"],
[dir="rtl"] .country-option[data-code="BH"],
[dir="rtl"] .country-option[data-code="OM"] {
    border-left: none;
    border-right: 3px solid var(--blue, #007bff);
}

/* Dark mode support (if implemented) */
@media (prefers-color-scheme: dark) {
    .country-dropdown {
        background: #fff !important; /* Ensure dropdown is always visible */
        border-color: #4a5568;
        box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
    }
    
    .region-header {
        background: #f8f9fa !important;
        color: #495057 !important;
    }
    
    .country-option {
        background: #fff !important;
        border-bottom-color: #e9ecef;
    }
    
    .country-option:hover {
        background: #f8f9fa !important;
    }
    
    .country-option .country-name {
        color: #495057 !important;
    }
    
    .country-option .phone-code {
        background: #f8f9fa !important;
        color: #6c757d !important;
    }
}
