/* ============================================================================
   ESCANER MOBILE v1 - TANDA 89.2 PRO PARTE B
   ============================================================================
   Modal full-screen con vista cámara + marco animado + feedback colorido
   ============================================================================ */

.mb-esc-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: #000;
    display: flex;
    flex-direction: column;
    color: #fff;
    overflow: hidden;
    animation: mbEscIn 0.2s ease-out;
}

@keyframes mbEscIn {
    from { opacity: 0; transform: scale(1.05); }
    to   { opacity: 1; transform: scale(1); }
}

/* === TOP BAR === */
.mb-esc-topbar {
    flex-shrink: 0;
    height: calc(56px + env(safe-area-inset-top));
    padding-top: env(safe-area-inset-top);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-left: 8px;
    padding-right: 8px;
    background: linear-gradient(180deg, rgba(0,0,0,.85), rgba(0,0,0,.4));
    position: relative;
    z-index: 10;
}

.mb-esc-title {
    font-size: 14px;
    font-weight: 800;
    letter-spacing: 4px;
    color: #fff;
}

.mb-esc-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255,255,255,.1);
    border: 1px solid rgba(255,255,255,.2);
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: transform .12s ease, background .2s ease;
}

.mb-esc-btn:active {
    transform: scale(0.92);
    background: rgba(255,255,255,.2);
}

.mb-esc-btn.mb-esc-flash-on {
    background: rgba(200,16,46,.85);
    border-color: rgba(200,16,46,1);
}

/* === STAGE (cámara + frame) === */
.mb-esc-stage {
    flex: 1;
    position: relative;
    background: #000;
    overflow: hidden;
}

.mb-esc-video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #000;
}

/* === FRAME ESCANEO === */
.mb-esc-frame {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(80vw, 320px);
    height: min(40vw, 180px);
    pointer-events: none;
    border-radius: 18px;
    overflow: hidden;
}

/* Esquinas tipo escáner profesional */
.mb-esc-corner {
    position: absolute;
    width: 32px;
    height: 32px;
    border-color: #c8102e;
    border-style: solid;
    border-width: 0;
    transition: border-color 0.2s ease;
}

.mb-esc-corner.tl { top: 0; left: 0; border-top-width: 4px; border-left-width: 4px; border-radius: 18px 0 0 0; }
.mb-esc-corner.tr { top: 0; right: 0; border-top-width: 4px; border-right-width: 4px; border-radius: 0 18px 0 0; }
.mb-esc-corner.bl { bottom: 0; left: 0; border-bottom-width: 4px; border-left-width: 4px; border-radius: 0 0 0 18px; }
.mb-esc-corner.br { bottom: 0; right: 0; border-bottom-width: 4px; border-right-width: 4px; border-radius: 0 0 18px 0; }

/* Línea láser que se mueve verticalmente */
.mb-esc-laser {
    position: absolute;
    left: 8%;
    right: 8%;
    height: 2px;
    background: linear-gradient(90deg, transparent, #c8102e, transparent);
    box-shadow: 0 0 12px #c8102e, 0 0 4px #c8102e;
    animation: mbEscLaser 2.2s ease-in-out infinite;
    top: 0;
}

@keyframes mbEscLaser {
    0%, 100% { top: 10%; opacity: 0; }
    20%      { opacity: 1; }
    80%      { opacity: 1; }
    50%      { top: 88%; }
}

/* Status flotante */
.mb-esc-status {
    position: absolute;
    top: calc(50% + min(20vw, 100px));
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: #fff;
    padding: 10px 20px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.5px;
    white-space: nowrap;
    border: 1px solid rgba(255,255,255,.1);
}

.mb-esc-status-err {
    background: rgba(239,91,91,.85);
    border-color: rgba(239,91,91,1);
}

.mb-esc-status-wait {
    background: rgba(200,16,46,.85);
    color: #1a1305;
    border-color: rgba(200,16,46,1);
}

/* === FEEDBACK FLOTANTE (al leer un código) === */
.mb-esc-feedback {
    position: absolute;
    bottom: 30%;
    left: 50%;
    transform: translateX(-50%) translateY(40px);
    background: rgba(46,204,113,.95);
    color: #003520;
    padding: 14px 28px;
    border-radius: 14px;
    font-size: 18px;
    font-weight: 800;
    box-shadow: 0 10px 30px rgba(0,0,0,.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease, transform .25s ease;
    max-width: 80vw;
    text-align: center;
    z-index: 5;
    letter-spacing: 0.5px;
}

.mb-esc-feedback.mb-esc-fb-ok,
.mb-esc-feedback.mb-esc-fb-rep,
.mb-esc-feedback.mb-esc-fb-err {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.mb-esc-feedback.mb-esc-fb-rep {
    background: rgba(200,16,46,.95);
    color: #1a1305;
}

.mb-esc-feedback.mb-esc-fb-err {
    background: rgba(239,91,91,.95);
    color: #fff;
}

/* === FLASH DE FRAME (verde/rojo/naranja según resultado) === */
.mb-esc-flash-ok .mb-esc-corner   { border-color: #2ecc71 !important; }
.mb-esc-flash-rep .mb-esc-corner  { border-color: #c8102e !important; }
.mb-esc-flash-err .mb-esc-corner  { border-color: #ef5b5b !important; }

.mb-esc-flash-ok .mb-esc-frame::after,
.mb-esc-flash-rep .mb-esc-frame::after,
.mb-esc-flash-err .mb-esc-frame::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 18px;
    pointer-events: none;
    animation: mbEscPulse 0.35s ease-out;
}

.mb-esc-flash-ok .mb-esc-frame::after  { box-shadow: inset 0 0 0 4px #2ecc71, 0 0 30px rgba(46,204,113,.6); }
.mb-esc-flash-rep .mb-esc-frame::after { box-shadow: inset 0 0 0 4px #c8102e, 0 0 30px rgba(200,16,46,.6); }
.mb-esc-flash-err .mb-esc-frame::after { box-shadow: inset 0 0 0 4px #ef5b5b, 0 0 30px rgba(239,91,91,.6); }

@keyframes mbEscPulse {
    from { opacity: 1; transform: scale(1.05); }
    to   { opacity: 0; transform: scale(1); }
}

/* === BOTTOM BAR === */
.mb-esc-bottombar {
    flex-shrink: 0;
    height: calc(80px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: linear-gradient(0deg, rgba(0,0,0,.85), rgba(0,0,0,.4));
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding-left: 16px;
    padding-right: 16px;
    z-index: 10;
}

.mb-esc-btn-mode {
    background: rgba(255,255,255,.06);
    border: 1px solid rgba(255,255,255,.15);
    border-radius: 14px;
    color: #fff;
    padding: 10px 16px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 76px;
    transition: transform .12s ease, background .2s ease;
}

.mb-esc-btn-mode:active {
    transform: scale(0.95);
    background: rgba(255,255,255,.15);
}

.mb-esc-modo-ico {
    font-size: 22px;
    line-height: 1;
}

.mb-esc-modo-txt {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.mb-esc-btn-modo.mb-esc-modo-on {
    background: rgba(200,16,46,.25);
    border-color: rgba(200,16,46,.7);
    color: #c8102e;
}

.mb-esc-btn-modo.mb-esc-modo-on .mb-esc-modo-ico {
    animation: mbEscRot 1.6s linear infinite;
}

@keyframes mbEscRot {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

.mb-esc-contador {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    color: rgba(255,255,255,.85);
}

.mb-esc-contador-num {
    font-size: 24px;
    font-weight: 800;
    color: #c8102e;
    line-height: 1;
}

.mb-esc-contador-lbl {
    font-size: 10px;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: rgba(255,255,255,.55);
}

/* === FAB del POS para abrir el escáner === */
.mb-esc-fab {
    position: fixed;
    bottom: calc(80px + env(safe-area-inset-bottom));
    right: 18px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2ecc71, #4ade80);
    color: #fff;
    border: none;
    font-size: 28px;
    box-shadow: 0 8px 24px rgba(46,204,113,.5), 0 2px 8px rgba(0,0,0,.3);
    cursor: pointer;
    z-index: 920;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: transform .15s var(--mb-ease-bnc, cubic-bezier(0.34, 1.56, 0.64, 1)), box-shadow .2s ease;
}

.mb-esc-fab:active {
    transform: scale(0.92);
    box-shadow: 0 4px 12px rgba(46,204,113,.5), 0 1px 3px rgba(0,0,0,.3);
}

/* Solo se ve en mobile y EN CUALQUIER tab del POS (v13.4) */
@media (min-width: 901px) {
    .mb-esc-fab { display: none !important; }
}

@media (max-width: 900px) {
    /* TANDA 89.2 v13.4: el FAB se muestra en CUALQUIER tab del POS, no solo BUSCAR.
       El cajero puede querer escanear desde CARRITO o COBRAR para agregar items.
       Antes: body:not(.mb-pos-tab-buscar) .mb-esc-fab { display: none } */
    body:not(.mb-pos-tab-buscar):not(.mb-pos-tab-carrito):not(.mb-pos-tab-cobrar) .mb-esc-fab {
        display: none !important;
    }
    body.mb-side-open .mb-esc-fab,
    body.mb-sheet-open .mb-esc-fab { opacity: 0; pointer-events: none; }
    body.mb-esc-open .mb-esc-fab { display: none !important; }
}

/* === MODAL CRÉAR PRODUCTO (cuando código no existe) === */
.mb-esc-create-modal {
    position: fixed;
    inset: 0;
    z-index: 2100;
    background: rgba(0,0,0,.7);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    animation: mbEscCreateBd 0.2s ease-out;
}

@keyframes mbEscCreateBd {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.mb-esc-create-card {
    background: #14171f;
    border-top-left-radius: 24px;
    border-top-right-radius: 24px;
    border-top: 1px solid #252934;
    padding: 28px 22px calc(22px + env(safe-area-inset-bottom));
    width: 100%;
    max-width: 480px;
    box-shadow: 0 -8px 40px rgba(0,0,0,.5);
    animation: mbEscCreateUp 0.32s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes mbEscCreateUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}

.mb-esc-create-card::before {
    content: "";
    display: block;
    width: 36px;
    height: 4px;
    background: #353b48;
    border-radius: 999px;
    margin: -14px auto 18px;
}

.mb-esc-create-ico {
    font-size: 56px;
    text-align: center;
    margin-bottom: 8px;
}

.mb-esc-create-title {
    font-size: 20px;
    font-weight: 800;
    color: #c8102e;
    text-align: center;
    margin: 0 0 6px;
}

.mb-esc-create-subtitle {
    font-size: 14px;
    color: #9aa5b4;
    text-align: center;
    margin: 0 0 6px;
    line-height: 1.5;
}

.mb-esc-create-codigo {
    background: #1a1e28;
    border: 1px solid #353b48;
    border-radius: 10px;
    padding: 10px 14px;
    font-family: 'Courier New', monospace;
    font-size: 16px;
    font-weight: 700;
    color: #c8102e;
    text-align: center;
    margin: 14px auto;
    max-width: 280px;
    letter-spacing: 1.5px;
}

.mb-esc-create-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 22px;
}

.mb-esc-create-btn {
    min-height: 52px;
    padding: 14px 20px;
    border-radius: 14px;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.5px;
    border: none;
    cursor: pointer;
    transition: transform .12s ease, background .2s ease;
}

.mb-esc-create-btn-yes {
    background: linear-gradient(135deg, #2ecc71, #4ade80);
    color: #003520;
    box-shadow: 0 4px 14px rgba(46,204,113,.4);
}

.mb-esc-create-btn-yes:active {
    transform: scale(0.97);
}

.mb-esc-create-btn-no {
    background: #1a1e28;
    color: #9aa5b4;
    border: 1px solid #353b48;
}

.mb-esc-create-btn-no:active {
    background: #232834;
    transform: scale(0.97);
}

/* ================================================================
   TANDA D - Error overlay del escáner (cuando no abre la cámara)
   ================================================================ */
.mb-esc-error-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    text-align: center;
}

.mb-esc-error-icon {
    font-size: 64px;
    margin-bottom: 14px;
    color: #c8102e;
}

.mb-esc-error-msg {
    color: #fff;
    font-size: 20px;
    font-weight: 900;
    margin-bottom: 8px;
}

.mb-esc-error-detail {
    color: #aaa;
    font-size: 13px;
    margin-bottom: 24px;
    max-width: 320px;
    line-height: 1.5;
}

.mb-esc-btn-retry {
    background: linear-gradient(135deg, #3ecf8e, #2eb277);
    color: #fff;
    border: none;
    padding: 14px 32px;
    border-radius: 28px;
    font-size: 15px;
    font-weight: 900;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(62, 207, 142, 0.3);
    transition: 0.15s;
}

.mb-esc-btn-retry:hover { transform: translateY(-1px); }
.mb-esc-btn-retry:active { transform: scale(0.97); }

/* ================================================================
   TANDA D - FAB del escáner (botón flotante en POS/Inventario/Recepción)
   ================================================================ */
.mb-fab-scan {
    position: fixed;
    right: 18px;
    bottom: 86px;     /* arriba del bottom-nav móvil */
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: #fff;
    border: 3px solid #fff;
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.4);
    font-size: 26px;
    cursor: pointer;
    z-index: 950;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.15s;
}

.mb-fab-scan:hover { transform: scale(1.05); }
.mb-fab-scan:active { transform: scale(0.95); }

/* En desktop ocultar el FAB - los usuarios usan lectores físicos */
@media (min-width: 901px) {
    .mb-fab-scan { display: none !important; }
}

/* En login no mostrarlo */
body:has(.login-shell) .mb-fab-scan { display: none !important; }

/* === Input manual del escaner (PC sin webcam o codigos no leibles) === */
.mb-esc-manual-bar {
    flex-shrink: 0;
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    background: rgba(0,0,0,0.5);
    border-top: 1px solid rgba(255,255,255,0.08);
}
.mb-esc-manual-input {
    flex: 1;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.15);
    color: #fff;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 14px;
    outline: none;
    min-width: 0;
}
.mb-esc-manual-input:focus {
    border-color: #c8102e;
    background: rgba(255,255,255,0.12);
}
.mb-esc-manual-input::placeholder { color: rgba(255,255,255,0.45); }
.mb-esc-manual-btn {
    background: linear-gradient(135deg, #c8102e, #e84050);
    color: #1a1305;
    border: none;
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.12s;
}
.mb-esc-manual-btn:hover { transform: translateY(-1px); }
.mb-esc-manual-btn:active { transform: translateY(0); }

/* === En PC: modal centrado (no fullscreen) para que se vea menos invasivo === */
@media (min-width: 901px) {
    .mb-esc-modal {
        background: rgba(0,0,0,0.85);
        backdrop-filter: blur(8px);
        align-items: center;
        justify-content: center;
        padding: 24px;
    }
    .mb-esc-modal::before {
        content: "";
        position: fixed;
        inset: 0;
        z-index: -1;
    }
    /* Container interno: centrado, max ancho razonable */
    .mb-esc-topbar {
        max-width: 640px;
        width: 100%;
        height: 56px;
        padding-top: 0;
        margin: 0 auto;
        background: linear-gradient(180deg, rgba(20,23,31,0.95), rgba(20,23,31,0.7));
        border-radius: 14px 14px 0 0;
    }
    .mb-esc-stage {
        max-width: 640px;
        width: 100%;
        max-height: 480px;
        margin: 0 auto;
        border-left: 1px solid rgba(255,255,255,0.05);
        border-right: 1px solid rgba(255,255,255,0.05);
    }
    .mb-esc-manual-bar {
        max-width: 640px;
        width: 100%;
        margin: 0 auto;
        border-radius: 0;
    }
    .mb-esc-bottombar {
        max-width: 640px;
        width: 100%;
        margin: 0 auto;
        border-radius: 0 0 14px 14px;
        background: linear-gradient(180deg, rgba(20,23,31,0.7), rgba(20,23,31,0.95));
    }
}
