/* ==========================================================================
   DataTables Custom Styling & Fixes (AdminLTE & Universal Theme Compatibility)
   ========================================================================== */

/* 1. Prevent buttons from inheriting conflicting dark grey background (#6c757d) from .btn-secondary */
.dt-buttons .btn[class*="btn-outline-"],
div.dataTables_wrapper div.dt-buttons.btn-group .btn[class*="btn-outline-"],
div.dt-buttons .btn[class*="btn-outline-"] {
    background-color: transparent !important;
    background-image: none !important;
    box-shadow: none !important;
}

/* 2. Style individual outline button variants cleanly */
.dt-buttons .btn.btn-outline-secondary,
div.dataTables_wrapper div.dt-buttons .btn.btn-outline-secondary {
    color: #6c757d !important;
    border-color: #6c757d !important;
}
.dt-buttons .btn.btn-outline-secondary:hover,
div.dataTables_wrapper div.dt-buttons .btn.btn-outline-secondary:hover {
    background-color: #6c757d !important;
    color: #ffffff !important;
}

.dt-buttons .btn.btn-outline-success,
div.dataTables_wrapper div.dt-buttons .btn.btn-outline-success {
    color: #28a745 !important;
    border-color: #28a745 !important;
}
.dt-buttons .btn.btn-outline-success:hover,
div.dataTables_wrapper div.dt-buttons .btn.btn-outline-success:hover {
    background-color: #28a745 !important;
    color: #ffffff !important;
}

.dt-buttons .btn.btn-outline-danger,
div.dataTables_wrapper div.dt-buttons .btn.btn-outline-danger {
    color: #dc3545 !important;
    border-color: #dc3545 !important;
}
.dt-buttons .btn.btn-outline-danger:hover,
div.dataTables_wrapper div.dt-buttons .btn.btn-outline-danger:hover {
    background-color: #dc3545 !important;
    color: #ffffff !important;
}

.dt-buttons .btn.btn-outline-primary,
div.dataTables_wrapper div.dt-buttons .btn.btn-outline-primary {
    color: #007bff !important;
    border-color: #007bff !important;
}
.dt-buttons .btn.btn-outline-primary:hover,
div.dataTables_wrapper div.dt-buttons .btn.btn-outline-primary:hover {
    background-color: #007bff !important;
    color: #ffffff !important;
}

/* 3. Button spacing - give each button separation instead of merged block */
.dt-buttons.btn-group,
div.dataTables_wrapper div.dt-buttons.btn-group {
    display: inline-flex !important;
    flex-wrap: wrap !important;
    gap: 0.375rem !important;
}
.dt-buttons.btn-group > .btn,
div.dataTables_wrapper div.dt-buttons.btn-group > .btn {
    border-radius: 4px !important;
    margin-left: 0 !important;
    font-size: 0.8125rem !important;
    font-weight: 500 !important;
    padding: 0.28rem 0.7rem !important;
    line-height: 1.5 !important;
}

/* 4. Column visibility dropdown menu styling */
div.dt-button-collection {
    border-radius: 6px !important;
    box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.15) !important;
    border: 1px solid rgba(0, 0, 0, 0.15) !important;
    padding: 0.4rem 0 !important;
    z-index: 2050 !important;
}
div.dt-button-collection .dt-button.dropdown-item {
    font-size: 0.8125rem !important;
    padding: 0.35rem 1rem !important;
}

/* 5. DataTables header and wrapper padding for all themes */
.dt-tabler-wrapper {
    padding: 0.85rem 1rem !important;
    width: 100% !important;
    box-sizing: border-box !important;
}
body.theme-tabler .dt-tabler-wrapper {
    padding: 0 !important;
}
.dt-header-row {
    margin: 0 0 0.75rem 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    flex-wrap: wrap !important;
    gap: 0.75rem !important;
    width: 100% !important;
    box-sizing: border-box !important;
}
/* If col-* classes are present inside dt-header-row or dt-footer-row, neutralize rigid grid widths */
.dt-header-row > [class*="col-"],
.dt-footer-row > [class*="col-"] {
    max-width: none !important;
    width: auto !important;
    flex: 0 1 auto !important;
}
.dt-buttons-col {
    display: flex !important;
    align-items: center !important;
    flex: 0 1 auto !important;
    padding: 0 !important;
}
.dt-search-col {
    display: flex !important;
    justify-content: flex-end !important;
    align-items: center !important;
    flex: 0 1 auto !important;
    margin-left: auto !important;
    padding: 0 !important;
}
.dt-search-col .dataTables_filter,
div.dataTables_wrapper div.dataTables_filter {
    margin: 0 !important;
    margin-left: auto !important;
    text-align: right !important;
}
.dt-search-col label,
div.dataTables_wrapper div.dataTables_filter label {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    margin-bottom: 0 !important;
    gap: 0.5rem !important;
    font-size: 0.875rem !important;
    white-space: nowrap !important;
}
.dt-search-col input.form-control-sm,
div.dataTables_wrapper div.dataTables_filter input {
    margin-left: 0.35rem !important;
    display: inline-block !important;
    width: auto !important;
    min-width: 180px !important;
    border-radius: 4px !important;
}
.dt-footer-row,
div.dataTables_wrapper > .row:last-child {
    margin: 0.75rem 0 0 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    flex-wrap: wrap !important;
    gap: 0.75rem !important;
    padding: 0.5rem 0 !important;
    font-size: 0.875rem !important;
    width: 100% !important;
    box-sizing: border-box !important;
}
.dt-info-col,
div.dataTables_wrapper div.dataTables_info {
    display: flex !important;
    align-items: center !important;
    flex: 0 1 auto !important;
    padding: 0 !important;
    margin: 0 !important;
    white-space: nowrap !important;
}
.dt-paginate-col,
div.dataTables_wrapper > .row:last-child > [class*="col-"]:last-child {
    display: flex !important;
    justify-content: flex-end !important;
    align-items: center !important;
    flex: 0 1 auto !important;
    margin-left: auto !important;
    padding: 0 !important;
}
div.dataTables_wrapper div.dataTables_paginate {
    display: flex !important;
    justify-content: flex-end !important;
    align-items: center !important;
    width: 100% !important;
    margin: 0 !important;
    margin-left: auto !important;
    padding: 0 !important;
    flex-wrap: wrap !important;
    text-align: right !important;
}
div.dataTables_wrapper div.dataTables_paginate ul.pagination {
    margin: 0 !important;
    justify-content: flex-end !important;
    margin-left: auto !important;
}
div.dataTables_wrapper div.dataTables_paginate .paginate_button {
    cursor: pointer !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
}

/* Also ensure standard DataTables top row (length & search) is aligned */
div.dataTables_wrapper > .row:first-child {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    flex-wrap: wrap !important;
    width: 100% !important;
    margin-bottom: 0.5rem !important;
}
div.dataTables_wrapper > .row:first-child > [class*="col-"]:last-child {
    display: flex !important;
    justify-content: flex-end !important;
    align-items: center !important;
    margin-left: auto !important;
}
div.dataTables_wrapper div.dataTables_filter {
    display: flex !important;
    justify-content: flex-end !important;
    align-items: center !important;
    width: 100% !important;
    margin: 0 !important;
    margin-left: auto !important;
    text-align: right !important;
}

@media (max-width: 767.98px) {
    div.dataTables_wrapper > .row:first-child,
    div.dataTables_wrapper > .row:last-child,
    .dt-header-row,
    .dt-footer-row {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.5rem !important;
    }
    div.dataTables_wrapper > .row:first-child > [class*="col-"],
    div.dataTables_wrapper > .row:last-child > [class*="col-"],
    .dt-buttons-col,
    .dt-search-col,
    .dt-info-col,
    .dt-paginate-col,
    .dt-header-row > [class*="col-"],
    .dt-footer-row > [class*="col-"] {
        width: 100% !important;
        max-width: 100% !important;
        justify-content: center !important;
        margin-left: 0 !important;
        text-align: center !important;
    }
    .dt-buttons.btn-group {
        justify-content: center !important;
        width: 100% !important;
    }
    div.dataTables_wrapper div.dataTables_filter {
        width: 100% !important;
        justify-content: center !important;
        text-align: center !important;
        margin: 0 auto !important;
    }
    div.dataTables_wrapper div.dataTables_filter label {
        width: 100% !important;
        justify-content: center !important;
    }
    div.dataTables_wrapper div.dataTables_filter input {
        width: 100% !important;
        max-width: 260px !important;
    }
    div.dataTables_wrapper div.dataTables_info {
        justify-content: center !important;
        text-align: center !important;
        width: 100% !important;
    }
    div.dataTables_wrapper div.dataTables_paginate {
        justify-content: center !important;
        width: 100% !important;
        margin: 0 auto !important;
    }
    div.dataTables_wrapper div.dataTables_paginate ul.pagination {
        justify-content: center !important;
    }
}

/* 6. Dark mode adjustments */
.dark-mode .dt-buttons .btn.btn-outline-secondary,
[data-bs-theme="dark"] .dt-buttons .btn.btn-outline-secondary,
[data-color-mode="dark"] .dt-buttons .btn.btn-outline-secondary {
    color: #adb5bd !important;
    border-color: #6c757d !important;
}
.dark-mode .dt-buttons .btn.btn-outline-secondary:hover,
[data-bs-theme="dark"] .dt-buttons .btn.btn-outline-secondary:hover,
[data-color-mode="dark"] .dt-buttons .btn.btn-outline-secondary:hover {
    background-color: #6c757d !important;
    color: #ffffff !important;
}
.dark-mode div.dt-button-collection,
[data-bs-theme="dark"] div.dt-button-collection,
[data-color-mode="dark"] div.dt-button-collection {
    background-color: #343a40 !important;
    border-color: #4b545c !important;
    color: #fff !important;
}
.dark-mode div.dt-button-collection .dt-button.dropdown-item,
[data-bs-theme="dark"] div.dt-button-collection .dt-button.dropdown-item,
[data-color-mode="dark"] div.dt-button-collection .dt-button.dropdown-item {
    color: #ced4da !important;
}
.dark-mode div.dt-button-collection .dt-button.dropdown-item:hover,
[data-bs-theme="dark"] div.dt-button-collection .dt-button.dropdown-item:hover,
[data-color-mode="dark"] div.dt-button-collection .dt-button.dropdown-item:hover {
    background-color: #495057 !important;
    color: #fff !important;
}
