/* Custom DataTable Styles */
.datatable-container {
    padding: 15px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* DataTable Wrapper */
.dataTables_wrapper {
    padding: 10px 0;
}

/* Search Box Styling */
.dataTables_filter input {
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 5px 10px;
    margin-left: 10px;
    transition: border-color 0.3s;
}

.dataTables_filter input:focus {
    border-color: #4CAF50;
    outline: none;
}

/* Length Menu Styling */
.dataTables_length select {
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 5px;
    margin: 0 5px;
}

/* Table Header Styling */
table.dataTable thead th {
    background: linear-gradient(180deg, #f8f9fa 0%, #e9ecef 100%);
    border-bottom: 2px solid #dee2e6;
    font-weight: 600;
    color: #495057;
    white-space: normal;
    word-wrap: break-word;
    word-break: break-word;
    line-height: 1.3;
    vertical-align: middle;
    position: relative;
    padding: 12px 30px 12px 12px; /* Extra right padding for sort arrows */
    min-width: 80px;
    max-width: 200px;
}

/* Let DataTables handle the sorting icons with its default styles */
/* Just enhance the color for better visibility */
table.dataTable thead .sorting_asc,
table.dataTable thead .sorting_desc {
    background-color: #f0f8f0;
}

table.dataTable thead .sorting:hover {
    background-color: #f8f9fa;
    cursor: pointer;
}

/* Style the active/inactive arrows for better UX */
/* When ascending: dim the active up arrow, highlight the clickable down arrow */
table.dataTable thead .sorting_asc:before {
    opacity: 0.125 !important;
}

table.dataTable thead .sorting_asc:after {
    color: #4CAF50 !important;
    opacity: 0.6 !important;
}

/* When descending: dim the active down arrow, highlight the clickable up arrow */
table.dataTable thead .sorting_desc:after {
    opacity: 0.125 !important;
}

table.dataTable thead .sorting_desc:before {
    color: #4CAF50 !important;
    opacity: 0.6 !important;
}

/* Table Body */
table.dataTable tbody tr {
    transition: background-color 0.2s;
}

table.dataTable tbody tr:hover {
    background-color: #f8f9fa !important;
}

table.dataTable tbody td {
    padding: 10px 18px;
    border-bottom: 1px solid #e9ecef;
}

/* Striped Rows */
table.dataTable.stripe tbody tr.odd {
    background-color: #fcfcfc;
}

table.dataTable.stripe tbody tr.even {
    background-color: #ffffff;
}

/* Pagination Styling */
.dataTables_paginate {
    margin-top: 15px;
}

.dataTables_paginate .paginate_button a {
    padding: 5px 12px;
    margin: 0 2px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #fff;
    color: #333;
    cursor: pointer;
    transition: all 0.3s;
}

.dataTables_paginate .paginate_button:hover:not(.disabled) a {
    background: #4CAF50;
    color: #fff;
    border-color: #4CAF50;
}

.dataTables_paginate .paginate_button.current a {
    background: #4CAF50;
    color: #fff;
    border-color: #4CAF50;
}

.dataTables_paginate .paginate_button.disabled a {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Info Text */
.dataTables_info {
    padding: 8px 0;
    color: #6c757d;
    font-size: 14px;
}

/* Export Buttons Styling */
.dt-buttons {
    margin-bottom: 10px;
}

.dt-button {
    padding: 6px 15px;
    margin-right: 5px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: linear-gradient(180deg, #ffffff 0%, #f8f9fa 100%);
    color: #333;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s;
}

.dt-button:hover {
    background: linear-gradient(180deg, #4CAF50 0%, #45a049 100%);
    color: #fff;
    border-color: #45a049;
}

/* Column Visibility Button */
.dt-button-collection {
    position: absolute;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    padding: 10px;
    z-index: 1000;
}

.dt-button-collection .dt-button {
    display: block;
    width: 100%;
    text-align: left;
    margin: 2px 0;
}

/* Responsive Design */
table.dataTable.responsive-table tbody td {
    white-space: normal;
    word-wrap: break-word;
}

/* Column Reorder Indicator */
.DTCR_clonedTable {
    background-color: white !important;
    opacity: 0.8;
    z-index: 1000;
}

/* Search Highlight */
.dataTable mark {
    background-color: #ffeb3b;
    padding: 0;
}

/* Column Search Inputs */
.column-search-input {
    width: 100%;
    padding: 5px 8px;
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 13px;
    margin: 2px 0;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.column-search-input:focus {
    border-color: #4CAF50;
    box-shadow: 0 0 0 0.2rem rgba(76, 175, 80, 0.25);
    outline: none;
}

/* Search Header Row */
thead tr.search-header {
    background-color: #f8f9fa;
}

thead tr.search-header th {
    padding: 8px;
    font-weight: normal;
    border-bottom: 1px solid #dee2e6;
    position: relative;
}

/* Ensure DataTables default sorting only appears in first header row */
/* The search row shouldn't have sorting classes anyway */

/* Image Preview in Table */
.datatable-image-preview {
    max-width: 100px;
    max-height: 60px;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    transition: transform 0.2s;
}

.datatable-image-preview:hover {
    transform: scale(1.1);
}

/* Modal for Full Image */
.image-modal {
    display: none;
    position: fixed;
    z-index: 9999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
}

.image-modal-content {
    margin: auto;
    display: block;
    max-width: 90%;
    max-height: 90%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.image-modal-close {
    position: absolute;
    top: 15px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
}

.image-modal-close:hover {
    color: #bbb;
}

/* Loading Overlay */
.datatable-loading {
    position: relative;
}

.datatable-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
}

.datatable-spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #4CAF50;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Fixed Header */
.dataTables_scrollHead {
    background: #fff;
    border-bottom: 2px solid #dee2e6;
}

/* Responsive Table */
@media screen and (max-width: 768px) {
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter {
        float: none;
        text-align: center;
        margin-bottom: 10px;
    }
    
    .dataTables_wrapper .dataTables_paginate {
        float: none;
        text-align: center;
    }
    
    .dt-buttons {
        text-align: center;
        margin-bottom: 10px;
    }
}

/* Custom Scrollbar for DataTable */
.dataTables_scrollBody::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.dataTables_scrollBody::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.dataTables_scrollBody::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.dataTables_scrollBody::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Enhanced Table Responsive Wrapper */
.table-responsive {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}

.table-responsive > .table {
    margin-bottom: 0;
    min-width: 600px; /* Ensure minimum width for readability */
}

/* Prevent table from breaking layout */
.datatable-container .table-responsive {
    border: none;
    box-shadow: none;
}

/* Ensure DataTable scroll works with bootstrap responsive wrapper */
.table-responsive .dataTables_wrapper {
    overflow: visible;
}

/* Enhanced horizontal scrolling for large tables */
@media screen and (max-width: 1200px) {
    .table-responsive > .table {
        min-width: 800px;
    }
    
    .datatable-container {
        padding: 10px;
    }
}

@media screen and (max-width: 992px) {
    .table-responsive > .table {
        min-width: 700px;
    }
    
    table.dataTable thead th {
        min-width: 120px;
        font-size: 13px;
        padding: 8px 12px;
    }
    
    table.dataTable tbody td {
        padding: 8px 12px;
        font-size: 13px;
    }
}

@media screen and (max-width: 768px) {
    .table-responsive > .table {
        min-width: 600px;
    }
    
    table.dataTable thead th {
        min-width: 100px;
        font-size: 12px;
        padding: 6px 8px;
    }
    
    table.dataTable tbody td {
        padding: 6px 8px;
        font-size: 12px;
    }
    
    .dt-buttons .dt-button {
        padding: 4px 8px;
        font-size: 12px;
        margin-right: 2px;
    }
}

/* Sticky horizontal scrollbar for better UX */
.table-responsive {
    position: relative;
}

/* Custom scrollbar for table-responsive wrapper */
.table-responsive::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

.table-responsive::-webkit-scrollbar-track {
    background: #f8f9fa;
    border-radius: 6px;
}

.table-responsive::-webkit-scrollbar-thumb {
    background: #6c757d;
    border-radius: 6px;
    border: 2px solid #f8f9fa;
}

.table-responsive::-webkit-scrollbar-thumb:hover {
    background: #495057;
}