/* =============================================================
   POS MOBILE - Optimización para dispositivos móviles y tablets
   Archivo único para mejorar la experiencia POS en PWA móvil
   ============================================================= */

/* ---- Optimizaciones de rendimiento ---- */
.pos-contenedoor * {
  -webkit-tap-highlight-color: transparent;
}
.pos-contenedoor {
  -webkit-overflow-scrolling: touch;
  touch-action: manipulation;
}

/* ---- TABLET: ≤ 992px ---- */
@media (max-width: 992px) {

  /* Header compacto */
  .pos-header-actions {
    padding: 2px 8px;
    min-height: 44px;
  }

  /* Tabs más visibles con badge de cantidad */
  .pos-tab-nav {
    background: linear-gradient(180deg, #1a1a2e, #16213e);
  }

  .pos-tab-nav label {
    padding: 14px 8px;
    font-size: 0.9em;
    transition: all 0.15s;
    position: relative;
  }

  .pos-tab-nav label.pos-tab-active {
    background: #0f3460;
    border-bottom: 3px solid #e94560;
    color: #fff;
  }

  /* Buscador de productos más accesible */
  .contenedor-productos-ventas input[type="text"],
  .contenedor-productos-ventas select,
  .contenedor-productos-ventas .select2-container .select2-selection {
    height: 44px !important;
    font-size: 16px !important; /* Evita zoom en iOS */
    border-radius: 8px !important;
  }

  /* Tarjetas de producto: sombra y efecto touch */
  .productos-pos .productos-pos-venta {
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    transition: transform 0.1s;
  }

  .productos-pos .productos-pos-venta:active {
    transform: scale(0.97);
  }

  /* Formulario carrito */
  #formVentaPos .form-control {
    height: 44px !important;
    font-size: 16px !important;
    border-radius: 8px !important;
  }

  #formVentaPos select.form-control {
    font-size: 16px !important;
  }

  #formVentaPos textarea.form-control {
    height: auto !important;
    min-height: 60px;
  }

  /* Tabla de items del carrito */
  .items-c {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -4px;
  }

  #formVentaPos .cantidaditempos {
    width: 70px;
    height: 36px !important;
    font-size: 16px !important;
  }

  #formVentaPos .preciounitariopos {
    width: 90px;
    height: 36px !important;
    font-size: 16px !important;
  }

  .tabla-items .btnEliminarItemCarroPos {
    min-width: 40px;
    min-height: 40px;
    font-size: 1.1em;
  }

  /* Totales más legibles */
  .super-contenedor-formulario-pos .tabla-totales tbody tr td:nth-child(2) {
    font-size: 1.3em !important;
    font-weight: 700;
  }

  /* Sección monto recibido/vuelto destacada */
  #formVentaPos #montoRecibido,
  #formVentaPos #vuelto {
    font-size: 1.4em !important;
    font-weight: 700;
    height: 50px !important;
    text-align: center;
  }

  /* Botones principales grandes y prominentes */
  .pos-contenedoor .contenedor-btns-carrito {
    gap: 8px;
    padding: 8px 12px;
    background: linear-gradient(180deg, #fff, #f8f8f8);
    border-top: 2px solid #e0e0e0;
  }

  .pos-contenedoor .contenedor-btns-carrito button {
    border-radius: 12px;
    font-weight: 700;
    letter-spacing: 0.5px;
    box-shadow: 0 3px 6px rgba(0,0,0,0.15);
  }

  .btnGuardarVentaPos {
    background: linear-gradient(135deg, #28a745, #218838) !important;
    border: none !important;
  }

  .btnEliminarCarro {
    background: linear-gradient(135deg, #dc3545, #c82333) !important;
    border: none !important;
  }

  /* Tipo comprobante más grande y táctil */
  .container-comprobants-pos {
    height: 42px;
    border-radius: 0 0 12px 12px;
  }

  .container-comprobants-pos label {
    height: 42px;
    font-size: 0.85em;
    letter-spacing: 1.5px;
  }

  /* Select2 mejorado */
  .select2-container--default .select2-selection--single {
    height: 44px !important;
    display: flex !important;
    align-items: center !important;
  }

  .select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 44px !important;
  }

  .select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 44px !important;
  }

  /* Menu herramientas más ancho en tablet */
  .contenedor-herramientas-pos {
    width: 280px;
  }

  .contenedor-herramientas-pos label {
    padding: 16px 20px;
    font-size: 0.95em;
  }
}

/* ---- MÓVIL: ≤ 767px ---- */
@media (max-width: 767px) {

  /* Ocultar menú de fotos en móvil */
  .contenedor-menu-pos .foto-pos {
    display: none;
  }

  /* Tabs compactos */
  .pos-tab-nav label {
    padding: 12px 4px;
    font-size: 0.8em;
  }

  .pos-tab-nav label i {
    display: block;
    font-size: 1.3em;
    margin-bottom: 2px;
  }

  /* =========================================
     CARRITO / COBRO - Vista móvil optimizada
     ========================================= */

  /* Contenedor general sin padding excesivo */
  .super-contenedor-formulario-pos {
    padding: 4px !important;
  }

  .super-contenedor-formulario-pos .box {
    margin-bottom: 0;
    border: none;
    box-shadow: none;
  }

  .super-contenedor-formulario-pos .box-body {
    padding: 6px !important;
  }

  .super-contenedor-formulario-pos .box-header {
    padding: 6px 8px !important;
  }

  /* Cliente: campos compactos */
  .pos-seccion-carrito .col-md-6,
  .pos-seccion-carrito .col-md-4 {
    padding: 2px 4px !important;
  }

  .pos-seccion-carrito label {
    font-size: 0.8em;
    margin-bottom: 2px;
  }

  /* Escáner input prominente */
  #searchpcPos {
    font-size: 18px !important;
    height: 46px !important;
    border: 2px solid #5741d3 !important;
    border-radius: 10px !important;
    text-align: center;
  }

  /* ---- TABLA DE ITEMS: formato cards en móvil ---- */
  .items-c {
    overflow-x: hidden !important;
  }

  .tabla-items {
    font-size: 0.85em !important;
    min-width: 0 !important;
    width: 100% !important;
  }

  /* Ocultar columna Código en móvil */
  .tabla-items thead th:first-child,
  .tabla-items tbody td:first-child {
    display: none;
  }

  .tabla-items thead {
    font-size: 0.78em;
  }

  .tabla-items thead th {
    padding: 4px 2px !important;
    white-space: nowrap;
    text-align: center;
  }

  .tabla-items tbody td {
    padding: 4px 2px !important;
    vertical-align: middle;
    text-align: center;
  }

  /* Descripción del producto en tabla: truncar */
  .tabla-items tbody td:nth-child(3) {
    text-align: left;
    font-size: 0.85em;
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Inputs cantidad y precio compactos */
  #formVentaPos .cantidaditempos {
    width: 50px !important;
    height: 32px !important;
    font-size: 14px !important;
    padding: 0 2px !important;
  }

  #formVentaPos .preciounitariopos {
    width: 70px !important;
    height: 32px !important;
    font-size: 14px !important;
    padding: 0 2px !important;
  }

  /* Botón eliminar item compacto */
  .tabla-items .btnEliminarItemCarroPos {
    min-width: 30px;
    min-height: 30px;
    padding: 4px 6px !important;
  }

  /* ---- DESCUENTO Y MÉTODO PAGO ---- */
  .nuevoProducto .col-md-5,
  .nuevoProducto .col-md-7 {
    width: 100% !important;
    float: none !important;
    padding: 0 4px !important;
  }

  .tabla-descuentos {
    margin-bottom: 0 !important;
  }

  .tabla-descuentos legend {
    font-size: 1em !important;
    margin: 4px 0 !important;
  }

  #formVentaPos #metodopago {
    height: 42px !important;
    font-size: 15px !important;
  }

  /* ---- RESUMEN / TOTALES ---- */
  .tabla-totales {
    font-size: 0.9em;
    margin-bottom: 4px !important;
  }

  .tabla-totales thead th {
    padding: 4px !important;
    font-size: 0.85em;
  }

  .tabla-totales tbody td {
    padding: 3px 6px !important;
  }

  /* Ocultar filas de totales vacíos para ganar espacio */
  .tabla-totales .op-exoneradas,
  .tabla-totales .op-inafectas,
  .tabla-totales .op-gratuitas,
  .tabla-totales .icbper {
    display: none;
  }

  /* Total final resaltado */
  .tabla-totales .op-total td {
    font-size: 1.4em !important;
    font-weight: 800 !important;
    color: #1a1a2e;
    border-top: 2px solid #333;
    padding-top: 8px !important;
  }

  /* ---- MONTO RECIBIDO / VUELTO ---- */
  .nuevoProducto > .col-lg-12 {
    padding: 0 !important;
  }

  .nuevoProducto > .col-lg-12 > .col-md-6 {
    width: 50% !important;
    float: left !important;
    padding: 2px 4px !important;
  }

  #formVentaPos #monto_pagado,
  #formVentaPos #total_vuelto {
    font-size: 1.2em !important;
    font-weight: 700;
    height: 46px !important;
    text-align: center;
    border-radius: 8px !important;
  }

  #formVentaPos #monto_pagado {
    border: 2px solid #28a745 !important;
  }

  #formVentaPos #total_vuelto {
    border: 2px solid #007bff !important;
    background: #f0f7ff;
  }

  /* ---- BOTONES GUARDAR / ELIMINAR ---- */
  .btnGuardarVentaPos,
  .btnEliminarCarro {
    font-size: 1.3em !important;
    padding: 12px !important;
    min-height: 52px;
    border-radius: 12px !important;
  }

  /* ---- MODAL EDITAR ITEM ---- */
  #modalEditarItemsPos .modal-dialog {
    margin: 0;
    width: 100%;
    max-width: 100%;
  }

  #modalEditarItemsPos .modal-content {
    border-radius: 0;
    overflow-y: auto;
  }

  #modalEditarItemsPos .form-control {
    height: 46px !important;
    font-size: 16px !important;
    text-align: center;
  }

  .descripcion-de-items {
    font-size: 1.2em;
    padding: 6px;
  }

  #btnPrecioNormal,
  #btnPrecioporMayor {
    min-height: 46px;
    font-size: 0.95em !important;
    margin: 3px 0;
    border-radius: 8px !important;
  }
}

/* ---- MÓVIL PEQUEÑO: ≤ 400px ---- */
@media (max-width: 400px) {
  .productos-pos .productos-pos-venta img {
    max-width: 70px;
    max-height: 70px;
  }

  .container-comprobants-pos label {
    font-size: 0.7em;
    letter-spacing: 0.5px;
  }
}

/* ---- PWA STANDALONE (cuando se ejecuta como app instalada) ---- */
@media (display-mode: standalone) {
  .pos-contenedoor {
    /* Respetar safe areas en notch phones */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .pos-header-actions {
    padding-top: env(safe-area-inset-top);
  }

  .pos-contenedoor .contenedor-btns-carrito {
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }
}

/* ---- Modo landscape en móvil ---- */
@media (max-width: 992px) and (orientation: landscape) {
  .productos-pos .productos-pos-venta img {
    width: 50px;
    height: 45px;
  }

  .pos-tab-nav label {
    padding: 8px 4px;
  }

  .pos-header-actions {
    padding: 2px 8px;
    min-height: 36px;
  }

  .pos-contenedoor .contenedor-btns-carrito button {
    min-height: 44px;
    font-size: 1.2em !important;
  }
}

/* ---- Animación de transición entre tabs ---- */
@media (max-width: 992px) {
  .pos-seccion-productos,
  .pos-seccion-carrito {
    animation: posFadeIn 0.2s ease-out;
  }

  @keyframes posFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
  }

  /* Badge contador de items en tab carrito */
  .pos-tab-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 10px;
    background: #e94560;
    color: #fff;
    font-size: 0.7em;
    font-weight: 800;
    margin-left: 4px;
    vertical-align: middle;
  }

  .pos-tab-badge:empty {
    display: none;
  }
}
