/* Container and Form Layout */
.taf-form-container {
    max-width: 600px;
    margin: 2rem auto;
    padding: 1.5rem;
    background-color: #ffffff;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
    font-family: Arial, sans-serif;
}

.taf-form-title {
    text-align: center;
    color: #333333;
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
}

.taf-form {
    display: flex;
    flex-direction: column;
}

/* Form Row and Groups */
.taf-form-row {
    display: flex;
    flex-wrap: wrap;
    margin: 0 -10px;
}

.taf-form-group {
    margin-bottom: 1rem;
    width: 100%;
    box-sizing: border-box;
    position: relative;
}

.taf-form-group-half {
    flex: 0 0 50%;
    max-width: 50%;
    padding: 0 10px;
    box-sizing: border-box;
}

/* Labels and Inputs */
.taf-label {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: bold;
    font-size: 0.9rem;
}

.taf-input,
.taf-button {
    width: 100%;
    height: 40px;
    padding: 0 0.5rem;
    border: 1px solid #cccccc;
    border-radius: 4px;
    font-size: 1rem;
    line-height: 38px;
    box-sizing: border-box;
}

/* Checkbox Styles */
.taf-checkbox-group {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.taf-checkbox {
    margin-top: 0.25rem;
}

.taf-checkbox-label {
    font-size: 0.8rem;
}

/* Button Styles */
.taf-button {
    background-color: #1ef1b6;
    color: #182244;
    border: none;
    cursor: pointer;
    transition: background-color .3s ease;
    border-radius: 30px;
    font-weight: 800;
}

.taf-button:hover {
    background-color: #0eaf82;
}

.taf-button:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
}

/* Validation Styles */
.taf-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.taf-validation-icon {
    position: absolute;
    right: 10px;
    display: none;
    width: 20px;
    height: 20px;
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    z-index: 5;
}

.taf-validation-message {
    display: none;
    font-size: 0.8rem;
    margin-top: 4px;
    min-height: 20px;
}

/* Valid state */
.taf-input.is-valid {
    border-color: #4CAF50;
}

.taf-input.is-valid + .taf-validation-icon {
    display: block;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%234CAF50"><path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"/></svg>');
}

.taf-input.is-valid ~ .taf-validation-message {
    display: block;
    color: #4CAF50;
}

/* Invalid state */
.taf-input.is-invalid {
    border-color: #F44336;
}

.taf-input.is-invalid + .taf-validation-icon {
    display: block;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23F44336"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg>');
}

.taf-input.is-invalid ~ .taf-validation-message {
    display: block;
    color: #F44336;
}

/* Phone Input Styles */
.taf-phone-group {
    position: relative;
}

.taf-phone-group .iti {
    width: 100%;
    display: block;
    position: relative;
}

/* Phone input base styles */
.iti--allow-dropdown .taf-phone-input {
    padding-left: 52px;
    padding-right: 35px !important; /* Space for validation icon */
    margin-left: 0;
}

/* Phone input validation icon positioning */
.taf-phone-group .taf-validation-icon {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 6;
    width: 20px;
    height: 20px;
    pointer-events: none;
}

/* Base Country List Styles */
.iti__country-list {
    position: absolute;
    z-index: 1000;
    max-height: 200px;
    overflow-y: scroll;
    background-color: white;
    border: 1px solid #CCC;
    width: 300px;
    top: 100%;
    z-index: 7;
}

/* Country Dropdown Positioning */
.iti__flag-container {
    z-index: 6;
}

.iti__selected-flag {
    padding: 0 6px 0 8px;
    display: flex;
    align-items: center;
}

/* Style validation states for phone input */
.taf-phone-group .iti--allow-dropdown .taf-phone-input.is-valid {
    border-color: #4CAF50;
}

.taf-phone-group .iti--allow-dropdown .taf-phone-input.is-invalid {
    border-color: #F44336;
}

/* RTL Styles */
.taf-rtl,
html[lang="ar"] {
    direction: rtl;
    text-align: right;
}

.taf-rtl .taf-validation-icon,
html[lang="ar"] .taf-validation-icon {
    right: auto;
    left: 10px;
}

/* RTL Phone Input Styles */
.taf-rtl .iti--allow-dropdown .taf-phone-input,
html[lang="ar"] .iti--allow-dropdown .taf-phone-input {
    padding-left: 35px !important; /* Space for validation icon */
    padding-right: 90px !important; /* Space for country selector */
    direction: ltr;
    text-align: right;
}

.taf-rtl .taf-phone-group .taf-validation-icon,
html[lang="ar"] .taf-phone-group .taf-validation-icon {
    right: auto;
    left: 10px;
}

.taf-rtl .iti__flag-container,
html[lang="ar"] .iti__flag-container {
    right: 0 !important;
    left: auto !important;
}

.taf-rtl .iti__country-list,
html[lang="ar"] .iti__country-list {
    text-align: right !important;
    direction: rtl !important;
    left: auto !important;
    right: 0 !important;
}

.taf-rtl .iti__country,
html[lang="ar"] .iti__country {
    padding: 5px 8px 5px 10px !important;
}

.taf-rtl .error-content,
html[lang="ar"] .error-content {
    flex-direction: row-reverse;
}

/* Error Message Styles */
.taf-message.taf-error {
    padding: 16px;
    border-radius: 8px;
    margin: 20px 0;
    font-size: 14px;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.taf-error.client-exists-error {
    background-color: #fff3e0;
    border: 1px solid #ffb74d;
    color: #e65100;
}

.taf-error.system-error {
    background-color: #ffebee;
    border: 1px solid #ef9a9a;
    color: #c62828;
}

.error-content {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.error-icon {
    flex-shrink: 0;
    font-size: 18px;
    margin-top: 2px;
}

.error-text {
    flex-grow: 1;
    font-weight: 500;
}

/* Animation */
.animate-shake {
    animation: shake 0.82s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes shake {
    10%, 90% { transform: translate3d(-1px, 0, 0); }
    20%, 80% { transform: translate3d(2px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
    40%, 60% { transform: translate3d(4px, 0, 0); }
}

/* Fix for intl-tel-input container */
.iti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 0;
    z-index: 2000;
}

/* Multiple Forms Support */
.taf-form[data-form-id] {
    position: relative;
}

/* Ensure proper stacking of elements */
.iti__selected-flag,
.iti__country-list {
    background-color: white;
}

/* Responsive Styles */
@media screen and (max-width: 767px) {
    .taf-form-group-half {
        flex: 0 0 100%;
        max-width: 100%;
    }
}

@media screen and (max-width: 480px) {
    .taf-form-container {
        padding: 1rem;
    }

    .taf-form-title {
        font-size: 1.25rem;
    }

    .taf-phone-group .taf-validation-icon {
        right: 8px;
        width: 18px;
        height: 18px;
    }

    .iti--allow-dropdown .taf-phone-input {
        padding-right: 30px !important;
    }
    
    .iti__country-list {
        width: 250px;
    }
    
    .taf-label {
        font-size: 0.85rem;
    }

    .taf-input,
    .taf-button {
        height: 38px;
        font-size: 0.9rem;
        line-height: 36px;
    }
    
    .taf-checkbox-label {
        font-size: 0.75rem;
    }
    
    html[lang="ar"] .iti__country-list,
    .taf-rtl .iti__country-list {
        width: 250px !important;
    }

    .taf-message.taf-error {
        padding: 12px;
        font-size: 13px;
    }

    .error-icon {
        font-size: 16px;
    }

    /* Fix for mobile safari input zoom */
    input[type="tel"],
    input[type="text"],
    input[type="email"] {
        font-size: 16px !important;
    }

    /* Mobile dropdown adjustments */
    .iti-mobile .iti--container {
        top: 30px;
        bottom: 30px;
        left: 30px;
        right: 30px;
        position: fixed;
    }

    .iti-mobile .iti--container .iti__country-list {
        max-height: 100%;
        width: 100%;
    }
}


/* Updated Mobile Styles for ITI Container */
@media screen and (max-width: 480px) {


    .iti-mobile .iti--container .iti__country-list {
        position:unset;
        scrollbar-width: thin;
    }

    /* Improved scrolling experience */
    .iti-mobile .iti--container .iti__country-list::-webkit-scrollbar {
        width: 6px;
    }

    .iti-mobile .iti--container .iti__country-list::-webkit-scrollbar-track {
        background: #f1f1f1;
        border-radius: 3px;
    }

    .iti-mobile .iti--container .iti__country-list::-webkit-scrollbar-thumb {
        background: #888;
        border-radius: 3px;
    }

    /* Ensure proper touch targets for mobile */
    .iti-mobile .iti--container .iti__country {
        padding: 10px 8px;
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    /* Add a semi-transparent overlay behind the dropdown */
    .iti-mobile .iti--container::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: -1;
    }
}

/* Additional responsive adjustments for very small screens */
@media screen and (max-width: 360px) {
    .iti-mobile .iti--container {
        width: calc(100% - 20px);
        padding: 10px;
    }

    .iti-mobile .iti--container .iti__country-list {
        max-height: calc(80vh - 20px);
    }
}