/* ============================================================
   Badge Scanner Overlay — persistent camera viewport
   ============================================================ */

/* ── Top-of-page scanner status banner ─────────────────────── */
.scanner-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10001;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px 20px;
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-align: center;
    color: #fff;
    transition: background-color 0.3s;
    min-height: 56px;
}

.scanner-banner-text {
    text-transform: uppercase;
}

/* Ready — green: safe to scan */
.scanner-banner-ready {
    background-color: #198754;
}

/* Processing — amber/yellow: wait */
.scanner-banner-processing {
    background-color: #fd7e14;
    animation: banner-pulse 1s ease-in-out infinite;
}

/* Success — bright green flash */
.scanner-banner-success {
    background-color: #20c997;
    animation: banner-flash 0.4s ease-out;
}

/* Error — red */
.scanner-banner-error {
    background-color: #dc3545;
}

@keyframes banner-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

@keyframes banner-flash {
    0% { background-color: #fff; color: #198754; }
    100% { background-color: #20c997; color: #fff; }
}

/* Push the main page content down so the banner doesn't overlap */
.scanner-banner ~ .badge-scanner-overlay {
    /* Overlay is fixed-position so no shift needed */
}

.badge-scanner-overlay {
    position: fixed;
    bottom: 110px;         /* above the footer + toggle button */
    left: 16px;
    z-index: 10000;
    width: 320px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 24px rgba(0,0,0,0.4);
    background: #000;
}

.badge-scanner-viewport {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
}

.badge-scanner-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Crosshair target overlay */
.badge-scanner-crosshair {
    position: absolute;
    inset: 20%;
    pointer-events: none;
}

.crosshair-corner {
    position: absolute;
    width: 24px;
    height: 24px;
    border-color: rgba(255,255,255,0.8);
    border-style: solid;
    border-width: 0;
}
.crosshair-corner.tl { top:0;left:0; border-top-width:3px; border-left-width:3px; border-top-left-radius:6px; }
.crosshair-corner.tr { top:0;right:0; border-top-width:3px; border-right-width:3px; border-top-right-radius:6px; }
.crosshair-corner.bl { bottom:0;left:0; border-bottom-width:3px; border-left-width:3px; border-bottom-left-radius:6px; }
.crosshair-corner.br { bottom:0;right:0; border-bottom-width:3px; border-right-width:3px; border-bottom-right-radius:6px; }

.badge-scanner-status {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 6px 12px;
    background: rgba(0,0,0,0.65);
    color: #fff;
    font-size: 0.85rem;
    text-align: center;
}

.badge-scanner-close {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 1;
}

/* Camera switcher dropdown (shown when >1 camera available) */
.badge-scanner-camera-switcher {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 1;
    max-width: 180px;
}

.badge-scanner-camera-switcher .form-select {
    background-color: rgba(0, 0, 0, 0.65);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.3);
    font-size: 0.75rem;
    padding: 0.2rem 1.8rem 0.2rem 0.5rem;
    cursor: pointer;
    -webkit-appearance: none;
}

.badge-scanner-camera-switcher .form-select:focus {
    border-color: rgba(255, 255, 255, 0.6);
    box-shadow: 0 0 0 0.15rem rgba(255, 255, 255, 0.2);
}

.badge-scanner-camera-switcher .form-select option {
    background-color: #212529;
    color: #fff;
}

/* ============================================================
   Footer badge-scan toggle button
   ============================================================ */
.badge-scan-footer-btn {
    position: fixed;
    bottom: 12px;          /* above the fixed footer bar */
    left: 16px;
    z-index: 9999;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    transition: transform 0.2s, background-color 0.2s;
}

.badge-scan-footer-btn:hover {
    transform: scale(1.1);
}

.badge-scan-footer-btn.active {
    background-color: #dc3545 !important;
    border-color: #dc3545 !important;
}

/* ============================================================
   Badge Photo Picker — gallery thumbnail selector
   ============================================================ */
.badge-photo-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 4px;
    border: 2px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.badge-photo-option:hover {
    border-color: #adb5bd;
}

.badge-photo-option.selected {
    border-color: #0d6efd;
    box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.25);
}

.badge-photo-option small {
    font-size: 0.65rem;
    color: #6c757d;
}

.badge-photo-thumb {
    width: 60px;
    height: 60px;
    border-radius: 6px;
    object-fit: cover;
}

.badge-photo-thumb-placeholder {
    width: 60px;
    height: 60px;
    border-radius: 6px;
    background: #e9ecef;
    color: #6c757d;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
}

/* ============================================================
   Badge Design — Credit Card Size (3.375" × 2.125")
   Vertical orientation: 2.125" wide × 3.375" tall
   ============================================================ */
.badge-card {
    width: 54mm;
    height: 86mm;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
    display: flex;
    flex-direction: column;
    font-family: 'Segoe UI', system-ui, sans-serif;
    position: relative;
}

.badge-card-front {
    text-align: center;
    padding: 0;
}

/* Lanyard punch-slot area */
.badge-lanyard-slot {
    height: 26px;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    background: #fff;
    flex-shrink: 0;
}

.badge-lanyard-hole {
    width: 48px;
    height: 16px;
    border-radius: 8px;
    border: 1px dashed #bbb;
    background: transparent;
    margin-top: 5mm;
}

.badge-front-header {
    background: #fff;
    padding: 6px 10px 2px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.badge-front-header img {
    height: 24px;
    width: auto;
    object-fit: contain;
}

.badge-front-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6px 8px;
    gap: 4px;
}

.badge-client-photo {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid #0d6efd;
}

.badge-client-photo-placeholder {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: #0d6efd;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    border: 3px solid #0a58ca;
}

.badge-client-name {
    font-size: 0.75rem;
    font-weight: 700;
    color: #212529;
    line-height: 1.2;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

.badge-client-subtitle {
    font-size: 0.6rem;
    font-weight: 500;
    color: #495057;
    line-height: 1.2;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
}

.badge-qr-code {
    width: 100px;
    height: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.badge-qr-code img,
.badge-qr-code svg {
    width: 100px;
    height: 100px;
}

.badge-qr-token-short {
    font-size: 0.45rem;
    letter-spacing: 0.06em;
    color: #555;
    margin-top: 1px;
    font-family: monospace;
    line-height: 1;
}

@media print {
    .badge-qr-token-short {
        color: #000;
    }
}

/* Back of badge */
.badge-card-back {
    padding: 0;
    display: flex;
    flex-direction: column;
}

/* Match the front lanyard slot on the back */
.badge-card-back .badge-lanyard-slot {
    height: 26px;
    flex-shrink: 0;
}

.badge-back-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 3mm 12px 12px;
}

.badge-back-header {
    text-align: center;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 2px solid #0d6efd;
}

.badge-back-header h6 {
    font-size: 0.85rem;
    font-weight: 700;
    color: #0d6efd;
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-back-instructions {
    flex: 1;
    font-size: 0.55rem;
    font-weight: 700;
    color: #495057;
    line-height: 1.2;
}

.badge-back-instructions ol {
    padding-left: 16px;
    margin: 0;
}

.badge-back-instructions li {
    margin-bottom: 4px;
}

.badge-back-footer {
    margin-top: auto;
    text-align: center;
    font-size: 0.5rem;
    font-weight: 700;
    color: #495057;
    border-top: 1px solid #dee2e6;
    padding-top: 4px;
}

/* ============================================================
   Badge Print Layout
   ============================================================ */
@media print {
    @page {
        size: 54mm 86mm;
        margin: 0;
    }

    .badge-print-sheet {
        page-break-inside: avoid;
    }

    .badge-card {
        width: 54mm;
        height: 86mm;
        border: none;
        border-radius: 0;
        box-shadow: none;
        margin: 0;
        padding: 0;
        page-break-after: always;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* Last card should not add trailing blank page */
    .badge-card:last-child {
        page-break-after: auto;
    }

    /* Hide everything except the badge when printing */
    body > *:not(.badge-print-container) {
        display: none !important;
    }

    .badge-print-container {
        display: block;
        padding: 0;
        margin: 0;
    }

    /* Hide screen-only labels */
    .badge-preview-label {
        display: none !important;
    }
}

/* ============================================================
   Badge Preview (on screen)
   ============================================================ */
.badge-preview-container {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
    justify-content: center;
}

.badge-preview-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #6c757d;
    text-align: center;
    margin-bottom: 8px;
    font-weight: 600;
}

/* ── Responsive: phones ────────────────────────────────────── */
@media (max-width: 575.98px) {
    .badge-scanner-overlay {
        width: calc(100vw - 32px);
        left: 16px;
        right: 16px;
        bottom: 110px;
    }
}

/* ============================================================
   Inline Print — iOS / iPadOS Safari fallback
   Safari blocks window.open from Blazor SignalR callbacks, so
   the badge HTML is injected into the current page and printed
   using window.print(). The body.badge-printing class scopes
   the rules so normal Ctrl+P / ⌘P is unaffected.
   ============================================================ */
#badge-inline-print {
    display: none; /* hidden on screen */
}

@media print {
    body.badge-printing > *:not(#badge-inline-print) {
        display: none !important;
    }

    body.badge-printing #badge-inline-print {
        display: block !important;
    }

    body.badge-printing #badge-inline-print .badge-card {
        width: 54mm;
        height: 86mm;
        border: none;
        border-radius: 0;
        box-shadow: none;
        margin: 0;
        padding: 0;
        page-break-after: always;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    body.badge-printing #badge-inline-print .badge-card:last-child {
        page-break-after: auto;
    }

    body.badge-printing #badge-inline-print .badge-preview-label {
        display: none !important;
    }
}
