/* ================================================
   BARCODE SCANNER - ESTILOS PARA MODAL DE CÁMARA
   ================================================ */

/* Modal Principal */
.barcode-scanner-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease-out;
}

/* Overlay oscuro */
.scanner-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
}

/* Contenedor del escáner */
.scanner-container {
    position: relative;
    background: #1a1a1a;
    border-radius: 16px;
    max-width: 800px;
    width: 95%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.3s ease-out;
}

/* Header del escáner */
.scanner-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1.5rem;
    border-radius: 16px 16px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.scanner-header h4 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    display: flex;
    align-items: center;
}

.btn-close-scanner {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.btn-close-scanner:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.btn-close-scanner:active {
    transform: scale(0.95);
}

/* Cuerpo del escáner */
.scanner-body {
    flex: 1;
    padding: 1.5rem;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    min-height: 400px;
}

/* Contenedor de video */
.video-container {
    position: relative;
    width: 100%;
    max-width: 600px;
    aspect-ratio: 4/3;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 0 30px rgba(102, 126, 234, 0.3);
}

#scannerVideo {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Marco de escaneo */
.scanner-frame {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80%;
    height: 60%;
    pointer-events: none;
}

/* Esquinas del marco */
.scanner-frame .corner {
    position: absolute;
    width: 40px;
    height: 40px;
    border: 3px solid #667eea;
}

.corner.top-left {
    top: 0;
    left: 0;
    border-right: none;
    border-bottom: none;
    border-radius: 8px 0 0 0;
}

.corner.top-right {
    top: 0;
    right: 0;
    border-left: none;
    border-bottom: none;
    border-radius: 0 8px 0 0;
}

.corner.bottom-left {
    bottom: 0;
    left: 0;
    border-right: none;
    border-top: none;
    border-radius: 0 0 0 8px;
}

.corner.bottom-right {
    bottom: 0;
    right: 0;
    border-left: none;
    border-top: none;
    border-radius: 0 0 8px 0;
}

/* Línea de escaneo animada */
.scan-line {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, #667eea, transparent);
    box-shadow: 0 0 10px #667eea;
    animation: scan 2s ease-in-out infinite;
}

@keyframes scan {
    0%, 100% {
        top: 0;
        opacity: 0;
    }
    50% {
        opacity: 1;
    }
    100% {
        top: 100%;
        opacity: 0;
    }
}

/* Instrucciones */
.scanner-instructions {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    color: white;
    background: rgba(0, 0, 0, 0.7);
    padding: 1rem 1.5rem;
    border-radius: 30px;
    backdrop-filter: blur(10px);
    white-space: nowrap;
    max-width: 90%;
}

.scanner-instructions p {
    margin: 0 0 0.5rem 0;
    font-size: 0.95rem;
    font-weight: 500;
}

.scanner-status {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    color: #667eea;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* Footer del escáner */
.scanner-footer {
    background: #1a1a1a;
    padding: 1.5rem;
    border-radius: 0 0 16px 16px;
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.btn-switch-camera,
.btn-manual-entry,
.btn-cancel-scan {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    font-size: 1rem;
    flex: 1;
    min-width: 140px;
    min-height: 44px;
}

.btn-switch-camera {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-switch-camera:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-switch-camera:active {
    transform: translateY(0);
}

.btn-manual-entry {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
}

.btn-manual-entry:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(40, 167, 69, 0.4);
}

.btn-manual-entry:active {
    transform: translateY(0);
}

.btn-cancel-scan {
    background: #6c757d;
    color: white;
}

.btn-cancel-scan:hover {
    background: #5a6268;
    transform: translateY(-2px);
}

.btn-cancel-scan:active {
    transform: translateY(0);
}

/* Debug info */
#debugInfo {
    font-family: 'Courier New', monospace;
    background: rgba(0, 0, 0, 0.7);
    padding: 0.5rem;
    border-radius: 4px;
    margin-top: 1rem;
    font-size: 0.75rem;
}

/* Animaciones */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Botón de escaneo en las tarjetas */
.btn-scan-barcode {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    width: 100%;
    min-height: 44px;
}

.btn-scan-barcode:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-scan-barcode:active {
    transform: translateY(0);
}

.btn-scan-barcode:disabled {
    background: linear-gradient(135deg, #e0e0e0 0%, #bdbdbd 100%);
    cursor: not-allowed;
    opacity: 0.6;
}

.btn-scan-barcode i {
    font-size: 1.1rem;
}

/* Indicador de cámara activa */
.camera-active-indicator {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #dc3545;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    z-index: 10001;
    animation: pulse 1.5s ease-in-out infinite;
    box-shadow: 0 2px 10px rgba(220, 53, 69, 0.3);
}

.camera-active-indicator i {
    animation: blink 1s ease-in-out infinite;
}

@keyframes blink {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.3;
    }
}

/* ================================================
   RESPONSIVE - TABLETS (768px - 1024px)
   ================================================ */

@media (max-width: 1024px) and (min-width: 769px) {
    .scanner-container {
        max-width: 700px;
        width: 90%;
    }

    .scanner-header {
        padding: 1.25rem;
    }

    .scanner-header h4 {
        font-size: 1.15rem;
    }

    .scanner-body {
        padding: 1.25rem;
        min-height: 380px;
    }

    .video-container {
        max-width: 550px;
    }

    .scanner-footer {
        padding: 1.25rem;
        gap: 0.875rem;
    }

    .btn-switch-camera,
    .btn-manual-entry,
    .btn-cancel-scan {
        font-size: 0.95rem;
        padding: 0.7rem 1.25rem;
    }
}

/* ================================================
   RESPONSIVE - TABLETS Y MÓVILES (577px - 768px)
   ================================================ */

@media (max-width: 768px) and (min-width: 577px) {
    .scanner-container {
        max-width: 100%;
        width: 95%;
        max-height: 95vh;
        border-radius: 12px;
    }

    .scanner-header {
        border-radius: 12px 12px 0 0;
        padding: 1rem;
    }

    .scanner-header h4 {
        font-size: 1.1rem;
    }

    .btn-close-scanner {
        width: 38px;
        height: 38px;
        font-size: 1.15rem;
    }

    .scanner-body {
        padding: 1rem;
        min-height: 350px;
    }

    .video-container {
        max-width: 100%;
        border-radius: 10px;
    }

    .scanner-frame .corner {
        width: 35px;
        height: 35px;
        border-width: 2.5px;
    }

    .scanner-instructions {
        bottom: 15px;
        padding: 0.75rem 1rem;
        max-width: 85%;
    }

    .scanner-instructions p {
        font-size: 0.9rem;
    }

    .scanner-status {
        font-size: 0.8rem;
    }

    .scanner-footer {
        padding: 1rem;
        gap: 0.75rem;
    }

    .btn-switch-camera,
    .btn-manual-entry,
    .btn-cancel-scan {
        padding: 0.7rem 1rem;
        font-size: 0.9rem;
        min-width: 120px;
    }

    .camera-active-indicator {
        top: 15px;
        right: 15px;
        font-size: 0.8rem;
        padding: 0.4rem 0.8rem;
    }
}

/* ================================================
   RESPONSIVE - MÓVILES (hasta 576px)
   ================================================ */

@media (max-width: 576px) {
    .scanner-container {
        max-width: 100%;
        width: 100%;
        max-height: 100vh;
        border-radius: 0;
    }

    .scanner-header {
        border-radius: 0;
        padding: 0.875rem;
    }

    .scanner-header h4 {
        font-size: 1rem;
        flex: 1;
    }

    .btn-close-scanner {
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
        min-width: 40px;
        flex-shrink: 0;
    }

    .scanner-body {
        padding: 0.75rem;
        min-height: 300px;
    }

    .video-container {
        max-width: 100%;
        border-radius: 8px;
        aspect-ratio: 3/4;
    }

    .scanner-frame {
        width: 85%;
        height: 65%;
    }

    .scanner-frame .corner {
        width: 30px;
        height: 30px;
        border-width: 2px;
    }

    .scanner-instructions {
        bottom: 10px;
        padding: 0.625rem 0.875rem;
        border-radius: 20px;
        white-space: normal;
        max-width: 90%;
    }

    .scanner-instructions p {
        font-size: 0.85rem;
        margin-bottom: 0.375rem;
    }

    .scanner-status {
        font-size: 0.75rem;
    }

    .scanner-footer {
        flex-direction: column;
        padding: 0.875rem;
        gap: 0.625rem;
    }

    .btn-switch-camera,
    .btn-manual-entry,
    .btn-cancel-scan {
        width: 100%;
        padding: 0.875rem 1rem;
        font-size: 0.95rem;
        min-width: unset;
        min-height: 48px;
    }

    .btn-scan-barcode {
        font-size: 0.9rem;
        padding: 0.875rem 1rem;
        min-height: 48px;
    }

    .camera-active-indicator {
        top: 10px;
        right: 10px;
        font-size: 0.75rem;
        padding: 0.375rem 0.75rem;
    }

    #debugInfo {
        font-size: 0.7rem;
        padding: 0.375rem;
        margin-top: 0.5rem;
    }
}

/* ================================================
   LANDSCAPE MODE - Optimización horizontal
   ================================================ */

@media (max-height: 600px) and (orientation: landscape) {
    .scanner-container {
        max-height: 98vh;
    }

    .scanner-header {
        padding: 0.625rem 0.875rem;
    }

    .scanner-header h4 {
        font-size: 0.95rem;
    }

    .btn-close-scanner {
        width: 32px;
        height: 32px;
        font-size: 1rem;
    }

    .scanner-body {
        padding: 0.75rem;
        min-height: unset;
    }

    .video-container {
        max-height: 50vh;
        aspect-ratio: 16/9;
    }

    .scanner-frame .corner {
        width: 25px;
        height: 25px;
    }

    .scanner-instructions {
        bottom: 8px;
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
    }

    .scanner-instructions p {
        font-size: 0.75rem;
        margin-bottom: 0.25rem;
    }

    .scanner-status {
        font-size: 0.7rem;
    }

    .scanner-footer {
        padding: 0.625rem 0.875rem;
        flex-direction: row;
        gap: 0.5rem;
    }

    .btn-switch-camera,
    .btn-manual-entry,
    .btn-cancel-scan {
        padding: 0.5rem 0.875rem;
        font-size: 0.85rem;
        min-height: 40px;
    }

    .camera-active-indicator {
        top: 8px;
        right: 8px;
        font-size: 0.7rem;
        padding: 0.3rem 0.6rem;
    }
}

/* ================================================
   ANDROID ESPECÍFICO - Optimizaciones
   ================================================ */

@media screen and (max-width: 768px) {
    /* Mejorar rendimiento en Android */
    .scanner-container {
        will-change: transform;
        transform: translateZ(0);
    }

    .video-container {
        will-change: transform;
        transform: translateZ(0);
    }

    /* Optimizar touch en Android */
    .btn-switch-camera,
    .btn-manual-entry,
    .btn-cancel-scan,
    .btn-close-scanner,
    .btn-scan-barcode {
        -webkit-tap-highlight-color: rgba(255, 255, 255, 0.1);
        touch-action: manipulation;
    }

    /* Prevenir zoom al tocar botones */
    button {
        touch-action: manipulation;
    }

    /* Mejora de contraste para Android */
    .scanner-instructions {
        text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    }
}

/* ================================================
   ACCESIBILIDAD
   ================================================ */

@media (prefers-reduced-motion: reduce) {
    .scan-line,
    .scanner-status,
    .camera-active-indicator i {
        animation: none !important;
    }

    .scanner-container {
        animation: none !important;
    }

    .barcode-scanner-modal {
        animation: none !important;
    }
}
