/* Custom styling for Tabulator tables */

.tabulator-table-container {
    position: relative;
}

.tabulator-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
    background-color: rgba(255, 255, 255, 0.9);
    padding: 20px;
    border-radius: 4px;
}

/* Hide ALL loading overlays and spinners */
.tabulator-loading,
.tabulator .tabulator-loading,
.tabulator-loading-overlay,
#preservation_queries_table_loading,
.tabulator-table-container .tabulator-loading,
.tabulator-table-container [role="status"]:has(.spinner-border) {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
}

/* Hide spinners within loading containers */
.tabulator-loading .spinner-border,
#preservation_queries_table_loading .spinner-border {
    display: none !important;
    visibility: hidden !important;
}

/* Hide spinners in content area that are not part of the table */
#kr-preservation-content .text-center.p-4:has(.spinner-border),
#kr-preservation-content .spinner-border:not(.tabulator-table-container .spinner-border) {
    display: none !important;
    visibility: hidden !important;
}

/* Ensure Tabulator cells are visible, but respect hidden columns */
/* Only apply inline-block if the element doesn't have display:none inline style */
.tabulator-cell:not(.tabulator-cell-hidden):not([aria-hidden="true"]) {
    display: inline-flex;
    justify-content: center;
    align-items: center;
}

.tabulator-row .tabulator-cell:not(.tabulator-cell-hidden):not([aria-hidden="true"]) {
    display: inline-flex;
    justify-content: center;
    align-items: center;
}

/* Hide columns that are marked as hidden by Tabulator */
.tabulator-col.tabulator-col-hidden,
.tabulator-col[aria-hidden="true"],
.tabulator-cell.tabulator-cell-hidden,
.tabulator-cell[aria-hidden="true"] {
    display: none !important;
    width: 0 !important;
    min-width: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
}

/* Respect inline display:none styles from Tabulator (has higher specificity than our rules) */
.tabulator-cell[style*="display: none"],
.tabulator-cell[style*="display:none"] {
    display: none !important;
}

.tabulator-col[style*="display: none"],
.tabulator-col[style*="display:none"] {
    display: none !important;
}

/* Set max width for columns */
.tabulator-col {
    max-width: 400px !important;
}

.tabulator-cell {
    max-width: 400px !important;
    overflow: visible;
    white-space: normal;
    word-wrap: break-word !important;
    word-break: break-word !important;
    white-space: normal !important;
}

/* Fix horizontal scrolling sync between header and body */
.tabulator-tableHolder {
    overflow-x: auto !important;
}

.tabulator-header-contents {
    overflow-x: auto !important;
}

/* Ensure header and body scroll together - use same scroll behavior */
.tabulator .tabulator-header {
    overflow-x: hidden;
}

.tabulator .tabulator-header .tabulator-header-contents {
    overflow-x: auto;
}

.tabulator .tabulator-tableHolder {
    overflow-x: auto !important;
}

/* Ensure Tabulator headers are visible - override inline styles */
.tabulator-headers[style*="height: 0px"],
.tabulator-headers[style*="height:0px"] {
    height: auto !important;
    min-height: 27px !important;
}

.tabulator-header {
    height: auto !important;
    min-height: 27px !important;
}

.tabulator-header .tabulator-header-contents {
    height: auto !important;
    min-height: 27px !important;
}

.tabulator-header .tabulator-header-contents .tabulator-headers {
    height: auto !important;
    min-height: 27px !important;
}

.tabulator-col {
    height: auto !important;
    min-height: 27px !important;
}

/* Force header visibility */
div.tabulator-headers {
    height: auto !important;
    min-height: 27px !important;
    display: block !important;
}

/* Ensure Bootstrap theme integration */
.tabulator .tabulator-header {
    border-top: 1px solid #dee2e6;
    background-color: #f8f9fa;
}

.tabulator .tabulator-header .tabulator-col {
    background-color: #f8f9fa;
    border-right: 1px solid #dee2e6;
}

.tabulator .tabulator-header .tabulator-col:hover {
    background-color: #e9ecef;
}

.tabulator .tabulator-tableHolder {
    border: 1px solid #dee2e6;
}

.tabulator .tabulator-row {
    border-bottom: 1px solid #dee2e6;
}

.tabulator .tabulator-row:hover {
    background-color: #f8f9fa;
}

.tabulator-row.tabulator-selected {
    background-color: #cfe2ff !important;
}

.tabulator-row.tabulator-selected:hover {
    background-color: #b6d4fe !important;
}

/* Custom row styling classes */
.tabulator-row.table-success {
    background-color: #d1e7dd !important;
}

.tabulator-row.table-success:hover {
    background-color: #badbcc !important;
}

.tabulator-row.table-warning {
    background-color: #fff3cd !important;
}

.tabulator-row.table-warning:hover {
    background-color: #ffecb5 !important;
}

.tabulator-row.table-danger {
    background-color: #f8d7da !important;
}

.tabulator-row.table-danger:hover {
    background-color: #f5c2c7 !important;
}

/* Cell styling */
.tabulator-cell {
    padding: 8px;
}

/* Header filter styling */
.tabulator .tabulator-header-filter input,
.tabulator .tabulator-header-filter select {
    width: 100%;
    padding: 4px;
    border: 1px solid #ced4da;
    border-radius: 0.25rem;
    font-size: 0.875rem;
}

.tabulator .tabulator-header-filter input:focus,
.tabulator .tabulator-header-filter select:focus {
    outline: none;
    border-color: #86b7fe;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

/* Sort indicators */
.tabulator .tabulator-col .tabulator-col-sorter {
    color: #6c757d;
}

.tabulator .tabulator-col.tabulator-sortable:hover .tabulator-col-sorter {
    color: #495057;
}

.tabulator .tabulator-col.tabulator-sorting-asc .tabulator-col-sorter,
.tabulator .tabulator-col.tabulator-sorting-desc .tabulator-col-sorter {
    color: #0d6efd;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .tabulator-table-container .input-group {
        max-width: 100% !important;
        margin-bottom: 0.5rem;
    }
    
    .tabulator-table-container .d-flex {
        flex-direction: column;
        align-items: stretch !important;
    }
    
    .tabulator-table-container .btn-group {
        width: 100%;
        margin-top: 0.5rem;
    }
    
    .tabulator-table-container .btn-group .btn {
        flex: 1;
    }
}

/* Loading state */
.tabulator .tabulator-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
}

/* Empty state */
.tabulator .tabulator-placeholder {
    padding: 40px;
    text-align: center;
    color: #6c757d;
}

/* Frozen column styling */
.tabulator .tabulator-frozen {
    background-color: #fff;
    z-index: 10;
}

.tabulator .tabulator-frozen-left {
    border-right: 2px solid #0d6efd;
    z-index: 100 !important;
}

.tabulator-header .tabulator-col-resize-handle:first-of-type{
    z-index: 1000 !important;
}

/* Ensure first column (frozen) has high z-index */
.tabulator .tabulator-header .tabulator-frozen-left,
.tabulator .tabulator-row .tabulator-cell.tabulator-frozen-left {
    z-index: 100 !important;
}

/* Column resize handle */
.tabulator .tabulator-col-resize-handle {
    background-color: #ccc;
    width: 3px;
}

.tabulator .tabulator-col-resize-handle:hover {
    background-color: #999;
    width: 5px;
}

/* More Options Dropdown */
.more-options-wrapper {
    position: relative;
}

.more-options-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: var(--bs-body-bg, #fff);
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 8px;
    min-width: 220px;
    z-index: 1050;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.more-options-dropdown.open {
    display: block;
}

.more-options-section {
    padding: 8px 0;
}

.more-options-section + .more-options-section {
    border-top: 1px solid var(--bs-border-color, #dee2e6);
}

.more-options-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--bs-secondary-color, #6c757d);
    padding: 4px 14px 8px;
}

.more-options-action {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    font-size: 13px;
    color: var(--bs-body-color, #212529);
    cursor: pointer;
    transition: background 0.15s;
}

.more-options-action:hover {
    background: var(--bs-tertiary-bg, #f8f9fa);
}

.more-options-col-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    font-size: 13px;
    color: var(--bs-body-color, #212529);
    cursor: pointer;
}

.more-options-col-item:hover {
    background: var(--bs-tertiary-bg, #f8f9fa);
}

.more-options-col-item input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: var(--bs-primary, #0d6efd);
    cursor: pointer;
    flex-shrink: 0;
}

.more-options-col-item input[type="checkbox"]:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.more-options-col-item span {
    flex: 1;
}

/* Active state for more options button */
.more-options-wrapper .btn.active {
    border-color: var(--bs-primary, #0d6efd);
    color: var(--bs-primary, #0d6efd);
    background: var(--bs-primary-bg-subtle, #cfe2ff);
}

