/**
 * CF7 Phone Field Styles - Improved UX
 * - Smaller, more compact country code selector
 * - Enhanced validation states with smooth transitions
 * - Better visual feedback and loading states
 */

.cf7-phone-field-container {
    display: block;
    width: 100%;
    position: relative;
}

.cf7-phone-input-group {
    display: flex;
    gap: 0;
    align-items: stretch;
    border: 2px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    background-color: #fff;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.cf7-phone-input-group:focus-within {
    border-color: #0073aa;
    box-shadow: 0 0 0 3px rgba(0, 115, 170, 0.1);
}

.cf7-phone-country-select {
    flex: 0 0 auto;
    min-width: 120px;
    max-width: 140px;
    padding: 12px 34px 12px 10px;
    border: none;
    border-right: 2px solid #f0f0f0;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;
    background-color: #fafafa;
    color: #333;
    cursor: pointer;
    transition: all 0.2s ease;
    outline: none;
    appearance: none;
    background-image: url('data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2010%2010%22%3E%3Cpath%20fill%3D%22%23666%22%20d%3D%22M5%207L1%203h8z%22%2F%3E%3C%2Fsvg%3E');
    background-repeat: no-repeat;
    background-position: right 6px center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cf7-phone-country-select:hover {
    background-color: #f5f5f5;
    border-right-color: #e0e0e0;
}

.cf7-phone-country-select:focus {
    background-color: #fff;
    border-right-color: #0073aa;
}

.cf7-phone-number-input {
    flex: 1 1 auto;
    min-width: 0;
    padding: 12px 14px;
    border: none !important;
    font-size: 15px;
    line-height: 1.5;
    background-color: #fff;
    outline: none !important;
    box-shadow: none !important;
    transition: background-color 0.2s ease;
}

.cf7-phone-number-input::placeholder {
    color: #999;
    opacity: 1;
}

/* Validation States with Smooth Animations */

/* Invalid State */
.cf7-phone-input-group.wpcf7-not-valid,
.cf7-phone-field-wrapper.wpcf7-not-valid .cf7-phone-input-group {
    border-color: #dc3232;
    animation: shake 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-8px); }
    75% { transform: translateX(8px); }
}

.cf7-phone-input-group.wpcf7-not-valid:focus-within,
.cf7-phone-field-wrapper.wpcf7-not-valid .cf7-phone-input-group:focus-within {
    border-color: #dc3232;
    box-shadow: 0 0 0 3px rgba(220, 50, 50, 0.1);
}

/* Error Icon (appears in input group) */
.cf7-phone-input-group.wpcf7-not-valid::after {
    content: '⚠';
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: #dc3232;
    font-size: 18px;
    pointer-events: none;
    animation: fadeIn 0.3s ease;
}

/* Success State */
.cf7-phone-input-group.wpcf7-valid {
    border-color: #46b450;
}

.cf7-phone-input-group.wpcf7-valid:focus-within {
    border-color: #46b450;
    box-shadow: 0 0 0 3px rgba(70, 180, 80, 0.1);
}

/* Success Icon (checkmark) */
.cf7-phone-input-group.wpcf7-valid::after {
    content: '✓';
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%) scale(0);
    color: #46b450;
    font-size: 18px;
    font-weight: bold;
    pointer-events: none;
    animation: successPop 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;
}

@keyframes successPop {
    0% { transform: translateY(-50%) scale(0); }
    50% { transform: translateY(-50%) scale(1.2); }
    100% { transform: translateY(-50%) scale(1); }
}

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

/* Error Message with Better Styling */
.cf7-phone-field-wrapper .wpcf7-not-valid-tip {
    margin-top: 8px;
    padding: 8px 12px;
    font-size: 13px;
    color: #dc3232;
    background-color: #fff5f5;
    border-left: 3px solid #dc3232;
    border-radius: 4px;
    display: flex;
    align-items: center;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.cf7-phone-field-wrapper .wpcf7-not-valid-tip::before {
    content: '⚠';
    margin-right: 8px;
    font-size: 14px;
}

/* Validating State (while checking) */
.cf7-phone-input-group.validating {
    border-color: #0073aa;
    position: relative;
}

.cf7-phone-input-group.validating::after {
    content: '';
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    border: 2px solid #0073aa;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* Disabled State */
.cf7-phone-input-group.disabled,
.cf7-phone-input-group:has(input:disabled) {
    background-color: #f5f5f5;
    cursor: not-allowed;
    opacity: 0.6;
    border-color: #e0e0e0;
}

.cf7-phone-country-select:disabled,
.cf7-phone-number-input:disabled {
    background-color: transparent;
    cursor: not-allowed;
}

/* Loading State for Container */
.cf7-phone-field-container.loading {
    opacity: 0.6;
    pointer-events: none;
}

.cf7-phone-field-container.loading::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    border: 2px solid #0073aa;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    z-index: 10;
}

/* Format Hint */
.cf7-phone-format-hint {
    font-size: 12px;
    color: #666;
    margin-top: 6px;
    display: flex;
    align-items: center;
    animation: fadeIn 0.3s ease;
}

.cf7-phone-format-hint::before {
    content: 'ℹ';
    margin-right: 6px;
    font-size: 14px;
    color: #0073aa;
}

/* Hide hidden field */
.cf7-phone-full-value {
    display: none !important;
}

/* Responsive Design */
@media (max-width: 600px) {
    .cf7-phone-country-select {
        min-width: 85px;
        max-width: 90px;
        font-size: 12px;
        padding: 11px 22px 11px 8px;
        background-position: right 4px center;
    }
    
    .cf7-phone-number-input {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 11px 12px;
    }
    
    .cf7-phone-input-group.wpcf7-not-valid::after,
    .cf7-phone-input-group.wpcf7-valid::after,
    .cf7-phone-input-group.validating::after {
        right: 10px;
        font-size: 16px;
    }
}

@media (max-width: 400px) {
    .cf7-phone-input-group {
        flex-direction: column;
    }
    
    .cf7-phone-country-select {
        max-width: 100%;
        border-right: none;
        border-bottom: 2px solid #f0f0f0;
    }
}

/* RTL Support */
[dir="rtl"] .cf7-phone-input-group {
    direction: rtl;
}

[dir="rtl"] .cf7-phone-country-select {
    border-right: none;
    border-left: 2px solid #f0f0f0;
    background-position: left 6px center;
    padding-left: 24px;
    padding-right: 10px;
}

[dir="rtl"] .cf7-phone-input-group.wpcf7-not-valid::after,
[dir="rtl"] .cf7-phone-input-group.wpcf7-valid::after,
[dir="rtl"] .cf7-phone-input-group.validating::after {
    right: auto;
    left: 14px;
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .cf7-phone-input-group {
        border-width: 3px;
    }
    
    .cf7-phone-country-select {
        border-right-width: 3px;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .cf7-phone-input-group {
        background-color: #1e1e1e;
        border-color: #444;
    }
    
    .cf7-phone-country-select {
        background-color: #2a2a2a;
        color: #fff;
        border-right-color: #333;
    background-image: url('data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2010%2010%22%3E%3Cpath%20fill%3D%22%23ddd%22%20d%3D%22M5%207L1%203h8z%22%2F%3E%3C%2Fsvg%3E');
    }
    
    .cf7-phone-country-select:hover {
        background-color: #333;
    }
    
    .cf7-phone-number-input {
        background-color: #1e1e1e;
        color: #fff;
    }
    
    .cf7-phone-number-input::placeholder {
        color: #888;
    }
    
    .cf7-phone-field-wrapper .wpcf7-not-valid-tip {
        background-color: #2a1515;
        border-left-color: #dc3232;
        color: #ff6b6b;
    }
}

/* Focus Visible for Accessibility */
.cf7-phone-country-select:focus-visible {
    outline: 3px solid #0073aa;
    outline-offset: 2px;
}

.cf7-phone-number-input:focus-visible {
    outline: none;
}

/* Remove conflicting input styling */
.cf7-phone-number-input {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* Ensure proper spacing in forms */
.wpcf7-form p .cf7-phone-field-wrapper {
    display: inline-block;
    width: 100%;
    max-width: 100%;
}

/* Smooth transitions for all states */
* {
    transition-property: border-color, background-color, box-shadow, transform, opacity;
    transition-duration: 0.3s;
    transition-timing-function: ease;
}

/* Custom country dropdown (shows flag icons) */
.cf7-phone-country-select-hidden {
    position: absolute !important;
    opacity: 0 !important;
    width: 1px !important;
    height: 1px !important;
    pointer-events: none !important;
}

.cf7-phone-country-dropdown {
    position: relative;
    min-width: 140px;
    max-width: 180px;
    display: flex;
    align-items: stretch;
}

.cf7-phone-country-button {
    appearance: none;
    -webkit-appearance: none;
    border: none;
    background: transparent;
    padding: 12px 36px 12px 12px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    width: 100%;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Arrow */
.cf7-phone-country-button:after {
    content: '';
    position: absolute;
    right: 12px;
    top: 50%;
    width: 10px;
    height: 10px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: translateY(-60%) rotate(45deg);
    opacity: 0.6;
    transition: transform 0.2s ease;
}

.cf7-phone-country-dropdown.open .cf7-phone-country-button:after {
    transform: translateY(-40%) rotate(-135deg);
}

.cf7-phone-country-list {
    position: absolute;
    left: 0;
    top: calc(100% + 6px);
    z-index: 99999;
    list-style: none;
    margin: 0;
    padding: 6px 0;
    min-width: 280px;
    max-width: 320px;
    max-height: 320px;
    overflow-y: auto;
    overflow-x: hidden;
    background: #fff;
    border: 1px solid rgba(0,0,0,0.15);
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
    display: none;
}

.cf7-phone-country-dropdown.open .cf7-phone-country-list {
    display: block;
    animation: dropdownSlideIn 0.2s ease;
}

@keyframes dropdownSlideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.cf7-phone-country-item {
    padding: 10px 14px;
    cursor: pointer;
    font-size: 14px;
    line-height: 1.6;
    transition: background-color 0.15s ease;
    display: flex;
    align-items: center;
    gap: 10px;
}

.cf7-phone-country-item:hover {
    background: rgba(0, 115, 170, 0.08);
}

.cf7-phone-country-item.selected {
    background: rgba(0, 115, 170, 0.12);
    font-weight: 500;
}

/* Flag icon styling using flag-icons library */
.country-flag-icon {
    width: 24px;
    height: 18px;
    border-radius: 2px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12);
    flex-shrink: 0;
    display: inline-block;
    background-size: cover;
    background-position: center;
}

.cf7-phone-country-button .country-flag-icon {
    width: 22px;
    height: 16px;
}

.country-code {
    color: #666;
    font-weight: 500;
    min-width: 42px;
    flex-shrink: 0;
}

.cf7-phone-country-button .country-code {
    color: #333;
}

.country-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #333;
}

/* Scrollbar styling for dropdown */
.cf7-phone-country-list::-webkit-scrollbar {
    width: 8px;
}

.cf7-phone-country-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.cf7-phone-country-list::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.cf7-phone-country-list::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Responsive adjustments */
@media (max-width: 600px) {
    .cf7-phone-country-dropdown {
        min-width: 120px;
        max-width: 140px;
    }
    
    .cf7-phone-country-button {
        padding: 11px 28px 11px 10px;
        font-size: 13px;
    }
    
    .cf7-phone-country-list {
        min-width: 260px;
    }
}
