/* ===== SurgiMAX POS — Responsive móvil / tablet ===== */

@media (max-width: 767.98px) {
    body.pos-mobile-active {
        padding-bottom: calc(var(--pos-fixed-total-height, 72px) + env(safe-area-inset-bottom, 0px) + 8px);
    }

    .pos-root {
        padding-bottom: calc(var(--pos-fixed-total-height, 72px) + env(safe-area-inset-bottom, 0px) + 4px);
    }

    /* Los productos se quedan en su recuadro. El carrito sigue en la página. */
    .pos-search-results-list {
        max-height: 200px !important;
        overflow-y: auto !important;
        flex: 0 1 auto !important;
        -webkit-overflow-scrolling: touch;
    }

    .pos-cart-list {
        max-height: none !important;
        overflow-y: visible !important;
        flex: 0 0 auto !important;
    }

    .pos-search-block,
    .pos-cart-block {
        height: auto !important;
    }

    .pos-root > .row {
        flex-direction: column;
    }

    .pos-root > .row > .col-12:first-child {
        overflow: visible;
        z-index: 1020;
    }

    .pos-header-row {
        overflow: visible;
    }

    .pos-search-block,
    .pos-cart-block,
    .pos-pay-column,
    .pos-actions-column,
    .pos-functions-block {
        width: 100%;
        max-width: 100%;
        flex: 0 0 100%;
    }

    .pos-actions-column .pos-functions-block {
        position: relative;
        z-index: 3;
        display: block !important;
    }

    body.pos-simple-mode .pos-actions-column {
        display: block !important;
    }

    .pos-pay-column {
        position: relative;
        z-index: 4;
        touch-action: manipulation;
        margin-bottom: 0.5rem;
        padding-bottom: calc(var(--pos-fixed-total-height, 72px) + 0.75rem);
    }

    .pos-pay-column .pos-block.pos-pay-block {
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
    }

    .pos-pay-column .pos-pay-btns {
        padding-bottom: 0;
        overflow: visible;
    }

    .pos-pay-column .pos-cashbox {
        width: 100%;
        margin-bottom: 0;
        padding-bottom: 0.75rem;
        overflow: visible;
    }

    #camposEfectivo {
        min-height: auto !important;
    }

    .pos-pay-actions-row {
        border-top: 1px solid #e5e7eb;
        flex-direction: column;
        gap: 0.65rem !important;
        padding-top: 0.85rem !important;
        margin-top: 0.85rem !important;
        padding-bottom: 0.5rem !important;
        margin-bottom: 0.25rem !important;
    }

    .pos-pay-actions-row #btnCobrar,
    .pos-pay-actions-row #btnPonerEspera {
        width: 100%;
        flex: 1 1 auto !important;
        min-height: 52px;
        font-size: 1rem !important;
    }

    .pos-pay-actions-row #btnPonerEspera {
        margin-bottom: 0;
    }

    .pos-actions-column .d-flex.gap-1 {
        flex-wrap: wrap;
    }

    .pos-actions-column .d-flex.gap-1 .btn {
        flex: 1 1 calc(50% - 0.35rem);
        min-width: calc(50% - 0.35rem);
        font-size: 0.82rem;
        padding-left: 0.35rem;
        padding-right: 0.35rem;
        white-space: normal;
        line-height: 1.15;
    }

    .pos-pay-column .pos-pay-block {
        padding-bottom: 0.75rem;
    }

    .pos-pay-column input,
    .pos-pay-column select,
    .pos-pay-column textarea {
        font-size: 16px;
    }

    .pos-payment-input,
    #abonoInicialCredito,
    #montoAhorrosUsarPos,
    #montoComplementoPos,
    #referenciaPago {
        touch-action: manipulation;
    }

    .pos-header-row {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.65rem;
        padding: 0.65rem !important;
    }

    body.pos-mobile-fixed-total .pos-header-row {
        padding-top: 0.65rem !important;
    }

    body.pos-mobile-fixed-total .pos-header-info-wrap {
        width: 100%;
    }

    /* Cámara, botón y total quedan fijos abajo y se mueven juntos al deslizar. */
    body.pos-mobile-fixed-total .pos-header-total-wrap {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1030;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        flex-direction: column;
        align-items: stretch;
        gap: 0.35rem;
        margin: 0;
        padding: 0.4rem 0.65rem calc(0.45rem + env(safe-area-inset-bottom, 0px));
        background: #fff;
        border-top: 1px solid #e5e7eb;
        box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.12);
    }

    body.pos-mobile-fixed-total #smxCamaraPos:not([hidden]) {
        flex: 0 0 auto;
        width: 100% !important;
        max-width: 100%;
        max-height: 132px;
        order: 0;
    }

    body.pos-mobile-fixed-total .smx-camara-pos-btn {
        width: 100%;
        min-height: 44px;
        order: 1;
    }

    body.pos-mobile-fixed-total .pos-header-total-wrap .pos-total-box {
        position: static;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 0.75rem;
        width: 100%;
        max-width: 100%;
        order: 2;
        margin: 0;
        padding: 0.45rem 0.65rem;
        border-radius: 10px;
        min-width: 0;
        box-sizing: border-box;
    }

    body.pos-mobile-fixed-total .pos-header-total-wrap .pos-total-label {
        margin-bottom: 0;
        font-size: 0.85rem;
        white-space: nowrap;
    }

    body.pos-mobile-fixed-total .pos-header-total-wrap .pos-total-value {
        font-size: clamp(1.35rem, 6.5vw, 1.85rem) !important;
        text-align: right;
        width: auto;
        flex: 1 1 auto;
        min-width: 0;
    }

    .pos-cart-header > .d-flex {
        flex-direction: column;
        align-items: stretch !important;
        gap: 0.5rem;
    }

    .pos-cart-header h5 {
        text-align: center;
        width: 100%;
    }

    #btnAgregarLineaLibre,
    .pos-cart-extra-btn {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        width: 100%;
        min-height: 48px;
        font-size: 0.92rem;
        font-weight: 600;
    }

    body.pos-simple-mode #btnAgregarLineaLibre {
        display: inline-flex !important;
    }

    .pos-header-info-wrap,
    .pos-header-total-wrap {
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }

    .pos-header-total-wrap .pos-total-box {
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    }

    .pos-info-content {
        width: 100%;
        min-width: 0;
    }

    .pos-info-title {
        font-size: 1rem;
        flex-wrap: wrap;
    }

    .pos-info-desc {
        flex-wrap: wrap;
        gap: 0.35rem 0.5rem;
        font-size: 0.72rem;
        line-height: 1.35;
    }

    .cliente-tag {
        flex-direction: column;
        align-items: stretch;
        gap: 0.35rem;
        width: 100%;
        margin-top: 0.5rem;
    }

    .cliente-label {
        font-size: 0.8rem;
    }

    .cliente-nombre-container {
        min-width: 0;
        width: 100%;
        max-width: 100%;
        padding: 0.5rem 0.65rem;
    }

    .cliente-nombre {
        font-size: 0.82rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        flex: 1;
        min-width: 0;
        display: block;
    }

    .pos-total-box {
        align-items: center !important;
        width: 100%;
        max-width: 100%;
        min-width: 0;
        box-sizing: border-box;
        padding: 0.65rem 0.85rem;
    }

    .pos-total-label {
        font-size: 0.75rem;
        margin-bottom: 0.15rem;
    }

    .pos-total-value {
        font-size: clamp(1.45rem, 7vw, 2rem) !important;
        line-height: 1.15;
        letter-spacing: 0;
        word-break: break-word;
        text-align: center;
        width: 100%;
    }

    /* Touch targets mínimo 48px */
    .pos-root .btn,
    .pos-root .search-toggle-btn,
    .pos-root .form-control,
    .pos-root .form-select,
    .pos-root .result-item .btn-add-to-cart,
    .pos-root .cart-item .item-remove,
    .pos-root #btnDoSearch,
    .pos-root #btnClearSearch {
        min-height: 48px;
        min-width: 48px;
    }

    .pos-search-group .form-control {
        font-size: 1rem;
    }

    /* Resultados de búsqueda: ocultar columnas secundarias */
    .result-item.product-item .item-code,
    .result-item.product-item .item-stock {
        display: none !important;
    }

    .result-item.product-item {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .result-item.product-item .item-info {
        flex: 1 1 60%;
        min-width: 0;
    }

    .result-item.product-item .item-details {
        flex: 0 0 auto;
    }

    .result-item.product-item .item-actions {
        flex: 1 1 100%;
    }

    .result-item.product-item .btn-add-to-cart {
        width: 100%;
        font-size: 1rem;
    }

    /* Numpad / cantidades más grandes */
    .cart-item .item-qty,
    .product-quantity-controls .item-qty {
        min-height: 48px !important;
        min-width: 56px !important;
        font-size: 1.2rem !important;
        text-align: center;
    }

    .product-quantity-controls .qty-btn {
        min-height: 48px;
        min-width: 48px;
        font-size: 1.25rem;
    }

    #montoRecibido {
        min-height: 52px !important;
        max-width: 100% !important;
        width: 100% !important;
        font-size: 1.5rem !important;
    }

    #metodoPago,
    #metodoComplementoPos {
        min-height: 48px;
        font-size: 1rem;
    }
}

/* Tablet: 2 columnas donde cabe */
@media (min-width: 768px) and (max-width: 991.98px) {
    .pos-root > .row > .col-lg-6 {
        flex: 0 0 100%;
        max-width: 100%;
    }
}

@media (hover: none) and (pointer: coarse) {
    .pos-root .btn,
    .navbar .nav-link,
    .dropdown-item,
    .btn-login {
        min-height: 44px;
    }

    .navbar .nav-link,
    .dropdown-item {
        display: flex;
        align-items: center;
    }
}

/* Módulos (no la caja): una columna, tablas que se desplazan, campos tocables */
@media (max-width: 767.98px) {
    main.app-content {
        padding: 0.85rem 0.7rem 1.75rem;
        max-width: 100%;
        overflow-x: auto;
    }

    main.app-content > .container,
    main.app-content > .container-fluid {
        padding-left: 0.15rem;
        padding-right: 0.15rem;
        max-width: 100%;
    }

    main.app-content h1,
    main.app-content .h1 {
        font-size: 1.3rem;
        line-height: 1.25;
    }

    main.app-content h2,
    main.app-content .h2 {
        font-size: 1.12rem;
    }

    main.app-content .d-flex.justify-content-between,
    main.app-content .d-flex.justify-content-between.align-items-center {
        flex-wrap: wrap;
        align-items: stretch !important;
        gap: 0.55rem;
    }

    main.app-content .card {
        border-radius: 14px;
        max-width: 100%;
    }

    main.app-content .card-header,
    main.app-content .card-body {
        padding: 0.85rem;
    }

    main.app-content .card {
        max-width: 100%;
    }

    main.app-content .table-responsive {
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    main.app-content .form-control,
    main.app-content .form-select {
        font-size: 16px;
        min-height: 46px;
    }

    main.app-content textarea.form-control {
        min-height: 96px;
    }

    main.app-content .modal-dialog {
        margin: 0.5rem auto;
        max-width: calc(100vw - 1rem);
    }

    main.app-content .btn-group {
        flex-wrap: wrap;
    }
}
