/* Pantallas de venta en el iMin M2 Max. El escritorio conserva sus estilos. */
@media (max-width: 767.98px) {
    body.m2max, body.m2max .wrapper, body.m2max .content-page {
        max-width: 100%;
        overflow-x: clip;
    }
    body.m2max .content-page { margin-left: 0 !important; }
    body.m2max:has(.m2max-action-bar) .content-page { padding-bottom: 92px; }
    body.m2max .content-page .container-fluid { padding-inline: 12px; min-width: 0; }
    body.m2max .content-page .row,
    body.m2max .content-page [class*="col-"] { min-width: 0; }
    body.m2max .content-page .card-body { padding: 14px !important; }
    body.m2max .content-page .pos-layout,
    body.m2max .content-page .row-main,
    body.m2max .content-page .card-main { height: auto !important; min-height: 0 !important; }
    body.m2max .content-page .pos-scrollable,
    body.m2max .content-page .table-scrollable { min-height: 0 !important; max-height: none !important; }

    body.m2max input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]),
    body.m2max select, body.m2max textarea,
    body.m2max .select2-selection { font-size: 16px !important; }
    body.m2max .btn, body.m2max button:not(.btn-close),
    body.m2max .nav-link, body.m2max .dropdown-item,
    body.m2max .form-control, body.m2max .form-select,
    body.m2max .select2-selection { min-height: 44px; }
    body.m2max .app-topbar .button-toggle-menu { min-width: 48px; min-height: 48px; }
    body.m2max .btn-close { min-width: 44px; min-height: 44px; background-size: 16px; }
    body.m2max .nav-tabs { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; }
    body.m2max .nav-tabs .nav-link { white-space: nowrap; }
    body.m2max .autocomplete-wrapper { min-width: 0 !important; }

    /* El catálogo se ofrece antes del carrito en los formularios clásicos. */
    body.m2max:has(#offcanvasCatalogo) .col-xl-8.order-xl-1 > .pt-1 {
        display: flex; flex-direction: column;
    }
    body.m2max:has(#offcanvasCatalogo) .col-xl-8.order-xl-1 > .pt-1 > .d-xl-none {
        order: -1;
        margin-top: 8px;
    }
    body.m2max:has(#offcanvasCatalogo) #table-products-selected {
        width: 100% !important; min-width: 0 !important;
    }
    body.m2max:has(.pos-doc-tabs) .pos-layout > .col-xl-5 { order: -1; }
    body.m2max .m2max-catalog-access { padding: 10px 12px 0; }
    body.m2max .offcanvas { width: min(100vw, 420px) !important; }

    body.m2max:has(#btn-save-receipt) .content-page .card-body > .row > :has(#inputBuscarCliente) {
        order: -1;
    }

    /* POS /venta: búsqueda inmediata y cesta en tarjetas. */
    body.m2max:has(#buscador-producto-inline) .vt-row-flex > .vt-col-flex:first-child {
        display: flex; flex-direction: column;
    }
    body.m2max:has(#buscador-producto-inline) .vt-row-flex > .vt-col-flex:first-child > .mb-3.d-flex.flex-column {
        order: -1; min-height: 0 !important;
    }
    body.m2max #buscador-producto-inline { min-width: 0; width: auto !important; flex: 1 1 auto; }
    body.m2max .input-group:has(> #buscador-producto-inline) { flex-wrap: nowrap; }
    body.m2max .vt-cart-scroll {
        flex: none !important; height: auto !important; min-height: 0 !important;
        max-height: none !important; overflow: visible !important;
    }
    body.m2max .vt-col-flex .border.rounded.overflow-hidden.d-flex.flex-column.flex-grow-1 {
        flex: none !important; height: auto !important; overflow: visible !important;
    }
    body.m2max #table-products-selected { display: block; width: 100% !important; min-width: 0 !important; table-layout: auto !important; }
    body.m2max #table-products-selected colgroup,
    body.m2max #table-products-selected thead { display: none !important; }
    body.m2max #table-products-selected tbody { display: block; width: 100%; }
    body.m2max #table-products-selected tbody tr {
        position: relative; display: grid; width: 100%; min-width: 0;
        grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px;
        padding: 12px; margin-bottom: 10px; border: 1px solid #dbe4ed;
        border-radius: 12px; box-shadow: 0 2px 6px rgba(25, 42, 60, .06);
        background: #fff !important;
    }
    body.m2max #table-products-selected tbody td {
        display: block; min-width: 0 !important; width: auto !important;
        padding: 0 !important; border: 0 !important; text-align: left !important;
    }
    body.m2max #table-products-selected tbody td:nth-child(1) { position: absolute; right: 12px; top: 12px; }
    body.m2max #table-products-selected tbody td:nth-child(2) { grid-column: 1 / -1; padding-right: 52px !important; font-weight: 700; }
    body.m2max #table-products-selected tbody td:nth-child(3) { grid-column: 1 / -1; color: #64748b; }
    body.m2max #table-products-selected tbody td:nth-child(4)::before,
    body.m2max #table-products-selected tbody td:nth-child(5)::before,
    body.m2max #table-products-selected tbody td:nth-child(6)::before {
        display: block; margin-bottom: 3px; color: #64748b; font-size: 12px; font-weight: 700;
    }
    body.m2max #table-products-selected tbody td:nth-child(4)::before { content: "Cantidad"; }
    body.m2max #table-products-selected tbody td:nth-child(5)::before { content: "Precio"; }
    body.m2max #table-products-selected tbody td:nth-child(6)::before { content: "Importe"; }
    body.m2max #table-products-selected tbody td:nth-child(6) { grid-column: 1 / -1; text-align: right !important; }
    body.m2max #table-products-selected tbody td:nth-child(6) label { font-size: 17px !important; }
    body.m2max #table-products-selected .btn-remove-item { width: 44px !important; height: 44px !important; }
    body.m2max .m2max-qty { display: flex; align-items: center; gap: 4px; }
    body.m2max .m2max-qty .input-cant { flex: 1; min-width: 42px; text-align: center; }
    body.m2max .m2max-qty button { flex: 0 0 44px; width: 44px; padding: 0; font-size: 22px; }

    /* Listados, incluidos DataTables: cada fila conserva sus acciones. */
    body.m2max .m2max-list-table,
    body.m2max .m2max-list-table tbody { display: block !important; width: 100% !important; min-width: 0 !important; }
    body.m2max .m2max-list-table thead,
    body.m2max .m2max-list-table colgroup { display: none !important; }
    body.m2max .m2max-list-table tbody tr {
        display: block !important; width: 100%; min-width: 0;
        margin: 0 0 10px; padding: 10px 12px;
        border: 1px solid #dbe4ed; border-radius: 12px; background: #fff;
        box-shadow: 0 2px 6px rgba(25, 42, 60, .05);
    }
    body.m2max .m2max-list-table tbody td {
        display: flex !important; align-items: center; justify-content: space-between;
        flex-wrap: wrap; gap: 4px 12px; min-width: 0 !important; width: 100% !important;
        padding: 7px 0 !important; border: 0 !important; border-bottom: 1px solid #edf1f5 !important;
        white-space: normal !important; text-align: right !important; overflow-wrap: anywhere;
    }
    body.m2max .m2max-list-table tbody td:last-child { border-bottom: 0 !important; }
    body.m2max .m2max-list-table tbody td::before {
        content: attr(data-m2max-label); color: #64748b; font-weight: 700; font-size: 12px;
        text-align: left;
    }
    body.m2max .m2max-list-table tbody td[data-m2max-label=""]::before { display: none; }
    body.m2max .m2max-list-table tbody td .btn { margin: 2px; }
    body.m2max .m2max-list-table tbody td[colspan] { display: block !important; text-align: center !important; }
    body.m2max .table-responsive:has(> .m2max-list-table) { overflow-x: clip !important; }
    body.m2max .dataTables_wrapper, body.m2max .dt-layout-row { max-width: 100%; min-width: 0; }

    /* Guía clásica: las columnas 8/4 ocupan el ancho disponible. */
    body.m2max:has(#GE) .content-page .container-fluid > .row > .col-8,
    body.m2max:has(#GE) .content-page .container-fluid > .row > .col-4 {
        flex: 0 0 100%; max-width: 100%;
    }
    body.m2max:has(#GE) .nav-tabs > .flex-grow-1 { flex: 0 0 100%; }
    body.m2max:has(#GE) #display-serie-numero {
        text-align: left !important; white-space: nowrap; font-size: 16px !important;
    }
    body.m2max .timeline-content { min-width: 0; flex: 1; }
    body.m2max .timeline-content > .d-flex.justify-content-between { flex-wrap: wrap; gap: 4px; }

    /* La acción principal siempre queda al alcance del pulgar. */
    body.m2max .m2max-action-bar {
        position: fixed; inset: auto 0 0; z-index: 1030;
        display: flex; align-items: center; justify-content: space-between; gap: 12px;
        min-height: 72px; padding: 10px max(12px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
        background: #fff; border-top: 1px solid #dbe4ed; box-shadow: 0 -4px 16px rgba(25, 42, 60, .12);
    }
    body.m2max .m2max-action-bar .m2max-total { min-width: 0; color: #0c7667; font-size: 19px; font-weight: 800; white-space: nowrap; }
    body.m2max .m2max-action-bar .m2max-total small { display: block; color: #64748b; font-size: 11px; }
    body.m2max .m2max-action-bar button { flex: 1; max-width: 260px; min-height: 50px; font-size: 16px; font-weight: 700; }
    body.m2max .m2max-original-save { display: none !important; }
    body.m2max .m2max-original-actions > :not(.m2max-original-save) { flex: 1; }
    body.m2max .m2max-action-bar.is-hidden,
    body.m2max.modal-open .m2max-action-bar { display: none; }

    body.m2max .modal-dialog,
    body.m2max .modal-dialog.modal-dialog-scrollable {
        width: 100vw !important; max-width: 100vw !important;
        height: 100dvh !important; min-height: 100dvh !important;
        margin: 0 !important;
    }
    body.m2max .modal-content { min-height: 100dvh; max-height: 100dvh; border-radius: 0 !important; }
    body.m2max .modal-body { overflow-y: auto; }
    /* El perfil contiene pocos datos: tarjeta centrada en lugar de un modal de alto completo. */
    body.m2max #modalPerfil .modal-dialog {
        width: min(460px, calc(100vw - 24px)) !important;
        max-width: min(460px, calc(100vw - 24px)) !important;
        height: calc(100dvh - 24px) !important;
        min-height: calc(100dvh - 24px) !important;
        margin: 12px auto !important;
    }
    body.m2max #modalPerfil .modal-content {
        min-height: 0;
        max-height: calc(100dvh - 24px);
        border-radius: 16px !important;
        overflow-y: auto !important;
    }
    body.m2max #modalPerfil .modal-body { overflow-y: visible; }
    body.m2max .swal2-container { padding: 0 !important; }
    body.m2max .swal2-popup { width: 100vw !important; max-width: 100vw !important; min-height: 100dvh; border-radius: 0 !important; }
    body.m2max .swal2-actions { gap: 8px; }
    body.m2max .swal2-actions button { min-height: 48px; }

    /* Botón ✕ "Limpiar cliente" dentro del campo Cliente: área táctil de 44 px. */
    body.m2max .btn-limpiar-cliente { width: 44px !important; height: 44px !important; right: 0 !important; font-size: 18px; }
    body.m2max #inputNombres { padding-right: 46px !important; }

    /* Emitidos: el buscador (oculto con d-none d-md-block) se muestra arriba a todo el ancho,
       y cada fila pasa a una tarjeta compacta de dos columnas para ver más ventas por pantalla. */
    body.m2max .card-header-main .d-flex:has(> .app-search > [data-table-search]) { flex: 1 1 100%; flex-wrap: wrap; }
    body.m2max .card-header-main .app-search:has(> [data-table-search]) {
        display: block !important; flex: 1 1 100%; margin-left: 0 !important; position: relative;
    }
    body.m2max .card-header-main .app-search > [data-table-search] { width: 100%; min-height: 44px; }
    body.m2max .m2max-list-table tbody tr {
        display: grid !important; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        grid-auto-flow: row dense; gap: 0 12px; padding: 8px 10px; margin-bottom: 8px;
    }
    body.m2max .m2max-list-table tbody td {
        display: block !important; padding: 3px 0 !important; border-bottom: 0 !important; text-align: left !important;
    }
    body.m2max .m2max-list-table tbody td::before {
        display: block; font-size: 10px; line-height: 1.2; text-transform: uppercase; letter-spacing: .02em;
    }
    body.m2max .m2max-list-table tbody td[data-m2max-vacia] { display: none !important; }
    body.m2max .m2max-list-table tbody td:last-child::before { display: none; }
    body.m2max .m2max-list-table tbody td:first-child { font-weight: 700; }
    body.m2max .m2max-list-table tbody td:last-child,
    body.m2max .m2max-list-table tbody td[data-m2max-label="Cliente"],
    body.m2max .m2max-list-table tbody td[colspan] { grid-column: 1 / -1; }
    body.m2max .m2max-list-table tbody td:last-child:not(:first-child) {
        margin-top: 4px; padding-top: 6px !important; border-top: 1px solid #edf1f5 !important;
    }
}
