/* Full-screen QR scanner (tenant/_scanner_stage.j2, js/scanner_camera.js).
 *
 * html5-qrcode decodes the region it centers in its <video>, mapping it per
 * axis from the video's layout size, so the video itself is never cropped or
 * transformed: it stays centered at its own aspect ratio, a blurred copy of
 * the stream fills the rest of the screen, and a blurred mask with a hole at
 * the box covers everything else. --box is the box side (set by the script),
 * --shift moves the box (and the video with it) up to make room for a sheet. */

.scanner-screen {
    position: fixed;
    inset: 0;
    z-index: 1045;
    background: #000;
}

.scanner-modal .modal-dialog {
    max-width: none;
    width: 100%;
    height: 100%;
    margin: 0;
}

/* Fade only: a transformed dialog would offset its fixed children. */
.scanner-modal.fade .modal-dialog {
    transform: none;
}

.scanner-modal .modal-content {
    height: 100%;
    border: 0;
    border-radius: 0;
    background: #000;
}

.scanner-stage {
    --box: 250px;
    --shift: 0px;
    --box-top: calc(50% + var(--shift) - var(--box) / 2);
    --box-bottom: calc(50% + var(--shift) + var(--box) / 2);
    --box-left: calc(50% - var(--box) / 2);
    --box-right: calc(50% + var(--box) / 2);
    position: absolute;
    inset: 0;
    overflow: hidden;
    background: #000;
    color: #fff;
}

.scanner-stage.has-pool {
    --shift: -15vh;
}

.scanner-backdrop {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: blur(18px) brightness(0.6);
    transform: scale(1.1);
}

/* html5-qrcode sets position: relative on #reader, so this wrapper centers it. */
.scanner-reader-wrap {
    position: absolute;
    left: 50%;
    top: calc(50% + var(--shift));
    width: 100%;
    transform: translate(-50%, -50%);
}

.scanner-reader-wrap video {
    display: block;
}

/* We draw our own box and shading. */
#qr-shaded-region {
    display: none !important;
}

.scanner-mask {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    clip-path: polygon(evenodd,
            0 0, 100% 0, 100% 100%, 0 100%, 0 0,
            var(--box-left) var(--box-top), var(--box-right) var(--box-top),
            var(--box-right) var(--box-bottom), var(--box-left) var(--box-bottom),
            var(--box-left) var(--box-top));
}

.scanner-box {
    position: absolute;
    left: var(--box-left);
    top: var(--box-top);
    width: var(--box);
    height: var(--box);
    border: 3px solid rgba(255, 255, 255, 0.9);
    border-radius: 14px;
    pointer-events: none;
}

.scanner-controls {
    position: absolute;
    left: 50%;
    top: calc(var(--box-bottom) + 20px);
    transform: translateX(-50%);
    display: flex;
    gap: 12px;
    align-items: center;
}

.scanner-hint {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(var(--box-bottom) + 76px);
    text-align: center;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.85);
}

.scanner-pill {
    min-width: 48px;
    height: 44px;
    padding: 0 16px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 22px;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.scanner-pill:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.6);
}

/* Camera, zoom, torch and sound together must fit a 360px phone. */
@media (max-width: 400px) {
    .scanner-controls {
        gap: 8px;
    }

    .scanner-pill {
        padding: 0 12px;
    }
}

/* Torch on. */
.scanner-torch-btn[aria-pressed="true"] {
    border-color: #fff;
    background: #fff;
    color: #212529;
}

/* Controls only while the camera runs. */
.scanner-stage:not(.is-running) .scanner-controls,
.scanner-stage:not(.is-running) .scanner-hint {
    display: none;
}

.scanner-close {
    position: absolute;
    top: calc(env(safe-area-inset-top, 0px) + 12px);
    right: 12px;
    z-index: 3;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 28px;
    line-height: 44px;
    text-align: center;
}

.scanner-top {
    position: absolute;
    top: calc(env(safe-area-inset-top, 0px) + 12px);
    left: 12px;
    right: 68px;
    z-index: 2;
}

.scanner-label {
    margin: 0;
    line-height: 44px;
    font-size: 1.05rem;
    font-weight: 600;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

.scanner-top .alert {
    margin: 8px 0 0;
}

.scanner-panel {
    background: rgba(255, 255, 255, 0.95);
    color: #212529;
    border-radius: 12px;
    padding: 8px 12px;
}

/* Bottom sheets: the camera list and the split payment pool. */
.scanner-sheet {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 4;
    max-height: 70%;
    overflow-y: auto;
    padding: 16px 16px calc(env(safe-area-inset-bottom, 0px) + 16px);
    border-radius: 16px 16px 0 0;
    background: #fff;
    color: #212529;
}

.scanner-sheet .list-group-item.active {
    background: #e9f2ff;
    border-color: #b8d4ff;
    color: #212529;
    font-weight: 600;
}

.scanner-pool {
    max-height: 32%;
}

/* Camera stopped while the pool stays open: let the sheet take over. */
.scanner-stage.is-idle .scanner-reader-wrap,
.scanner-stage.is-idle .scanner-mask,
.scanner-stage.is-idle .scanner-box {
    visibility: hidden;
}

.scanner-stage.is-idle~.scanner-pool {
    max-height: 85%;
}
