/**
 * Form Styles for AJAX Submissions
 * 
 * Includes styles for intl-tel-input, Turnstile widget,
 * validation states, and form messages.
 * 
 * @package Trader2B_Lite
 */

/* Form Messages */
.form-error-message,
.form-success-message {
    margin-bottom: 1.5rem;
}

.form-error-message .alert,
.form-success-message .alert {
    padding: 1rem 1.25rem;
    border-radius: 8px;
    font-size: 0.95rem;
    line-height: 1.5;
}

.alert-danger {
    background-color: #f8d7da;
    border: 1px solid #f5c2c7;
    color: #842029;
}

.alert-success {
    background-color: #d1e7dd;
    border: 1px solid #badbcc;
    color: #0f5132;
}

/* Form Input Validation States */
.form-control.is-invalid {
    border-color: #dc3545;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23dc3545' viewBox='0 0 12 12'%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);
    padding-right: calc(1.5em + 0.75rem);
}

.form-control.is-invalid:focus {
    border-color: #dc3545;
    box-shadow: 0 0 0 0.25rem rgba(220, 53, 69, 0.25);
}

.form-control.is-valid {
    border-color: #198754;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 8 8'%3e%3cpath fill='%23198754' 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);
    padding-right: calc(1.5em + 0.75rem);
}

/* International Phone Input Styling */
.iti {
    display: block;
    width: 100%;
    position: relative;
}

.iti__flag-container {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    padding: 0;
}

.iti__selected-flag {
    padding: 0 8px 0 12px;
    background-color: transparent;
    border: none;
    cursor: pointer;
    height: 100%;
    display: flex;
    align-items: center;
}

.iti__selected-dial-code {
    color: #333 !important;
    font-size: 14px;
    margin-left: 6px;
}

.iti__arrow {
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 4px solid #555;
    margin-left: 6px;
}

.iti__country-list {
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    max-height: 250px;
    z-index: 9999;
    background-color: #fff;
    border: 1px solid #ddd;
    margin-top: 4px;
    width: 300px;
}

.iti__country {
    padding: 8px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
}

.iti__country-name,
.iti__dial-code {
    color: #333 !important;
    font-size: 14px;
}

.iti__country-name {
    margin-left: 6px;
    margin-right: auto;
}

.iti__dial-code {
    color: #666 !important;
}

.iti__country:hover {
    background-color: #f5f5f5;
}

.iti__country:hover .iti__country-name,
.iti__country:hover .iti__dial-code {
    color: #000 !important;
}

.iti__country.iti__highlight {
    background-color: #e9ecef;
}

.iti__country.iti__highlight .iti__country-name,
.iti__country.iti__highlight .iti__dial-code {
    color: #000 !important;
}

.iti--allow-dropdown .phone-input-field {
    padding-left: 60px;
}

.phone-input-field {
    width: 100%;
    padding: 10px 15px;
    font-size: 16px;
    border: 1px solid #ced4da;
    border-radius: 8px;
}

.phone-input-field:focus {
    outline: none;
    border-color: #80bdff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

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

.phone-input-field.is-valid {
    border-color: #198754;
}

/* Turnstile Widget Container */
.cf-turnstile-container {
    margin: 1rem 0;
    display: flex;
    justify-content: flex-start;
    align-items: center;
}

.cf-turnstile {
    transform-origin: 0 0;
}

/* Ensure Turnstile fits on mobile */
@media (max-width: 576px) {
    .cf-turnstile {
        transform: scale(0.85);
        transform-origin: 0 0;
    }
    
    .cf-turnstile-container {
        min-height: 65px;
    }
}

@media (max-width: 400px) {
    .cf-turnstile {
        transform: scale(0.75);
    }
}

/* Submit Button States */
.trader2b-ajax-form button[type="submit"]:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.trader2b-ajax-form .spinner-border-sm {
    width: 1rem;
    height: 1rem;
    border-width: 0.15em;
}

/* Form Group Spacing */
.trader2b-ajax-form .form-group {
    margin-bottom: 1rem;
}

/* Terms & Conditions Checkbox */
.form-check-input {
    cursor: pointer;
}

.form-check-input:checked {
    background-color: #198754;
    border-color: #198754;
}

/* Responsive Adjustments */
@media (max-width: 768px) {
    .form-error-message .alert,
    .form-success-message .alert {
        font-size: 0.875rem;
        padding: 0.875rem 1rem;
    }
}

/* Loading State for Form */
.trader2b-ajax-form.loading {
    opacity: 0.7;
    pointer-events: none;
}

/* Phone Group Styling */
.phone-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.phone-group .form-select {
    width: auto;
    min-width: 80px;
    max-width: 100px;
}

/* Custom Alert Animations */
@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.form-error-message .alert,
.form-success-message .alert {
    animation: slideDown 0.3s ease-out;
}

/* Ensure consistent spacing */
.trader2b-ajax-form .btn-container {
    margin-top: 1.5rem;
}

/* Focus states for accessibility */
.form-control:focus,
.phone-input-field:focus {
    outline: none;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

/* Spinner styles */
.spinner-border {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    vertical-align: text-bottom;
    border: 0.2em solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spinner-border 0.75s linear infinite;
}

@keyframes spinner-border {
    to {
        transform: rotate(360deg);
    }
}
