/**
 * Scanner Styles
 */
.osat-modal--scanner .osat-modal__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
}

/* Small "X" close button (replaces the old "Close" text button) */
.osat-scanner-close-x {
    -webkit-appearance: none;
    appearance: none;
    border: none;
    background: transparent;
    color: var(--osat-secondary-text-color, #666);
    font-size: 1.75rem;
    line-height: 1;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex: 0 0 auto;
}
.osat-scanner-close-x:hover {
    background: rgba(0, 0, 0, 0.06);
    color: var(--osat-text-color, #111);
}

.osat-scanner-status {
    position: absolute;
    top: 100%;
    left: var(--osat-spacing-md);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--osat-primary-color);
    margin-top: -5px;
}

#osat-scanner-container { position: relative; }

#osat-qr-reader {
    width: 100% !important;
    border: none !important;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
}

/* "Sounds" toggle overlaid bottom-right of the camera preview (outside the QR frame) */
.osat-sound-toggle {
    position: absolute;
    bottom: 10px;
    right: 10px;
    z-index: 5;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.55);
    cursor: pointer;
    user-select: none;
}
.osat-sound-toggle__label {
    color: #fff;
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1;
}
.osat-sound-toggle input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}
.osat-sound-toggle__track {
    position: relative;
    width: 30px;
    height: 16px;
    border-radius: 999px;
    background: var(--osat-danger-color, #c62828); /* off = red */
    transition: background-color 0.2s ease;
    flex: 0 0 auto;
}
.osat-sound-toggle__thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #fff;
    transition: transform 0.2s ease;
}
.osat-sound-toggle input:checked + .osat-sound-toggle__track {
    background: #2e7d32; /* on = green */
}
.osat-sound-toggle input:checked + .osat-sound-toggle__track .osat-sound-toggle__thumb {
    transform: translateX(14px);
}

#osat-qr-reader__dashboard {
    display: none !important;
}

.osat-scanner-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-top: 15px;
}

.osat-scanner-action-btn.is-active {
    background-color: var(--osat-primary-color);
    color: white;
}

.osat-scan-result {
    padding: 20px;
    background: #f9f9f9;
    border-radius: 8px;
    border: 1px solid #eee;
    text-align: center;
}

.osat-scan-card h4 {
    margin: 10px 0 5px;
}

.osat-scan-thumb {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid #ddd;
    margin-bottom: 10px;
}

/* Larger asset photo on the default scan result card */
.osat-scan-photo {
    display: block;
    width: 100%;
    max-width: 280px;
    max-height: 260px;
    object-fit: contain;
    margin: 0 auto 12px;
    border-radius: 10px;
    border: 1px solid var(--osat-border-color, #ddd);
    background: #fff;
}
.osat-scan-photo--empty {
    height: 200px;
    background: linear-gradient(135deg, #eef1f4 0%, #e2e6ea 100%);
}

/* Location action card (Stocktake / Check In / Check Out / Edit Location) */
.osat-location-actions {
    grid-template-columns: repeat(2, 1fr);
}

/* ---- Location-based activity session (camera + Finish + scanned list) ---- */
.osat-activity-card {
    text-align: left;
}
.osat-activity-finish {
    width: 100%;
    margin-bottom: 12px;
}
.osat-activity-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 45vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.osat-activity-empty {
    text-align: center;
    color: var(--osat-secondary-text-color, #777);
    padding: 16px 8px;
    margin: 0;
}
.osat-activity-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border: 1px solid var(--osat-border-color, #eee);
    border-radius: 8px;
    background: #fff;
}
.osat-activity-thumb {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    object-fit: cover;
    border-radius: 6px;
    background: #f0f0f0;
    border: 1px solid var(--osat-border-color, #eee);
}
/* Neutral placeholder when an item has no photo (avoids a broken <img>) */
.osat-activity-thumb--empty,
.osat-scan-thumb--empty {
    display: inline-block;
    background:
        linear-gradient(135deg, #eef1f4 0%, #e2e6ea 100%);
}
.osat-activity-name {
    flex: 1 1 auto;
    font-weight: 600;
    word-break: break-word;
}
.osat-activity-remove {
    flex: 0 0 auto;
    background: none;
    border: 1px solid var(--osat-danger-color, #c62828);
    color: var(--osat-danger-color, #c62828);
    border-radius: 6px;
    padding: 8px 14px;
    min-height: 44px;
    cursor: pointer;
    font-size: 0.85rem;
}
.osat-activity-remove:hover {
    background: var(--osat-danger-color, #c62828);
    color: #fff;
}

/* ---- Mobile: full-screen scanner modal (no page behind, maximise space) ---- */
@media (max-width: 768px) {
    /* Fill the viewport. !important + the #id beat the base .osat-modal { max-width:500px }
       definitively (and survive a browser holding an older cached stylesheet). */
    #osat-scanner-modal.osat-modal-overlay {
        padding: 0 !important;
        align-items: stretch;
    }
    #osat-scanner-modal .osat-modal--scanner {
        width: 100% !important;
        max-width: 100% !important;
        height: 100vh;
        height: 100dvh;          /* dynamic viewport — accounts for mobile browser chrome */
        max-height: 100vh !important;
        max-height: 100dvh !important;
        margin: 0 !important;
        border-radius: 0 !important;
        display: flex;
        flex-direction: column;
    }

    /* Move the header (QR Scanner title + X) to the BOTTOM on mobile; body fills + scrolls above it. */
    #osat-scanner-modal .osat-modal__header {
        order: 2;
        border-bottom: none;
        border-top: 1px solid var(--osat-border-color, #e3e6ea);
    }
    #osat-scanner-modal .osat-modal__body {
        order: 1;
        display: flex;
        flex-direction: column;
        flex: 1 1 auto;
        overflow-y: auto;
    }

    /* Default (selection / decision / summary cards): instruction on top, then the card
       ON TOP of the camera so it's reachable without scrolling; camera, then buttons. */
    #osat-scanner-modal #osat-scanner-instruction { order: 0; }
    #osat-scanner-modal #osat-scan-result         { order: 1; margin-top: 0; }
    #osat-scanner-modal #osat-scanner-container    { order: 2; }
    #osat-scanner-modal #osat-scanner-actions      { order: 3; }

    /* While a scanning loop is RUNNING: keep the camera up top (below the instruction)
       and let the live scanned list sit below it — the user only scrolls to see the list. */
    #osat-scanner-modal.osat-scanner--scanning #osat-scanner-container { order: 1; }
    #osat-scanner-modal.osat-scanner--scanning #osat-scan-result       { order: 2; }

    #osat-scanner-modal .osat-activity-list {
        max-height: none;        /* let the whole body scroll instead of a nested box */
    }
}
