
/* ==========================
   DATATABLES · Classic ERP
   Diseño Compacto y Responsive
   ========================== */

/* Toolbar - Barra de herramientas superior */
.datatable-toolbar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    padding: 8px 0;
}

.datatable-toolbar input[type="text"] {
    max-width: 250px;
    height: 28px;
    font-size: 12px;
    padding: 4px 8px;
}

/* Footer - Info y paginación */
.datatable-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    padding: 8px 0;
    font-size: 12px;
    gap: 12px;
    flex-wrap: wrap;
}


/* Info y paginación fijas abajo del panel */
.datatable-fixed-footer {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    background: #fff;
    z-index: 10;
    border-top: 1px solid var(--border-soft);
    border-radius: 0 0 8px 8px;
    min-height: 48px;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
    font-size: 12px;
    gap: 12px;
}
.datatable-fixed-footer .dataTables_info {
    font-size: 12px;
    color: #555;
    font-weight: 400;
    padding: 0 !important;
}
.datatable-fixed-footer .dataTables_paginate {
    display: flex;
    gap: 2px;
    align-items: center;
}

.dataTables_info {
    color: var(--text-main);
    font-size: 12px;
}

.dataTables_paginate {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    flex-wrap: wrap;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
}

.dataTables_paginate .paginate_button {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    min-height: 24px !important;
    min-width: 24px !important;
    padding: 0 7px !important;
    border: 1px solid var(--border-soft);
    background: linear-gradient(to bottom, #ffffff, #f4f6fa);
    color: var(--text-main) !important;
    font-size: 11px;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none !important;
    text-align: center;
    user-select: none;
    line-height: 1;
}

.dataTables_paginate .paginate_button:hover:not(.disabled) {
    background: linear-gradient(to bottom, #ffffff, #ecf1f8);
    border-color: var(--border-strong);
    color: var(--color-primary) !important;
    transform: translateY(-1px);
}

.dataTables_paginate .paginate_button.current {
    background: linear-gradient(to bottom, var(--color-primary), var(--color-primary-dark));
    color: #ffffff !important;
    border-color: var(--color-primary-dark);
    font-weight: 700;
    box-shadow: 0 2px 6px rgba(0, 128, 61, 0.22);
}

.dataTables_paginate .paginate_button.current:hover {
    background: linear-gradient(to bottom, var(--color-primary-dark), #143c26);
    border-color: #143c26;
}

.dataTables_paginate .paginate_button.disabled,
.dataTables_paginate .paginate_button.disabled:hover {
    cursor: not-allowed;
    opacity: 0.5;
    background: #f8fafc;
    color: #9ca3af !important;
    border-color: #e5e7eb;
    transform: none;
}

.dataTables_paginate .paginate_button.previous,
.dataTables_paginate .paginate_button.next {
    font-weight: 500;
}

/* Ordenamiento en headers */
table.dataTable thead th,
table.dataTable thead td {
    position: relative;
}

table.dataTable thead th.sorting,
table.dataTable thead th.sorting_asc,
table.dataTable thead th.sorting_desc {
    cursor: pointer;
    padding-right: 24px;
}

table.dataTable thead th.sorting:before,
table.dataTable thead th.sorting:after,
table.dataTable thead th.sorting_asc:before,
table.dataTable thead th.sorting_asc:after,
table.dataTable thead th.sorting_desc:before,
table.dataTable thead th.sorting_desc:after {
    position: absolute;
    right: 8px;
    display: block;
    opacity: 0.3;
    font-size: 10px;
}

table.dataTable thead th.sorting:before,
table.dataTable thead th.sorting_asc:before {
    content: "▲";
    top: 10px;
}

table.dataTable thead th.sorting:after,
table.dataTable thead th.sorting_desc:after {
    content: "▼";
    bottom: 10px;
}

table.dataTable thead th.sorting_asc:before {
    opacity: 1;
}

table.dataTable thead th.sorting_desc:after {
    opacity: 1;
}

/* Processing - Cargando datos */
.dataTables_processing {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid #d0d5dd;
    border-radius: 4px;
    padding: 12px 20px;
    font-size: 13px;
    color: #555;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    z-index: 100;
}

/* Empty - Sin datos */
.dataTables_empty {
    text-align: center;
    padding: 24px;
    font-size: 13px;
    color: #6b7280;
    font-style: italic;
}

/* Tabla responsive - Columnas expandibles */
table.table-classic.dataTable {
    table-layout: fixed !important;
    width: 100% !important;
    border-collapse: separate !important;
    border-spacing: 0 !important;
    border: 1px solid var(--border-soft);
    border-radius: 8px;
    overflow: hidden;
    background: var(--table-bg);
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.05);
}

/*
@media (min-width: 769px) {
    table.table-classic.table-column.dataTable {
        table-layout: auto !important;
    }

    table.table-classic.table-column.dataTable th,
    table.table-classic.table-column.dataTable td {
        vertical-align: top;
    }

    table.table-classic.table-column.dataTable th:nth-child(1),
    table.table-classic.table-column.dataTable td:nth-child(1) {
        width: 42px;
        white-space: nowrap;
    }

    table.table-classic.table-column.dataTable th:nth-child(2),
    table.table-classic.table-column.dataTable td:nth-child(2) {
        width: 110px;
        white-space: nowrap;
    }

    table.table-classic.table-column.dataTable th:nth-child(3),
    table.table-classic.table-column.dataTable td:nth-child(3) {
        width: 110px;
        white-space: nowrap;
    }

    table.table-classic.table-column.dataTable th:nth-child(4),
    table.table-classic.table-column.dataTable td:nth-child(4) {
        width: 110px;
        white-space: nowrap;
    }

    table.table-classic.table-column.dataTable th:nth-child(5),
    table.table-classic.table-column.dataTable td:nth-child(5) {
        width: 260px;
        min-width: 220px;
    }

    table.table-classic.table-column.dataTable th:nth-child(6),
    table.table-classic.table-column.dataTable td:nth-child(6) {
        width: auto;
        min-width: 360px;
    }

    table.table-classic.table-column.dataTable th:nth-child(7),
    table.table-classic.table-column.dataTable td:nth-child(7) {
        width: 110px;
        white-space: nowrap;
    }

    table.table-classic.table-column.dataTable th:nth-child(8),
    table.table-classic.table-column.dataTable td:nth-child(8) {
        width: 90px;
        white-space: nowrap;
        text-align: center;
    }
}
*/

/* =====================================================
   DATATABLES · Ajuste general de columnas
   ===================================================== */

table.table-classic.dataTable {
    table-layout: auto !important;
    width: 100% !important;
}

table.table-classic.dataTable th,
table.table-classic.dataTable td {
    vertical-align: middle !important;
    padding: 6px 8px !important;
}

/* Encabezados compactos */
table.table-classic.dataTable th {
    white-space: nowrap !important;
}

/* Celdas normales */
table.table-classic.dataTable td {
    white-space: normal !important;
    overflow-wrap: anywhere;
}

/* Columnas vacías no deben ocupar espacio */
table.table-classic.dataTable th:empty,
table.table-classic.dataTable td:empty {
    width: 1% !important;
    min-width: 0 !important;
    max-width: 20px !important;
    padding-left: 2px !important;
    padding-right: 2px !important;
}

/* Primera columna normalmente es número/check/control */
table.table-classic.dataTable th:first-child,
table.table-classic.dataTable td:first-child {
    width: 1% !important;
    white-space: nowrap !important;
}

/* Última columna normalmente acciones */
table.table-classic.dataTable th:last-child,
table.table-classic.dataTable td:last-child {
    width: 1% !important;
    white-space: nowrap !important;
    text-align: center;
}

/* Columnas cortas comunes */
table.table-classic.dataTable td.dt-nowrap,
table.table-classic.dataTable th.dt-nowrap,
table.table-classic.dataTable td.dt-center,
table.table-classic.dataTable th.dt-center {
    white-space: nowrap !important;
}

/* Evita columnas exageradamente anchas */
table.table-classic.dataTable th,
table.table-classic.dataTable td {
    max-width: 420px;
}

table.table-classic.dataTable th,
table.table-classic.dataTable td {
    vertical-align: top;
}

table.table-classic.dataTable th {
    white-space: nowrap !important;
    background: var(--table-header-bg);
    color: var(--text-main);
    font-weight: 700;
    border-bottom: 1px solid var(--border-soft);
    border-right: 1px solid rgba(0, 0, 0, 0.04);
    padding: 8px 10px;
    letter-spacing: 0.01em;
}

table.table-classic.dataTable td {
    white-space: normal !important;
    overflow-wrap: break-word;
    word-break: normal;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    border-right: 1px solid rgba(0, 0, 0, 0.04);
    padding: 7px 10px;
    color: var(--text-main);
    background: var(--table-bg);
}

table.table-classic.dataTable th:last-child,
table.table-classic.dataTable td:last-child {
    border-right: none;
}

table.table-classic.dataTable tbody tr:nth-child(even) td {
    background: #f8fafc;
}

table.table-classic.dataTable tbody tr:hover td {
    background: var(--table-row-hover);
    transition: background-color 0.15s ease;
}

/* Ajustes globales para toolbars con buscador externo */
.module-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
}

.module-toolbar .dt-external-search {
    min-width: 220px;
}

.module-toolbar .dt-external-search .input-group {
    width: 100%;
}

/* Utilidades reutilizables para celdas específicas */
table.table-classic.dataTable th.dt-nowrap,
table.table-classic.dataTable td.dt-nowrap {
    white-space: nowrap !important;
}

table.table-classic.dataTable th.dt-center,
table.table-classic.dataTable td.dt-center {
    text-align: center !important;
}

table.table-classic.dataTable td.dt-ellipsis {
    max-width: 220px;
    white-space: nowrap !important;
    overflow: hidden;
    text-overflow: ellipsis;
}

table.table-classic.dataTable td.dt-middle,
table.table-classic.dataTable th.dt-middle {
    vertical-align: middle;
}

table.table-classic.dataTable th:first-child,
table.table-classic.dataTable td:first-child {
    width: 1% !important;
    white-space: nowrap !important;
}

table.dataTable.dtr-inline.collapsed > tbody > tr > td.dtr-control:before,
table.dataTable.dtr-inline.collapsed > tbody > tr > th.dtr-control:before {
    background-color: #2f4c79;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px #d0d5dd;
    margin-top: -8px;
}

table.dataTable.dtr-inline.collapsed > tbody > tr.parent > td.dtr-control:before,
table.dataTable.dtr-inline.collapsed > tbody > tr.parent > th.dtr-control:before {
    background-color: #e74c3c;
}

table.dataTable > tbody > tr.child {
    background-color: #f9fafb;
}

table.dataTable > tbody > tr.child td {
    padding: 8px 12px;
    font-size: 12px;
}

table.dataTable > tbody > tr.child ul.dtr-details {
    margin: 0;
    padding: 0;
    list-style: none;
}

table.dataTable > tbody > tr.child ul.dtr-details > li {
    padding: 6px 0;
    border-bottom: 1px solid #e5e7eb;
}

table.dataTable > tbody > tr.child ul.dtr-details > li:last-child {
    border-bottom: none;
}

table.dataTable > tbody > tr.child span.dtr-title {
    font-weight: 600;
    color: #374151;
    display: inline-block;
    min-width: 120px;
}

table.dataTable > tbody > tr.child span.dtr-data {
    color: #6b7280;
}

/* Responsive - Media queries */
@media screen and (max-width: 768px) {
    table.table-classic.mobile-stacked {
        --stack-label-width: 110px;
        --stack-row-gap: 8px;
        --stack-row-padding-x: 12px;
        --stack-row-padding-y: 10px;
    }

    .table-wrapper,
    .dataTables_wrapper,
    .dataTables_scroll,
    .dataTables_scrollBody {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
    }

    .dataTables_wrapper .row,
    .dataTables_wrapper .col-sm-12,
    .dataTables_wrapper .col-md-6,
    .dataTables_wrapper .col-md-5,
    .dataTables_wrapper .col-md-7 {
        margin-left: 0 !important;
        margin-right: 0 !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    table.table-classic.mobile-stacked,
    table.table-classic.mobile-stacked[style] {
        width: 100% !important;
    }

    table.table-classic.mobile-stacked colgroup {
        display: none !important;
    }

    table.table-classic.mobile-stacked th[style],
    table.table-classic.mobile-stacked td[style] {
        width: auto !important;
        min-width: 0 !important;
        max-width: none !important;
    }

    table.table-classic.mobile-stacked thead {
        display: none;
    }

    table.table-classic.mobile-stacked tbody,
    table.table-classic.mobile-stacked tr,
    table.table-classic.mobile-stacked td {
        display: block;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box;
    }

    table.table-classic.mobile-stacked tbody tr {
        margin-bottom: 12px;
        padding: var(--stack-row-padding-y) var(--stack-row-padding-x) 8px;
        border-radius: 8px;
        background-color: #f8f9fa;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.10);
        border: 1px solid rgba(0, 0, 0, 0.06);
    }

    table.table-classic.mobile-stacked tbody td {
        display: flex;
        gap: var(--stack-row-gap);
        align-items: flex-start;
        white-space: normal !important;
        word-break: break-word;
        padding-top: 4px !important;
        padding-bottom: 4px !important;
        border-right: 0 !important;
        border-bottom: 1px solid rgba(0, 0, 0, 0.06) !important;
        background: transparent !important;
        overflow-wrap: anywhere;
    }

    table.table-classic.mobile-stacked tbody td:last-child {
        border-bottom: 0 !important;
    }

    table.table-classic.mobile-stacked tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        flex: 0 0 var(--stack-label-width);
        max-width: var(--stack-label-width);
        color: var(--text-main);
    }

    table.table-classic.mobile-stacked tbody td > * {
        min-width: 0;
        max-width: 100%;
        white-space: normal;
    }

    table.table-classic.mobile-stacked tbody td .cell-value {
        flex: 1 1 auto;
        min-width: 0;
        max-width: 100%;
        white-space: normal;
        word-break: break-word;
        overflow-wrap: anywhere;
    }

    table.table-classic.mobile-stacked tbody td .cell-value > * {
        max-width: 100%;
        white-space: normal;
    }

    table.table-classic.mobile-stacked tbody td small {
        display: inline-block;
    }

    [data-theme="dark"] table.table-classic.mobile-stacked tbody tr {
        background: #2d2d2d;
        border-color: #404040;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
    }

    [data-theme="dark"] table.table-classic.mobile-stacked tbody td {
        border-bottom-color: #404040 !important;
        color: #e0e0e0 !important;
    }

    [data-theme="dark"] table.table-classic.mobile-stacked tbody td::before {
        color: #d1d5db;
    }

    .datatable-footer {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .dataTables_paginate {
        width: 100%;
        justify-content: center;
    }
    
    .datatable-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    
    .datatable-toolbar input[type="text"] {
        max-width: 100%;
    }

    .module-toolbar {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        align-items: center;
    }

    .module-toolbar > #SearchTable,
    .module-toolbar .dt-external-search {
        min-width: 0;
        width: 100%;
    }

    .module-toolbar > #SearchTable .input-group,
    .module-toolbar .dt-external-search .input-group {
        width: 100%;
    }

    .module-toolbar .btn-classic,
    .module-toolbar .btn,
    .module-toolbar .btn-sm {
        white-space: nowrap;
        margin-left: 0 !important;
        flex: 0 0 auto;
    }

    table.table-classic.dataTable {
        font-size: 11px;
    }

    table.table-classic.dataTable th,
    table.table-classic.dataTable td {
        padding: 6px 5px;
    }

    .dataTables_info {
        text-align: center;
        padding-left: 0 !important;
    }
}

@media screen and (max-width: 576px) {
    table.table-classic.mobile-stacked {
        --stack-label-width: 96px;
        --stack-row-gap: 7px;
        --stack-row-padding-x: 10px;
        --stack-row-padding-y: 9px;
    }
}

@media screen and (max-width: 430px) {
    table.table-classic.mobile-stacked {
        --stack-label-width: 90px;
        --stack-row-gap: 6px;
        --stack-row-padding-x: 9px;
        --stack-row-padding-y: 8px;
    }

    table.table-classic.mobile-stacked tbody td {
        font-size: 11px;
    }
}

@media screen and (max-width: 390px) {
    table.table-classic.mobile-stacked {
        --stack-label-width: 84px;
        --stack-row-gap: 6px;
        --stack-row-padding-x: 8px;
        --stack-row-padding-y: 8px;
    }
}

@media screen and (max-width: 360px) {
    table.table-classic.mobile-stacked {
        --stack-label-width: 78px;
        --stack-row-gap: 5px;
        --stack-row-padding-x: 7px;
        --stack-row-padding-y: 7px;
    }

    table.table-classic.mobile-stacked tbody td {
        padding-top: 3px !important;
        padding-bottom: 3px !important;
    }
}

@media screen and (max-width: 460px) {
    .module-toolbar .btn-classic,
    .module-toolbar .btn,
    .module-toolbar .btn-sm {
        justify-self: start;
    }
}

/* Dark Mode */
[data-theme="dark"] .table-wrapper {
    background: #2a2a2a !important;
    border-color: #444 !important;
}

[data-theme="dark"] table.dataTable thead th {
    background: #333 !important;
    color: #e0e0e0 !important;
    border-bottom-color: #444 !important;
}

[data-theme="dark"] .table-wrapper thead {
    background-color: #2a2a2a !important;
    color: #d1d5db !important;
    border-bottom-color: #3a3a3a !important;
}

[data-theme="dark"] .datatable-toolbar {
    color: #e0e0e0;
}

[data-theme="dark"] .datatable-footer {
    color: #e0e0e0;
}

[data-theme="dark"] .dataTables_info {
    color: #d1d5db;
}

[data-theme="dark"] .dataTables_paginate {
    background: transparent;
    color: #e0e0e0;
    border-color: transparent;
}

[data-theme="dark"] .dataTables_paginate .paginate_button {
    background: linear-gradient(to bottom, #2d2d2d, #262626) !important;
    border-color: #444 !important;
    color: #e0e0e0 !important;
}

[data-theme="dark"] .dataTables_paginate .paginate_button:hover:not(.disabled):not(.current) {
    background: linear-gradient(to bottom, #353535, #2c2c2c) !important;
    border-color: #555 !important;
    color: #fff !important;
}

[data-theme="dark"] .dataTables_paginate .paginate_button.current {
    background: linear-gradient(to bottom, var(--color-primary), var(--color-primary-dark)) !important;
    border-color: var(--color-primary-dark) !important;
    color: #ffffff !important;
}

[data-theme="dark"] .dataTables_paginate .paginate_button.current:hover {
    background: linear-gradient(to bottom, var(--color-primary-dark), #143c26) !important;
    border-color: #143c26 !important;
}

[data-theme="dark"] .dataTables_paginate .paginate_button.disabled,
[data-theme="dark"] .dataTables_paginate .paginate_button.disabled:hover {
    background: #1a1a1a !important;
    border-color: #333 !important;
    color: #666 !important;
}

[data-theme="dark"] .dataTables_paginate a,
[data-theme="dark"] .dataTables_paginate span,
[data-theme="dark"] .dataTables_paginate .ellipsis {
    color: #e0e0e0 !important;
    background: transparent !important;
}

[data-theme="dark"] #dt-pagination,
[data-theme="dark"] #dt-pagination-products {
    color: #e0e0e0;
}

[data-theme="dark"] .dataTables_wrapper .dataTables_paginate {
    color: #e0e0e0 !important;
}

[data-theme="dark"] .dataTables_processing {
    background: rgba(42, 42, 42, 0.98);
    border-color: #444;
    color: #d1d5db;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .dataTables_empty {
    color: #9ca3af;
}

[data-theme="dark"] table.dataTable > tbody > tr.child {
    background-color: #1f1f1f;
}

[data-theme="dark"] table.dataTable > tbody > tr.child ul.dtr-details > li {
    border-bottom-color: #333;
}

[data-theme="dark"] table.dataTable > tbody > tr.child span.dtr-title {
    color: #d1d5db;
}

[data-theme="dark"] table.dataTable > tbody > tr.child span.dtr-data {
    color: #9ca3af;
}

/* Dark Mode - DataTables específico */
[data-theme="dark"] table.dataTable {
    background: #2a2a2a !important;
    color: #e0e0e0 !important;
    border-color: #444 !important;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.25);
}

[data-theme="dark"] table.dataTable tbody td {
    background-color: #2a2a2a !important;
    color: #d1d5db !important;
    border-bottom-color: #3a3a3a !important;
    border-right-color: #3a3a3a !important;
}

[data-theme="dark"] table.dataTable tbody tr {
    background-color: #2a2a2a !important;
}

[data-theme="dark"] table.dataTable tbody tr:nth-child(even),
[data-theme="dark"] table.dataTable tbody tr:nth-child(even) td {
    background-color: #2e2e2e !important;
}

[data-theme="dark"] table.dataTable tbody tr:hover,
[data-theme="dark"] table.dataTable tbody tr:hover td {
    background-color: #3a3a3a !important;
}

[data-theme="dark"] table.dataTable.display tbody tr.odd > .sorting_1,
[data-theme="dark"] table.dataTable.order-column.stripe tbody tr.odd > .sorting_1 {
    background-color: #2a2a2a !important;
}

[data-theme="dark"] table.dataTable.display tbody tr.even > .sorting_1,
[data-theme="dark"] table.dataTable.order-column.stripe tbody tr.even > .sorting_1 {
    background-color: #2e2e2e !important;
}

[data-theme="dark"] table.dataTable.display tbody tr:hover > .sorting_1,
[data-theme="dark"] table.dataTable.order-column.hover tbody tr:hover > .sorting_1 {
    background-color: #3a3a3a !important;
}

[data-theme="dark"] .datatable-toolbar input[type="text"] {
    background: #333 !important;
    border-color: #555 !important;
    color: #e0e0e0 !important;
}

[data-theme="dark"] .datatable-toolbar input[type="text"]::placeholder {
    color: #888 !important;
}

