:root {
    /* Tabulator specific theme variables */
    --tabulator-background: #fff;
    --tabulator-text: #333;
    --tabulator-border: #ddd;
    --tabulator-header-background: #f3f3f3;
    --tabulator-header-text: #333;
    --tabulator-row-border: #ddd;
    --tabulator-row-background: #fff;
    --tabulator-row-background-hover: #f5f5f5;
}

/* ==========================================================================
   PREVENT WINDOW-LEVEL SCROLLING
   ========================================================================== */

/* Critical: Prevent any window-level scrolling */
body {
    overflow: hidden !important;
}

/* ==========================================================================
   ROBUST RESPONSIVE LAYOUT
   ========================================================================== */

/* Make main container a flexbox for table pages with proper height containment */
main {
    display: flex;
    flex-direction: column;
    /* Account for: top bar (45.6px) + main margin-top (30px) + main padding-top (28px) + footer (40px) */
    /* height removed: computed via JS from measured DOM to eliminate footer gap */
    height: var(--calculated-main-height, auto);
    min-height: 0; /* Allow flex items to shrink below content size */
    overflow: visible; /* Allow status to paint beyond main's content box (avoid clipping) */
    box-sizing: border-box;
    padding-top: 28px; /* Restore the original padding-top */
    padding-left: 10px;
    padding-right: 10px;
    padding-bottom: 0;
}

@media (min-width: 768px) {
    main {
        padding-left: 28px;
        padding-right: 28px;
    }
}

/* References page container */
[data-page-type='references'] {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0; /* Allow flex items to shrink */
    width: 100%;
    box-sizing: border-box;
    overflow: visible; /* Allow status line to paint fully (do not clip at container edge) */
}

/* Search controls - fixed height, no shrinking */
.search-controls {
    flex-shrink: 0; /* Don't shrink search controls */
    margin: 0 0 1rem 0;
}

/* Table container - takes remaining space and manages its own scrolling */
#references-table {
    /* Fix container to the measured table height so status sits flush above the footer */
    flex: 0 0 var(--calculated-table-height, auto);
    height: auto;
    min-height: 0; /* Allow shrinking below content size */
    width: 100%;
    overflow: hidden; /* Container doesn't scroll, table does */
    box-sizing: border-box;
}

/* Let Tabulator handle height through JavaScript configuration */
#references-table .tabulator {
    /* Remove height constraints - let Tabulator's JS height option control this */
}

/* Force Tabulator's table holder to always show vertical scrollbar */
#references-table .tabulator-tableholder {
    overflow-y: auto !important; /* Show vertical scrollbar only when needed */
    overflow-x: auto !important; /* Horizontal scroll when needed */
    scrollbar-gutter: stable both-edges; /* Reserve space for scrollbars to prevent width oscillation */
    width: 100%;
}

/* Webkit browsers (Chrome, Safari) - force prominent scrollbar */




/* Status message - fixed height, no shrinking */
.table-status {
    flex-shrink: 0; /* Don't shrink status */
    min-height: 1.5rem;
}

/* ==========================================================================
   BASE TABLE STYLES (Visual Only - No Layout Constraints)
   ========================================================================== */

.tabulator {
    background-color: var(--tabulator-background);
    border: 1px solid var(--tabulator-border);
    font-size: var(--base-font-size);
    margin: 0;
    border: none !important;
    line-height: 1.4 !important;
    /* Remove all width/layout constraints */
}

/* Header Styles */
.tabulator .tabulator-header {
    background-color: var(--tabulator-header-background);
    color: var(--tabulator-header-text);
    border-bottom: 2px solid var(--tabulator-border);
    font-weight: bold;
    font-size: var(--base-font-size) !important;
    padding-left: 0;
}

.tabulator .tabulator-header .tabulator-col {
    background-color: var(--tabulator-header-background);
    border-right: 1px solid var(--tabulator-border);
}

.tabulator .tabulator-header .tabulator-col:first-child {
    padding-left: 0;
}

.tabulator .tabulator-header .tabulator-col:last-child {
    border-right: none;
}

.tabulator .tabulator-header .tabulator-col .tabulator-col-content {
    font-weight: bold !important;
}

/* Table Body Styles */
.tabulator .tabulator-tableholder {
    /* Remove all overflow constraints - let Tabulator handle */
    background: repeating-linear-gradient(to bottom, var(--tabulator-background) 0px, var(--tabulator-background) 50px, #f3f3f3 50px, #f3f3f3 100px);
    padding: 0 !important;
    margin: 0 !important;
    box-sizing: border-box !important;
}

.tabulator-row {
    border-bottom: 1px solid var(--tabulator-border);
    background-color: transparent !important;
    margin-bottom: 0 !important;
}

.tabulator-row .tabulator-cell {
    border-right: 1px solid var(--tabulator-border);
    padding: 0px 2px !important;
    vertical-align: middle !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

.tabulator-row .tabulator-cell:last-child {
    border-right: none;
}

.tabulator-row .tabulator-cell:first-child {
    border-left: none !important;
}

.tabulator-row:hover {
    background-color: var(--tabulator-row-background-hover) !important;
}

/* Column specific styles - Title single-line with ellipsis */
.tabulator-cell.cell-title {
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    font-weight: 500 !important;
}

.tabulator-cell.cell-title a {
    display: inline-block;
    max-width: 100%;
    white-space: inherit;
    overflow: inherit;
    text-overflow: inherit;
}

/* Title split: keep action text ellipsized and mark visible */
.tabulator-cell.cell-title .title-cell {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    min-width: 0; /* allow children to shrink */
}

.tabulator-cell.cell-title .title-action {
    flex: 1 1 auto;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    outline: none; /* visible :focus styles below */
}


.tabulator-cell.cell-title .title-action:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
    border-radius: 2px;
}

/* Links in table cells */
.tabulator-cell a {
    color: var(--link-color);
    text-decoration: none;
    display: inline-block;
    max-width: 100%;
    white-space: inherit;
    overflow: inherit;
    text-overflow: inherit;
}

.tabulator-cell a:hover {
    text-decoration: underline;
}

/* Sorting styles */
.tabulator-col.tabulator-sortable:hover {
    background-color: var(--tabulator-row-background-hover);
}

.tabulator-col.tabulator-sortable[aria-sort='none'] .tabulator-col-content:after {
    border-top: 4px solid #bbb;
}

.tabulator-col.tabulator-sortable[aria-sort='ascending'] .tabulator-col-content:after,
.tabulator-col.tabulator-sortable[aria-sort='descending'] .tabulator-col-content:after {
    border-top: 4px solid var(--accent-color);
}

/* Table status */
.table-status {
    font-size: calc(var(--base-font-size) * 0.9);
    color: var(--text-muted);
    padding: 0 0.75rem;
    border-top: none;
    background-color: var(--tabulator-background);
    text-align: right;
    min-height: 1.5rem;
    line-height: 1.5rem;
    box-sizing: border-box;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Loading indicator */
.loader {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-radius: 50%;
    border-top: 3px solid var(--accent-color);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}


/* ==========================================================================
   Search Controls
   ========================================================================== */
.search-controls {
    margin: 0 0 1rem 0;
}

.search-box {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.search-box input {
    flex: 1;
    padding: 0.5em;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

.search-box button {
    padding: 0.5em 1em;
    background-color: var(--accent-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.search-box button:hover {
    background-color: #1976d2;
}

.search-box button.secondary {
    background-color: var(--text-muted);
}

.search-box button.secondary:hover {
    background-color: #4d4d4d;
}

.search-options-container {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-wrap: nowrap;
    gap: 8px;
    min-height: 24px;
}

.search-options {
    display: flex;
    column-gap: 10px;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    flex-wrap: nowrap;
}

.search-options label {
    display: inline-flex;
    align-items: center;
    gap: 0.3em;
    cursor: pointer;
    height: 24px;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
}

.search-options input[type='checkbox'] {
    cursor: pointer;
}

.search-options label span {
    display: inline-block;
    max-width: 12ch;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-status {
    color: var(--text-muted);
    font-style: italic;
    margin-left: auto;
    line-height: 24px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.button.secondary:disabled {
    background-color: #ccc;
    cursor: not-allowed;
    opacity: 0.6;
}

.button.secondary:disabled:hover {
    background-color: #ccc;
}

@media (max-width: 768px) {
    .search-options-container {
        flex-direction: row;
    }

    .search-options {
        flex-direction: row;
        flex-wrap: nowrap;
        flex: 1 1 auto;
        min-width: 0;
    }

    .search-status {
        margin-left: auto;
        margin-top: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        min-width: 0;
    }

    .search-options label span {
        max-width: 10ch;
    }
}

/* ==========================================================================
   Tooltips (Tabulator bubble)
   ========================================================================== */
.tabulator-tooltip {
    /* Slightly larger than base text for readability */
    font-size: calc(var(--base-font-size, 16px) * 1.12);
    line-height: 1.4;
    padding: 6px 8px;
    border: 7px solid var(--tabulator-border);
}
