/* Barcode Scanner — ESYON Barcode Scanner Module */

#scanner-overlay {
    position: fixed;
    inset: 0;
    z-index: 300;
    background: #000;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;

    &[hidden] { display: none; }

    & #scanner-video {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    & .scanner-ui {
        position: relative;
        z-index: 10;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 1.25rem;
    }

    & .scanner-frame {
        position: relative;
        width: 260px;
        height: 160px;
        border: 2px solid rgba(255, 255, 255, 0.3);
        border-radius: 0.5rem;
    }

    & .scanner-corner {
        position: absolute;
        width: 20px;
        height: 20px;
        border-color: #fff;
        border-style: solid;
        border-width: 0;

        &.tl { top: -2px;    left: -2px;   border-top-width: 3px; border-left-width: 3px;  border-top-left-radius: 4px; }
        &.tr { top: -2px;    right: -2px;  border-top-width: 3px; border-right-width: 3px; border-top-right-radius: 4px; }
        &.bl { bottom: -2px; left: -2px;   border-bottom-width: 3px; border-left-width: 3px;  border-bottom-left-radius: 4px; }
        &.br { bottom: -2px; right: -2px;  border-bottom-width: 3px; border-right-width: 3px; border-bottom-right-radius: 4px; }
    }

    & .scanner-line {
        position: absolute;
        left: 8px;
        right: 8px;
        height: 2px;
        background: var(--color-primary);
        animation: scanner-sweep 2s ease-in-out infinite;
    }

    & .scanner-hint {
        color: rgba(255, 255, 255, 0.85);
        font-size: 0.875rem;
        font-weight: 500;
        text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    }

    & #scanner-close-btn {
        position: absolute;
        top: 1rem;
        right: 1rem;
        z-index: 20;
        width: 44px;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 9999px;
        background: rgba(255, 255, 255, 0.2);
        color: #fff;
        border: none;
        cursor: pointer;
        backdrop-filter: blur(4px);
        transition: background 0.15s ease;

        &:hover { background: rgba(255, 255, 255, 0.35); }
        &:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
    }
}

@keyframes scanner-sweep {
    0%, 100% { top: 10%; }
    50%       { top: 80%; }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

#scanner-modal {
    &[hidden] { display: none; }

    & #scanner-modal-backdrop {
        position: fixed;
        inset: 0;
        z-index: 210;
        background: rgba(0, 0, 0, 0.5);
    }

    & #scanner-modal-sheet {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 220;
        background: #fff;
        border-radius: 1.5rem 1.5rem 0 0;
        box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.15);
        max-height: 90dvh;
        overflow-y: auto;

        @media (min-width: 480px) {
            position: fixed;
            inset: 0;
            margin: auto;
            bottom: auto;
            border-radius: 1rem;
            width: min(420px, calc(100% - 2rem));
            max-height: 85dvh;
        }
    }

    & #scanner-modal-body {
        padding: 1.25rem;
    }
}

.scanner-modal-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 1.5rem 0;
    text-align: center;
}

.scanner-spinner {
    width: 2rem;
    height: 2rem;
    border: 2px solid var(--color-primary);
    border-top-color: transparent;
    border-radius: 9999px;
    animation: spin 0.7s linear infinite;
}

.scanner-icon-error {
    width: 3rem;
    height: 3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 9999px;
    background: #fee2e2;
    color: #ef4444;
    font-size: 1.25rem;
    font-weight: 700;
}

.scanner-modal-title {
    font-weight: 600;
    color: #111827;
}

.scanner-modal-hint {
    font-size: 0.875rem;
    color: #6b7280;
}

.scanner-product-header {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1rem;
}

.scanner-product-img {
    width: 4rem;
    height: 4rem;
    border-radius: 0.5rem;
    object-fit: contain;
    background: #f9fafb;
    flex-shrink: 0;
}

.scanner-product-meta {
    min-width: 0;
}

.scanner-product-title {
    font-weight: 600;
    color: #111827;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.scanner-product-artnum {
    font-size: 0.75rem;
    color: #9ca3af;
    margin-top: 0.125rem;
}

.scanner-product-price {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-primary);
    margin-top: 0.25rem;
}

.scanner-form {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.scanner-btn-full {
    width: 100%;
}

.scanner-btn-secondary {
    height: 3rem;
    padding-inline: 1rem;
    border-radius: 9999px;
    border: 1px solid #d1d5db;
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
    background: #fff;
    cursor: pointer;
    transition: background 0.15s ease;
    white-space: nowrap;

    &:hover { background: #f9fafb; }
    &:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
}

.scanner-fallback {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 0.5rem 0;
}

.scanner-manual-row {
    display: flex;
    gap: 0.5rem;

    & input {
        flex: 1;
        height: 2.75rem;
        padding-inline: 1rem;
        border: 1px solid #d1d5db;
        border-radius: 9999px;
        font-size: 0.875rem;

        &:focus {
            outline: none;
            border-color: var(--color-primary);
            box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-primary) 20%, transparent);
        }
    }

    & button {
        height: 2.75rem;
        padding-inline: 1.25rem;
        border-radius: 9999px;
        font-size: 0.875rem;
        font-weight: 600;
        white-space: nowrap;
    }
}

.scanner-manual-error {
    font-size: 0.8125rem;
    color: #ef4444;
    margin-top: -0.25rem;

    &[hidden] { display: none; }
}

#scanner-toast {
    position: fixed;
    top: 1.25rem;
    left: 1rem;
    right: 1rem;
    z-index: 410;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    background: #fff;
    border-left: 4px solid var(--color-success, #198754);
    border-radius: 0.5rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12), 0 1px 4px rgba(0, 0, 0, 0.08);
    font-size: 0.875rem;
    font-weight: 400;
    color: #111827;
    pointer-events: none;
    opacity: 0;
    transform: translateY(-0.75rem);
    transition: opacity 0.22s ease, transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);

    &.scanner-toast-in {
        opacity: 1;
        transform: translateY(0);
    }

    &.scanner-toast-out {
        opacity: 0;
        transform: translateY(-0.75rem);
    }

    & .scanner-toast-icon {
        flex-shrink: 0;
        width: 1.25rem;
        height: 1.25rem;
        color: var(--color-success, #198754);
    }

    & strong {
        font-weight: 600;
    }
}
