/* floating scan button */
.scan-fab {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 150;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: 4px solid rgb(255, 229, 10);
    border-radius: 40px;
    background: #d32a2a;
    color: white;
    font-family: inherit;
    font-size: 20px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 8px 18px rgb(22 28 45 / 35%);
    transition: all 0.2s ease-in-out;
}
.scan-fab:hover {
    transform: scale(1.06);
    background: #b62222;
}
.scan-fab .bi {
    font-size: 26px;
}
/* a modal covers the page, the floating button would only be in the way */
.scan-fab.is-hidden {
    opacity: 0;
    transform: scale(0.8);
    pointer-events: none;
}

/* scan control inside the deck header */
.deck-scan {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 40px;
    background: #d32a2a;
    color: white;
    cursor: pointer;
}
.deck-scan:hover {
    opacity: 0.5;
}
.deck-scan .bi {
    font-size: 34px;
}

/* scanner panel */
.scanner-modal .background,
.scanner-modal .background * {
    box-sizing: border-box;
}
.scanner-modal .background {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
    z-index: 300;
}
.scan-panel {
    width: 100%;
    max-width: 640px;
    max-height: 92vh;
    overflow-y: auto;
    background: #e9e9e9;
    border: 8px solid rgb(255, 229, 10);
    border-radius: 8px;
    box-shadow: 0 22px 34px rgb(22 28 45 / 45%);
}
.scan-panel .header-bar {
    height: 60px;
    font-size: 26px;
    padding: 0 1.25rem;
    position: sticky;
    top: 0;
    z-index: 2;
}
.scan-panel .header-bar .bi-x {
    font-size: 44px;
}
.scan-body {
    padding: 1.25rem;
}

/* camera / preview stage */
.scan-stage {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    background: #2b2b2b;
    border-radius: 6px;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}
.scan-stage video,
.scan-stage img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}
.scan-stage [hidden] {
    display: none;
}
.scan-guide {
    position: absolute;
    top: 8%;
    left: 12%;
    right: 12%;
    height: 22%;
    border: 3px dashed rgba(255, 229, 10, 0.9);
    border-radius: 4px;
    pointer-events: none;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}
.scan-guide span {
    transform: translateY(120%);
    color: rgb(255, 229, 10);
    font-size: 13px;
    font-weight: 700;
    text-shadow: 0 1px 3px black;
    white-space: nowrap;
}
.scan-placeholder {
    position: absolute;
    color: #cfcfcf;
    font-size: 16px;
    text-align: center;
    padding: 0 2rem;
}

/* controls */
.scan-controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem;
    margin: 1rem 0 0.75rem;
}
.scan-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.6rem 1.1rem;
    border: 3px solid #d32a2a;
    border-radius: 40px;
    background: white;
    color: #d32a2a;
    font-family: inherit;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
}
.scan-btn:hover {
    background: #d32a2a;
    color: white;
}
.scan-btn.primary {
    background: #d32a2a;
    color: white;
}
.scan-btn.primary:hover {
    background: #b62222;
}
.scan-btn:disabled,
.scan-btn[disabled] {
    opacity: 0.45;
    cursor: not-allowed;
    background: white;
    color: #d32a2a;
}

.scan-status {
    text-align: center;
    font-size: 16px;
    line-height: 1.4;
    min-height: 1.4em;
    color: #444;
}
.scan-status.error {
    color: #d32a2a;
    font-weight: 700;
}

.scan-progress {
    height: 10px;
    margin: 0.75rem 0;
    background: #cdcdcd;
    border-radius: 10px;
    overflow: hidden;
}
.scan-progress-bar {
    height: 100%;
    width: 0;
    background: #356abc;
    transition: width 0.2s ease-out;
}

/* candidate results */
.scan-results {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin: 0.75rem 0;
}
.scan-result {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: white;
    border: 3px solid transparent;
    border-radius: 8px;
}
.scan-result.best {
    border-color: rgb(255, 229, 10);
}
.scan-result img {
    width: 56px;
    height: 56px;
    object-fit: contain;
    background: #f3f3f3;
    border-radius: 50%;
}
.scan-result-name {
    flex: 1;
    font-size: 19px;
    font-weight: 700;
    text-transform: capitalize;
}
.scan-result-score {
    font-size: 13px;
    font-weight: 400;
    color: #777;
    display: block;
    text-transform: none;
}

/* manual fallback */
.scan-manual {
    border-top: 2px solid #cdcdcd;
    padding-top: 1rem;
    margin-top: 0.5rem;
}
.scan-manual label {
    font-size: 15px;
    color: #444;
}
.scan-manual-row {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}
.scan-manual-row input {
    flex: 1;
    min-width: 0;
    padding: 0.6rem 1rem;
    border: 3px solid #cdcdcd;
    border-radius: 40px;
    font-family: inherit;
    font-size: 16px;
}
.scan-manual-row input:focus {
    outline: none;
    border-color: #356abc;
}

@media (max-width: 640px) {
    /* out of the header's way and within thumb reach */
    .scan-fab {
        top: auto;
        bottom: 16px;
        right: 16px;
        padding: 0.7rem 1.1rem;
        font-size: 16px;
    }
    .scan-fab .bi {
        font-size: 22px;
    }
    .scan-panel .header-bar {
        font-size: 22px;
    }
    .scan-controls .scan-btn {
        flex: 1 1 100%;
        justify-content: center;
    }
}
