/* Data Tables System */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    border-radius: 10px;
    position: relative;
}

.data-table,
.portal-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13.5px;
    text-align: left;
    background: var(--bg-card);
}

.data-table thead th,
.portal-table thead th {
    background-color: var(--bg-input);
    padding: 12px 16px;
    font-size: 11.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.data-table tbody td,
.portal-table tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-main);
    vertical-align: middle;
}

.data-table tbody tr:hover,
.portal-table tbody tr:hover {
    background-color: var(--bg-card-hover);
}

/* For free-text columns (error messages, descriptions, notes) that can run long
   and would otherwise stretch the whole table. Hover/tap shows the full text via title="". */
.cell-truncate {
    display: inline-block;
    max-width: 320px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    vertical-align: middle;
}

.data-table tbody tr:last-child td,
.portal-table tbody tr:last-child td {
    border-bottom: none;
}

/* Pinned Sticky Table Actions Column */
.data-table th.text-right,
.data-table td.text-right,
.portal-table th.text-right,
.portal-table td.text-right {
    text-align: right;
    white-space: nowrap;
    position: sticky;
    right: 0;
    z-index: 5;
    box-shadow: -4px 0 8px -2px rgba(0, 0, 0, 0.08);
}

.data-table thead th.text-right,
.portal-table thead th.text-right {
    background-color: var(--bg-input) !important;
}

.data-table tbody td.text-right,
.portal-table tbody td.text-right {
    background-color: var(--bg-card);
}

.data-table tbody tr:hover td.text-right,
.portal-table tbody tr:hover td.text-right {
    background-color: var(--bg-card-hover);
}

.table-actions-cell {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    justify-content: flex-end;
}

/* DataTable Enhancer Controls & Pagination */
.dt-container {
    width: 100%;
    margin-bottom: 12px;
}

.dt-controls-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
    position: sticky;
    left: 0;
}

.dt-search-box {
    position: relative;
    flex: 1 1 200px;
    max-width: 360px;
    min-width: 160px;
}

.dt-search-box i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 13px;
    pointer-events: none;
}

.dt-search-box input {
    padding-left: 36px !important;
    height: 38px;
    font-size: 13px;
    border-radius: 8px;
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.dt-search-box input:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.dt-length-box {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12.5px;
    color: var(--text-muted);
    font-weight: 600;
}

.dt-length-box select {
    height: 38px;
    padding: 4px 10px;
    font-size: 12.5px;
    border-radius: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    cursor: pointer;
}

/* Sortable Headers */
.data-table thead th.sortable,
.portal-table thead th.sortable {
    cursor: pointer;
    user-select: none;
    transition: color 0.15s ease, background-color 0.15s ease;
}

.data-table thead th.sortable:hover,
.portal-table thead th.sortable:hover {
    color: var(--primary);
    background-color: var(--bg-card-hover);
}

.dt-sort-icon {
    margin-left: 6px;
    font-size: 11px;
    opacity: 0.4;
    transition: opacity 0.15s ease, color 0.15s ease;
}

.data-table thead th.sortable.sort-asc .dt-sort-icon,
.data-table thead th.sortable.sort-desc .dt-sort-icon,
.portal-table thead th.sortable.sort-asc .dt-sort-icon,
.portal-table thead th.sortable.sort-desc .dt-sort-icon {
    opacity: 1;
    color: var(--primary);
}

/* Pagination Bar */
.dt-pagination-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
    flex-wrap: wrap;
    font-size: 12.5px;
    color: var(--text-muted);
    position: sticky;
    left: 0;
}

.dt-info {
    font-weight: 500;
}

/* With server-side paging, the info text and the "Show" selector sit side by
   side (templates/pagination.php). The client-side enhancer puts the selector
   above the table, so this group is not used there. */
.dt-pagination-left {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

/* Page buttons are rendered server-side as <a>; :disabled only applies to
   <button>, so the same look is given through aria. */
.dt-page-btn[aria-disabled="true"] {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.dt-pagination-nav {
    display: flex;
    align-items: center;
    gap: 4px;
}

.dt-page-btn {
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-main);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.dt-page-btn:hover:not(:disabled):not(.active) {
    background: var(--bg-card-hover);
    border-color: var(--primary);
    color: var(--primary);
}

.dt-page-btn.active {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
}

.dt-page-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
