/**
 * DataTables Custom Styles for Django Project
 * Compatible with Bootstrap 5 and Bootstrap Icons
 *
 * Usage: Include this file in any template using DataTables
 * <link rel="stylesheet" href="{% static 'css/datatables-custom.css' %}">
 */

/* ========================================
   1. SORTING ICONS CUSTOMIZATION
   ======================================== */


/* Remove ONLY the default DataTables sorting icons (not our custom ones) */
/* Be specific about what we're removing */
table.dataTable > thead .sorting:before,
table.dataTable > thead .sorting_asc:before,
table.dataTable > thead .sorting_desc:before,
table.dataTable > thead .sorting_asc_disabled:before,
table.dataTable > thead .sorting_desc_disabled:before,
table.dataTable > thead .sorting_asc_disabled:after,
table.dataTable > thead .sorting_desc_disabled:after {
    content: none !important;
}

/* Sortable column (shows both arrows) */
table.dataTable thead .sorting {
    position: relative;
    cursor: pointer;
    padding-right: 25px !important;
}

table.dataTable thead .sorting:after {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    content: "⇅" !important; /* Unicode that always works */
    opacity: 0.5;
    font-size: 1.2rem;
    transition: opacity 0.2s ease;
}

/* Column sorted ascending */
table.dataTable thead .sorting_asc {
    position: relative;
    cursor: pointer;
    padding-right: 25px !important;
}

table.dataTable thead .sorting_asc:before {
    content: none !important; /* Remove default */
}

table.dataTable thead .sorting_asc:after {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    content: "↑" !important; /* Unicode up arrow */
    opacity: 0.8;
    font-size: 1.2rem;
    color: #0d6efd; /* Bootstrap primary color */
}

/* Column sorted descending */
table.dataTable thead .sorting_desc {
    position: relative;
    cursor: pointer;
    padding-right: 25px !important;
}

table.dataTable thead .sorting_desc:before {
    content: none !important; /* Remove default */
}

table.dataTable thead .sorting_desc:after {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    content: "↓" !important; /* Unicode down arrow */
    opacity: 0.8;
    font-size: 1.2rem;
    color: #0d6efd; /* Bootstrap primary color */
}

/* Hover effect on sortable columns */
table.dataTable thead .sorting:hover:after {
    opacity: 0.6;
}

table.dataTable thead .sorting_asc:hover:after,
table.dataTable thead .sorting_desc:hover:after {
    opacity: 1;
}

/* Disabled sorting columns */
table.dataTable thead .sorting_disabled {
    cursor: default;
}

/* ========================================
   2. BOOTSTRAP 5 PAGINATION STYLING
   ======================================== */

/* Ensure proper Bootstrap 5 pagination structure */
.dataTables_wrapper .dataTables_paginate {
    margin-top: 1rem;
    display: flex;
    justify-content: flex-end;
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
    box-sizing: border-box;
    display: inline-block;
    min-width: 1.5em;
    padding: 0;
    margin: 0;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    border: none;
    background: transparent;
}

.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    background: none;
    border: none;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
    background: none !important;
    border: none !important;
    color: inherit !important;
}

/* ========================================
   3. FORM CONTROLS STYLING
   ======================================== */

/* Length menu select */
.dataTables_wrapper .dataTables_length select {
    width: auto;
    display: inline-block;
    margin: 0 0.5rem;
}

.dataTables_wrapper .dataTables_length label {
    font-weight: normal;
    margin-bottom: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Search input (if enabled) */
.dataTables_wrapper .dataTables_filter {
    text-align: right;
}

.dataTables_wrapper .dataTables_filter label {
    font-weight: normal;
    margin-bottom: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: flex-end;
}

.dataTables_wrapper .dataTables_filter input {
    width: auto;
    display: inline-block;
    margin-left: 0.5rem;
}

/* ========================================
   4. INFO TEXT STYLING
   ======================================== */

.dataTables_wrapper .dataTables_info {
    color: #6c757d;
    font-size: 0.875rem;
    padding-top: 0.85rem;
}

/* ========================================
   5. PROCESSING INDICATOR
   ======================================== */

.dataTables_processing {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 40px;
    margin-left: -50%;
    margin-top: -20px;
    text-align: center;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid #ddd;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ========================================
   0006_controlpoint_migrate_to_core_location.py. EMPTY TABLE STYLING
   ======================================== */

.dataTables_empty {
    text-align: center;
    padding: 2rem !important;
    color: #6c757d;
}

/* ========================================
   7. RESPONSIVE ADJUSTMENTS
   ======================================== */

/* Mobile responsive */
@media (max-width: 767px) {
    .dataTables_wrapper .row {
        margin: 0;
    }

    .dataTables_wrapper .col-sm-12 {
        padding: 0;
        margin-bottom: 0.5rem;
    }

    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter {
        text-align: center;
    }

    .dataTables_wrapper .dataTables_filter label,
    .dataTables_wrapper .dataTables_length label {
        justify-content: center;
    }

    .dataTables_wrapper .dataTables_info {
        text-align: center;
        margin-bottom: 0.5rem;
    }

    .dataTables_wrapper .dataTables_paginate {
        justify-content: center;
    }

    /* Smaller font size on mobile */
    table.dataTable {
        font-size: 0.875rem;
    }

    /* Reduce padding on mobile */
    table.dataTable thead th,
    table.dataTable tbody td {
        padding: 0.5rem;
    }
}

/* Tablet adjustments */
@media (min-width: 768px) and (max-width: 991px) {
    table.dataTable {
        font-size: 0.9375rem;
    }
}

/* ========================================
   8. UTILITIES & HELPERS
   ======================================== */

/* Highlight row on hover */
table.dataTable.table-hover tbody tr:hover {
    background-color: rgba(0, 0, 0, 0.035);
}

/* Striped table compatibility */
table.dataTable.table-striped tbody tr.odd {
    background-color: rgba(0, 0, 0, 0.03);
}

/* Fixed header support */
table.dataTable.fixedHeader-floating {
    position: fixed !important;
}

/* ========================================
   9. DARK MODE SUPPORT (Optional)
   ======================================== */

@media (prefers-color-scheme: dark) {
    .dataTables_wrapper .dataTables_info {
        color: #adb5bd;
    }

    .dataTables_processing {
        background: rgba(33, 37, 41, 0.9);
        color: #f8f9fa;
        border-color: #495057;
    }

    .dataTables_empty {
        color: #adb5bd;
    }

    table.dataTable.table-hover tbody tr:hover {
        background-color: rgba(255, 255, 255, 0.035);
    }

    table.dataTable.table-striped tbody tr.odd {
        background-color: rgba(255, 255, 255, 0.03);
    }
}

/* Bootstrap 5 dark theme class support */
[data-bs-theme="dark"] .dataTables_wrapper .dataTables_info {
    color: #adb5bd;
}

[data-bs-theme="dark"] .dataTables_processing {
    background: rgba(33, 37, 41, 0.9);
    color: #f8f9fa;
    border-color: #495057;
}

[data-bs-theme="dark"] .dataTables_empty {
    color: #adb5bd;
}

/* ========================================
   10. CUSTOM CLASSES
   ======================================== */

/* Compact table style */
.dataTable-compact {
    font-size: 0.875rem;
}

.dataTable-compact thead th,
.dataTable-compact tbody td {
    padding: 0.25rem 0.5rem;
}

/* No borders style */
.dataTable-no-borders,
.dataTable-no-borders thead,
.dataTable-no-borders tbody,
.dataTable-no-borders tfoot,
.dataTable-no-borders th,
.dataTable-no-borders td {
    border: none !important;
}

/* Center align specific columns */
.dt-center {
    text-align: center !important;
}

.dt-right {
    text-align: right !important;
}

.dt-left {
    text-align: left !important;
}

/* ========================================
   11. PRINT STYLES
   ======================================== */

@media print {
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter,
    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        display: none !important;
    }

    table.dataTable {
        border-collapse: collapse !important;
    }

    table.dataTable thead th,
    table.dataTable tbody td {
        border: 1px solid #dee2e6 !important;
        padding: 0.5rem !important;
    }
}