/* ----- Barcode scanner (LG.barcode) -------------------------------------
 *
 * Sized for a phone held one-handed at a counter, which is where this is
 * actually used: the video is the largest thing on screen, the number box is
 * always visible under it rather than behind a "having trouble?" link, and
 * every target clears 44px so it can be hit without looking.
 *
 * WHY THIS IS ITS OWN FILE. These rules used to sit in admin.css, which only
 * the admin layout loads. The public scan page therefore rendered the
 * scanner with no styles at all - the video at its intrinsic size, no
 * overlay, and the aiming guide invisible even though the element was there.
 * Any page that loads js/barcode-scanner.js must load this beside it.
 */
.lgbc {
    position: fixed;
    inset: 0;
    z-index: 2000;                 /* over the till's sticky basket rail */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(15, 18, 26, .82);
}

.lgbc__panel {
    position: relative;
    width: 100%;
    max-width: 26rem;
    padding: 1rem;
    border-radius: .9rem;
    background: #fff;
    box-shadow: 0 1.6rem 3rem rgba(0, 0, 0, .35);
}

.lgbc__x {
    position: absolute;
    top: .35rem;
    right: .5rem;
    width: 2.5rem;
    height: 2.5rem;
    border: 0;
    background: none;
    font-size: 1.6rem;
    line-height: 1;
    color: #6b7280;
    cursor: pointer;
}
.lgbc__x:hover { color: #111827; }

.lgbc__video {
    position: relative;
    overflow: hidden;
    aspect-ratio: 4 / 3;
    margin: 1.6rem 0 .6rem;
    border-radius: .6rem;
    background: #0f121a;
}
.lgbc__video video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ----- the aiming guide -----
 *
 * A barcode is wide and short, so the box is too: its shape alone tells
 * somebody how to hold the packet, without anybody having to say it. The
 * surround is dimmed by one enormous spread shadow rather than four
 * positioned overlays, which keeps it exact at every aspect ratio.
 */
.lgbc__reticle {
    position: absolute;
    top: 50%;
    left: 8%;
    width: 84%;
    height: 30%;
    transform: translateY(-50%);
    border-radius: .4rem;
    box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45);
    pointer-events: none;
}

/*
 * Corner brackets, not a full rectangle. A continuous border competes with
 * the bars themselves for the eye; four corners read instantly as "put it
 * in here" and leave the middle clean for the thing being read.
 */
.lgbc__reticle::before,
.lgbc__reticle::after {
    content: "";
    position: absolute;
    width: 1.6rem;
    height: 1.6rem;
    border: .2rem solid #fff;
}
.lgbc__reticle::before {
    top: -.1rem;
    left: -.1rem;
    border-right: 0;
    border-bottom: 0;
    border-radius: .4rem 0 0 0;
}
.lgbc__reticle::after {
    right: -.1rem;
    bottom: -.1rem;
    border-left: 0;
    border-top: 0;
    border-radius: 0 0 .4rem 0;
}

/* The other two corners, on a bare element so the pseudo-elements above
 * stay one bracket each and nothing has to be faked with gradients. */
.lgbc__corners {
    position: absolute;
    inset: 0;
    pointer-events: none;
}
.lgbc__corners::before,
.lgbc__corners::after {
    content: "";
    position: absolute;
    width: 1.6rem;
    height: 1.6rem;
    border: .2rem solid #fff;
}
.lgbc__corners::before {
    top: -.1rem;
    right: -.1rem;
    border-left: 0;
    border-bottom: 0;
    border-radius: 0 .4rem 0 0;
}
.lgbc__corners::after {
    bottom: -.1rem;
    left: -.1rem;
    border-right: 0;
    border-top: 0;
    border-radius: 0 0 0 .4rem;
}

/*
 * A line sweeping the box says "still looking" without a spinner stealing
 * the middle of the frame. It is decoration only - decoding does not depend
 * on where the line happens to be - so it stops dead under reduced motion.
 */
.lgbc__sweep {
    position: absolute;
    left: 6%;
    right: 6%;
    top: 0;
    height: .12rem;
    border-radius: .12rem;
    background: linear-gradient(90deg, transparent, #ffd166, transparent);
    animation: lgbc-sweep 2.1s ease-in-out infinite;
    pointer-events: none;
}

@keyframes lgbc-sweep {
    0%, 100% { top: 12%; opacity: .35; }
    50% { top: 88%; opacity: 1; }
}

/* Inside the frame, where somebody aiming a camera is already looking. */
.lgbc__hint {
    position: absolute;
    left: 0;
    right: 0;
    bottom: .5rem;
    margin: 0;
    text-align: center;
    font-size: .8125rem;
    font-weight: 600;
    color: #fff;
    text-shadow: 0 1px .2rem rgba(0, 0, 0, .9);
    pointer-events: none;
}

.lgbc__status {
    margin: 0 0 .75rem;
    font-size: .875rem;
    color: #4b5563;
    min-height: 1.25rem;
}
.lgbc__status.is-bad { color: #b42318; font-weight: 600; }

.lgbc__manual label {
    display: block;
    margin-bottom: .3rem;
    font-size: .8125rem;
    font-weight: 600;
    color: #374151;
}
.lgbc__row { display: flex; gap: .5rem; }
.lgbc__row input {
    flex: 1 1 auto;
    min-width: 0;
    height: 2.75rem;
    padding: 0 .7rem;
    border: 1px solid #d1d5db;
    border-radius: .45rem;
    font-size: 1.05rem;
    /* Digits line up while they are being read back against a packet. */
    font-variant-numeric: tabular-nums;
}
.lgbc__row input:focus {
    outline: 2px solid #3d52a8;
    outline-offset: 1px;
    border-color: #3d52a8;
}
.lgbc__go {
    flex: 0 0 auto;
    height: 2.75rem;
    padding: 0 1rem;
    border: 0;
    border-radius: .45rem;
    background: #3d52a8;
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}
.lgbc__go:hover { background: #334590; }

.lgbc__any {
    display: flex;
    align-items: center;
    gap: .4rem;
    margin: .85rem 0 0;
    font-size: .8125rem;
    color: #374151;
}
.lgbc__any span { color: #6b7280; }

/*
 * A short phone in landscape has almost no height to give away. Trading the
 * 4:3 frame for 16:9 keeps the number box on screen without scrolling,
 * which is the one control that must never be out of reach.
 */
@media (max-height: 34rem) {
    .lgbc__video {
        aspect-ratio: 16 / 9;
        margin-top: 1.4rem;
    }
    .lgbc__hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .lgbc, .lgbc__panel { transition: none; }
    .lgbc__sweep { animation: none; top: 50%; }
}
