/**
 * Systempos - Mobile & Tablet Responsive Optimization
 * Optimizado para Android, iPhone (iOS Safari), iPad, Tablets y pantallas móviles.
 */

:root {
    --touch-target-min: 44px;
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

/* ==========================================================================
   1. MEJORAS DE USABILIDAD TÁCTIL Y VIEWPORT
   ========================================================================== */
html, body {
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
}

body {
    padding-top: var(--safe-area-top);
    padding-bottom: var(--safe-area-bottom);
}

/* Botones e inputs con área táctil cómoda en móviles */
@media (max-width: 991.98px) {
    .btn, 
    .form-control, 
    .form-select, 
    .input-group-text,
    .page-link {
        min-height: var(--touch-target-min);
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 0.95rem;
    }

    .btn-sm, .form-control-sm, .form-select-sm {
        min-height: 38px;
        font-size: 0.875rem;
    }

    .form-check-input {
        width: 1.4em;
        height: 1.4em;
    }

    .dropdown-item {
        padding: 0.75rem 1.25rem;
        font-size: 1rem;
    }
}

/* ==========================================================================
   2. NAVBAR Y HEADER MÓVIL
   ========================================================================== */
.navbar-top {
    position: sticky;
    top: 0;
    z-index: 1030;
    transition: all 0.3s ease;
}

@media (max-width: 767.98px) {
    .navbar-top {
        padding: 0.5rem 0.75rem;
    }

    .navbar-top .btn {
        padding: 0.375rem 0.6rem;
    }

    #sidebarCollapse {
        width: 42px;
        height: 42px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.25rem;
    }

    /* Ocultar textos no esenciales en la barra superior móvil */
    .navbar-top .user-name-text,
    .navbar-top .role-badge-text {
        display: none !important;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.75rem;
        margin-bottom: 1rem;
    }

    .page-header > div:last-child {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .page-header > div:last-child .btn {
        flex: 1 1 auto;
    }
}

/* ==========================================================================
   3. SIDEBAR RESPONSIVE FLUIDO CON TOUCH BACKDROP
   ========================================================================== */
@media (max-width: 991.98px) {
    #sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 280px !important;
        max-width: 85vw;
        z-index: 1050;
        background: #1a1d20;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        display: block !important;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    #sidebar.active {
        transform: translateX(0);
    }

    #content {
        width: 100% !important;
        min-width: 100% !important;
    }

    .sidebar-backdrop {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(2px);
        z-index: 1040;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .sidebar-backdrop.show {
        display: block;
        opacity: 1;
    }

    #sidebar ul li a {
        padding: 14px 20px;
        font-size: 1.05rem;
    }
}

/* ==========================================================================
   4. TABLAS Y DATATABLES RESPONSIVE EN MÓVILES
   ========================================================================== */
.table-responsive {
    -webkit-overflow-scrolling: touch;
    border-radius: 0.5rem;
    margin-bottom: 0.5rem;
}

@media (max-width: 767.98px) {
    /* Ajustes para DataTables en pantallas pequeñas */
    div.dataTables_wrapper div.dataTables_length,
    div.dataTables_wrapper div.dataTables_filter,
    div.dataTables_wrapper div.dataTables_info,
    div.dataTables_wrapper div.dataTables_paginate {
        text-align: center !important;
        display: flex;
        justify-content: center;
        width: 100%;
        margin-bottom: 0.5rem;
    }

    div.dataTables_wrapper div.dataTables_filter input {
        width: 100% !important;
        margin-left: 0 !important;
        margin-top: 0.25rem;
    }

    div.dataTables_wrapper div.dataTables_paginate ul.pagination {
        justify-content: center !important;
        flex-wrap: wrap;
    }

    .table th, .table td {
        padding: 0.6rem 0.5rem;
        font-size: 0.85rem;
    }
}

/* ==========================================================================
   5. CONTENEDORES, TARJETAS Y GRILLAS EN MÓVILES
   ========================================================================== */
@media (max-width: 767.98px) {
    .main-content {
        padding: 12px 10px !important;
    }

    .card {
        border-radius: 0.6rem;
        margin-bottom: 0.75rem;
    }

    .card-body {
        padding: 1rem 0.85rem;
    }

    .card-header {
        padding: 0.75rem 0.85rem;
    }

    /* Grillas apilables fluidas */
    .row.g-3, .row.g-4 {
        --bs-gutter-x: 0.65rem;
        --bs-gutter-y: 0.65rem;
    }

    .hover-card {
        padding: 1rem !important;
    }
}

/* ==========================================================================
   6. OPTIMIZACIÓN ESPECIAL PARA POS EN MÓVILES Y TABLETS
   ========================================================================== */
@media (max-width: 991.98px) {
    #pos-container {
        flex-direction: column !important;
        gap: 1rem !important;
    }

    #pos-venta, #pos-productos {
        width: 100% !important;
        min-width: 100% !important;
        flex: 1 1 100% !important;
    }

    #cart-items {
        max-height: 45vh !important;
    }

    .pos-btn-pagar {
        font-size: 1.15rem !important;
        padding: 0.85rem !important;
    }
}

@media (max-width: 575.98px) {
    .pos-header-info {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.5rem;
    }

    .pos-header-info > div {
        width: 100%;
    }

    #almacen-selector {
        width: 100% !important;
    }

    /* Modal a pantalla completa en móviles */
    .modal-dialog {
        margin: 0.5rem;
    }

    .modal-content {
        border-radius: 0.75rem;
    }
}

/* ==========================================================================
   7. FORMULARIOS FLUIDOS
   ========================================================================== */
@media (max-width: 767.98px) {
    .form-label {
        font-size: 0.9rem;
        margin-bottom: 0.25rem;
    }

    .btn-group {
        display: flex;
        width: 100%;
    }

    .btn-group .btn {
        flex: 1;
    }
}
