/*
 * The scan page (controllers/scan/scan.vm): the camera picture with a viewfinder, its status line and buttons.
 * barcodescanner.js reads the part of the picture under .scan-frame, so the frame's size here is what is read.
 */

.scan-stage {
    position: relative;
    overflow: hidden;
    height: min(62vh, 560px);
    min-height: 320px;
    background: #0a1518;
    color: #fff;
}

@media (min-width: 992px) {
    .scan-stage {
        max-width: 720px;
        margin: 1.5rem auto 0;
        border-radius: 1.25rem;
        box-shadow: 0 24px 48px rgba(15, 31, 36, 0.25);
    }
}

.scan-stage #preview {
    position: absolute;
    inset: 0;
}

.scan-stage .scan-video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.scan-stage.scanning .scan-video,
.scan-stage.found .scan-video {
    opacity: 1;
}

/* Darkened picture around the frame */
.scan-frame {
    position: absolute;
    left: 50%;
    top: 46%;
    width: min(84%, 520px);
    aspect-ratio: 2 / 1;
    transform: translate(-50%, -50%);
    border-radius: 1rem;
    box-shadow: 0 0 0 100vmax rgba(10, 21, 24, 0.55);
    transition: box-shadow 0.2s ease;
}

.scan-frame .corner {
    position: absolute;
    width: 34px;
    height: 34px;
    border: 4px solid #fff;
    transition: border-color 0.2s ease;
}

.scan-frame .corner.tl { top: -2px; left: -2px; border-right: 0; border-bottom: 0; border-top-left-radius: 1rem; }
.scan-frame .corner.tr { top: -2px; right: -2px; border-left: 0; border-bottom: 0; border-top-right-radius: 1rem; }
.scan-frame .corner.bl { bottom: -2px; left: -2px; border-right: 0; border-top: 0; border-bottom-left-radius: 1rem; }
.scan-frame .corner.br { bottom: -2px; right: -2px; border-left: 0; border-top: 0; border-bottom-right-radius: 1rem; }

.scan-frame .scan-laser {
    position: absolute;
    left: 6%;
    right: 6%;
    top: 50%;
    height: 2px;
    border-radius: 2px;
    background: #ff6a3d;
    box-shadow: 0 0 10px 2px rgba(255, 106, 61, 0.7);
    opacity: 0;
}

.scan-stage.scanning .scan-laser {
    opacity: 1;
    animation: scan-laser 2.2s ease-in-out infinite;
}

@keyframes scan-laser {
    0%, 100% { transform: translateY(-38px); }
    50% { transform: translateY(38px); }
}

@media (prefers-reduced-motion: reduce) {
    .scan-stage.scanning .scan-laser {
        animation: none;
    }
}

.scan-stage.found .scan-frame .corner {
    border-color: #2bd486;
}

.scan-stage.found .scan-laser {
    opacity: 0;
}

.scan-stage.stopped .scan-frame,
.scan-stage.starting .scan-frame {
    box-shadow: 0 0 0 100vmax rgba(10, 21, 24, 0.75);
}

/* Status line under the frame */
.scan-status {
    position: absolute;
    left: 1rem;
    right: 1rem;
    bottom: 4.75rem;
    text-align: center;
    font-weight: 600;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}


#scanStatus {
    display: inline-block;
    max-width: 30rem;
    padding: 0.45rem 0.9rem;
    border-radius: 999px;
    background: rgba(10, 21, 24, 0.55);
}

#scanStatus[data-kind=success] {
    background: #1f9d63;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    letter-spacing: 0.06em;
}

#scanStatus[data-kind=warning] {
    background: rgba(160, 82, 0, 0.85);
}

.scan-starting-spinner {
    position: absolute;
    left: 50%;
    top: 46%;
    transform: translate(-50%, -50%);
    font-size: 2rem;
    opacity: 0;
}

.scan-stage.starting .scan-starting-spinner {
    opacity: 0.9;
}

/* Round buttons at the bottom of the picture */
.scan-controls {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 1rem;
    display: flex;
    justify-content: center;
    gap: 0.75rem;
}

.scan-controls .btn-scan {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-width: 48px;
    height: 48px;
    padding: 0 1rem;
    border-radius: 999px;
    font-weight: 600;
    color: #fff;
    background: rgba(255, 255, 255, 0.16);
    border: 1px solid rgba(255, 255, 255, 0.28);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
}

.scan-controls .btn-scan:hover {
    background: rgba(255, 255, 255, 0.26);
}

.scan-controls .btn-scan.sound-off {
    color: rgba(255, 255, 255, 0.7);
}

.scan-controls .btn-scan.active {
    color: #0f1f24;
    background: #ffd95a;
    border-color: #ffd95a;
}

/* Typed code under the picture */
.scan-manual {
    max-width: 720px;
    margin: 0 auto;
}

.scan-manual .form-control {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 1.125rem;
    letter-spacing: 0.08em;
}

.scan-tips li {
    margin-bottom: 0.375rem;
}

.scan-tips i {
    width: 1.25rem;
    color: var(--dld-primary, #0e7c74);
}

/* "Scan again" only when the camera stopped */
.scan-controls .scan-restart {
    display: none;
}

.scan-stage.stopped .scan-controls .scan-restart {
    display: inline-flex;
}

/* Room for 13 digits next to the button on a phone */
@media (max-width: 575.98px) {
    .scan-manual .form-control {
        letter-spacing: 0.02em;
    }

    .scan-manual .input-group .btn {
        --bs-btn-padding-x: 1rem;
        font-size: 1rem;
    }
}

/* Writing a review: one line on why to scan, over the top of the camera */
.scan-benefit {
    position: absolute;
    z-index: 3;
    top: 0.875rem;
    left: 50%;
    transform: translateX(-50%);
    width: max-content;
    max-width: calc(100% - 2rem);
    padding: 0.5rem 0.875rem;
    border-radius: 999px;
    background: rgba(10, 21, 24, 0.72);
    font-weight: 600;
    font-size: 0.925rem;
    text-align: center;
    backdrop-filter: blur(4px);
}
