/**
 * Correcciones de Maquetado para Sales y Purchases
 * Corrige problemas de alineación en campos de fecha y DataTables
 * Fecha: Noviembre 2025
 */

/* ============================================
   Correcciones para el header de filtros
   ============================================ */

.box-header.with-border {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    padding: 10px 15px;
}

/* Contenedor de filtros de fecha */
.box-header .pull-right {
    display: flex !important;
    flex-wrap: wrap;
    gap: 10px !important;
    align-items: center !important;
    margin-left: auto;
}

/* Input groups de fecha */
.box-header .input-group {
    display: flex;
    align-items: center;
    width: auto !important;
    margin: 0;
}

.box-header .input-group-addon {
    display: flex;
    align-items: center;
    white-space: nowrap;
    padding: 6px 12px;
    font-size: 14px;
    font-weight: 400;
    line-height: 1.42857143;
    text-align: center;
    background-color: #eee;
    border: 1px solid #ccc;
    border-radius: 4px 0 0 4px;
}

.box-header .input-group .form-control {
    width: 150px !important;
    height: 34px;
    padding: 6px 12px;
    font-size: 14px;
    line-height: 1.42857143;
    border: 1px solid #ccc;
    border-left: 0;
    border-radius: 0 4px 4px 0;
}

/* Botón de filtrar */
.box-header .btn {
    height: 34px;
    padding: 6px 12px;
    font-size: 14px;
    line-height: 1.42857143;
    white-space: nowrap;
    vertical-align: middle;
}

/* ============================================
   Correcciones para DataTables
   ============================================ */

.box-body {
    overflow-x: auto;
    padding: 15px;
}

/* Asegurar que la tabla sea responsive */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Tabla principal */
.salesTable,
.purchasesTable {
    width: 100% !important;
    margin-bottom: 0;
    border-collapse: collapse;
}

/* Headers de la tabla */
.salesTable thead th,
.purchasesTable thead th {
    background-color: #f4f4f4;
    font-weight: bold;
    border: 1px solid #ddd;
    padding: 8px;
    text-align: left;
    vertical-align: middle;
    white-space: nowrap;
}

/* Celdas de la tabla */
.salesTable tbody td,
.purchasesTable tbody td {
    border: 1px solid #ddd;
    padding: 8px;
    vertical-align: middle;
}

/* Wrapper de DataTables */
.dataTables_wrapper {
    width: 100%;
    clear: both;
}

.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter {
    padding: 10px 0;
}

.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate {
    padding: 10px 0;
}

/* ============================================
   Responsive para móviles
   ============================================ */

@media (max-width: 768px) {
    
    /* Ajustar header en móviles */
    .box-header.with-border {
        flex-direction: column;
        align-items: flex-start;
    }
    
    /* Filtros en móviles */
    .box-header .pull-right {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        margin-left: 0;
    }
    
    /* Input groups ocupan todo el ancho */
    .box-header .input-group {
        width: 100% !important;
    }
    
    .box-header .input-group .form-control {
        width: 100% !important;
        flex: 1;
    }
    
    /* Botones ocupan todo el ancho */
    .box-header .btn {
        width: 100%;
    }
    
    /* Tabla responsive en móviles */
    .box-body {
        padding: 10px 5px;
    }
    
    .salesTable,
    .purchasesTable {
        font-size: 12px;
    }
    
    .salesTable thead th,
    .purchasesTable thead th,
    .salesTable tbody td,
    .purchasesTable tbody td {
        padding: 5px;
        font-size: 12px;
    }
    
    /* Ocultar algunas columnas en móviles para mejor visualización */
    .salesTable thead th:nth-child(4),
    .salesTable tbody td:nth-child(4),
    .purchasesTable thead th:nth-child(4),
    .purchasesTable tbody td:nth-child(4) {
        display: none;
    }
}

@media (max-width: 576px) {
    
    /* En pantallas muy pequeñas, ocultar más columnas */
    .salesTable thead th:nth-child(5),
    .salesTable tbody td:nth-child(5),
    .purchasesTable thead th:nth-child(7),
    .purchasesTable tbody td:nth-child(7) {
        display: none;
    }
}

/* ============================================
   Correcciones para DataTables Responsive
   ============================================ */

/* Control de expansión de filas en móviles */
.dtr-control::before {
    display: inline-block;
    color: #3c8dbc;
    border: 2px solid #3c8dbc;
    border-radius: 14px;
    box-shadow: 0 0 3px #ccc;
    background-color: white;
    content: '+';
    text-align: center;
    font-weight: bold;
    width: 16px;
    height: 16px;
    line-height: 12px;
    margin-right: 5px;
}

.dtr-control.collapsed::before {
    content: '+';
}

.dtr-control.expanded::before {
    content: '-';
}

/* Detalles expandidos */
.dtr-details {
    background-color: #f9f9f9;
}

.dtr-details li {
    border-bottom: 1px solid #ddd;
    padding: 5px 0;
}

/* ============================================
   Correcciones adicionales para alineación
   ============================================ */

/* Asegurar que los botones de acción estén alineados */
.btn-group {
    display: inline-flex;
    vertical-align: middle;
}

.btn-group .btn {
    margin: 0 2px;
}

/* Iconos en botones */
.btn i {
    margin-right: 5px;
}

.btn i:only-child {
    margin-right: 0;
}

/* Fix para input date en algunos navegadores */
input[type="date"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

input[type="date"]::-webkit-inner-spin-button,
input[type="date"]::-webkit-calendar-picker-indicator {
    opacity: 1;
    cursor: pointer;
}

/* ============================================
   Mejoras visuales
   ============================================ */

/* Hover en filas de tabla */
.salesTable tbody tr:hover,
.purchasesTable tbody tr:hover {
    background-color: #f5f5f5;
    cursor: pointer;
}

/* Alternancia de colores en filas */
.salesTable tbody tr:nth-child(even),
.purchasesTable tbody tr:nth-child(even) {
    background-color: #fafafa;
}

/* Scroll suave */
.box-body {
    scroll-behavior: smooth;
}

/* Indicador de scroll si hay overflow */
.box-body::after {
    content: '';
    display: block;
    height: 1px;
    clear: both;
}
