.table-preference-managed .fixed-table-header th,
.table-preference-managed .fixed-table-body th {
    position: relative;
}

.table-preference-managed .fixed-table-header > table,
.table-preference-managed .fixed-table-body > table,
.table-preference-managed .fixed-table-footer > table {
    table-layout: fixed;
}

.crm-single-table-kernel > .fixed-table-container {
    padding-bottom: 0 !important;
}

.crm-single-table-kernel .fixed-table-header,
.crm-single-table-kernel .fixed-table-footer:empty {
    display: none !important;
}

.crm-single-table-kernel .fixed-table-body {
    height: 100%;
    min-height: 0;
}

.crm-single-table-kernel .fixed-table-body > table {
    margin-top: 0 !important;
}

/* Managed list rows share the compact customer-list spacing. Keep natural
 * growth for wrapped text, images and controls, and honor taller user rows.
 * Direct-child selectors deliberately exclude nested editors/detail tables. */
.crm-single-table-kernel.table-preference-managed .fixed-table-body > table > tbody > tr > td {
    height: max(30px, var(--ui-table-row-height, 30px));
    padding-top: 4px !important;
    padding-bottom: 4px !important;
    vertical-align: middle;
}

/* Carry the existing surface through otherwise transparent rows so frozen
 * cells cannot show scrolling text underneath. Low specificity preserves
 * zebra stripes, hover, selection and business-status row backgrounds. */
.table-preference-managed :where(.fixed-table-body,
    .fixed-table-body > table,
    .fixed-table-body > table > tbody,
    .fixed-table-body > table > tbody > tr) {
    background-color: inherit;
}

html body .crm-single-table-kernel.table-preference-managed .fixed-table-container .fixed-table-body > table > thead,
html body .crm-single-table-kernel.table-preference-managed .fixed-table-container .fixed-table-body > table#table > thead {
    display: table-header-group !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    visibility: visible !important;
}

html body .crm-single-table-kernel.table-preference-managed .fixed-table-container .fixed-table-body > table > thead > tr,
html body .crm-single-table-kernel.table-preference-managed .fixed-table-container .fixed-table-body > table#table > thead > tr {
    display: table-row !important;
    height: var(--ui-table-header-height, 36px) !important;
    max-height: none !important;
    overflow: visible !important;
    visibility: visible !important;
}

html body .crm-single-table-kernel.table-preference-managed .fixed-table-container .fixed-table-body > table > thead > tr > th,
html body .crm-single-table-kernel.table-preference-managed .fixed-table-container .fixed-table-body > table#table > thead > tr > th {
    position: sticky !important;
    z-index: 5;
    top: 0;
    height: var(--ui-table-header-height, 36px) !important;
    max-height: none !important;
    padding-top: 4px !important;
    padding-bottom: 4px !important;
    line-height: calc(var(--ui-table-header-height, 36px) - 8px) !important;
    overflow: visible !important;
    visibility: visible !important;
    border-bottom: 1px solid var(--ui-border-color, #dce3ea) !important;
    background: var(--ui-table-header-bg, #f8fafc);
}

html body .crm-single-table-kernel.table-preference-managed .fixed-table-container .fixed-table-body > table > thead > tr > th .th-inner,
html body .crm-single-table-kernel.table-preference-managed .fixed-table-container .fixed-table-body > table#table > thead > tr > th .th-inner {
    display: block !important;
    /* Bootstrap Table can leave a stale pixel width after a column resize. */
    width: auto !important;
    max-width: 100%;
    box-sizing: border-box;
    height: calc(var(--ui-table-header-height, 36px) - 8px) !important;
    min-height: 0 !important;
    max-height: calc(var(--ui-table-header-height, 36px) - 8px) !important;
    padding: 0 !important;
    margin: 0 !important;
    line-height: calc(var(--ui-table-header-height, 36px) - 8px) !important;
    overflow: hidden !important;
    visibility: visible !important;
}

html body .crm-single-table-kernel.table-preference-managed .fixed-table-container .fixed-table-body > table > thead > tr > th .fht-cell,
html body .crm-single-table-kernel.table-preference-managed .fixed-table-container .fixed-table-body > table#table > thead > tr > th .fht-cell {
    display: none !important;
}

.table-preference-col-resizer {
    position: absolute;
    z-index: 20;
    top: 0;
    right: -5px;
    width: 10px;
    height: 100%;
    cursor: col-resize;
    background: transparent;
    touch-action: none;
}

/* The final handle must not extend the table's horizontal scroll range. */
.table-preference-managed th:last-child > .table-preference-col-resizer {
    right: 0;
}

.table-preference-managed .table-preference-sticky-left,
.table-preference-managed .table-preference-sticky-right {
    position: sticky !important;
    z-index: 3;
    background: inherit;
    background-clip: padding-box;
}

.table-preference-managed thead .table-preference-sticky-left,
.table-preference-managed thead .table-preference-sticky-right {
    z-index: 6;
}

.table-preference-managed .table-preference-sticky-left {
    box-shadow: 1px 0 0 var(--ui-border-color, #dce3ea);
}

.table-preference-managed .table-preference-sticky-right {
    box-shadow: -1px 0 0 var(--ui-border-color, #dce3ea);
}

.table-preference-managed .fixed-columns,
.table-preference-managed .fixed-columns-right {
    display: none !important;
}

.crm-table-scroll-host {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.crm-horizontal-drag-scroll,
.table-preference-pan-enabled tbody td {
    cursor: grab;
}

.crm-horizontal-drag-scroll thead,
.crm-horizontal-drag-scroll a,
.crm-horizontal-drag-scroll button,
.crm-horizontal-drag-scroll input,
.crm-horizontal-drag-scroll select,
.crm-horizontal-drag-scroll textarea,
.crm-horizontal-drag-scroll label,
.crm-horizontal-drag-scroll .btn,
.crm-horizontal-drag-scroll [contenteditable="true"],
.table-preference-pan-enabled tbody td a,
.table-preference-pan-enabled tbody td button,
.table-preference-pan-enabled tbody td input,
.table-preference-pan-enabled tbody td select,
.table-preference-pan-enabled tbody td textarea {
    cursor: auto;
}

.crm-horizontal-drag-scroll-active,
.crm-horizontal-drag-scroll-active *,
.table-preference-panning,
.table-preference-panning tbody td {
    cursor: grabbing !important;
    user-select: none !important;
}

.table-preference-col-resizer:hover {
    background: color-mix(in srgb, var(--ui-accent-color, #2f6fed) 34%, transparent);
}

body.table-preference-resizing {
    cursor: col-resize !important;
    user-select: none !important;
}

.table-preference-managed.table-preference-ellipsis .fixed-table-body tbody td {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* Actions are decisions, not long-form data. Keep every rendered action fully
 * visible while ordinary data cells continue to use the selected wrap mode. */
.table-preference-managed .fixed-table-body tbody td.table-preference-operation {
    overflow: visible !important;
    white-space: nowrap !important;
    text-overflow: clip !important;
}

.table-preference-managed.table-preference-wrap .fixed-table-body tbody td {
    min-width: 70px;
    white-space: normal;
    overflow-wrap: break-word;
    word-break: normal;
}

.table-preference-managed.table-preference-wrap .fixed-table-body tbody td > *:not(.btn-group):not(.btn) {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 4;
}

.table-preference-managed .fixed-table-body td.bs-checkbox,
.table-preference-managed .fixed-table-body td[data-table-preference-field*="amount"],
.table-preference-managed .fixed-table-body td[data-table-preference-field*="price"],
.table-preference-managed .fixed-table-body td[data-table-preference-field*="date"],
.table-preference-managed .fixed-table-body td[data-table-preference-field*="time"],
.table-preference-managed .fixed-table-body td[data-table-preference-field*="status"],
.table-preference-managed .fixed-table-body td[data-table-preference-field="operate"],
.table-preference-managed .fixed-table-body td .btn-group,
.table-preference-managed .fixed-table-body td .btn {
    white-space: nowrap;
}

.ui-table-preference-actions {
    align-items: end;
}

.ui-table-preference-reset-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.ui-table-preference-reset-actions .btn {
    min-height: 32px;
    white-space: nowrap;
}

.table-preference-native-scrollbar-hidden {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.table-preference-native-scrollbar-hidden::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;
}

.table-preference-persistent-scrollbar {
    position: sticky;
    z-index: 12;
    bottom: 0;
    width: 100%;
    height: 14px;
    overflow-x: scroll;
    overflow-y: hidden;
    border-top: 1px solid #dfe6ee;
    background: #f5f7fa;
    scrollbar-color: #7f93ad #e8edf3;
    scrollbar-width: auto;
    scrollbar-gutter: stable;
}

.table-preference-persistent-scrollbar > div {
    height: 1px;
}

.table-preference-persistent-scrollbar::-webkit-scrollbar {
    display: block;
    height: 13px;
}

.table-preference-persistent-scrollbar::-webkit-scrollbar-track {
    border-radius: 8px;
    background: #e8edf3;
}

.table-preference-persistent-scrollbar::-webkit-scrollbar-thumb {
    min-width: 36px;
    border: 2px solid #e8edf3;
    border-radius: 8px;
    background: #7f93ad;
}

.table-preference-persistent-scrollbar::-webkit-scrollbar-thumb:hover {
    background: #627994;
}
