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;

    &.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: 100vh;
        background: var(--color-bg, #fff);
        border-radius: 0;
        box-shadow: 0 8px 32px rgb(0 0 0 / 0.35);
        overflow-x: hidden;
        overflow-y: auto;
    }

    #payment-microblink-target {
        flex: 1 1 auto;
        display: flex;
        flex-direction: column;
        width: 100%;
        max-width: 100vw;
        height: auto;
        min-height: 50vh;

        > * {
            width: 100% !important;
            min-height: 50vh !important;
        }

        #camera-manager-mount-point {
            width: 100% !important;
            height: auto !important;
            min-height: 50vh !important;

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

        :is(video, canvas) {
            display: block;
            width: 100% !important;
            height: auto !important;
            min-height: 50vh !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;
}

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