/**
 * CDT sort styles.
 */

/* ===============================================
   Sortable header styles
   =============================================== */

/* Sortable header cell */
.cdt-table thead th.cdt-sortable {
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    position: relative;
    padding-right: 24px; /* Space for the sort icon. */
    transition: background-color 0.2s ease, color 0.2s ease;
}

/* Hover background */
.cdt-table thead th.cdt-sortable:hover {
    background-color: #f0f0f0;
    color: #0073aa;
}

/* Active sorted header */
.cdt-table thead th.cdt-sortable.cdt-sort-active {
    background-color: #e8f4f8;
    color: #0073aa;
    font-weight: 600;
}

/* ===============================================
   Sort icon styles
   =============================================== */

/* Sort icon container */
.cdt-sort-icon {
    display: inline-block;
    width: 16px;
    height: 16px;
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.3;
    transition: opacity 0.2s ease;
}

/* Reveal the icon on hover */
.cdt-sortable:hover .cdt-sort-icon {
    opacity: 0.6;
}

/* Emphasize the icon when active */
.cdt-sortable.cdt-sort-active .cdt-sort-icon {
    opacity: 1;
}

/* Default sort icon (double arrow) */
.cdt-sort-icon::before {
    content: '';
    display: block;
    width: 0;
    height: 0;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

/* Up arrow in the default state */
.cdt-sort-icon::before {
    top: 2px;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 6px solid #999;
}

.cdt-sort-icon::after {
    content: '';
    display: block;
    width: 0;
    height: 0;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: 2px;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid #999;
}

/* Ascending sort icon */
.cdt-sort-icon.asc::before {
    border-bottom-color: #0073aa;
}

.cdt-sort-icon.asc::after {
    opacity: 0.2;
}

/* Descending sort icon */
.cdt-sort-icon.desc::before {
    opacity: 0.2;
}

.cdt-sort-icon.desc::after {
    border-top-color: #0073aa;
}

/* ===============================================
   Alternate style: Unicode arrows
   Fallback when the CSS arrows do not render properly
   =============================================== */

/* Unicode arrow style */
.cdt-sort-icon-unicode {
    font-family: monospace;
    font-size: 12px;
    line-height: 1;
    color: #999;
}

.cdt-sortable:hover .cdt-sort-icon-unicode {
    color: #0073aa;
}

.cdt-sortable.sorted-asc .cdt-sort-icon-unicode::after {
    content: ' ▲';
    color: #0073aa;
}

.cdt-sortable.sorted-desc .cdt-sort-icon-unicode::after {
    content: ' ▼';
    color: #0073aa;
}

/* ===============================================
   Table row highlight
   =============================================== */

/* Optionally highlight the sorted column */
.cdt-table.cdt-highlight-sorted-column tbody td[data-column] {
    transition: background-color 0.3s ease;
}

.cdt-table.cdt-highlight-sorted-column.sorted-asc tbody td[data-column],
.cdt-table.cdt-highlight-sorted-column.sorted-desc tbody td[data-column] {
    position: relative;
}

/* Apply a highlight to cells in the sorted column */
.cdt-table.cdt-highlight-sorted-column thead th.cdt-sort-active ~ tbody tr td:nth-child(n) {
    /* nth-child must be configured dynamically in JavaScript, so only generic styling lives here. */
}

/* ===============================================
   Animation effects
   =============================================== */

/* Loading animation while sorting */
.cdt-table.cdt-sorting {
    opacity: 0.6;
    pointer-events: none;
    position: relative;
}

.cdt-table.cdt-sorting::after {
    content: '';
    display: block;
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin-left: -20px;
    margin-top: -20px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #0073aa;
    border-radius: 50%;
    animation: cdt-spin 1s linear infinite;
}

@keyframes cdt-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ===============================================
   Responsive adjustments
   =============================================== */

@media screen and (max-width: 768px) {
    /* Use a smaller sort icon on mobile. */
    .cdt-sort-icon {
        width: 12px;
        height: 12px;
    }

    .cdt-sort-icon::before,
    .cdt-sort-icon::after {
        border-left-width: 4px;
        border-right-width: 4px;
    }

    .cdt-sort-icon::before {
        border-bottom-width: 5px;
    }

    .cdt-sort-icon::after {
        border-top-width: 5px;
    }

    /* Adjust header padding. */
    .cdt-table thead th.cdt-sortable {
        padding-right: 20px;
    }
}

/* ===============================================
   Dark mode support (optional)
   =============================================== */

@media (prefers-color-scheme: dark) {
    .cdt-table thead th.cdt-sortable:hover {
        background-color: #2c2c2c;
        color: #4a9eff;
    }

    .cdt-table thead th.cdt-sortable.cdt-sort-active {
        background-color: #1e3a5f;
        color: #4a9eff;
    }

    .cdt-sort-icon::before,
    .cdt-sort-icon::after {
        border-bottom-color: #666;
        border-top-color: #666;
    }

    .cdt-sort-icon.asc::before {
        border-bottom-color: #4a9eff;
    }

    .cdt-sort-icon.desc::after {
        border-top-color: #4a9eff;
    }

    .cdt-table.cdt-sorting::after {
        border-color: #444;
        border-top-color: #4a9eff;
    }
}

/* ===============================================
   Accessibility
   =============================================== */

/* Focus outline */
.cdt-table thead th.cdt-sortable:focus {
    outline: 2px solid #0073aa;
    outline-offset: -2px;
}

/* Keyboard navigation */
.cdt-table thead th.cdt-sortable:focus:not(:focus-visible) {
    outline: none;
}

.cdt-table thead th.cdt-sortable:focus-visible {
    outline: 2px solid #0073aa;
    outline-offset: -2px;
}

/* Screen-reader helper text */
.cdt-sort-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* ===============================================
   Print styles
   =============================================== */

@media print {
    /* Hide sort icons when printing. */
    .cdt-sort-icon {
        display: none;
    }

    /* Disable highlight styling. */
    .cdt-table thead th.cdt-sortable.cdt-sort-active {
        background-color: transparent;
        font-weight: normal;
    }
}
