/* ==========================================================================
   ITEM TABLE BLOCK AND TOOLBAR
   ========================================================================== */

.itemtable {
    /* Highlight color: the block's own (set by the script), else the theme's
       --primary, else a neutral gray */
    --itemtable-accent: var(--primary, #4a5568);
    --itemtable-accent-dark: var(--primary-dark, #2d3748);
    margin: 1em 0;
    overflow-x: auto;
}

.itemtable-toolbar {
    margin-bottom: 15px;
    display: flex;
    gap: 15px;
    align-items: center;
    flex-wrap: wrap;
}

/* Force vertical alignment consistency across inputs and buttons */
.itemtable-search,
.itemtable-toolbar-btn {
    height: 38px;
    margin: 0;
    box-sizing: border-box;
}

.itemtable-search {
    padding: 5px 10px;
    width: 300px;
    max-width: 100%;
    border: 1px solid #ccc;
    border-radius: 4px;
}

.itemtable-toolbar-btn {
    padding: 0 15px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: var(--itemtable-accent);
    color: #fff;
    border: none;
    border-radius: 4px;
    font-weight: 600;
}

.itemtable-toolbar-btn:hover {
    filter: brightness(1.1);
}

.itemtable-toolbar-right {
    margin-left: auto;
    display: flex;
    gap: 10px;
    align-items: center;
}

/* Column Toggle Dropdown - Inline Checkboxes */
.itemtable-dropdown-container {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.itemtable-column-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    background: white;
    border: 1px solid #ccc;
    z-index: 1000;
    padding: 10px;
    min-width: 180px;
    max-height: 300px;
    overflow-y: auto;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    margin-top: 5px;
}

.itemtable-column-menu.itemtable-open {
    display: block;
}

.itemtable-column-menu .itemtable-column-label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    cursor: pointer;
    font-weight: normal;
    white-space: nowrap;
}

.itemtable-column-menu .itemtable-column-checkbox {
    margin: 0;
    cursor: pointer;
}

/* Table and paginator */
.itemtable-wrapper {
    overflow: hidden;
    /* The script sets the block's fixed height; this is the fallback */
    height: 60vh;
    min-height: 150px;
    max-width: 100%;
    border: 1px solid #ccc;
    background: #fff;
    display: flex;
    flex-direction: column;
}

.itemtable-table {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    width: 100% !important;
    border: none !important;
}

/* Protect Tabulator's native math from Omeka's global CSS */
.itemtable .tabulator, .itemtable .tabulator * {
    box-sizing: border-box !important;
}

.itemtable .tabulator-row .tabulator-cell {
    white-space: normal !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    font-size: 0.875rem;
}

.itemtable .tabulator .tabulator-header .tabulator-col-title {
    white-space: normal !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    font-size: 0.97rem !important;
    font-weight: bold !important;
}

/* Header filters are hidden until the filters button is clicked */
.itemtable-table.itemtable-hide-filters .tabulator-header-filter {
    display: none !important;
}

/* Rows of private items (only logged-in users get them) */
.itemtable .tabulator-row.itemtable-row-private {
    background-color: #ffe6e6;
}

a.itemtable-view-link {
    color: var(--itemtable-accent);
    text-decoration: underline;
    text-underline-offset: 3px;
    font-weight: bold;
}

/* Tabulator's own footer is replaced by the paginator below */
.itemtable .tabulator .tabulator-footer {
    display: none !important;
}

/* ==========================================================================
   PAGINATOR
   ========================================================================== */

.itemtable-paginator {
    display: flex;
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    background-color: transparent;
    border-top: 1px solid #ccc;
    font-size: 0.875rem;
    flex-shrink: 0;
    width: 100%;
    box-sizing: border-box;
    overflow-x: auto; /* Allow scrolling only if the screen gets ridiculously narrow */
}

/* 3 Equal-width columns keep the center block perfectly aligned */
.itemtable-paginator-left,
.itemtable-paginator-center,
.itemtable-paginator-right {
    flex: 1 1 33%;
    display: flex;
    align-items: center;
}

.itemtable-paginator-left {
    justify-content: flex-start;
    white-space: nowrap;
}

.itemtable-paginator-center {
    justify-content: center;
    flex-wrap: nowrap;
    gap: 8px;
    white-space: nowrap;
}

.itemtable-paginator-right {
    justify-content: flex-end;
    gap: 8px;
    white-space: nowrap; /* Keeps label and select on one line */
}

.itemtable-paginator select,
.itemtable-paginator input,
.itemtable-page-btn {
    height: 32px !important;
    box-sizing: border-box;
    margin: 0 !important;
}

/* Keep the theme from restyling the page size dropdown */
.itemtable-paginator .itemtable-page-size {
    appearance: auto !important;
    -webkit-appearance: auto !important;
    -moz-appearance: auto !important;
    background-image: none !important; /* Strips the theme's custom arrow */
    padding: 0 8px !important;
    width: auto !important;
    min-width: 70px;
}

.itemtable-page-btn {
    padding: 0 12px !important;
    border: none;
    background-color: var(--itemtable-accent);
    color: #fff !important;
    cursor: pointer;
    border-radius: 4px;
    font-size: 1rem;
    font-weight: bold;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 35px;
}

.itemtable-page-btn:hover:not(:disabled) {
    filter: brightness(1.1);
}

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

.itemtable-page-jump {
    display: inline-flex;
    align-items: center;
    height: 32px;
    gap: 6px;
    margin: 0 8px;
    white-space: nowrap;
}

.itemtable-paginator .itemtable-page-input {
    width: 50px !important;
    text-align: center;
    padding: 0 4px !important;
    border: 1px solid #ccc !important;
    border-radius: 4px !important;
    font-size: 0.875rem !important;
}

/* Paginator "Page Size:" label and its dropdown */
.itemtable-page-size-label {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 32px;
    margin: 0;
    white-space: nowrap;
}

/* Edit link next to View, only on rows the logged-in user may edit */
a.itemtable-edit-link {
    margin-left: 0.5em;
    color: var(--itemtable-accent);
    text-decoration: none;
    font-size: 1.1em;
}

a.itemtable-edit-link:hover,
a.itemtable-edit-link:focus {
    color: var(--itemtable-accent-dark);
}

/* Parts of the footer the block turned off */
.itemtable-paginator[hidden],
.itemtable-paginator-left[hidden] {
    display: none;
}

/* ==========================================================================
   DISPLAY SETTINGS (block form > Display). Themes can restyle these classes.
   ========================================================================== */

/* Styles. Standard is Tabulator's own look (striped rows). */
.itemtable-style-plain .tabulator-row.tabulator-row-even {
    background-color: #fff;
}

.itemtable-style-bordered .tabulator-row .tabulator-cell {
    border-right: 1px solid #ccc;
}

.itemtable-style-bordered .tabulator-row {
    border-bottom: 1px solid #ccc;
}

.itemtable-style-minimal .itemtable-wrapper {
    border: 0;
}

.itemtable-style-minimal .tabulator,
.itemtable-style-minimal .tabulator .tabulator-header,
.itemtable-style-minimal .tabulator .tabulator-header .tabulator-col {
    border: 0;
    background-color: transparent;
}

.itemtable-style-minimal .tabulator .tabulator-header {
    border-bottom: 2px solid #ccc;
}

.itemtable-style-minimal .tabulator-row,
.itemtable-style-minimal .tabulator-row.tabulator-row-even {
    background-color: transparent;
    border-bottom: 1px solid #eee;
}

.itemtable-style-minimal .tabulator-row .tabulator-cell {
    border-right: 0;
}

/* Density: space around the cell text */
.itemtable-density-compact .tabulator-row .tabulator-cell {
    padding: 2px 4px;
}

.itemtable-density-roomy .tabulator-row .tabulator-cell {
    padding: 10px 8px;
}

.itemtable-density-roomy .tabulator .tabulator-header .tabulator-col .tabulator-col-content {
    padding: 10px 8px;
}

/* Long text cut off with "…" instead of wrapping */
.itemtable.itemtable-nowrap .tabulator-row .tabulator-cell {
    white-space: nowrap !important;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Grow to fit the rows instead of a fixed height that scrolls */
.itemtable-height-auto .itemtable-wrapper {
    height: auto;
    min-height: 0;
}

.itemtable-height-auto .itemtable-table {
    flex: 0 0 auto !important;
}

/* Visitors can drag the bottom-right corner to change the height (fixed height only).
   Left out on touch screens, where the corner is too small to drag. */
.itemtable-resizable .itemtable-wrapper {
    resize: vertical;
}

@media (pointer: coarse) {
    .itemtable-resizable .itemtable-wrapper {
        resize: none;
    }
}
