/*
 * Universal Theme Compatibility CSS - Authyo OTP Authentication for WooCommerce
 * This file is loaded last to override theme styles and ensure form consistency.
 * Add custom theme compatibility fixes here.
 */

/*
 * Phone field (country code + number) on the login, register and checkout forms.
 *
 * One joined control: the country code sits on the left, the number on the right, inside a
 * single border that highlights as a whole when either part is focused. The country selector is
 * compact ("+91"); the full country names are in its list.
 *
 * Two variants share these rules:
 *  - login / register: the wrapper is `.authyo-phone-field` inside `.authyo-otp-auth-container`.
 *    The selector starts collapsed to zero width and is revealed by the `.authyo-cc-visible`
 *    class (toggled by the form scripts) once a mobile number is being typed.
 *  - checkout: the wrapper is `.authyo-phone-field.authyo-phone-field--always` and the selector
 *    is always shown.
 *
 * Themes commonly style bare `select` / `input` elements (full width, display:block !important,
 * their own borders and backgrounds), and checkout.css has ID-based !important rules for
 * #checkout-country-code. Everything structural here is therefore doubled (.x.x) and, for the
 * checkout selectors, includes the ID so it out-ranks them.
 *
 * Colours can be changed from a theme, for example:
 *     .authyo-otp-auth-container, .authyo-phone-field { --authyo-accent: #d63384; }
 */
.authyo-otp-auth-container,
.authyo-phone-field--always {
    --authyo-accent: #2271b1;
    --authyo-focus-ring: rgba(34, 113, 177, 0.22);
    --authyo-border: #c9ced6;
    --authyo-muted: #667085;
    --authyo-radius: 6px;
}

/*
 * The container is already the card. The form inside it used to draw a second border, shadow and
 * padding of its own (a card inside a card), which wastes a lot of width on a phone and leaves the
 * input too narrow. Flatten the inner box so the container's padding is the only padding.
 */
.authyo-otp-auth-container .authyo-otp-auth-form.authyo-otp-auth-form {
    padding: 0 !important;
    border: 0 !important;
    box-shadow: none !important;
    background: transparent !important;
}

@media (max-width: 480px) {
    .authyo-otp-auth-container.authyo-otp-auth-container {
        margin: 0.75rem 0.5rem;
        padding: 1.25rem 1rem;
    }
}

/* --- the joined control --- */
.authyo-otp-auth-container .authyo-phone-field.authyo-phone-field,
.phone-input-wrapper.authyo-phone-field.authyo-phone-field--always.authyo-phone-field--always {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    grid-template-columns: none !important;
    align-items: stretch !important;
    gap: 0 !important;
    width: 100% !important;
    box-sizing: border-box !important;
    margin: 0 !important;
    padding: 0 !important;
    background: transparent !important;   /* inherits the card, so it also works on dark themes */
    border: 1px solid var(--authyo-border) !important;
    border-radius: var(--authyo-radius) !important;
    overflow: hidden !important;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

/* checkout keeps some space above and below the control */
.phone-input-wrapper.authyo-phone-field.authyo-phone-field--always.authyo-phone-field--always {
    margin: 8px 0 6px !important;
}

.authyo-otp-auth-container .authyo-phone-field.authyo-phone-field:focus-within,
.phone-input-wrapper.authyo-phone-field.authyo-phone-field--always.authyo-phone-field--always:focus-within {
    border-color: var(--authyo-accent) !important;
    box-shadow: 0 0 0 3px var(--authyo-focus-ring) !important;
}

/* --- country selector (login / register): collapsed until a mobile number is being typed --- */
.authyo-otp-auth-container .authyo-phone-field.authyo-phone-field select.authyo-country-select.authyo-country-select {
    display: block !important;
    box-sizing: border-box !important;
    flex: 0 0 0 !important;
    width: 0 !important;
    min-width: 0 !important;
    max-width: 0 !important;
    min-height: 46px !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    outline: 0 !important;
    opacity: 0 !important;
    visibility: hidden !important;
    overflow: hidden !important;
    background-color: rgba(128, 128, 128, 0.12) !important;
    /* many themes draw their own arrow as a background image; with the native arrow that shows two */
    background-image: none !important;
    color: inherit !important;
    font-size: 16px !important;
    line-height: 1.3 !important;
    cursor: pointer;
    -webkit-appearance: auto !important;
    appearance: auto !important;
    transition:width 0.18s ease, min-width 0.18s ease, max-width 0.18s ease, padding 0.18s ease, opacity 0.18s ease;
}

/* --- country selector, shown: login / register once revealed, and always on checkout --- */
.authyo-otp-auth-container .authyo-phone-field.authyo-phone-field select.authyo-country-select.authyo-country-select.authyo-cc-visible,
.phone-input-wrapper.authyo-phone-field--always.authyo-phone-field--always select.authyo-country-select.authyo-country-select,
.phone-input-wrapper.authyo-phone-field--always.authyo-phone-field--always select#checkout-country-code,
.phone-input-wrapper.authyo-phone-field--always.authyo-phone-field--always select#checkout-shipping-country-code {
    display: block !important;
    box-sizing: border-box !important;
    flex: 0 0 auto !important;
    width: 88px !important;
    min-width: 88px !important;
    max-width: 88px !important;
    min-height: 46px !important;
    height: auto !important;
    margin: 0 !important;
    /* logical properties: the selector is the first item, so on a right-to-left page it sits on the right
       and its divider and padding must mirror (a physical border-right would land on the outer edge). */
    padding-block: 0 !important;
    padding-inline: 10px 4px !important;
    border: 0 !important;
    border-inline-end: 1px solid var(--authyo-border) !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    outline: 0 !important;
    opacity: 1 !important;
    visibility: visible !important;
    overflow: hidden !important;
    background-color: rgba(128, 128, 128, 0.12) !important;
    background-image: none !important;
    color: inherit !important;
    font-size: 16px !important;
    line-height: 1.3 !important;
    cursor: pointer;
    -webkit-appearance: auto !important;
    appearance: auto !important;
}

/* The open list: system colours stay readable on light and dark themes alike. */
.authyo-phone-field select.authyo-country-select option {
    background-color: Canvas;
    color: CanvasText;
}

/* --- the number / email input fills the rest of the row --- */
.authyo-otp-auth-container .authyo-phone-field.authyo-phone-field input:not([type="hidden"]),
.phone-input-wrapper.authyo-phone-field--always.authyo-phone-field--always input:not([type="hidden"]),
.phone-input-wrapper.authyo-phone-field--always.authyo-phone-field--always input#billing_phone,
.phone-input-wrapper.authyo-phone-field--always.authyo-phone-field--always input#shipping_phone,
.phone-input-wrapper.authyo-phone-field--always.authyo-phone-field--always input#billing-phone,
.phone-input-wrapper.authyo-phone-field--always.authyo-phone-field--always input#shipping-phone {
    box-sizing: border-box !important;
    flex: 1 1 auto !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    min-height: 46px !important;
    height: auto !important;
    margin: 0 !important;
    padding: 10px 14px !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    outline: 0 !important;
    background: transparent !important;
    font-size: 16px !important;   /* 16px stops iOS Safari zooming the page on focus */
    line-height: 1.3 !important;
    /* What is typed (an email, a phone number) is left-to-right text even on a right-to-left page; the
       placeholder follows the page language. */
    unicode-bidi: plaintext;
}

/*
 * What will be sent: small, muted, directly under the field - the same on login, register and
 * checkout (the checkout spans carry their own inline size/colour, which this overrides).
 * Only the look is set here; showing/hiding stays with the scripts.
 */
.number-preview.number-preview {
    margin: 6px 2px 0 !important;
    font-size: 13px !important;
    font-style: normal !important;
    line-height: 1.4 !important;
    color: #667085 !important;
}

@media (prefers-reduced-motion: reduce) {
    .authyo-otp-auth-container .authyo-phone-field.authyo-phone-field,
    .authyo-otp-auth-container .authyo-phone-field.authyo-phone-field select.authyo-country-select.authyo-country-select {
        transition: none !important;
    }
}
