﻿/* ═══════════════════════════════════════════════════════════════════════════
   Card Scanner — web chrome, mirrors the native NativeScannerPage:
   full-screen camera · teal guide · top bar (close / status / torch / flip)
   · Continuous|Single pill · big Start/Stop button · undo toasts · session
   tray sheet · save-destination sheet on exit. Palette from the native page.
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
    --scn-teal: #51d9a8;
    --scn-teal-soft: rgba(39, 224, 165, 0.20);
    --scn-red: #ef4444;
    --scn-ink: #0f0f13;
    --scn-card: #282834;
    --scn-sheet: #1b1c24;
    --scn-text: #eef0f6;
    --scn-muted: #9aa0aa;
    --scn-circle: rgba(0, 0, 0, 0.80);
}

body.scanner-open {
    overflow: hidden;
}

.scn {
    position: fixed;
    inset: 0;
    z-index: 4000;
    background: #000;
    color: var(--scn-text);
    font-family: inherit;
    -webkit-user-select: none;
    user-select: none;
}

/* ── Layer 0: camera ───────────────────────────────────────────────────── */
.scn__stage {
    position: absolute;
    inset: 0;
    overflow: hidden;
    background: #000;
}

    .scn__stage video {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

/* ── Layer 1: guide + hint + guide-size ─────────────────────────────────── */
.scn__center {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    pointer-events: none;
}

.scn__guide {
    width: min(72vw, calc(54vh * 63 / 88), 380px);
    aspect-ratio: 63 / 88;
    border: 2px solid var(--scn-teal);
    border-radius: 16px;
    box-shadow: 0 0 0 200vmax rgba(0, 0, 0, 0.50);
    position: relative;
}

    /* centre line, like the native page's hairline */
    .scn__guide::after {
        content: "";
        position: absolute;
        left: 0;
        right: 0;
        top: 50%;
        height: 1px;
        background: rgba(39, 224, 165, 0.27);
    }

.scn__hint {
    font-size: 11px;
    color: rgba(39, 224, 165, 0.55);
    letter-spacing: 0.02em;
}

.scn__zoom {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 999px;
    background: var(--scn-circle);
    border: 1px solid rgba(39, 224, 165, 0.20);
    color: var(--scn-teal);
}

    .scn__zoom svg {
        width: 14px;
        height: 14px;
    }

    .scn__zoom input[type="range"] {
        width: 130px;
        accent-color: var(--scn-teal);
    }

.scn__zoom-label {
    font-size: 11px;
    font-weight: 800;
    min-width: 32px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* ── Layer 3: top bar ───────────────────────────────────────────────────── */
.scn__top {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px 0;
    padding-top: calc(8px + env(safe-area-inset-top, 0px));
}

.scn__circle {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    border-radius: 22px;
    border: none;
    background: var(--scn-circle);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

    .scn__circle svg {
        width: 20px;
        height: 20px;
    }

    .scn__circle:hover {
        background: rgba(39, 224, 165, 0.25);
    }

    .scn__circle.scn__circle--on {
        background: var(--scn-teal);
        color: var(--scn-ink);
    }

.scn__status {
    flex: 1;
    min-width: 0;
    text-align: center;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.8);
}

.scn__status--success {
    color: var(--scn-teal);
}

.scn__status--warn {
    color: #f5c542;
}

.scn__status--error {
    color: #ff5b6e;
}

/* ── Pills: Continuous|Single (left) · target (right) ──────────────────── */
.scn__pills {
    position: absolute;
    left: 16px;
    right: 16px;
    top: calc(60px + env(safe-area-inset-top, 0px));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    pointer-events: none;
}

.scn__pill {
    pointer-events: auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 14px;
    background: var(--scn-circle);
    border: 1px solid rgba(39, 224, 165, 0.20);
    color: var(--scn-muted);
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    max-width: 60%;
}

    .scn__pill.scn__pill--on {
        color: var(--scn-teal);
    }

    .scn__pill svg {
        width: 14px;
        height: 14px;
        flex: 0 0 auto;
        color: var(--scn-teal);
    }

.scn__pill--target select {
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    border: none;
    color: var(--scn-text);
    font-size: 12px;
    font-weight: 600;
    max-width: 180px;
    text-overflow: ellipsis;
    cursor: pointer;
    padding-right: 4px;
}

    .scn__pill--target select:focus {
        outline: none;
    }

    .scn__pill--target select option,
    .scn__pill--target select optgroup {
        color: var(--scn-text);
        background: var(--scn-sheet);
    }

/* ── Toasts (above the scan button) ─────────────────────────────────────── */
.scn__toasts {
    position: absolute;
    left: 16px;
    right: 16px;
    bottom: calc(132px + env(safe-area-inset-bottom, 0px));
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.scn__toast {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 12px;
    background: var(--scn-card);
    border-left: 3px solid var(--scn-teal);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
    animation: scn-toast-in 0.18s ease-out;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

    .scn__toast svg {
        width: 16px;
        height: 16px;
        color: var(--scn-teal);
        flex: 0 0 auto;
    }

.scn__toast--out {
    opacity: 0;
    transform: translateY(6px);
}

.scn__toast-text {
    flex: 1;
    min-width: 0;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

    .scn__toast-text b {
        color: #fff;
    }

.scn__toast-undo {
    border: none;
    background: transparent;
    color: var(--scn-teal);
    font-weight: 800;
    font-size: 13px;
    cursor: pointer;
    padding: 4px 6px;
}

@keyframes scn-toast-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

/* ── Bottom: tray chip + Start/Stop ─────────────────────────────────────── */
.scn__bottom {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 0 20px;
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(to top, rgba(0, 0, 0, 0.55), transparent);
}

.scn__tray {
    align-self: center;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: var(--scn-circle);
    color: var(--scn-text);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

    .scn__tray svg {
        width: 14px;
        height: 14px;
        transition: transform 0.2s ease;
    }

    .scn__tray.scn__tray--open svg {
        transform: rotate(180deg);
    }

.scn__tray-total {
    color: var(--scn-teal);
    font-weight: 800;
}

.scn__tray-badge {
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: #f5c542;
    color: var(--scn-ink);
    font-size: 11px;
    font-weight: 800;
    line-height: 18px;
    text-align: center;
}

.scn__start {
    height: 56px;
    border: none;
    border-radius: 28px;
    background: var(--scn-teal);
    color: var(--scn-ink);
    font-size: 16px;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(39, 224, 165, 0.30);
    transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

    .scn__start svg {
        width: 18px;
        height: 18px;
    }

    .scn__start:active {
        transform: scale(0.99);
    }

    .scn__start.scn__start--stop {
        background: var(--scn-red);
        color: #fff;
        box-shadow: 0 8px 24px rgba(239, 68, 68, 0.30);
    }

/* ── Sheets: session tray · exit/save ───────────────────────────────────── */
.scn__sheet {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 5;
    background: var(--scn-sheet);
    border-radius: 24px 24px 0 0;
    padding: 10px 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.55);
    display: flex;
    flex-direction: column;
    max-height: 56vh;
    animation: scn-sheet-in 0.2s ease-out;
}

    .scn__sheet[hidden] {
        display: none;
    }

@keyframes scn-sheet-in {
    from {
        transform: translateY(24px);
        opacity: 0;
    }

    to {
        transform: none;
        opacity: 1;
    }
}

.scn__sheet-grip {
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: #5a5d68;
    margin: 0 auto 10px;
}

.scn__sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    font-weight: 700;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.scn__sheet-close {
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--scn-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

    .scn__sheet-close svg {
        width: 16px;
        height: 16px;
    }

.scn__list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-top: 4px;
}

.scn__empty {
    padding: 26px 12px;
    text-align: center;
    color: var(--scn-muted);
    font-size: 13px;
}

.scn__row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 2px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.scn__row-thumb {
    width: 34px;
    height: 48px;
    object-fit: cover;
    border-radius: 4px;
    background: #23242e;
    flex: 0 0 auto;
}

.scn__row-thumb--ph {
    display: inline-block;
}

.scn__row-info {
    flex: 1;
    min-width: 0;
}

.scn__row-name {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.scn__row-meta {
    font-size: 11px;
    color: var(--scn-muted);
    letter-spacing: 0.06em;
}

.scn__row--pending .scn__row-meta {
    color: #f5c542;
}

.scn__row-price {
    font-size: 14px;
    font-weight: 700;
    color: var(--scn-teal);
    white-space: nowrap;
}

.scn__row-qty {
    font-size: 13px;
    color: #b9bccb;
    min-width: 28px;
    text-align: right;
}

.scn__row-undo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--scn-muted);
    cursor: pointer;
}

    .scn__row-undo svg {
        width: 14px;
        height: 14px;
    }

    .scn__row-undo:hover {
        background: rgba(255, 91, 110, 0.16);
        color: #ff5b6e;
    }

/* exit / save sheet */
.scn__exit-text {
    margin: 12px 0 8px;
    color: var(--scn-muted);
    font-size: 13px;
}

.scn__exit-select {
    width: 100%;
    background: #111;
    color: var(--scn-text);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
}

.scn__exit-actions {
    display: flex;
    gap: 10px;
    margin-top: 14px;
}

.scn__btn {
    flex: 1;
    height: 48px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: #111;
    color: var(--scn-text);
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
}

.scn__btn--primary {
    flex: 1.4;
    background: var(--scn-teal);
    color: var(--scn-ink);
    border-color: transparent;
}

.scn__btn--danger {
    background: var(--scn-red);
    color: #fff;
    border-color: transparent;
}

/* ── Launch FAB (Collections & Decks) ───────────────────────────────────── */
.scanner-fab {
    position: fixed;
    right: 18px;
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
    z-index: 850;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 18px;
    border: none;
    border-radius: 999px;
    background: linear-gradient(135deg, #3dd6ff, #27e0a5);
    color: #0f0f13;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    box-shadow: 0 6px 22px rgba(61, 214, 255, 0.35);
    transition: transform 0.15s ease;
}

    .scanner-fab:hover {
        transform: translateY(-2px);
    }

    .scanner-fab svg {
        width: 18px;
        height: 18px;
    }

/* ── Desktop ─────────────────────────────────────────────────────────────── */
@media (min-width: 900px) {
    .scanner-fab {
        bottom: 26px;
    }

    .scn__top {
        padding: 16px 24px 0;
    }

    .scn__pills {
        left: 24px;
        right: 24px;
        top: 72px;
    }

    .scn__bottom {
        align-items: center;
    }

        .scn__bottom .scn__start {
            width: 100%;
            max-width: 520px;
        }

    .scn__toasts {
        left: 50%;
        right: auto;
        width: min(92vw, 520px);
        transform: translateX(-50%);
    }

    .scn__sheet {
        left: 50%;
        right: auto;
        width: min(96vw, 560px);
        transform: translateX(-50%);
        border-radius: 24px 24px 0 0;
    }

    .scn__zoom input[type="range"] {
        width: 180px;
    }
}

@media (max-width: 380px) {
    .scn__zoom input[type="range"] {
        width: 100px;
    }

    .scn__pill--target select {
        max-width: 130px;
    }
}
