/* 
  ==============================================================
  CITYCELL GSM - BLOQUE 1 DE ESTABILIZACIÓN ESTRUCTURAL MULTI-ENTORNO
  ==============================================================
  Protecciones forenses de maquetación y corrección de bugs de renderizado (WebKit/Blink/Gecko)
*/

/* 1. IMPULSAR INERCIA TÁCTIL (Aceleración GPU) */
.modal-body,
.citycell-modal-body,
.qs-payments-scroll,
.rc-parts-list,
.table-wrap,
div[style*="overflow-y: auto"] {
    -webkit-overflow-scrolling: touch !important;
    scroll-behavior: smooth !important;
    will-change: scroll-position !important;
}

/* 2. LEVANTAR EL MURO ANTI FLEX-SHRINK */
.modal-header,
.modal-footer,
.citycell-modal-header,
.citycell-modal-footer,
.drawer-header,
.drawer-footer-actions,
.swal2-header,
.swal2-actions {
    flex-shrink: 0 !important;
}

/* 3. SANEAR LOS DRAWER OVERLAYS (Cero Clics Fantasma) */
.drawer-overlay,
#purchase-drawer-overlay,
#warranty-drawer-overlay {
    position: fixed !important;
    inset: 0 !important;
    z-index: 15000 !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    backdrop-filter: blur(4px) !important;
    -webkit-backdrop-filter: blur(4px) !important;
    background-color: rgba(15, 23, 42, 0.5) !important;
    transition: opacity 0.3s ease, visibility 0.3s ease !important;
}

/* Estados de activación elástica */
.drawer-overlay.active,
.drawer-overlay.show,
.drawer-overlay:not(.hidden),
#purchase-drawer-overlay.active,
#purchase-drawer-overlay.show,
#purchase-drawer-overlay:not(.hidden),
#warranty-drawer-overlay.active,
#warranty-drawer-overlay.show,
#warranty-drawer-overlay:not(.hidden) {
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
}

/* 4. BLINDAR ZONA SEGURA (iOS Safe Area) */
.modal-footer-sticky,
.citycell-modal-footer,
.drawer-footer-actions {
    padding-bottom: calc(15px + env(safe-area-inset-bottom)) !important;
}

@media screen and (max-width: 991.98px) {
    .modal-footer-sticky,
    .citycell-modal-footer {
        margin-bottom: 65px !important;
    }
}

/* 
  ==============================================================
  CITYCELL GSM - MÓDULO 2: CAJA REGISTRADORA LÍQUIDA
  ==============================================================
*/

/* 1. BREAKPOINT INTERMEDIO DE MOSTRADOR (.modal-adaptive-body) */
@media (max-width: 1200px) and (min-width: 901px) {
    .modal-adaptive-body {
        grid-template-columns: 320px 1fr !important;
        gap: 12px !important;
    }
}

/* 2. APILAMIENTO VERTICAL DE FILA DE PAGOS (.qs-payment-row / .qs-inputs-row-adaptive) */
@media (max-width: 576px) {
    /* Intercepta la fila de inputs combinados del renderizador de checkout */
    .qs-payment-row div[style*="display: flex"],
    div:has(> .qs-amount-input) {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
        width: 100% !important;
    }
    
    .qs-payment-row div[style*="display: flex"] > div,
    div:has(> .qs-amount-input) > div {
        width: 100% !important;
        max-width: 100% !important;
        flex: none !important;
        height: 44px !important; /* Altura ergonómica táctil */
    }
}

/* 3. SANEAMIENTO DE CONTENEDORES DE CONTROLES DEL POS */
@media (max-width: 991px) {
    .qs-cart-container,
    #qs-footer-container > div {
        padding: 12px !important;
    }
}

/* 
  ==============================================================
  CITYCELL GSM - MÓDULO 3: RECEPCIÓN DE ÓRDENES E HISTORIALES
  ==============================================================
*/

/* 1. CLASES ESPEJO PARA SUSTITUIR GRILLAS INLINE DE FORMULARIOS */
.rc-grid-form-two-cols {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 20px !important;
}
.rc-grid-form-three-cols {
    display: grid !important;
    grid-template-columns: 1fr 1fr 1fr !important;
    gap: 15px !important;
}

@media (max-width: 768px) {
    .rc-grid-form-two-cols,
    .rc-grid-form-three-cols,
    .citycell-form-section[style*="display: grid"],
    div[style*="display: grid; grid-template-columns: 1.5fr 1fr;"],
    div[style*="display: grid; grid-template-columns: 1.5fr 1fr"] {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }
}

/* 2. DESACOPLE DEL PATRÓN DE SEGURIDAD (Muro contra el Conflicto 'Fat-Finger') */
@media (max-width: 768px) {
    .rc-col-pattern {
        width: 100% !important;
        border-left: none !important;
        padding-left: 0 !important;
        margin-top: 25px !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
    }
    .pattern-lock-container {
        transform: scale(1.1) !important; /* Incrementa la superficie de interacción táctil */
        margin: 10px auto !important;
    }
}

/* 3. DESBORDE CINÉTICO EN PESTAÑAS RMA (.rma-tabs-container) */
.rma-tabs-container, 
div:has(> #subtab-rma-client) {
    display: flex !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    gap: 8px !important;
    padding-bottom: 5px !important;
}
.rma-tabs-container::-webkit-scrollbar {
    display: none !important; /* Oculta barra para look de app nativa */
}

/* 4. COLAPSO DE TABLAS DE HISTORIALES A TARJETAS FEED */
@media screen and (max-width: 768px) {
    #repairs-premium-table,
    .table-wrap table {
        display: block !important;
        width: 100% !important;
    }
    #repairs-premium-table thead,
    .table-wrap table thead {
        display: none !important; /* Esconde cabeceras rígidas */
    }
    #repairs-premium-table tbody tr,
    .table-wrap table tbody tr {
        display: block !important;
        margin-bottom: 15px !important;
        border: 1px solid #e2e8f0 !important;
        border-radius: 12px !important;
        padding: 10px !important;
        background: #fff !important;
    }
    #repairs-premium-table td,
    .table-wrap table td {
        display: flex !important;
        justify-content: space-between !important;
        padding: 6px 8px !important;
        border: none !important;
        font-size: 0.85rem !important;
    }
    
    /* Inject label text inside cards using standard data attributes if exists */
    #repairs-premium-table td[data-label]::before,
    .table-wrap table td[data-label]::before {
        content: attr(data-label) !important;
        font-weight: 700 !important;
        color: #94a3b8 !important;
        font-size: 0.8rem !important;
        text-transform: uppercase !important;
    }
}

/* 
  ==============================================================
  CITYCELL GSM - BLOQUE 4: COMPACTACIÓN DE CAJA REGISTRADORA Y TABLA EXTERIOR
  ==============================================================
*/

@media (max-width: 768px) {
    /* Reducir el inflado de los contenedores de grupo y columnas del modal checkout */
    .modal-adaptive-body,
    .citycell-modal-body,
    .modal-column-sticky {
        padding: 10px 15px !important;
        gap: 8px !important;
    }
    
    /* Compactar los títulos de sección internos como DATOS DEL CLIENTE, BUSCAR PRODUCTOS */
    .modal-adaptive-body h5,
    .modal-adaptive-body h6,
    .modal-adaptive-body div[style*="font-weight: bold"],
    .modal-adaptive-body .chk-label,
    div[class*="title"] {
        margin-top: 6px !important;
        margin-bottom: 4px !important;
        font-size: 0.8rem !important;
    }
    
    /* Ajustar el tamaño y márgenes de las filas de inputs */
    .modal-adaptive-body .form-group,
    .modal-adaptive-body div[style*="display: flex"] {
        margin-bottom: 6px !important;
    }
    
    /* Minimizar el tamaño del contenedor del carrito vacío (Resumen) */
    .qs-cart-container,
    div:has(> .ph-shopping-cart) {
        padding: 8px !important;
        min-height: auto !important;
    }

    /* Reducir el footer y botones de acción */
    .citycell-modal-footer,
    .swal2-actions,
    .modal-footer-sticky {
        padding: 8px 15px !important;
        margin-top: 10px !important;
        display: flex !important;
        justify-content: center !important;
        gap: 10px !important;
    }
    
    .citycell-modal-footer button,
    .swal2-actions button,
    #qs-finalize-btn {
        height: 40px !important;
        font-size: 0.9rem !important;
        padding: 0 15px !important;
    }

    /* Colapso responsivo de la tabla exterior de pedidos pendientes (Caja y Pedidos) */
    #admin-tab-caja table,
    .table-wrap-elite table {
        display: block !important;
        width: 100% !important;
    }
    
    #admin-tab-caja thead,
    .table-wrap-elite thead {
        display: none !important;
    }
    
    #admin-tab-caja tbody tr,
    .table-wrap-elite tbody tr {
        display: block !important;
        margin-bottom: 12px !important;
        border: 1px solid #e2e8f0 !important;
        border-radius: 10px !important;
        padding: 10px !important;
        background: #fff !important;
    }
    
    #admin-tab-caja td,
    .table-wrap-elite td {
        display: flex !important;
        justify-content: space-between !important;
        padding: 5px 8px !important;
        border: none !important;
        font-size: 0.85rem !important;
    }

    #admin-tab-caja td[data-label]::before,
    .table-wrap-elite td[data-label]::before {
        content: attr(data-label) !important;
        font-weight: 700 !important;
        color: #94a3b8 !important;
        font-size: 0.8rem !important;
        text-transform: uppercase !important;
    }
}

/* 
  ==============================================================
  CITYCELL GSM - MÓDULO 5: REPARACIONES Y RECEPCIÓN SIMÉTRICA
  ==============================================================
*/

@media (max-width: 768px) {
    /* 1. REORGANIZACIÓN E ELIMINACIÓN DE OVERFLOW EN LA CABECERA DE REPARACIONES */
    #admin-tab-repairs > div:first-child,
    .dashboard-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 12px !important;
        width: 100% !important;
    }
    
    #admin-tab-repairs > div:first-child h2,
    .dashboard-header h2, 
    .view-title {
        font-size: 1.5rem !important;
        line-height: 1.2 !important;
        width: 100% !important;
    }

    #admin-tab-repairs > div:first-child > div {
        width: 100% !important;
        display: flex !important;
        justify-content: flex-start !important;
        gap: 10px !important;
    }

    /* 2. FLEX-WRAP OBLIGATORIO EN BUSCADOR Y FILTROS */
    #admin-tab-repairs .sales-controls-row,
    .dashboard-controls,
    .control-presets,
    .filters-group-elite,
    div:has(> .preset-btn) {
        flex-wrap: wrap !important;
        width: 100% !important;
        max-width: 100% !important;
        gap: 8px !important;
    }
    
    /* Forzar que el input de búsqueda tome el 100% si se apila */
    #admin-tab-repairs .search-box-elite,
    .dashboard-controls input[type="text"],
    .dashboard-controls .search-bar-wrapper {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 100% !important;
    }

    .filters-group-elite {
        display: flex !important;
        flex-wrap: wrap !important;
        justify-content: flex-start !important;
        align-items: center !important;
    }
}

/* Custom Premium Select Styling for the Reception Modal Dropdown */
select#rc-order-type {
    width: auto;
    height: 42px !important;
    font-family: 'Outfit', 'Inter', sans-serif !important;
    font-size: 0.85rem !important;
    font-weight: 700 !important;
    color: #0f172a !important;
    border-radius: 12px !important;
    border: 1px solid #cbd5e1 !important;
    background: #f8fafc url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") no-repeat right 12px center !important;
    background-size: 16px !important;
    padding: 0 35px 0 15px !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    appearance: none !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02) !important;
}

select#rc-order-type:hover {
    border-color: #94a3b8 !important;
    background-color: #f1f5f9 !important;
}

select#rc-order-type:focus {
    border-color: #2563eb !important;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1) !important;
    background-color: #ffffff !important;
    outline: none !important;
}

@media (max-width: 768px) {
    /* 3. CORRECCIÓN DE CHOQUE EN EL MODAL (Recepción de Equipo) */
    #repair-checkin-modal-overlay .citycell-modal-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 12px !important;
        position: relative !important;
    }
    
    /* El div contenedor de select + botón de cerrar para que ocupe todo el ancho */
    #repair-checkin-modal-overlay .citycell-modal-header > div:last-child {
        width: 100% !important;
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
        margin-top: 10px !important;
        gap: 10px !important;
    }

    #repair-checkin-modal-overlay .citycell-modal-header select,
    #rc-order-type {
        flex: 1 !important;
        width: 100% !important;
        max-width: calc(100% - 50px) !important;
    }

    #repair-checkin-modal-overlay .citycell-close-btn {
        flex-shrink: 0 !important;
        width: 38px !important;
        height: 38px !important;
        border-radius: 8px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
}

/* 
  ==============================================================
  CITYCELL GSM - MÓDULO 6: CONTROL DE INVENTARIO Y CORRECCIÓN DE SCROLL
  ==============================================================
*/

/* Limitación elástica de altura y control de flex para citycell modals */
.citycell-modal-content {
    display: flex !important;
    flex-direction: column !important;
    max-height: 85vh !important;
    position: relative !important;
    overflow: hidden !important;
}

/* Permitir que los formularios intermedios propaguen el flujo flex hacia el modal-body */
.citycell-modal-content > form {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 !important;
    min-height: 0 !important;
    overflow: hidden !important;
}

/* Forzar scroll táctil suave e inercias de scroll en el cuerpo del modal */
.citycell-modal-body {
    flex: 1 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    padding-bottom: 25px !important;
}

.sales-client-cell-wrap {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    gap: 4px;
    width: 100%;
}

@media (max-width: 768px) {
    .citycell-modal-content {
        max-height: 90vh !important;
    }

    /* Forzar alineación derecha y pila vertical en tarjetas de historial de ventas en móviles */
    .sales-client-cell-wrap {
        align-items: flex-end !important;
        text-align: right !important;
    }
    
    .sales-client-cell-wrap .client-name-elite,
    .sales-client-cell-wrap div {
        text-align: right !important;
    }
}

/* 
  ==============================================================
  CITYCELL GSM - MÓDULO 9: DETALLE DE ORDEN RESPONSIVO
  ==============================================================
*/

@media (max-width: 768px) {
    /* Reducir el padding en la cabecera y el cuerpo del modal de detalle de orden */
    #sale-details-modal .modal-paper-card > div:first-child {
        padding: 20px 20px 10px 20px !important;
    }
    
    #sale-details-modal .modal-paper-card > div[style*="overflow-y:auto"] {
        padding: 15px 15px 25px 15px !important;
    }

    /* Evitar el solapamiento forzando flex vertical en la cabecera del modal */
    #sale-details-modal .modal-paper-card > div:first-child > table,
    #sale-details-modal .modal-paper-card > div:first-child > table tr,
    #sale-details-modal .modal-paper-card > div:first-child > table td {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        text-align: center !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    #sale-details-modal .modal-paper-card > div:first-child > table td {
        padding: 5px 0 !important;
    }

    #sale-details-modal .modal-paper-card > div:first-child > table td .invoice-brand {
        height: auto !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        margin-bottom: 15px !important;
        overflow: visible !important;
    }

    #sale-details-modal .modal-paper-card > div:first-child > table td .invoice-brand img {
        height: 50px !important;
        width: auto !important;
        object-position: center !important;
        margin: 0 auto !important;
    }

    #sale-details-modal .modal-paper-card > div:first-child > table td:last-child {
        text-align: center !important;
    }

    #sale-details-modal .modal-paper-card > div:first-child > table td:last-child h3 {
        text-align: center !important;
        font-size: 1.15rem !important;
        line-height: 1.3 !important;
    }

    #sale-details-modal .modal-paper-card > div:first-child > table td:last-child div {
        justify-content: center !important;
        margin-top: 4px !important;
    }

    /* Apilar verticalmente y centrar el bloque de datos del cliente */
    #sale-details-modal .modal-paper-card table + div {
        flex-direction: column !important;
        gap: 10px !important;
        padding: 12px !important;
    }
    
    #sale-details-modal .modal-paper-card table + div > div {
        border-left: none !important;
        padding-left: 0 !important;
        border-bottom: 1px solid #e2e8f0 !important;
        padding-bottom: 10px !important;
        width: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        text-align: center !important;
    }
    
    #sale-details-modal .modal-paper-card table + div > div:last-child {
        border-bottom: none !important;
        padding-bottom: 0 !important;
    }

    /* Ajustes responsivos para la tabla de productos (invoice-table) en móviles */
    #sale-details-modal .invoice-table {
        display: table !important;
        width: 100% !important;
        table-layout: fixed !important;
        border-collapse: collapse !important;
        margin-top: 10px !important;
    }

    #sale-details-modal .invoice-table thead {
        display: table-header-group !important;
        background: #f1f5f9 !important;
    }

    #sale-details-modal .invoice-table tbody {
        display: table-row-group !important;
    }

    #sale-details-modal .invoice-table tr {
        display: table-row !important;
    }

    #sale-details-modal .invoice-table th,
    #sale-details-modal .invoice-table td {
        display: table-cell !important;
        padding: 8px 6px !important;
        font-size: 0.75rem !important;
        vertical-align: middle !important;
        border-bottom: 1px solid #f1f5f9 !important;
    }

    #sale-details-modal .invoice-table th {
        font-size: 0.65rem !important;
        font-weight: 800 !important;
        color: #64748b !important;
        text-transform: uppercase !important;
    }

    /* Anchos específicos de columnas en móvil para evitar desbordes */
    #sale-details-modal .invoice-table th:nth-child(1),
    #sale-details-modal .invoice-table td:nth-child(1) {
        width: auto !important; /* Descripción */
        text-align: left !important;
        word-break: break-word !important;
    }

    #sale-details-modal .invoice-table th:nth-child(2),
    #sale-details-modal .invoice-table td:nth-child(2) {
        width: 40px !important; /* Cantidad */
        text-align: center !important;
    }

    #sale-details-modal .invoice-table th:nth-child(3),
    #sale-details-modal .invoice-table td:nth-child(3) {
        width: 75px !important; /* Precio */
        text-align: right !important;
    }

    #sale-details-modal .invoice-table th:nth-child(4),
    #sale-details-modal .invoice-table td:nth-child(4) {
        width: 75px !important; /* Total */
        text-align: right !important;
    }

    /* Ajustes responsivos para la tabla del historial de abonos en móviles */
    #sale-details-modal div[style*="margin-top:20px"] table {
        display: table !important;
        width: 100% !important;
        table-layout: fixed !important;
        border-collapse: collapse !important;
    }

    #sale-details-modal div[style*="margin-top:20px"] table thead {
        display: table-header-group !important;
    }

    #sale-details-modal div[style*="margin-top:20px"] table tbody {
        display: table-row-group !important;
    }

    #sale-details-modal div[style*="margin-top:20px"] table tr {
        display: table-row !important;
    }

    #sale-details-modal div[style*="margin-top:20px"] table th,
    #sale-details-modal div[style*="margin-top:20px"] table td {
        display: table-cell !important;
        padding: 6px 4px !important;
        font-size: 0.75rem !important;
        border-bottom: 1px solid #e2e8f0 !important;
    }

    #sale-details-modal div[style*="margin-top:20px"] table th:nth-child(1),
    #sale-details-modal div[style*="margin-top:20px"] table td:nth-child(1) {
        width: 80px !important; /* Fecha */
        text-align: left !important;
    }

    #sale-details-modal div[style*="margin-top:20px"] table th:nth-child(2),
    #sale-details-modal div[style*="margin-top:20px"] table td:nth-child(2) {
        width: auto !important; /* Método */
        text-align: left !important;
    }

    #sale-details-modal div[style*="margin-top:20px"] table th:nth-child(3),
    #sale-details-modal div[style*="margin-top:20px"] table td:nth-child(3) {
        width: 80px !important; /* Monto */
        text-align: right !important;
    }

    /* ==============================================================
       CITYCELL GSM - MÓDULO 11: HISTORIAL Y ORDEN DE COMPRAS RESPONSIVO
       ============================================================== */

    /* Forzar flex vertical en cabecera de Historial de Compras */
    #admin-tab-purchases_log > div:first-child {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 15px !important;
    }

    #admin-tab-purchases_log > div:first-child h2,
    .dashboard-title-elite {
        font-size: 1.5rem !important;
        text-align: left !important;
    }

    #purchases-actions-container {
        width: 100% !important;
        justify-content: flex-start !important;
        flex-wrap: wrap !important;
        gap: 10px !important;
    }

    /* Reducir paddings en el modal/drawer de compras para ganar espacio */
    #purchase-drawer .modal-paper-card > div:first-child {
        padding: 20px 20px 10px 20px !important;
    }

    #purchase-drawer .modal-paper-card > div[style*="overflow-y:auto"] {
        padding: 0px 15px 15px 15px !important;
    }

    #purchase-drawer .modal-paper-card > div:last-child {
        padding: 10px 15px 15px 15px !important;
    }

    /* Forzar apilamiento en cabecera del drawer de compras */
    #purchase-drawer .modal-paper-card > div:first-child > div:has(> .invoice-brand) {
        flex-direction: column !important;
        align-items: center !important;
        text-align: center !important;
        gap: 15px !important;
    }

    #purchase-drawer .invoice-brand {
        display: flex !important;
        justify-content: center !important;
        width: 100% !important;
    }

    #purchase-drawer .invoice-brand img {
        margin: 0 auto !important;
        height: 40px !important;
    }

    #purchase-drawer .invoice-meta {
        text-align: center !important;
        padding-right: 0 !important;
        width: 100% !important;
    }

    #purchase-drawer .invoice-meta div {
        justify-content: center !important;
    }

    /* Apilar bloque de datos del proveedor (Info Box Row) */
    #purchase-drawer .modal-paper-card > div:first-child > div[style*="background:#f8fafc"] {
        flex-direction: column !important;
        gap: 10px !important;
        padding: 12px !important;
    }

    #purchase-drawer .modal-paper-card > div:first-child > div[style*="background:#f8fafc"] > div {
        border-left: none !important;
        padding-left: 0 !important;
        border-bottom: 1px solid #e2e8f0 !important;
        padding-bottom: 8px !important;
        width: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        text-align: center !important;
    }

    #purchase-drawer .modal-paper-card > div:first-child > div[style*="background:#f8fafc"] > div:last-child {
        border-bottom: none !important;
        padding-bottom: 0 !important;
    }

    /* Formato tabular elástico para la tabla de items de compra (invoice-table) en el drawer */
    #purchase-drawer .invoice-table {
        display: table !important;
        width: 100% !important;
        table-layout: fixed !important;
        border-collapse: collapse !important;
        margin-top: 10px !important;
    }

    #purchase-drawer .invoice-table thead {
        display: table-header-group !important;
        background: #f1f5f9 !important;
    }

    #purchase-drawer .invoice-table tbody {
        display: table-row-group !important;
    }

    #purchase-drawer .invoice-table tr {
        display: table-row !important;
    }

    #purchase-drawer .invoice-table th,
    #purchase-drawer .invoice-table td {
        display: table-cell !important;
        padding: 8px 6px !important;
        font-size: 0.75rem !important;
        vertical-align: middle !important;
        border-bottom: 1px solid #f1f5f9 !important;
    }

    #purchase-drawer .invoice-table th {
        font-size: 0.65rem !important;
        font-weight: 800 !important;
        color: #64748b !important;
        text-transform: uppercase !important;
    }

    /* Anchos específicos de columnas en móvil para evitar desbordes */
    #purchase-drawer .invoice-table th:nth-child(1),
    #purchase-drawer .invoice-table td:nth-child(1) {
        width: auto !important; /* Descripción */
        text-align: left !important;
        word-break: break-word !important;
    }

    #purchase-drawer .invoice-table th:nth-child(2),
    #purchase-drawer .invoice-table td:nth-child(2) {
        width: 40px !important; /* Cantidad */
        text-align: center !important;
    }

    #purchase-drawer .invoice-table th:nth-child(3),
    #purchase-drawer .invoice-table td:nth-child(3) {
        width: 75px !important; /* Costo Unit. */
        text-align: right !important;
    }

    #purchase-drawer .invoice-table th:nth-child(4),
    #purchase-drawer .invoice-table td:nth-child(4) {
        width: 75px !important; /* Total */
        text-align: right !important;
    }

    /* Historial de Abonos en el drawer de compras */
    #purchase-drawer div[style*="margin-top:20px"] table {
        display: table !important;
        width: 100% !important;
        table-layout: fixed !important;
        border-collapse: collapse !important;
    }

    #purchase-drawer div[style*="margin-top:20px"] table thead {
        display: table-header-group !important;
    }

    #purchase-drawer div[style*="margin-top:20px"] table tbody {
        display: table-row-group !important;
    }

    #purchase-drawer div[style*="margin-top:20px"] table tr {
        display: table-row !important;
    }

    #purchase-drawer div[style*="margin-top:20px"] table th,
    #purchase-drawer div[style*="margin-top:20px"] table td {
        display: table-cell !important;
        padding: 6px 4px !important;
        font-size: 0.75rem !important;
        border-bottom: 1px solid #e2e8f0 !important;
    }

    #purchase-drawer div[style*="margin-top:20px"] table th:nth-child(1),
    #purchase-drawer div[style*="margin-top:20px"] table td:nth-child(1) {
        width: 80px !important; /* Fecha */
        text-align: left !important;
    }

    #purchase-drawer div[style*="margin-top:20px"] table th:nth-child(2),
    #purchase-drawer div[style*="margin-top:20px"] table td:nth-child(2) {
        width: auto !important; /* Método */
        text-align: left !important;
    }

    #purchase-drawer div[style*="margin-top:20px"] table th:nth-child(3),
    #purchase-drawer div[style*="margin-top:20px"] table td:nth-child(3) {
        width: 80px !important; /* Monto */
        text-align: right !important;
    }

    /* Alinear total de compra al centro en móviles */
    #purchase-drawer .modal-paper-card > div:last-child > div:first-child {
        justify-content: center !important;
        margin-bottom: 15px !important;
    }

    /* Apilar firmas y botones en el pie de página de compra */
    #purchase-drawer .modal-paper-card > div:last-child > div[style*="justify-content:space-between"] {
        flex-direction: column !important;
        align-items: center !important;
        gap: 15px !important;
        margin-top: 15px !important;
    }

    #purchase-drawer .modal-paper-card > div:last-child > div[style*="justify-content:space-between"] > div {
        width: 100% !important;
        text-align: center !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
    }

    #purchase-drawer .modal-paper-card > div:last-child > div[style*="justify-content:space-between"] > div:first-child div {
        margin-bottom: 5px !important;
    }

    /* ==============================================================
       CITYCELL GSM - MÓDULO 12: REORGANIZACIÓN DE GASTOS OPERATIVOS
       ============================================================== */

    /* Forzar flex vertical en cabecera de Gastos Operativos */
    #admin-tab-expenses > div:first-child {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 15px !important;
    }

    #admin-tab-expenses > div:first-child h2 {
        font-size: 1.5rem !important;
        text-align: left !important;
    }

    #admin-tab-expenses > div:first-child > div[style*="display:flex"] {
        width: 100% !important;
        justify-content: flex-start !important;
        flex-wrap: wrap !important;
        gap: 10px !important;
    }

    /* Colapsar la tabla de gastos en tarjetas responsivas en móvil */
    #admin-tab-expenses table {
        display: block !important;
        width: 100% !important;
    }

    #admin-tab-expenses thead {
        display: none !important;
    }

    #admin-tab-expenses tbody tr {
        display: block !important;
        margin-bottom: 15px !important;
        border-bottom: 8px solid #f1f5f9 !important;
        padding: 12px 10px !important;
        background: white !important;
        border-radius: 12px !important;
        border: 1px solid #e2e8f0 !important;
    }

    #admin-tab-expenses td[data-label] {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        padding: 8px 6px !important;
        border: none !important;
        border-bottom: 1px dashed #f1f5f9 !important;
        font-size: 0.85rem !important;
        text-align: right !important;
    }

    #admin-tab-expenses td[data-label]:last-child {
        border-bottom: none !important;
    }

    #admin-tab-expenses td[data-label]::before {
        content: attr(data-label) !important;
        font-weight: 700 !important;
        color: #94a3b8 !important;
        font-size: 0.8rem !important;
        text-transform: uppercase !important;
        text-align: left !important;
        margin-right: 15px !important;
    }

    /* ==============================================================
       CITYCELL GSM - MÓDULO 13: REORGANIZACIÓN DE COMISIONES Y LIQUIDACIONES
       ============================================================== */

    /* Dar formato responsivo al tfoot de las tablas en table-wrap-elite para evitar deformaciones */
    .table-wrap-elite tfoot {
        display: block !important;
        border-top: 2px solid #e2e8f0 !important;
        background: #f8fafc !important;
    }

    .table-wrap-elite tfoot tr {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        padding: 15px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .table-wrap-elite tfoot td {
        display: block !important;
        width: 100% !important;
        text-align: center !important;
        padding: 5px 0 !important;
        border: none !important;
        font-size: 1rem !important;
    }

    .table-wrap-elite tfoot td[colspan] {
        font-weight: 800 !important;
        color: #475569 !important;
    }

    .table-wrap-elite tfoot td#comm-total-pending {
        font-size: 1.4rem !important;
        font-weight: 900 !important;
        color: #10b981 !important;
    }

    /* Fix table body squeeze on mobile */
    #admin-tab-caja tbody,
    .table-wrap-elite tbody {
        display: block !important;
        width: 100% !important;
    }

    /* Pending Commissions Card Grid Layout (Mobile) */
    #comm-settlement-body tr {
        display: grid !important;
        grid-template-areas: 
            "check role"
            "name name"
            "fecha ref"
            "labor wholesale"
            "comm status" !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
        padding: 12px 14px !important;
        border-radius: 12px !important;
        border: 1px solid #e2e8f0 !important;
        background: #ffffff !important;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03) !important;
        margin-bottom: 16px !important;
    }

    #comm-settlement-body td[data-label="Elegir"]::before,
    #comm-settlement-body td[data-label="Empleado"]::before,
    #comm-settlement-body td[data-label="Rol"]::before,
    #comm-settlement-body td[data-label="Estado"]::before {
        display: none !important;
    }

    #comm-settlement-body td:nth-child(1) {
        grid-area: check !important;
        justify-content: flex-start !important;
        align-items: center !important;
    }

    #comm-settlement-body td:nth-child(5) {
        grid-area: role !important;
        justify-content: flex-end !important;
        align-items: center !important;
    }

    #comm-settlement-body td:nth-child(4) {
        grid-area: name !important;
        justify-content: flex-start !important;
        font-weight: 850 !important;
        font-size: 1.1rem !important;
        color: #1e293b !important;
        border-bottom: 1px solid #f1f5f9 !important;
        padding-bottom: 6px !important;
        margin-bottom: 4px !important;
        width: 100% !important;
    }

    #comm-settlement-body td:nth-child(2) {
        grid-area: fecha !important;
    }

    #comm-settlement-body td:nth-child(3) {
        grid-area: ref !important;
    }

    #comm-settlement-body td:nth-child(6) {
        grid-area: labor !important;
    }

    #comm-settlement-body td:nth-child(7) {
        grid-area: wholesale !important;
    }

    #comm-settlement-body td:nth-child(8) {
        grid-area: comm !important;
        background: #f0fdf4 !important;
        border-radius: 8px !important;
        padding: 6px 10px !important;
        border: 1px solid #dcfce7 !important;
    }

    #comm-settlement-body td:nth-child(9) {
        grid-area: status !important;
        justify-content: flex-end !important;
        align-items: center !important;
    }

    /* Settlements History Card Grid Layout (Mobile) */
    #comm-history-body tr {
        display: grid !important;
        grid-template-areas: 
            "lote user"
            "name name"
            "fecha concept"
            "amount amount" !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
        padding: 12px 14px !important;
        border-radius: 12px !important;
        border: 1px solid #e2e8f0 !important;
        background: #ffffff !important;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03) !important;
        margin-bottom: 16px !important;
    }

    #comm-history-body td[data-label="Empleado"]::before,
    #comm-history-body td[data-label="Lote"]::before,
    #comm-history-body td[data-label="Concepto"]::before,
    #comm-history-body td[data-label="Procesado Por"]::before {
        display: none !important;
    }

    #comm-history-body td:nth-child(2) {
        grid-area: lote !important;
        justify-content: flex-start !important;
        align-items: center !important;
    }

    #comm-history-body td:nth-child(6) {
        grid-area: user !important;
        justify-content: flex-end !important;
        align-items: center !important;
    }

    #comm-history-body td:nth-child(3) {
        grid-area: name !important;
        justify-content: flex-start !important;
        font-weight: 850 !important;
        font-size: 1.1rem !important;
        color: #1e293b !important;
        border-bottom: 1px solid #f1f5f9 !important;
        padding-bottom: 6px !important;
        margin-bottom: 4px !important;
        width: 100% !important;
    }

    #comm-history-body td:nth-child(1) {
        grid-area: fecha !important;
    }

    #comm-history-body td:nth-child(4) {
        grid-area: concept !important;
        justify-content: flex-end !important;
        align-items: center !important;
    }

    #comm-history-body td:nth-child(5) {
        grid-area: amount !important;
        background: #f0fdf4 !important;
        border-radius: 8px !important;
        padding: 6px 10px !important;
        border: 1px solid #dcfce7 !important;
    }
}

/* ==============================================================
   CITYCELL GSM - MÓDULO 15: BITÁCORA DE AUDITORÍA ELITE RESPONSIVA
   ============================================================== */

/* Base Styles for Bitácora (Desktop & General) */
.log-card-premium {
    background: white;
    border-radius: 16px;
    border: 1px solid #f1f5f9;
    padding: 18px;
    display: flex;
    align-items: flex-start;
    gap: 20px;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}
.log-card-time {
    min-width: 90px;
    text-align: center;
    border-right: 2px solid #f8fafc;
    padding-right: 15px;
    flex-shrink: 0;
}
.log-card-date-text {
    font-weight: 900;
    color: #0f172a;
    font-size: 0.95rem;
}
.log-card-time-badge {
    font-size: 0.75rem;
    color: #3b82f6;
    font-weight: 800;
    background: #eff6ff;
    padding: 2px 8px;
    border-radius: 20px;
    display: inline-block;
    margin-top: 5px;
}
.log-card-body {
    flex: 1;
    min-width: 0;
}
.log-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    gap: 15px;
}
.log-card-badges {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.log-card-user {
    text-align: right;
    flex-shrink: 0;
}
.log-card-username {
    font-size: 0.9rem;
    font-weight: 950;
    color: #0f172a;
}
.log-card-useremail {
    font-size: 0.7rem;
    color: #64748b;
    font-weight: 700;
}
.log-card-details-box {
    background: #f8fafc;
    padding: 12px 16px;
    border-radius: 12px;
    border: 1px solid #f1f5f9;
}

/* Forensic Summary Card */
.logs-forensic-card {
    margin-bottom: 25px;
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    border-radius: 20px;
    padding: 25px;
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 10px 25px -10px rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.05);
}
.logs-forensic-stats {
    display: flex;
    gap: 35px;
    border-left: 1px solid rgba(255,255,255,0.1);
    padding-left: 35px;
    align-items: center;
}

/* Filters Group */
.logs-filters-group {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

/* Responsive Overrides (Tablet & Mobile) */
@media (max-width: 991px) {
    .logs-filters-group {
        width: 100% !important;
        justify-content: flex-start !important;
        gap: 12px !important;
    }
}

@media (max-width: 768px) {
    /* Title Layout */
    #admin-tab-logs .dashboard-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 15px !important;
    }
    #admin-tab-logs .dashboard-header > div {
        width: 100% !important;
    }
    #admin-tab-logs .dashboard-header .header-actions {
        width: 100% !important;
        justify-content: flex-start !important;
        gap: 10px !important;
    }

    /* Filters Layout */
    #admin-tab-logs .sales-controls-row {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 15px !important;
    }
    
    #admin-tab-logs .search-box-elite {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 100% !important;
    }

    .logs-filters-group {
        width: 100% !important;
        gap: 10px !important;
    }

    .logs-filters-group > div {
        flex: 1 1 calc(50% - 5px) !important;
        min-width: 135px !important;
        box-sizing: border-box !important;
    }

    .logs-filters-group > div select {
        width: 100% !important;
    }

    /* Force presets and date range to stack to full width below selects */
    .logs-filters-group > div:nth-child(3),
    .logs-filters-group > div:nth-child(4) {
        flex: 1 1 100% !important;
        justify-content: center !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    /* Forensic Summary Card */
    .logs-forensic-card {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 20px !important;
        padding: 18px !important;
    }
    .logs-forensic-stats {
        width: 100% !important;
        border-left: none !important;
        border-top: 1px solid rgba(255,255,255,0.1) !important;
        padding-left: 0 !important;
        padding-top: 20px !important;
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 10px !important;
    }

    /* Log Cards */
    .log-card-premium {
        flex-direction: column !important;
        gap: 12px !important;
        padding: 14px !important;
    }
    .log-card-time {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        min-width: auto !important;
        width: 100% !important;
        border-right: none !important;
        border-bottom: 2px solid #f8fafc !important;
        padding-right: 0 !important;
        padding-bottom: 8px !important;
    }
    .log-card-time-badge {
        margin-top: 0 !important;
    }
    .log-card-body {
        width: 100% !important;
    }
    .log-card-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 10px !important;
        margin-bottom: 12px !important;
    }
    .log-card-badges {
        width: 100% !important;
        justify-content: space-between !important;
    }
    .log-card-user {
        text-align: left !important;
        width: 100% !important;
        border-top: 1px dashed #f1f5f9 !important;
        padding-top: 8px !important;
    }
}

/* ==============================================================
   CITYCELL GSM - MÓDULO 16: CIERRE DE CAJA (ARQUEO) RESPONSIVO
   ============================================================== */

/* Base Styles */
.audit-actions-container {
    display: flex;
    justify-content: flex-end;
    gap: 15px;
    margin-bottom: 25px;
    flex-wrap: wrap;
}
.audit-grid-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 25px;
    margin-bottom: 25px;
}
.audit-row-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 15px;
    background: #f8fafc;
    border-radius: 12px;
    border: 1px solid #f1f5f9;
}
.audit-sales-totals-footer {
    margin-top: 25px;
    padding: 20px;
    background: #f8fafc;
    border-radius: 16px;
    border: 1px solid #f1f5f9;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-left: 4px solid var(--primary);
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
}
.audit-totals-left {
    display: flex;
    gap: 30px;
    align-items: center;
}
.audit-totals-right {
    display: flex;
    gap: 40px;
    align-items: center;
}
.audit-debug-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 25px;
}
.audit-summary-footer {
    margin-top: 25px;
    padding: 25px;
    background: white;
    border-radius: 20px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Tablet Overrides (< 992px) */
@media (max-width: 991px) {
    .audit-grid-container {
        grid-template-columns: 1fr !important;
        gap: 20px !important;
    }
    .audit-debug-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 20px !important;
    }
    .audit-sales-totals-footer {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 20px !important;
    }
    .audit-totals-left,
    .audit-totals-right {
        width: 100% !important;
        justify-content: space-between !important;
        gap: 20px !important;
    }
    .audit-totals-right > div:last-child {
        border-left: none !important;
        padding-left: 0 !important;
        text-align: right !important;
    }
}

/* Mobile Overrides (< 768px) */
@media (max-width: 768px) {
    .audit-actions-container {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
    }
    .audit-actions-container button,
    .audit-actions-container a {
        width: 100% !important;
        justify-content: center !important;
    }
    .audit-debug-grid {
        grid-template-columns: 1fr !important;
        gap: 15px !important;
    }
    .audit-summary-footer {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 20px !important;
        padding: 20px 15px !important;
    }
    .audit-summary-footer button {
        width: 100% !important;
        justify-content: center !important;
    }

    /* History Table Cards Collapse */
    .audit-history-table {
        display: block !important;
        width: 100% !important;
    }
    .audit-history-table thead {
        display: none !important;
    }
    .audit-history-table tbody {
        display: block !important;
        width: 100% !important;
    }
    .audit-history-table tbody tr {
        display: block !important;
        margin-bottom: 12px !important;
        border: 1px solid #e2e8f0 !important;
        border-radius: 10px !important;
        padding: 10px !important;
        background: #fff !important;
    }
    .audit-history-table td {
        display: flex !important;
        justify-content: space-between !important;
        padding: 6px 8px !important;
        border: none !important;
        font-size: 0.85rem !important;
        text-align: right !important;
    }
    .audit-history-table td[data-label]::before {
        content: attr(data-label) !important;
        font-weight: 700 !important;
        color: #94a3b8 !important;
        font-size: 0.8rem !important;
        text-transform: uppercase !important;
        text-align: left !important;
    }
    .audit-history-table td[data-label="Acción"] {
        justify-content: flex-end !important;
        align-items: center !important;
    }
}

/* Compact Mobile (< 480px) */
@media (max-width: 480px) {
    .audit-row-item {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
        padding: 12px !important;
    }
    .audit-row-item > div:last-child {
        width: 100% !important;
    }
    .audit-row-item input {
        width: 100% !important;
    }
    .audit-totals-left,
    .audit-totals-right {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
    }
    .audit-totals-left > div,
    .audit-totals-right > div {
        text-align: left !important;
    }
    .audit-totals-right > div:last-child {
        text-align: left !important;
    }
}

/* Modal Grid for Detailed Cash Audit */
.audit-modal-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    text-align: left;
}

@media (max-width: 768px) {
    .audit-modal-grid {
        grid-template-columns: 1fr !important;
        gap: 15px !important;
    }
}
