/* Dense, spreadsheet-like list tables */
.table-scroll {
    max-height: calc(100vh - 230px);
    overflow: auto;
    border: 1px solid var(--bs-border-color);
}

.table-dense {
    font-size: 0.8125rem;
    margin-bottom: 0;
    white-space: nowrap;
}

.table-dense > :not(caption) > * > * {
    padding: 0.2rem 0.45rem;
    vertical-align: middle;
}

.table-dense thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--bs-tertiary-bg);
    box-shadow: inset 0 -1px 0 var(--bs-border-color);
}

/* The filter row sticks right under the header row */
.table-dense thead tr.filter-row th {
    top: 1.75rem;
    font-weight: normal;
}

.table-dense .filter-row .form-control,
.table-dense .filter-row .form-select {
    font-size: 0.8125rem;
    padding-top: 0.1rem;
    padding-bottom: 0.1rem;
    min-width: 6rem;
}

.table-dense th a {
    display: block;
}

.table-dense .btn-sm {
    --bs-btn-padding-y: 0.05rem;
    --bs-btn-font-size: 0.75rem;
}

.col-wrap {
    white-space: normal;
}

/* Editable spreadsheet-like grid (grid.js) */
.zgrid {
    outline: none;
    cursor: cell;
    max-height: calc(100vh - 330px);
    min-height: 12rem;
}

.zgrid-table {
    table-layout: auto;
    user-select: none;
}

.zgrid-table td {
    height: 1.7rem;
    max-width: 28rem;
    overflow: hidden;
    text-overflow: ellipsis;
}

.zgrid-rowhead {
    width: 2.5rem;
    text-align: right;
    color: var(--bs-secondary-color);
    background: var(--bs-tertiary-bg);
    font-weight: normal;
}

.zgrid-rowhead.zgrid-dirty {
    box-shadow: inset 3px 0 0 var(--bs-warning);
}

.zgrid-sortable {
    cursor: pointer;
}

.zgrid:focus td.zgrid-active,
.zgrid td.zgrid-active {
    outline: 2px solid var(--bs-primary);
    outline-offset: -2px;
}

.zgrid td.zgrid-invalid {
    background-color: var(--bs-danger-bg-subtle);
    box-shadow: inset 0 0 0 1px var(--bs-danger);
}

.zgrid td .zgrid-editor {
    width: 100%;
    min-width: 6rem;
    border: 0;
    padding: 0;
    margin: 0;
    font: inherit;
    background: var(--bs-body-bg);
    outline: none;
}

/* Catalog section tree */
.catalog-tree-list {
    list-style: none;
    padding-left: 0.9rem;
    margin: 0;
}

.catalog-tree > .catalog-tree-list {
    padding-left: 0;
}

.catalog-tree-link {
    display: block;
    padding: 0.1rem 0.4rem;
    border-radius: 0.2rem;
    color: inherit;
    text-decoration: none;
}

.catalog-tree-link:hover {
    background: var(--bs-tertiary-bg);
}

.catalog-tree-link.active {
    background: var(--bs-primary-bg-subtle);
    font-weight: 600;
}

/* Typeahead suggestions of a grid cell */
.zgrid-suggest {
    z-index: 1050;
    max-height: 22rem;
    overflow-y: auto;
    font-size: 0.8125rem;
}

.zgrid-suggest .list-group-item {
    padding: 0.2rem 0.5rem;
    cursor: pointer;
}

/* Search box of the navigation bar */
.nav-search {
    width: 15rem;
}

/* ---------- Narrow screens (the navigation bar folds into a menu below 992px) ---------- */
@media (max-width: 991.98px) {
    .nav-search {
        width: 100%;
    }
}

/* ---------- Phones ---------- */
@media (max-width: 767.98px) {
    /* Controls large enough for a finger; 16px text also stops the phone from zooming into a field */
    .btn-sm,
    .table-dense .btn-sm {
        --bs-btn-padding-y: 0.4rem;
        --bs-btn-padding-x: 0.75rem;
        --bs-btn-font-size: 0.95rem;
    }

    .form-control-sm,
    .form-select-sm,
    textarea.form-control {
        font-size: 1rem;
        min-height: 2.5rem;
    }

    /* The page itself scrolls; no second scrolling area inside it */
    .table-scroll {
        max-height: none;
    }

    /* A table with class "table-stack" shows every row as a card: label on the left, value on the right */
    .table-scroll:has(> .table-stack),
    .table-responsive:has(> .table-stack) {
        overflow: visible;
        border: 0 !important;
    }

    .table-stack {
        white-space: normal;
        font-size: 0.9375rem;
        border: 0;
    }

    .table-stack thead {
        display: none;
    }

    .table-stack tbody tr {
        display: block;
        margin-bottom: 0.5rem;
        border: 1px solid var(--bs-border-color);
        border-radius: 0.375rem;
        overflow: hidden;
    }

    .table-stack tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 0.75rem;
        padding: 0.3rem 0.6rem;
        border: 0;
        text-align: right;
        max-width: none;
    }

    .table-stack tbody td::before {
        content: attr(data-label);
        flex: 0 0 42%;
        text-align: left;
        font-weight: 600;
        color: var(--bs-secondary-color);
    }

    /* Cells without a label (buttons, "nothing found") use the whole width */
    .table-stack tbody td:not([data-label])::before {
        content: none;
    }

    .table-stack tbody td:not([data-label]) {
        justify-content: flex-end;
    }

    .table-stack tbody td[colspan] {
        justify-content: center;
    }

    /* An empty value is not worth a line */
    .table-stack tbody td:empty {
        display: none;
    }

    /* Fields inside a card take the space next to their label */
    .table-stack tbody td > .form-control,
    .table-stack tbody td > .form-select {
        flex: 1 1 auto;
        width: auto !important;
        min-width: 0 !important;
    }
}
