/**
 * Smart Phone Input Styles
 */

.phone-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
}

.country-selector {
    flex-shrink: 0;
    width: 120px;
    padding: 8px 12px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    background: white;
    font-size: 14px;
    color: #495057;
}

.country-selector:focus {
    border-color: #86b7fe;
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

.phone-input-wrapper input[type="tel"] {
    flex: 1;
    min-width: 0; /* Prevent flex item from being wider than its container */
}

.phone-input-wrapper input[type="tel"].is-valid {
    border-color: #198754;
    padding-right: calc(1.5em + 0.75rem);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='%23198754' d='m2.3 6.73.52.53.53-.53-1.04-1.04.54-.54 1.54 1.54-.52.52-.55-.53-.52.52zm1.47-2.88L5.84 1.8l.53.52-2.04 2.05-.53-.52z'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right calc(0.375em + 0.1875rem) center;
    background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

.phone-input-wrapper input[type="tel"].is-invalid {
    border-color: #dc3545;
    padding-right: calc(1.5em + 0.75rem);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' width='12' height='12' fill='none' stroke='%23dc3545'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath d='m5.5 5.5 1 1m0 0 1 1m-1-1 1-1m-1 1-1 1'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right calc(0.375em + 0.1875rem) center;
    background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

.phone-tooltip {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 8px 12px;
    font-size: 12px;
    color: #6c757d;
    z-index: 1000;
    margin-top: 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    display: none;
}

.phone-tooltip::before {
    content: '';
    position: absolute;
    top: -5px;
    left: 20px;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 5px solid #f8f9fa;
}

.phone-help-text,
.form-text.phone-help {
    font-size: 12px;
    color: #6c757d;
    margin-top: 4px;
    display: block;
}

.phone-help-text.country-specific {
    color: #0d6efd;
    font-weight: 500;
}

/* Country flags in dropdown */
.country-selector option {
    padding: 4px 8px;
    font-size: 14px;
}

/* Loading state */
.phone-input-wrapper.loading .country-selector {
    background-image: url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTggMTVBNyA3IDAgMSAxIDggMSIgc3Ryb2tlPSIjNzc4ODk5IiBzdHJva2Utd2lkdGg9IjIiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIvPgo8L3N2Zz4K');
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 16px;
    animation: spin 1s linear infinite;
}

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

/* Responsive design */
@media (max-width: 576px) {
    .phone-input-wrapper {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .country-selector {
        width: 100%;
    }

    .phone-tooltip {
        position: static;
        margin-top: 8px;
        display: block !important;
    }

    .phone-tooltip::before {
        display: none;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .country-selector {
        background-color: #2d3748;
        color: #e2e8f0;
        border-color: #4a5568;
    }

    .phone-tooltip {
        background-color: #2d3748;
        color: #e2e8f0;
        border-color: #4a5568;
    }

    .phone-tooltip::before {
        border-bottom-color: #2d3748;
    }

    .phone-help-text.country-specific {
        color: #63b3ed;
    }
}

/* Bootstrap integration */
.was-validated .phone-input-wrapper input[type="tel"]:valid {
    border-color: #198754;
}

.was-validated .phone-input-wrapper input[type="tel"]:invalid {
    border-color: #dc3545;
}

/* Focus states */
.phone-input-wrapper:focus-within {
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
    border-radius: 4px;
}

/* Error messages */
.phone-error-message {
    display: block;
    width: 100%;
    margin-top: 4px;
    font-size: 12px;
    color: #dc3545;
}

/* Success messages */
.phone-success-message {
    display: block;
    width: 100%;
    margin-top: 4px;
    font-size: 12px;
    color: #198754;
}