section.payment-microblink {
    margin: 0 0 1rem;

    &.hidden {
        display: none;
    }

    .payment-microblink__header-row {
        align-items: center;
        display: flex;
        gap: 0.75rem;
        justify-content: space-between;
    }

    .payment-microblink__controls {
        display: flex;
        gap: 0.5rem;
        margin: 0.5rem 0 0.75rem;

        button {
            display: inline-flex;
            align-items: center;
            aspect-ratio: auto;
            height: auto;
            width: fit-content;
            white-space: nowrap;
        }
    }

    .payment-microblink__dl-grid {
        margin-top: 0.75rem;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.75rem;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;

        > * {
            min-width: 0;
            max-width: 100%;
            box-sizing: border-box;
        }
    }

    .payment-microblink__dl-label {
        margin: 0;
        text-align: center;
        font-size: 0.9rem;
        font-weight: 600;

        &.payment-microblink__dl-label--full {
            grid-column: 1 / -1;
        }
    }

    .payment-microblink__dl-cell {
        position: relative;
        border: 1px solid rgb(0 0 0 / 0.15);
        border-radius: 0.4rem;
        padding: 0.5rem;
        background: rgb(0 0 0 / 0.02);
        overflow: hidden;
        min-width: 0;
        max-width: 100%;
        box-sizing: border-box;

        img {
            display: block;
            width: 100%;
            max-width: 100%;
            min-height: 8rem;
            border-radius: 0.25rem;
            object-fit: contain;
            background: rgb(0 0 0 / 0.04);
            box-sizing: border-box;
        }

        .payment-microblink__dl-overlay {
            position: absolute;
            inset: 0.5rem;
            display: flex;
            align-items: center;
            justify-content: center;
            color: rgb(0 0 0 / 0.45);
            pointer-events: none;

            i {
                font-size: 5rem;
                line-height: 1;
            }
        }

        img[data-captured="true"] + .payment-microblink__dl-overlay {
            display: none;
        }

        &.payment-microblink__dl-cell--full {
            grid-column: 1 / -1;

            img {
                min-height: 5rem;
                max-height: 14rem;
            }
        }

        &.payment-microblink__dl-cell--portrait img {
            max-height: 18rem;
            object-fit: contain;
        }
    }
}

/* Override base.css grid rule: div.fieldWrapper > div { display: grid; } */
section.payment-microblink div.fieldWrapper > div.payment-microblink__scanner-wrap {
    display: none;

    &.open {
        display: block;
    }
}

/* Top-level so styles apply when JS hoists the element to document.body */
.payment-microblink__scanner-wrap {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    top: 58px;
    overflow: hidden;

    &.open {
        display: block;
    }

    .payment-microblink__flyout-backdrop {
        position: absolute;
        inset: 0;
        z-index: 0;
        background: rgb(0 0 0 / 0.55);
    }

    .payment-microblink__flyout-panel {
        position: absolute;
        inset: 0;
        z-index: 1;
        display: flex;
        flex-direction: column;
        min-height: 0;
        max-height: 100%;
        background: var(--color-bg, #fff);
        border-radius: 0;
        box-shadow: 0 8px 32px rgb(0 0 0 / 0.35);
        overflow: hidden;
    }

    #payment-microblink-target,
    #identity-microblink-target {
        flex: 1 1 auto;
        display: flex;
        flex-direction: column;
        width: 100%;
        max-width: 100%;
        min-height: 0;
        height: 100%;
        overflow: hidden;

        > * {
            width: 100% !important;
            max-width: 100% !important;
            min-height: 0 !important;
            max-height: 100% !important;
            box-sizing: border-box;
        }

        #camera-manager-mount-point {
            width: 100% !important;
            height: 100% !important;
            max-height: 100% !important;
            min-height: 0 !important;

            :is(video, canvas) {
                display: block;
                width: 100% !important;
                height: 100% !important;
                max-width: 100% !important;
                max-height: 100% !important;
                min-height: 0 !important;
                margin: 0 auto;
                object-fit: contain !important;
            }
        }

        :is(video, canvas) {
            display: block;
            width: 100% !important;
            height: auto !important;
            max-width: 100% !important;
            max-height: 100% !important;
            min-height: 0 !important;
            object-fit: contain !important;
        }
    }

    .payment-microblink__loading-overlay {
        /* Updated from JS while WASM/resources download */
        --mb-load-progress: 0;
        position: absolute;
        inset: 0;
        z-index: 2;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 1rem;
        background: var(--color-bg, #fff);

        &[hidden] {
            display: none;
        }

        p {
            margin: 0;
            font-size: 1rem;
            opacity: 0.7;
        }

        .payment-microblink__load-progress {
            width: min(100%, 20rem);
            margin: 0;
        }

        .payment-microblink__load-progress-track {
            display: block;
            height: 0.5rem;
            overflow: hidden;
            border-radius: 999px;
            background: rgb(0 0 0 / 0.08);
        }

        .payment-microblink__load-progress-fill {
            display: block;
            height: 100%;
            width: calc(var(--mb-load-progress, 0) * 1%);
            border-radius: inherit;
            background: var(--color-primary, #2563eb);
            transition: width 0.15s ease-out;
        }

        .payment-microblink__load-progress-label {
            margin: 0;
            font-size: 0.875rem;
            font-variant-numeric: tabular-nums;
            opacity: 0.85;
        }
    }

    .payment-microblink__spinner {
        width: 2.5rem;
        height: 2.5rem;
        border: 3px solid rgb(0 0 0 / 0.12);
        border-top-color: var(--color-primary, #2563eb);
        border-radius: 50%;
        animation: mb-spin 0.8s linear infinite;
    }
}

body.microblink-flyout-active {
    overflow: hidden;
}

/* Identity scanner is a single-side back-only scan; the SDK skips its built-in
 * onboarding modal in this mode, so we render our own card-style overlay on top
 * of the camera (visually equivalent to payment's onboarding modal). */
.payment-microblink__identity-onboarding {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgb(0 0 0 / 0.55);
    box-sizing: border-box;

    &[hidden] {
        display: none;
    }

    .payment-microblink__identity-onboarding-card {
        background: var(--color-bg, #fff);
        color: var(--color-fg, #111);
        border-radius: 0.75rem;
        box-shadow: 0 8px 32px rgb(0 0 0 / 0.35);
        padding: 1.5rem 1.25rem;
        width: min(92vw, 28rem);
        max-height: min(80vh, 28rem);
        overflow: auto;
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        text-align: center;
    }

    .payment-microblink__identity-onboarding-title {
        margin: 0;
        font-size: 1.15rem;
        font-weight: 700;
    }

    .payment-microblink__identity-onboarding-body {
        margin: 0;
        font-size: 0.95rem;
        line-height: 1.4;
    }

    .payment-microblink__identity-onboarding-start {
        align-self: center;
        margin-top: 0.5rem;
        padding: 0.6rem 1.2rem;
        font-size: 1rem;
        font-weight: 600;
        border: none;
        border-radius: 0.4rem;
        background: var(--color-primary, #2563eb);
        color: #fff;
        cursor: pointer;
    }
}

@keyframes mb-spin {
    to {
        transform: rotate(360deg);
    }
}
