/*!
 * EgyEmail - client area modal styles.
 *
 * Colour tokens are emitted inline by Frontend::themeCss() from the admin
 * "Interface" tab; everything below consumes them. The .egyev-dark class is
 * applied by the script when it detects a dark template (SOP step 5.2).
 */

.egyev-overlay {
    --egyev-bg: #ffffff;
    --egyev-fg: #111827;
    --egyev-muted: #6b7280;
    --egyev-border: #e5e7eb;
    --egyev-field-bg: #ffffff;
    --egyev-shadow: 0 24px 60px rgba(15, 23, 42, .22);
    --egyev-danger: #dc2626;
    --egyev-danger-bg: #fef2f2;
    --egyev-success: #059669;
    --egyev-success-bg: #ecfdf5;

    position: fixed;
    inset: 0;
    z-index: 2147483000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(15, 23, 42, .55);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    opacity: 0;
    transition: opacity .18s ease;
    font-family: inherit;
}

.egyev-overlay[hidden] {
    display: none !important;
}

/*
 * Everything the script hides inside the modal - the two panes, the alert, the
 * attempts counter, the spinner - is hidden with the `hidden` attribute.
 *
 * That attribute is only a UA-stylesheet `display:none`, so it loses to an
 * inline style. Client area themes routinely run jQuery `.show()` over their
 * forms, which stamps `style="display:block"` on our panes and reveals the code
 * step and the address step at the same time. `!important` is the only author
 * declaration that outranks an inline style, so it is required here rather than
 * being a shortcut.
 */
.egyev-overlay [hidden] {
    display: none !important;
}

.egyev-overlay.egyev-visible {
    opacity: 1;
}

.egyev-overlay.egyev-dark {
    --egyev-bg: #111827;
    --egyev-fg: #f3f4f6;
    --egyev-muted: #9ca3af;
    --egyev-border: #374151;
    --egyev-field-bg: #1f2937;
    --egyev-shadow: 0 24px 60px rgba(0, 0, 0, .55);
    --egyev-danger: #f87171;
    --egyev-danger-bg: #3f1d1d;
    --egyev-success: #34d399;
    --egyev-success-bg: #06301f;
}

/* ---------------------------------------------------------------- modal box */

.egyev-modal {
    position: relative;
    width: 100%;
    max-width: 420px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    padding: 32px 28px 24px;
    border-radius: var(--egyev-radius, 12px);
    background: var(--egyev-bg);
    color: var(--egyev-fg);
    box-shadow: var(--egyev-shadow);
    text-align: center;
    transform: translateY(14px) scale(.98);
    transition: transform .18s ease;
    box-sizing: border-box;
}

.egyev-visible .egyev-modal {
    transform: none;
}

.egyev-modal *,
.egyev-modal *::before,
.egyev-modal *::after {
    box-sizing: border-box;
}

.egyev-close {
    position: absolute;
    top: 10px;
    inset-inline-end: 12px;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--egyev-muted);
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}

.egyev-close:hover {
    background: var(--egyev-border);
    color: var(--egyev-fg);
}

.egyev-logo {
    margin-bottom: 14px;
}

.egyev-logo img {
    max-height: 44px;
    max-width: 180px;
}

.egyev-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 62px;
    height: 62px;
    margin: 0 auto 16px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--egyev-primary, #2563eb) 12%, transparent);
    color: var(--egyev-primary, #2563eb);
}

.egyev-icon svg {
    width: 30px;
    height: 30px;
}

.egyev-title {
    margin: 0 0 8px;
    font-size: 20px;
    font-weight: 600;
    line-height: 1.35;
    color: var(--egyev-fg);
}

.egyev-intro {
    margin: 0 0 20px;
    font-size: 14px;
    line-height: 1.6;
    color: var(--egyev-muted);
}

/*
 * The address is always left-to-right even inside an Arabic sentence, so it is
 * isolated from the surrounding bidi run - otherwise the domain and the
 * trailing punctuation get reordered. inline-block keeps it whole when the line
 * wraps instead of splitting it mid-address on a narrow screen.
 */
.egyev-intro strong {
    display: inline-block;
    direction: ltr;
    unicode-bidi: isolate;
    max-width: 100%;
    overflow-wrap: break-word;
    color: var(--egyev-fg);
}

/* -------------------------------------------------------------------- alert */

.egyev-alert {
    margin: 0 0 16px;
    padding: 11px 14px;
    border-radius: calc(var(--egyev-radius, 12px) * .6);
    font-size: 13px;
    line-height: 1.5;
    text-align: start;
}

.egyev-alert[hidden] {
    display: none;
}

.egyev-alert.egyev-alert-error {
    background: var(--egyev-danger-bg);
    color: var(--egyev-danger);
}

.egyev-alert.egyev-alert-success {
    background: var(--egyev-success-bg);
    color: var(--egyev-success);
}

.egyev-alert.egyev-alert-info {
    background: color-mix(in srgb, var(--egyev-primary, #2563eb) 10%, transparent);
    color: var(--egyev-primary, #2563eb);
}

/* Follow-up links inside an alert (e.g. "log in instead"). */
.egyev-alert-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    margin-top: 10px;
    padding-top: 9px;
    border-top: 1px solid currentColor;
    /* The rule is a hairline separator, not a border in its own right. */
    border-top-color: color-mix(in srgb, currentColor 22%, transparent);
}

.egyev-overlay .egyev-alert-link {
    display: inline-block;
    min-height: 24px;
    color: inherit;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.egyev-overlay .egyev-alert-link:hover {
    opacity: .78;
    text-decoration: underline;
}

/* --------------------------------------------------------------- code entry */

.egyev-label {
    display: block;
    margin-bottom: 10px;
    font-size: 13px;
    font-weight: 500;
    color: var(--egyev-muted);
    text-align: start;
}

.egyev-code-inputs {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 18px;
    direction: ltr;
}

/*
 * Sized with !important for the same reason as the hidden field: a theme rule
 * on `input[type="text"]` ties on specificity and wins on source order, which
 * would collapse the fixed digit boxes.
 */
.egyev-overlay .egyev-code-inputs input {
    /* Shrinkable on purpose: six fixed 46px boxes plus gaps overflow a 320px
       phone, and a horizontal scrollbar on a code field is unusable. */
    flex: 0 1 auto;
    width: 46px !important;
    height: 56px !important;
    min-width: 0;
    max-width: none;
    padding: 0 !important;
    margin: 0 !important;
    border: 1.5px solid var(--egyev-border);
    border-radius: calc(var(--egyev-radius, 12px) * .7);
    background: var(--egyev-field-bg);
    color: var(--egyev-fg);
    font-size: 24px;
    font-weight: 600;
    text-align: center;
    transition: border-color .15s ease, box-shadow .15s ease;
    -moz-appearance: textfield;
}

.egyev-code-inputs input::-webkit-outer-spin-button,
.egyev-code-inputs input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.egyev-code-inputs input:focus {
    outline: none;
    border-color: var(--egyev-primary, #2563eb);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--egyev-primary, #2563eb) 22%, transparent);
}

.egyev-code-inputs.egyev-shake {
    animation: egyev-shake .4s;
}

.egyev-code-inputs.egyev-error input {
    border-color: var(--egyev-danger);
}

@keyframes egyev-shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-7px); }
    40%, 80% { transform: translateX(7px); }
}

@media (prefers-reduced-motion: reduce) {
    .egyev-overlay,
    .egyev-modal,
    .egyev-code-inputs.egyev-shake {
        transition: none;
        animation: none;
    }
}

/*
 * Visually hidden fallback field. The !important flags are deliberate: client
 * area themes routinely style bare `input[type="text"]` (often width:100%),
 * which outranks a single class selector and would otherwise stretch this
 * element far past the modal and add a horizontal scrollbar.
 */
.egyev-overlay .egyev-code-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    min-width: 0 !important;
    max-width: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0 !important;
}

/* ------------------------------------------------------- address pane input */

/*
 * Same defensive sizing as the digit boxes: themes commonly style bare
 * `input[type="email"]`, which ties on specificity and wins on source order.
 */
.egyev-overlay .egyev-email-input {
    display: block;
    width: 100% !important;
    height: auto !important;
    margin: 0 0 18px !important;
    padding: 12px 14px !important;
    border: 1.5px solid var(--egyev-border) !important;
    border-radius: calc(var(--egyev-radius, 12px) * .7);
    background: var(--egyev-field-bg);
    color: var(--egyev-fg);
    font-size: 15px;
    font-family: inherit;
    text-align: start;
    box-sizing: border-box;
}

.egyev-overlay .egyev-email-input:focus {
    outline: none;
    border-color: var(--egyev-primary, #2563eb) !important;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--egyev-primary, #2563eb) 22%, transparent);
}

/* --------------------------------------------------- locked field on the page */

.egyev-locked-field {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2359616e' stroke-width='2' stroke-linecap='round'%3E%3Crect x='4' y='11' width='16' height='10' rx='2'/%3E%3Cpath d='M8 11V7a4 4 0 0 1 8 0v4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 15px 15px;
    padding-right: 34px;
    cursor: not-allowed;
    opacity: .85;
}

[dir="rtl"] .egyev-locked-field {
    background-position: left 10px center;
    padding-right: 12px;
    padding-left: 34px;
}

.egyev-lock-note {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin: -6px 0 12px;
    font-size: 12px;
    line-height: 1.5;
    opacity: .8;
}

.egyev-lock-change {
    padding: 0;
    border: 0;
    background: none;
    color: var(--egyev-primary, #2563eb);
    font-size: 12px;
    font-family: inherit;
    text-decoration: underline;
    cursor: pointer;
}

/* ------------------------------------------------------------------ captcha */

.egyev-captcha-prompt {
    margin: 0 0 8px;
    font-size: 12px;
    color: var(--egyev-muted);
}

.egyev-captcha {
    display: flex;
    justify-content: center;
    margin-bottom: 16px;
    transform-origin: center;
}

@media (max-width: 400px) {
    .egyev-captcha {
        transform: scale(.86);
    }
}

.egyev-attempts {
    margin: 0 0 12px;
    font-size: 12px;
    color: var(--egyev-danger);
}

.egyev-attempts[hidden] {
    display: none;
}

/* ------------------------------------------------------------------ buttons */

.egyev-btn {
    display: block;
    width: 100%;
    padding: 13px 18px;
    border: 0;
    border-radius: calc(var(--egyev-radius, 12px) * .7);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s ease, opacity .15s ease;
}

.egyev-btn-primary {
    background: var(--egyev-primary, #2563eb);
    color: #fff;
}

.egyev-btn-primary:hover:not(:disabled) {
    background: var(--egyev-accent, #1e40af);
}

.egyev-btn:disabled {
    opacity: .55;
    cursor: not-allowed;
}

.egyev-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 18px;
    margin-top: 16px;
}

.egyev-link {
    padding: 0;
    border: 0;
    background: none;
    color: var(--egyev-primary, #2563eb);
    font-size: 13px;
    cursor: pointer;
    text-decoration: none;
}

.egyev-link:hover:not(:disabled) {
    text-decoration: underline;
}

.egyev-link:disabled {
    color: var(--egyev-muted);
    cursor: default;
}

.egyev-link-muted {
    color: var(--egyev-muted);
}

.egyev-expiry {
    margin: 16px 0 0;
    font-size: 12px;
    color: var(--egyev-muted);
}

/* ------------------------------------------------------------------ spinner */

.egyev-spinner {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--egyev-radius, 12px);
    background: color-mix(in srgb, var(--egyev-bg) 78%, transparent);
}

.egyev-spinner[hidden] {
    display: none;
}

.egyev-spinner span {
    width: 34px;
    height: 34px;
    border: 3px solid var(--egyev-border);
    border-top-color: var(--egyev-primary, #2563eb);
    border-radius: 50%;
    animation: egyev-spin .7s linear infinite;
}

@keyframes egyev-spin {
    to { transform: rotate(360deg); }
}

/* --------------------------------------------------------- inline notice */

.egyev-login-notice .egyev-open-modal {
    font-weight: 600;
    text-decoration: underline;
    cursor: pointer;
}

/* ------------------------------------------------------------- small screens */

@media (max-width: 480px) {
    .egyev-overlay {
        padding: 12px;
        /* Anchor to the bottom: on a phone the modal is within thumb reach and
           does not jump when the on-screen keyboard opens. */
        align-items: flex-end;
    }

    .egyev-modal {
        max-height: calc(100vh - 24px);
        padding: 26px 16px 18px;
    }

    .egyev-title {
        font-size: 18px;
    }

    .egyev-icon {
        width: 52px;
        height: 52px;
        margin-bottom: 12px;
    }

    .egyev-code-inputs {
        gap: 6px;
    }

    .egyev-overlay .egyev-code-inputs input {
        width: 44px !important;
        height: 52px !important;
        font-size: 20px;
    }

    /* Comfortable touch targets for the secondary controls. */
    .egyev-actions {
        gap: 10px;
        justify-content: space-between;
    }

    .egyev-link {
        min-height: 44px;
        padding: 0 4px;
        font-size: 14px;
    }

    .egyev-close {
        top: 6px;
        inset-inline-end: 6px;
        width: 44px;
        height: 44px;
        font-size: 28px;
    }
}

/* Very narrow phones: let the boxes take an even share of what is left. */
@media (max-width: 360px) {
    .egyev-code-inputs {
        gap: 4px;
    }

    .egyev-overlay .egyev-code-inputs input {
        width: 100% !important;
        max-width: 44px;
        font-size: 18px;
    }
}

/*
 * iOS zooms the whole page in when a focused field is under 16px. The code
 * boxes are already larger; the address field has to be pinned explicitly.
 */
@media (max-width: 820px) {
    .egyev-overlay .egyev-email-input {
        font-size: 16px;
    }
}

@supports (height: 100dvh) {
    .egyev-modal {
        max-height: calc(100dvh - 40px);
    }

    @media (max-width: 480px) {
        .egyev-modal {
            max-height: calc(100dvh - 24px);
        }
    }
}
