/* FMS Tables */
.fms-table { width: 100%; border-collapse: collapse; font-size: var(--fms-text-sm); color: var(--fms-text); }
.fms-table th, .fms-table td { padding: 6px 10px; border-bottom: 1px solid var(--fms-border); text-align: left; white-space: nowrap; }
.fms-table tbody td { font-size: 0.82rem; }
.fms-table thead th {
    background: var(--fms-th-bg); color: var(--fms-th-color);
    font-size: var(--fms-text-xs); font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.5px;
    position: sticky; top: 0; z-index: 2;
    border-bottom: 1px solid var(--fms-th-border);
}
.fms-table tbody tr { transition: background-color 0.12s ease; }
.fms-table tbody tr:hover { background: var(--fms-tr-hover); }
.fms-table tbody tr:nth-child(even) { background: var(--fms-tr-stripe); }
.fms-table tbody tr:nth-child(even):hover { background: var(--fms-tr-hover); }

/* Row types */
.fms-tr-total { background: var(--fms-tr-total) !important; font-weight: 600; }
.fms-tr-section { background: var(--fms-tr-section) !important; font-weight: 600; }
.fms-tr-highlight { background: var(--fms-tr-highlight) !important; color: var(--fms-tr-highlight-text) !important; }
.fms-tr-orphan { background: var(--fms-tr-orphan) !important; }
.fms-tr-mismatch { background: var(--fms-tr-mismatch) !important; }

/* Number alignment */
.fms-table .text-end, .fms-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.fms-table .text-center { text-align: center; }

/* Compact variant */
.fms-table-compact th, .fms-table-compact td { padding: 4px 8px; font-size: var(--fms-text-xs); }

/* Sortable header */
.fms-table th[data-sort] { cursor: pointer; user-select: none; }
.fms-table th[data-sort]:hover { background: var(--fms-th-border); }
.fms-table th .sort-icon { margin-left: 4px; opacity: 0.4; }
.fms-table th.sorted .sort-icon { opacity: 1; }

/* Responsive wrapper */
.fms-table-wrapper { overflow: auto; border: 1px solid var(--fms-border); border-radius: var(--fms-radius); }
.fms-table-wrapper::-webkit-scrollbar { width: 8px; height: 8px; }
.fms-table-wrapper::-webkit-scrollbar-track { background: transparent; }
.fms-table-wrapper::-webkit-scrollbar-thumb { background: #adb5bd; border-radius: 4px; }
.fms-table-wrapper::-webkit-scrollbar-thumb:hover { background: #868e96; }
[data-theme="dark"] .fms-table-wrapper::-webkit-scrollbar-thumb { background: #444; }

/* Pagination */
.fms-pagination { display: flex; align-items: center; justify-content: space-between; gap: var(--fms-space-md); font-size: var(--fms-text-sm); color: var(--fms-text-secondary); }
.fms-pagination-pages { display: flex; gap: 2px; }
.fms-pagination-pages a, .fms-pagination-pages span {
    padding: 4px 10px; border-radius: var(--fms-radius); border: 1px solid var(--fms-border);
    color: var(--fms-text); font-size: var(--fms-text-xs); text-decoration: none;
}
.fms-pagination-pages a:hover { background: var(--fms-bg); }
.fms-pagination-pages .active { background: var(--fms-primary); color: var(--fms-text-inverse); border-color: var(--fms-primary); }

/* ============================================
   DataTables — Zero-conflict custom styling
   No DataTables CSS loaded. We own all styles.
   ============================================ */

/* Base table */
table.dataTable {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    font-family: var(--fms-font);
}

/* Header */
table.dataTable thead th {
    background: #000000;
    color: #ffffff;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    padding: 9px 14px;
    white-space: nowrap;
    border-bottom: 2px solid #333;
    border-right: 1px solid #222;
    cursor: pointer;
    position: relative;
    user-select: none;
}
table.dataTable thead th:last-child {
    border-right: none;
}
table.dataTable thead th:hover {
    background: #1a1a1a;
}

/* Sort indicators — DataTables adds these classes */
table.dataTable thead th.sorting,
table.dataTable thead th.sorting_asc,
table.dataTable thead th.sorting_desc {
    padding-right: 28px;
}

table.dataTable thead th.sorting:after {
    content: '⇅';
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.55rem;
    color: rgba(255,255,255,0.25);
}
table.dataTable thead th.sorting_asc:after {
    content: '▲';
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.5rem;
    color: #60a5fa;
}
table.dataTable thead th.sorting_desc:after {
    content: '▼';
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.5rem;
    color: #60a5fa;
}

/* Body */
table.dataTable tbody td {
    font-size: 0.82rem;
    padding: 6px 14px;
    border-bottom: 1px solid var(--fms-border-light);
    background: var(--fms-bg-card);
    color: var(--fms-text);
    white-space: nowrap;
}
table.dataTable tbody tr:hover td {
    background: var(--fms-tr-hover);
}

/* Striped rows */
table.dataTable tbody tr:nth-child(even) td {
    background: var(--fms-tr-stripe);
}
table.dataTable tbody tr:nth-child(even):hover td {
    background: var(--fms-tr-hover);
}

/* Scroll containers — DataTables creates these for scrollX */
.dataTables_scrollHead {
    background: #000000;
    border-bottom: 2px solid #333;
}
.dataTables_scrollBody {
    border: 1px solid var(--fms-border);
    border-top: none;
}
/* Hide duplicate thead in scroll body */
.dataTables_scrollBody thead {
    visibility: hidden;
    height: 0;
    line-height: 0;
    overflow: hidden;
}
.dataTables_scrollBody thead th {
    padding: 0;
    height: 0;
    border: none;
}

/* Wrapper */
.dataTables_wrapper {
    font-family: var(--fms-font);
    padding: 0;
    max-width: 100%;
    overflow: hidden;
}
.dataTables_wrapper::after {
    content: '';
    display: table;
    clear: both;
}

/* Top section: length + search */
.dataTables_wrapper .dataTables_length {
    float: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
}
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter {
    margin-bottom: 4px;
}
.dataTables_wrapper .dataTables_length label {
    font-size: 0.8rem;
    color: var(--fms-text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}
.dataTables_wrapper .dataTables_length select {
    font-family: var(--fms-font);
    font-size: 0.8rem;
    padding: 4px 10px;
    border: 1px solid var(--fms-border);
    border-radius: 4px;
    background: var(--fms-bg-card);
    color: var(--fms-text);
    min-width: 70px;
}

.dataTables_wrapper .dataTables_filter {
    float: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
}
.dataTables_wrapper .dataTables_filter label {
    font-size: 0;
}
.dataTables_wrapper .dataTables_filter input {
    font-family: var(--fms-font);
    font-size: 0.8rem;
    padding: 6px 14px;
    border: 1px solid var(--fms-border);
    border-radius: 4px;
    background: var(--fms-bg-card);
    color: var(--fms-text);
    width: 280px;
    outline: none;
    transition: border-color 0.2s;
}
.dataTables_wrapper .dataTables_filter input:focus {
    border-color: var(--fms-accent);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

/* Bottom section: info + pagination */
.dataTables_wrapper .dataTables_info {
    float: left;
    font-size: 0.75rem;
    color: var(--fms-text-secondary);
    padding: 10px 12px;
}

.dataTables_wrapper .dataTables_paginate {
    float: right;
    padding: 8px 12px;
    display: flex;
    gap: 3px;
    align-items: center;
}
.dataTables_wrapper .dataTables_paginate span {
    display: flex;
    gap: 3px;
}
.dataTables_wrapper .dataTables_paginate .paginate_button {
    font-family: var(--fms-font);
    font-size: 0.72rem;
    padding: 4px 10px;
    border: 1px solid var(--fms-border);
    border-radius: 4px;
    background: var(--fms-bg-card);
    color: var(--fms-text);
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
}
.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    background: var(--fms-bg);
    border-color: var(--fms-accent);
    color: var(--fms-accent);
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background: var(--fms-accent);
    color: #ffffff;
    border-color: var(--fms-accent);
    font-weight: 600;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled {
    opacity: 0.3;
    cursor: default;
    pointer-events: none;
}

/* Processing overlay */
.dataTables_wrapper .dataTables_processing {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--fms-bg-card);
    border: 1px solid var(--fms-border);
    border-radius: 6px;
    padding: 10px 20px;
    font-size: 0.8rem;
    color: var(--fms-text);
    z-index: 20;
    box-shadow: var(--fms-shadow-md);
}

/* Empty table */
.dataTables_wrapper .dataTables_empty {
    text-align: center;
    padding: 40px;
    color: var(--fms-text-secondary);
    font-size: 0.85rem;
}

/* ======= Dark Mode ======= */
[data-theme="dark"] table.dataTable thead th {
    background: #111111;
    border-bottom-color: #444;
    border-right-color: #333;
}
[data-theme="dark"] table.dataTable thead th:hover {
    background: #222222;
}

[data-theme="dark"] table.dataTable tbody td {
    background: var(--fms-bg-card);
    color: var(--fms-text);
    border-bottom-color: var(--fms-border);
}
[data-theme="dark"] table.dataTable tbody tr:hover td {
    background: var(--fms-tr-hover);
}
[data-theme="dark"] table.dataTable tbody tr:nth-child(even) td {
    background: var(--fms-tr-stripe);
}

[data-theme="dark"] .dataTables_scrollHead {
    background: #111111;
    border-bottom-color: #444;
}
[data-theme="dark"] .dataTables_scrollBody {
    border-color: var(--fms-border);
}

[data-theme="dark"] .dataTables_wrapper .dataTables_length select,
[data-theme="dark"] .dataTables_wrapper .dataTables_filter input {
    background: var(--fms-bg-card);
    color: var(--fms-text);
    border-color: var(--fms-border);
}

[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button {
    background: var(--fms-bg-card);
    color: var(--fms-text);
    border-color: var(--fms-border);
}
[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    background: rgba(37, 99, 235, 0.15);
    border-color: var(--fms-accent);
}
[data-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background: var(--fms-accent);
    color: #ffffff;
    border-color: var(--fms-accent);
}

/* Reset sort button */
.fms-dt-reset-sort {
    font-family: var(--fms-font);
    font-size: 0.72rem;
    padding: 5px 10px;
    margin-right: 8px;
    border: 1px solid var(--fms-border);
    border-radius: 4px;
    background: var(--fms-bg-card);
    color: var(--fms-text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    vertical-align: middle;
    line-height: 1.4;
}
.fms-dt-reset-sort:hover {
    border-color: var(--fms-accent);
    color: var(--fms-accent);
    background: var(--fms-bg);
}
[data-theme="dark"] .fms-dt-reset-sort {
    background: var(--fms-bg-card);
    color: var(--fms-text-secondary);
    border-color: var(--fms-border);
}
[data-theme="dark"] .fms-dt-reset-sort:hover {
    border-color: var(--fms-accent);
    color: var(--fms-accent);
}

/* View toggle buttons — align with length dropdown */
.fms-dt-view-toggle {
    display: inline-flex;
    gap: 0;
    margin-left: 12px;
    vertical-align: middle;
}
.fms-dt-view-toggle button {
    font-family: var(--fms-font);
    font-size: 0.72rem;
    padding: 4px 10px;
    border: 1px solid var(--fms-border);
    background: var(--fms-bg-card);
    color: var(--fms-text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    line-height: 1.4;
}
.fms-dt-view-toggle button:first-child {
    border-radius: 4px 0 0 4px;
    border-right: none;
}
.fms-dt-view-toggle button:last-child {
    border-radius: 0 4px 4px 0;
}
.fms-dt-view-toggle button.active {
    background: var(--fms-primary);
    color: var(--fms-text-inverse);
    border-color: var(--fms-primary);
}
[data-theme="dark"] .fms-dt-view-toggle button {
    background: var(--fms-bg-card);
    color: var(--fms-text-secondary);
    border-color: var(--fms-border);
}
[data-theme="dark"] .fms-dt-view-toggle button.active {
    background: var(--fms-accent);
    border-color: var(--fms-accent);
    color: #ffffff;
}

/* Striped mode (default) */
table.dataTable.fms-striped tbody tr:nth-child(even) td {
    background: var(--fms-tr-stripe);
}
table.dataTable.fms-striped tbody tr:nth-child(even):hover td {
    background: var(--fms-tr-hover);
}
table.dataTable.fms-striped tbody td {
    border-bottom: none;
    border-right: none;
}

/* Bordered mode */
table.dataTable.fms-bordered tbody td {
    border: 1px solid var(--fms-border);
}
table.dataTable.fms-bordered tbody tr:nth-child(even) td {
    background: var(--fms-bg-card);
}
table.dataTable.fms-bordered tbody tr:hover td {
    background: var(--fms-tr-hover);
}

/* Dark mode for both */
[data-theme="dark"] table.dataTable.fms-striped tbody tr:nth-child(even) td {
    background: var(--fms-tr-stripe);
}
[data-theme="dark"] table.dataTable.fms-bordered tbody td {
    border-color: var(--fms-border);
}

/* Toolbar — single line with space-between */
.fms-dt-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    gap: 12px;
    flex-wrap: nowrap;
}
.fms-dt-toolbar .dataTables_length {
    float: none;
    display: flex;
    align-items: center;
    padding: 0;
    margin: 0;
    white-space: nowrap;
}
.fms-dt-toolbar .dataTables_filter {
    float: none;
    display: flex;
    align-items: center;
    padding: 0;
    margin: 0;
}
.fms-dt-toolbar .fms-dt-view-toggle {
    margin-left: 12px;
}
.fms-dt-toolbar .fms-dt-reset-sort {
    margin-right: 8px;
}

/* Bottom bar */
.fms-dt-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
}
.fms-dt-bottom .dataTables_info {
    float: none;
    padding: 0;
}
.fms-dt-bottom .dataTables_paginate {
    float: none;
    padding: 0;
}

