/*
 * Lead capture popup (template-parts/lead-popup.php, assets/js/lead-popup.js).
 * Colours reuse the theme tokens: primary #003366, dark-blue #090F4E,
 * primary-blue #1e3adb, purple #6A35FF, stat-blue #E6E9FF.
 */

.d2i-lead-popup[hidden] {
    display: none;
}

html.d2i-lead-popup-open {
    overflow: hidden;
}

.d2i-lead-popup {
    position: fixed;
    inset: 0;
    z-index: 99997; /* below the cookie banner (99998) and its dialog (99999) */
    display: grid;
    place-items: center;
    padding: 16px;
    font-family: 'Poppins', sans-serif;
}

/* ---------- Overlay ---------- */
.d2i-lead-popup__overlay {
    position: absolute;
    inset: 0;
    background: rgba(9, 15, 78, 0.6);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity 0.24s ease-out;
}

/* ---------- Dialog ---------- */
.d2i-lead-popup__dialog {
    position: relative;
    display: grid;
    grid-template-columns: 5fr 7fr;
    /* Cap the row at the dialog's max-height. Without this the row grows to fit the
       form (e.g. once validation errors appear) and the overflow is clipped instead
       of scrolling inside .d2i-lead-popup__body. */
    grid-template-rows: minmax(0, 1fr);
    width: min(960px, 100%);
    max-height: min(680px, calc(100vh - 32px));
    max-height: min(680px, calc(100dvh - 32px));
    background: #ffffff;
    border-radius: 20px;
    overflow: hidden;
    box-shadow:
        0 32px 64px -16px rgba(9, 15, 78, 0.45),
        0 0 0 1px rgba(9, 15, 78, 0.06);
    opacity: 0;
    transform: translateY(16px) scale(0.97);
    transition:
        opacity 0.32s cubic-bezier(0.16, 1, 0.3, 1),
        transform 0.32s cubic-bezier(0.16, 1, 0.3, 1);
}

/* The dialog itself takes focus on open (so screen readers announce it and mobile
   keyboards don't pop up); it is not an interactive control, so no ring. */
.d2i-lead-popup__dialog:focus {
    outline: none;
}

.d2i-lead-popup.is-open .d2i-lead-popup__overlay {
    opacity: 1;
}

.d2i-lead-popup.is-open .d2i-lead-popup__dialog {
    opacity: 1;
    transform: none;
}

/* Exit is quicker than entry so closing never feels sluggish. */
.d2i-lead-popup.is-closing .d2i-lead-popup__overlay,
.d2i-lead-popup.is-closing .d2i-lead-popup__dialog {
    transition-duration: 0.18s;
    transition-timing-function: ease-in;
}

/* ---------- Close button ---------- */
.d2i-lead-popup__close {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 3;
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: #F3F7FF;
    color: #090F4E;
    cursor: pointer;
    transition: background-color 0.15s ease, transform 0.15s ease;
}

.d2i-lead-popup__close:hover {
    background: #E6E9FF;
}

.d2i-lead-popup__close:active {
    transform: scale(0.94);
}

.d2i-lead-popup__close:focus-visible {
    outline: 3px solid #003366;
    outline-offset: 2px;
}

/* ---------- Left: image panel ---------- */
.d2i-lead-popup__media {
    position: relative;
    min-height: 100%;
    background: #003366;
    overflow: hidden;
    isolation: isolate;
}

.d2i-lead-popup__image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scale(1.08);
    transition: transform 1.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.d2i-lead-popup.is-open .d2i-lead-popup__image {
    transform: scale(1);
}

/* Brand-tinted gradient keeps the white copy readable over any photo. */
.d2i-lead-popup__media::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 1;
    background:
        linear-gradient(180deg, rgba(0, 51, 102, 0.15) 0%, rgba(0, 51, 102, 0.35) 40%, rgba(9, 15, 78, 0.94) 100%);
}

.d2i-lead-popup__media-content {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2;
    padding: 32px 28px;
    color: #ffffff;
}

.d2i-lead-popup__media-heading {
    margin: 0 0 16px;
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.3;
    color: #ffffff;
    text-wrap: balance;
}

.d2i-lead-popup__highlights {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 12px;
}

.d2i-lead-popup__highlights li {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 0;
    font-size: 0.9rem;
    line-height: 1.45;
    color: #ffffff;
}

.d2i-lead-popup__check {
    flex: none;
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    margin-top: 1px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    color: #ffffff;
}

/* ---------- Right: copy + form ---------- */
.d2i-lead-popup__body {
    padding: 40px 40px 32px;
    overflow-y: auto;
    overscroll-behavior: contain;
    min-width: 0;
}

.d2i-lead-popup__eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 14px;
    padding: 6px 12px;
    border-radius: 999px;
    background: #E6E9FF;
    color: #1e3adb;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.d2i-lead-popup__pulse {
    position: relative;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22a35a;
}

.d2i-lead-popup__pulse::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: #22a35a;
    /* Two pulses (4s) then stop. WCAG 2.2.2 Pause, Stop, Hide: auto-playing motion that
       runs alongside other content must end within 5s or offer a pause control. The
       popup is display:none until opened, so the pulses play as it appears. */
    animation: d2i-lead-popup-pulse 2s ease-out 2;
}

@keyframes d2i-lead-popup-pulse {
    0% { transform: scale(1); opacity: 0.6; }
    80%, 100% { transform: scale(2.6); opacity: 0; }
}

.d2i-lead-popup__title {
    margin: 0 48px 10px 0; /* clear the close button */
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.25;
    color: #090F4E;
    text-wrap: balance;
}

.d2i-lead-popup__desc {
    margin: 0 0 24px;
    font-size: 0.975rem;
    line-height: 1.6;
    color: #374151;
}

/* Form fields: the theme's default inputs use a white border, invisible on a white card. */
.d2i-lead-popup__form .forminator-ui.forminator-custom-form {
    margin: 0 !important;
}

.d2i-lead-popup__form .forminator-row {
    margin-bottom: 14px !important;
}

.d2i-lead-popup__form .forminator-input,
.d2i-lead-popup__form .forminator-textarea {
    width: 100%;
    padding: 13px 16px !important;
    border: 1px solid #D2DFF5 !important;
    border-radius: 10px !important;
    background: #F3F7FF !important;
    color: #090F4E;
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

.d2i-lead-popup__form .forminator-textarea {
    min-height: 96px !important;
    height: 96px;
    resize: vertical;
}

.d2i-lead-popup__form .forminator-input:hover,
.d2i-lead-popup__form .forminator-textarea:hover {
    border-color: #9fb6e3 !important;
}

.d2i-lead-popup__form .forminator-input:focus,
.d2i-lead-popup__form .forminator-textarea:focus {
    background: #ffffff !important;
    border-color: #1e3adb !important;
    box-shadow: 0 0 0 3px rgba(30, 58, 219, 0.18) !important;
    outline: none;
}

.d2i-lead-popup__form .forminator-input:focus-visible,
.d2i-lead-popup__form .forminator-textarea:focus-visible {
    outline: 2px solid #090F4E;
    outline-offset: 1px;
}

/* Material design draws an underline bar; the bordered field replaces it here. */
.d2i-lead-popup__form .forminator-input--wrap::after,
.d2i-lead-popup__form .forminator-textarea--wrap::after {
    display: none !important;
}

.d2i-lead-popup__form .forminator-label {
    font-size: 0.85rem !important;
    font-weight: 500 !important;
    color: #090F4E !important;
}

/* Submit button: mirrors the site's primary button utility classes
   (Forminator renders its own <button>, so the Tailwind classes can't be added to it):
   px-8 py-4 bg-primary text-white no-underline hover:no-underline font-semibold rounded-lg
   hover:bg-darkBlue hover:text-white active:scale-95 transition-all duration-300
   focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2
   Scoped by #d2i-lead-popup to outrank Forminator's per-form stylesheet
   (uploads/forminator/.../style-123.css), which sets padding, transition and a black
   :focus ring with !important on a five-class selector. */
#d2i-lead-popup .forminator-ui.forminator-custom-form .forminator-button.forminator-button-submit {
    padding: 1rem 2rem !important;                 /* px-8 py-4 */
    background: #003366 !important;                /* bg-primary */
    color: #ffffff !important;                     /* text-white */
    text-decoration: none !important;              /* no-underline */
    font-weight: 600 !important;                   /* font-semibold */
    border: 0 !important;
    border-radius: 0.5rem !important;              /* rounded-lg */
    box-shadow: none !important;
    transition: all 300ms cubic-bezier(0.4, 0, 0.2, 1) !important; /* transition-all duration-300 */
}

#d2i-lead-popup .forminator-ui.forminator-custom-form .forminator-button.forminator-button-submit:hover {
    background: #090F4E !important;                /* hover:bg-darkBlue */
    color: #ffffff !important;                     /* hover:text-white */
    text-decoration: none !important;              /* hover:no-underline */
}

#d2i-lead-popup .forminator-ui.forminator-custom-form .forminator-button.forminator-button-submit:active {
    transform: scale(0.95);                        /* active:scale-95 */
}

/* Forminator's own :focus ring would also show on mouse click; only keyboard focus gets a ring. */
#d2i-lead-popup .forminator-ui.forminator-custom-form .forminator-button.forminator-button-submit:focus {
    outline: none !important;
    box-shadow: none !important;
}

#d2i-lead-popup .forminator-ui.forminator-custom-form .forminator-button.forminator-button-submit:focus-visible {
    outline: none !important;                      /* focus-visible:outline-none */
    /* ring-2 ring-primary ring-offset-2 (white offset) */
    box-shadow: 0 0 0 2px #ffffff, 0 0 0 4px #003366 !important;
}

.d2i-lead-popup__form .forminator-response-message.forminator-success {
    border-radius: 10px;
}

/* ---------- Short screens (laptops, zoomed-in browsers): tighten vertical rhythm ---------- */
@media (min-width: 768px) and (max-height: 800px) {
    .d2i-lead-popup__body {
        padding: 28px 32px 24px;
    }

    .d2i-lead-popup__eyebrow {
        margin-bottom: 10px;
    }

    .d2i-lead-popup__title {
        font-size: 1.5rem;
        margin-bottom: 6px;
    }

    .d2i-lead-popup__desc {
        margin-bottom: 16px;
        font-size: 0.925rem;
    }

    .d2i-lead-popup__form .forminator-row {
        margin-bottom: 10px !important;
    }

    .d2i-lead-popup__form .forminator-textarea {
        min-height: 80px !important;
        height: 80px;
    }

    .d2i-lead-popup__media-content {
        padding: 24px;
    }
}

/* ---------- Tablet / mobile ---------- */
@media (max-width: 767px) {
    .d2i-lead-popup {
        padding: 12px;
    }

    /* The whole dialog scrolls as one column: image + highlights scroll away with the
       form instead of staying pinned and eating the screen. */
    .d2i-lead-popup__dialog {
        display: block;
        max-height: calc(100vh - 24px);
        max-height: calc(100dvh - 24px);
        overflow-y: auto;
        overscroll-behavior: contain;
        border-radius: 16px;
    }

    /* Close button stays reachable while scrolling. It takes no vertical space
       (10 + 44 - 54 = 0), so the image still starts at the top edge. */
    .d2i-lead-popup__close {
        position: sticky;
        top: 10px;
        right: auto;
        margin: 10px 10px -54px auto;
        background: rgba(255, 255, 255, 0.92);
        box-shadow: 0 2px 8px rgba(9, 15, 78, 0.18);
    }

    /* Image panel grows with its text; the photo fills the space behind it. */
    .d2i-lead-popup__media {
        min-height: 0;
    }

    .d2i-lead-popup__media-content {
        position: relative;
        padding: 112px 20px 22px; /* top space lets the photo show above the copy */
    }

    .d2i-lead-popup__media-heading {
        margin: 0 0 12px;
        font-size: 1.1rem;
    }

    .d2i-lead-popup__highlights {
        gap: 8px;
    }

    .d2i-lead-popup__highlights li {
        font-size: 0.85rem;
    }

    .d2i-lead-popup__body {
        padding: 24px 20px 20px;
        overflow: visible;
    }

    .d2i-lead-popup__title {
        margin-right: 0;
        font-size: 1.35rem;
    }

    .d2i-lead-popup__desc {
        margin-bottom: 18px;
        font-size: 0.9rem;
    }
}

/* ---------- Reduced motion: fade only, no movement ---------- */
@media (prefers-reduced-motion: reduce) {
    .d2i-lead-popup__dialog,
    .d2i-lead-popup__image {
        transform: none !important;
        transition-property: opacity;
    }

    .d2i-lead-popup__pulse::after {
        animation: none;
    }

    .d2i-lead-popup__close {
        transition: none;
    }

    #d2i-lead-popup .forminator-ui.forminator-custom-form .forminator-button.forminator-button-submit:active {
        transform: none;
    }
}
