/**
 * Form Validation Styles
 * Enhanced styling for form validation feedback
 */

/* Valid field styling */
.form-control.is-valid,
.form-control-modern.is-valid {
    border-color: #28a745;
    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='%2328a745' d='M2.3 6.73L.6 4.53c-.4-1.04.46-1.4 1.1-.8l1.1 1.4 3.4-3.8c.6-.63 1.6-.27 1.2.7l-4 4.6c-.43.5-.8.4-1.1.1z'/%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);
}

.form-control.is-valid:focus,
.form-control-modern.is-valid:focus {
    border-color: #28a745;
    box-shadow: 0 0 0 0.2rem rgba(40, 167, 69, 0.25);
}

/* Invalid field styling */
.form-control.is-invalid,
.form-control-modern.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 stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23dc3545' stroke='none'/%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);
}

.form-control.is-invalid:focus,
.form-control-modern.is-invalid:focus {
    border-color: #dc3545;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25);
}

/* Feedback messages */
.invalid-feedback {
    display: none;
    width: 100%;
    margin-top: 0.25rem;
    font-size: 0.875em;
    color: #dc3545;
    font-weight: 500;
}

.invalid-feedback.d-block,
.form-control.is-invalid ~ .invalid-feedback {
    display: block;
}

.valid-feedback {
    display: none;
    width: 100%;
    margin-top: 0.25rem;
    font-size: 0.875em;
    color: #28a745;
    font-weight: 500;
}

.valid-feedback.d-block,
.form-control.is-valid ~ .valid-feedback {
    display: block;
}

/* Input group validation */
.input-group .form-control.is-invalid {
    border-color: #dc3545;
}

.input-group .form-control.is-valid {
    border-color: #28a745;
}

/* Animation for validation state changes */
.form-control,
.form-control-modern {
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out, background-image 0.15s ease-in-out;
}

/* Phone input group specific */
.phone-input-group .form-control.is-invalid {
    border-color: #dc3545;
}

.phone-input-group .form-control.is-valid {
    border-color: #28a745;
}

/* Error shake animation */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.form-control.is-invalid.shake,
.form-control-modern.is-invalid.shake {
    animation: shake 0.5s;
}

/* Loading state for async validation */
.form-control.validating {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='%236c757d' d='M10 3a7 7 0 0 0 0 14v-2a5 5 0 0 1 0-10V3z'/%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);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Password strength indicator */
.password-strength {
    height: 4px;
    margin-top: 0.5rem;
    border-radius: 2px;
    background: #e9ecef;
    overflow: hidden;
    transition: all 0.3s ease;
}

.password-strength-bar {
    height: 100%;
    transition: width 0.3s ease, background-color 0.3s ease;
    width: 0%;
}

.password-strength-bar.weak {
    width: 33%;
    background: #dc3545;
}

.password-strength-bar.medium {
    width: 66%;
    background: #ffc107;
}

.password-strength-bar.strong {
    width: 100%;
    background: #28a745;
}

/* Helper text */
.form-text {
    margin-top: 0.25rem;
    font-size: 0.875em;
    color: #6c757d;
}

.form-text.text-danger {
    color: #dc3545 !important;
}

.form-text.text-success {
    color: #28a745 !important;
}

/* Tooltip validation */
.validation-tooltip {
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 5;
    display: none;
    max-width: 100%;
    padding: 0.25rem 0.5rem;
    margin-top: 0.1rem;
    font-size: 0.875rem;
    color: #fff;
    background-color: rgba(220, 53, 69, 0.9);
    border-radius: 0.25rem;
}

.form-control.is-invalid ~ .validation-tooltip {
    display: block;
}

/* Responsive adjustments */
@media (max-width: 576px) {
    .invalid-feedback,
    .valid-feedback {
        font-size: 0.8125em;
    }
}

/* Focus ring for accessibility */
.form-control:focus,
.form-control-modern:focus {
    outline: 0;
}

/* Custom checkbox/radio validation */
.form-check-input.is-invalid ~ .form-check-label {
    color: #dc3545;
}

.form-check-input.is-valid ~ .form-check-label {
    color: #28a745;
}

/* Role selection button validation */
.role-selection-btn.error {
    border-color: #dc3545 !important;
    animation: shake 0.5s;
}

.user-type-error {
    color: #dc3545;
    font-size: 0.875em;
    margin-top: 0.5rem;
    font-weight: 500;
}

/* Phone number validation helpers */
.phone-digit-counter {
    font-size: 0.8125em;
    font-weight: 500;
    transition: color 0.3s ease;
}

.phone-hint {
    font-size: 0.8125em;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Numeric input styling */
input[type="tel"].form-control,
input[type="tel"].form-control-modern {
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.5px;
}

/* Phone input group with counter */
.phone-input-group {
    position: relative;
}

.phone-input-group .phone-digit-counter {
    position: relative;
    display: block;
}

/* Real-time validation indicator */
.validating-indicator {
    position: absolute;
    right: 2.5rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.875em;
    color: #6c757d;
}

/* Numeric-only field hint */
.numeric-only-hint {
    position: absolute;
    top: -1.5rem;
    right: 0;
    font-size: 0.75em;
    color: #6c757d;
    background: #fff;
    padding: 0.125rem 0.5rem;
    border-radius: 0.25rem;
    border: 1px solid #e9ecef;
    opacity: 0;
    transition: opacity 0.3s ease;
}

input:focus ~ .numeric-only-hint {
    opacity: 1;
}
