/**
 * Fintly Phone Input & Country Code Styling.
 * Provides unified styling for phone input rows with Select2 country dropdowns.
 */

.fintly-phone-row {
    display: flex;
    align-items: stretch;
    width: 100%;
    min-height: 48px;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    background: #ffffff;
    position: relative;
    box-sizing: border-box;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.fintly-phone-row:focus-within {
    border-color: #01848f !important;
    box-shadow: 0 0 0 2px rgba(1, 132, 143, 0.2) !important;
}

.fintly-phone-row.has-error,
.fintly-phone-row:has([aria-invalid="true"]),
.fintly-phone-row:has(.wpcf7-not-valid) {
    border-color: #dc2626 !important;
    box-shadow: 0 0 0 1px #dc2626 !important;
}

/* Country code Select2 container */
.fintly-phone-row > .phone-code-select2 {
    width: 105px;
    min-width: 100px;
    flex-shrink: 0;
    position: relative;
    border-right: 1px solid #d1d5db;
    display: flex;
    align-items: center;
    box-sizing: border-box;
}

.fintly-phone-row > .phone-code-select2 select {
    width: 100%;
    height: 100%;
    opacity: 0;
    position: absolute;
}

.fintly-phone-row .phone-code-select2 .select2-container {
    width: 100% !important;
    height: 100% !important;
    display: flex !important;
    align-items: center !important;
}

.fintly-phone-row .phone-code-select2 .select2-selection--single {
    height: 100% !important;
    min-height: 44px;
    width: 100% !important;
    border: 0 !important;
    border-radius: 0.5rem 0 0 0.5rem !important;
    background: transparent !important;
    display: flex !important;
    align-items: center !important;
    outline: none !important;
    box-shadow: none !important;
    cursor: pointer;
    box-sizing: border-box;
}

.fintly-phone-row .phone-code-select2 .select2-selection__rendered {
    padding-left: 10px !important;
    padding-right: 24px !important;
    color: #1f2937 !important;
    font-size: 0.875rem !important;
    font-family: inherit !important;
    font-weight: 500 !important;
    line-height: 1 !important;
    display: inline-flex !important;
    align-items: center !important;
    white-space: nowrap !important;
    overflow: visible !important;
}

.fintly-phone-row .phone-code-select2 .select2-selection__arrow {
    height: 100% !important;
    width: 20px !important;
    right: 4px !important;
    top: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    pointer-events: none;
}

.fintly-phone-row .phone-code-select2 .select2-selection__arrow b {
    border-color: #6b7280 transparent transparent transparent !important;
    border-width: 5px 4px 0 4px !important;
}

.fintly-phone-row .phone-code-select2 .select2-container--open .select2-selection__arrow b {
    border-color: transparent transparent #01848f transparent !important;
    border-width: 0 4px 5px 4px !important;
}

/* CF7 wrapper when wrapping phone row */
.wpcf7-form-control-wrap.fintly-phone-wrap {
    display: block !important;
    position: relative !important;
    width: 100% !important;
    align-self: flex-start !important;
}

/* Phone input */
.fintly-phone-row .wpcf7-form-control-wrap {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    position: static;
}

.fintly-phone-row input[type="tel"] {
    flex: 1 1 0% !important;
    min-width: 0 !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 46px;
    border: 0 !important;
    outline: none !important;
    background: transparent !important;
    padding: 0.65rem 0.85rem !important;
    font-size: 0.875rem !important;
    color: #111827 !important;
    box-shadow: none !important;
    border-radius: 0 0.5rem 0.5rem 0 !important;
}

.fintly-phone-row input[type="tel"]::placeholder {
    color: #9ca3af !important;
}

/* Select2 Dropdown Styling */
.fintly-country-dropdown,
.fintly-phone-select2-dropdown,
.select2-dropdown.fintly-country-dropdown,
.select2-dropdown.fintly-phone-select2-dropdown {
    width: min(320px, calc(100vw - 40px)) !important;
    min-width: 290px !important;
    max-width: calc(100vw - 20px) !important;
    border: 1px solid #01848f !important;
    border-radius: 0.5rem !important;
    background: #ffffff !important;
    color: #1f2937 !important;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.15), 0 8px 10px -6px rgba(0, 0, 0, 0.1) !important;
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
    font-size: 0.8125rem !important;
    z-index: 999999 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
}

/* Enforce dropdown container width on the parent container attached to body */
.select2-container--open:has(.fintly-country-dropdown),
.select2-container--open:has(.fintly-phone-select2-dropdown) {
    width: min(320px, calc(100vw - 40px)) !important;
    min-width: 290px !important;
    max-width: calc(100vw - 20px) !important;
    z-index: 999999 !important;
}

.fintly-country-dropdown .select2-search--dropdown,
.fintly-phone-select2-dropdown .select2-search--dropdown {
    padding: 0.5rem !important;
    background: #f9fafb !important;
    border-bottom: 1px solid #e5e7eb !important;
    box-sizing: border-box !important;
}

.fintly-country-dropdown .select2-search__field,
.fintly-phone-select2-dropdown .select2-search__field {
    border: 1px solid #d1d5db !important;
    border-radius: 0.375rem !important;
    background: #ffffff !important;
    color: #111827 !important;
    padding: 0.5rem 0.65rem !important;
    font-size: 0.8125rem !important;
    outline: none !important;
    width: 100% !important;
    box-sizing: border-box !important;
    display: block !important;
}

.fintly-country-dropdown .select2-search__field:focus,
.fintly-phone-select2-dropdown .select2-search__field:focus {
    border-color: #01848f !important;
    box-shadow: 0 0 0 2px rgba(1, 132, 143, 0.2) !important;
}

.fintly-country-dropdown .select2-results__options,
.fintly-phone-select2-dropdown .select2-results__options {
    max-height: 240px !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    padding: 0.25rem 0 !important;
    margin: 0 !important;
    list-style: none !important;
}

.fintly-country-dropdown .select2-results__option,
.fintly-phone-select2-dropdown .select2-results__option {
    padding: 0.5rem 0.75rem !important;
    display: flex !important;
    align-items: center !important;
    color: #374151 !important;
    font-size: 0.8125rem !important;
    line-height: 1.4 !important;
    cursor: pointer !important;
    white-space: nowrap !important;
    user-select: none !important;
    box-sizing: border-box !important;
}

.fintly-country-dropdown .select2-results__option[aria-selected="true"],
.fintly-country-dropdown .select2-results__option--selected,
.fintly-phone-select2-dropdown .select2-results__option[aria-selected="true"],
.fintly-phone-select2-dropdown .select2-results__option--selected {
    background: #e6f4f5 !important;
    color: #01848f !important;
    font-weight: 600 !important;
}

.fintly-country-dropdown .select2-results__option--highlighted[aria-selected],
.fintly-country-dropdown .select2-results__option--highlighted.select2-results__option--selectable,
.fintly-phone-select2-dropdown .select2-results__option--highlighted[aria-selected],
.fintly-phone-select2-dropdown .select2-results__option--highlighted.select2-results__option--selectable {
    background: #01848f !important;
    color: #ffffff !important;
}

.partner-country-option,
.fintly-select2-item {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    width: 100% !important;
    white-space: nowrap !important;
}

.partner-country-option img,
.partner-country-flag,
.fintly-select2-flag {
    width: 20px !important;
    height: 15px !important;
    object-fit: cover !important;
    flex-shrink: 0 !important;
    border-radius: 2px !important;
    display: inline-block !important;
    vertical-align: middle !important;
}

.partner-country-selection,
.fintly-select2-selected {
    display: inline-flex !important;
    align-items: center !important;
    gap: 6px !important;
    font-size: 0.875rem !important;
    font-weight: 500 !important;
    white-space: nowrap !important;
    line-height: 1 !important;
}

.partner-country-name,
.fintly-select2-name {
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

.partner-country-dial,
.fintly-select2-dial {
    font-weight: 500 !important;
    color: inherit !important;
    white-space: nowrap !important;
    line-height: 1 !important;
}

/* Error message positioning in CF7 and Enquiry form */
.fintly-phone-error,
.fintly-phone-wrap .wpcf7-not-valid-tip,
.fintly-phone-wrap + .wpcf7-not-valid-tip,
.fintly-phone-row + .wpcf7-not-valid-tip,
.fintly-phone-row ~ .wpcf7-not-valid-tip,
.fintly-cf7-phone-row ~ .wpcf7-not-valid-tip,
.fintly-phone-row .wpcf7-not-valid-tip {
    display: block !important;
    width: 100% !important;
    color: #dc2626 !important;
    font-size: 0.75rem !important;
    line-height: 1.25 !important;
    margin-top: 0.35rem !important;
    font-family: inherit !important;
    font-weight: 400 !important;
    clear: both !important;
    box-sizing: border-box !important;
}

/* Country Enquiry Form integration */
.get-started-form .form-field {
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}

.get-started-form .fintly-phone-row {
    border-color: #CCE6E6;
}

.get-started-form .fintly-phone-row > .phone-code-select2 {
    border-right-color: #CCE6E6;
}

.get-started-form .fintly-phone-row:focus-within {
    border-color: #01848F !important;
    box-shadow: 0 0 0 3px rgba(1, 132, 143, 0.15) !important;
}

.get-started-form .fintly-phone-row.has-error {
    border-color: #DC2626 !important;
    box-shadow: none !important;
}

.get-started-form .form-error,
#getStartedForm .form-error,
#getStartedNameError,
#getStartedMobileError,
#getStartedEmailError {
    position: static !important;
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    margin-top: 4px !important;
    font-size: 11px !important;
    line-height: 1.25 !important;
    color: #DC2626 !important;
    word-break: break-word !important;
    overflow-wrap: break-word !important;
}

.get-started-form .form-error:empty,
#getStartedForm .form-error:empty,
#getStartedNameError:empty,
#getStartedMobileError:empty,
#getStartedEmailError:empty {
    display: none !important;
}

.wpcf7-form .wpcf7-not-valid-tip {
    display: block !important;
    width: 100% !important;
    color: #dc2626 !important;
    font-size: 11px !important;
    line-height: 1.3 !important;
    margin-top: 4px !important;
}
