/* Phone Input Redesign - Mobile-First Approach */

/* Phone Input Container */
.phone-input-redesign {
    position: relative;
    margin-bottom: 16px;
}

.phone-container {
    display: flex;
    gap: 8px;
    align-items: stretch;
    position: relative;
}

/* Country Select Button */
.phone-country-select {
    flex-shrink: 0;
    position: relative;
}

.country-select-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 12px 14px;
    background: var(--bg-hover);
    border: 1px solid var(--border-default);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    height: 48px;
    min-width: 90px;
}

.country-select-btn:hover {
    background: var(--bg-active);
    border-color: var(--border-hover);
}

.country-select-btn:active {
    transform: scale(0.98);
}

.selected-country {
    display: flex;
    align-items: center;
    gap: 6px;
}

.country-flag {
    font-size: 20px;
    line-height: 1;
    display: flex;
    align-items: center;
}

.country-code {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', monospace;
}

.dropdown-icon {
    color: var(--text-tertiary);
    transition: transform 0.2s ease;
    margin-left: 2px;
}

.country-select-btn:hover .dropdown-icon {
    color: var(--text-secondary);
}

.country-select-btn.active .dropdown-icon {
    transform: rotate(180deg);
}

/* Phone Number Input */
.phone-number-input {
    flex: 1;
    padding: 16px 18px;
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 500;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', monospace;
    transition: all 0.2s ease;
    height: 48px;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.phone-number-input::placeholder {
    color: var(--text-muted);
    font-weight: 400;
}

.phone-number-input:hover {
    border-color: var(--border-hover);
}

.phone-number-input:focus {
    outline: none;
    border-color: var(--border-focus);
    background: var(--bg-hover);
}

/* Country Selection Modal */
.country-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.country-modal.active {
    opacity: 1;
    pointer-events: auto;
}

.country-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.country-modal-content {
    position: relative;
    background: var(--bg-secondary);
    border-radius: 24px 24px 0 0;
    width: 100%;
    max-width: 500px;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
}

.country-modal.active .country-modal-content {
    transform: translateY(0);
}

/* Modal Header */
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    border-bottom: 1px solid var(--border-default);
}

.modal-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-hover);
    border: none;
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: var(--bg-active);
    color: var(--text-primary);
}

/* Country Search */
.country-search {
    padding: 16px;
    border-bottom: 1px solid var(--border-default);
}

.search-input {
    width: 100%;
    padding: 12px 16px 12px 42px;
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: 8px;
    font-size: 16px;
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.search-input::placeholder {
    color: var(--text-muted);
}

.search-input:focus {
    outline: none;
    border-color: var(--border-focus);
    background: var(--bg-hover);
}

.search-icon {
    position: absolute;
    left: 28px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    color: var(--text-tertiary);
    pointer-events: none;
}

/* Country List */
.country-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    -webkit-overflow-scrolling: touch;
}

.country-list::-webkit-scrollbar {
    width: 6px;
}

.country-list::-webkit-scrollbar-track {
    background: var(--bg-hover);
    border-radius: 3px;
}

.country-list::-webkit-scrollbar-thumb {
    background: var(--border-hover);
    border-radius: 3px;
}

.country-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: transparent;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
    text-align: left;
}

.country-item:hover {
    background: var(--bg-hover);
}

.country-item:active {
    background: var(--bg-active);
    transform: scale(0.98);
}

.country-item.selected {
    background: var(--bg-active);
    border: 1px solid var(--border-hover);
}

.country-flag-large {
    font-size: 24px;
    width: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.country-info {
    flex: 1;
    min-width: 0;
}

.country-name {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.country-item:hover .country-name {
    color: var(--primary-2);
}

.country-details {
    font-size: 13px;
    color: var(--text-tertiary);
}

.country-code-display {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-secondary);
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', monospace;
}

/* Popular Countries Section */
.popular-section {
    padding: 12px 8px 8px;
    border-bottom: 1px solid var(--border-default);
}

.popular-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    padding: 0 8px;
}

/* Loading State */
.country-list.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-default);
    border-top-color: var(--primary-2);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    text-align: center;
}

.empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-text {
    font-size: 14px;
    color: var(--text-tertiary);
}

/* Error States */
.phone-input-redesign.error .phone-number-input {
    border-color: var(--error);
    background: var(--error-bg);
}

.phone-input-redesign.error .country-select-btn {
    border-color: var(--error);
}

/* Success States */
.phone-input-redesign.success .phone-number-input {
    border-color: var(--success);
    background: var(--success-bg);
    padding-right: 44px;
}

.phone-input-redesign.success .country-select-btn {
    border-color: var(--success);
}

/* Success Icon for Phone Input */
.phone-input-redesign .success-icon {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    opacity: 0;
    pointer-events: none;
    z-index: 10;
}

.phone-input-redesign.success .success-icon {
    opacity: 1;
    animation: successBounce 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* Mobile Specific Styles */
@media (max-width: 480px) {
    .phone-container {
        gap: 6px;
    }
    
    .country-select-btn {
        padding: 12px 10px;
        min-width: 80px;
    }
    
    .country-code {
        font-size: 13px;
    }
    
    .dropdown-icon {
        width: 14px;
        height: 14px;
    }
    
    .phone-number-input {
        font-size: 16px; /* Prevent zoom on iOS */
        padding: 16px 14px;
    }
    
    /* Full screen modal on mobile */
    .country-modal-content {
        max-height: 85vh;
        border-radius: 16px 16px 0 0;
    }
    
    .modal-header {
        padding: 16px;
    }
    
    .modal-title {
        font-size: 16px;
    }
    
    .country-search {
        padding: 12px;
    }
    
    .search-input {
        padding: 10px 14px 10px 38px;
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    .search-icon {
        left: 24px;
        width: 18px;
        height: 18px;
    }
    
    .country-item {
        padding: 10px 12px;
    }
    
    .country-flag-large {
        font-size: 20px;
        width: 28px;
    }
    
    .country-name {
        font-size: 14px;
    }
    
    .country-code-display {
        font-size: 14px;
    }
}

/* Tablet and Desktop */
@media (min-width: 768px) {
    /* Modal appears as dropdown on desktop */
    .country-modal {
        position: absolute;
        top: auto;
        left: auto;
        right: auto;
        bottom: auto;
        background: none;
        padding: 0;
    }
    
    .country-modal-overlay {
        display: none;
    }
    
    .country-modal-content {
        position: absolute;
        top: calc(100% + 8px);
        left: 0;
        width: 360px;
        max-height: 400px;
        border-radius: 12px;
        transform: translateY(-10px) scale(0.95);
        opacity: 0;
        box-shadow: var(--shadow-xl);
        border: 1px solid var(--border-default);
    }
    
    .country-modal.active .country-modal-content {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
    
    .modal-header {
        padding: 16px;
    }
    
    .country-search {
        padding: 0 16px 16px;
    }
}

/* Light Theme Adjustments */
[data-theme="light"] .country-select-btn {
    background: white;
    border-color: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .country-select-btn:hover {
    background: rgba(0, 0, 0, 0.02);
    border-color: rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .phone-number-input {
    background: white;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
}

[data-theme="light"] .country-modal-content {
    background: white;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .modal-close {
    background: rgba(0, 0, 0, 0.04);
}

[data-theme="light"] .modal-close:hover {
    background: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .search-input {
    background: rgba(0, 0, 0, 0.02);
}

[data-theme="light"] .country-item:hover {
    background: rgba(0, 0, 0, 0.02);
}

[data-theme="light"] .country-item:active {
    background: rgba(0, 0, 0, 0.04);
}

[data-theme="light"] .country-item.selected {
    background: rgba(102, 126, 234, 0.08);
    border-color: rgba(102, 126, 234, 0.2);
}

/* Animations */
@keyframes modalSlideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Accessibility */
.country-select-btn:focus-visible,
.modal-close:focus-visible,
.search-input:focus-visible,
.country-item:focus-visible {
    outline: 2px solid var(--primary-2);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .country-select-btn,
    .phone-number-input,
    .country-item {
        border-width: 2px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .country-modal,
    .country-modal-content,
    .country-select-btn,
    .dropdown-icon,
    .country-item {
        transition: none;
    }
    
    .loading-spinner {
        animation: none;
        opacity: 0.5;
    }
}