/*
 * Tables.
 *
 * No zebra and no vertical rules between columns: the eye follows a row without them, and both
 * would fight the row highlighting, which carries real meaning here.
 *
 * The header is sticky, because the tables in this project are long (core.md §5.5). The
 * box scrolls sideways on its own so that the page never does at any phone width.
 */

/*
 * The box scrolls, not the page: sideways because a wide table must never make the page
 * scroll sideways, and downwards because that is what makes the heading stay on screen.
 *
 * A sticky heading sticks to its scroll container. While the box scrolled only sideways, the
 * container it stuck to never moved vertically and the heading scrolled away with the rows —
 * which is what core.md §5.5 asks not to happen. Capped rather than fixed in height, so
 * a table of three rows takes three rows.
 */
.app-table-box {
    max-height: var(--table-height);
    overflow: auto;
    /* Only sideways: a finger that reaches the bottom of the table goes on scrolling the page. */
    overscroll-behavior-x: contain;
}

.app-table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: var(--numeric);
}

.app-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: var(--space-3) var(--space-4);
    /* An inset shadow rather than a border: with border-collapse the line belongs to the
       table, not to the cell, so it stays behind while the sticky heading moves and the
       heading ends up floating over the rows with nothing between them. */
    box-shadow: inset 0 -1px 0 var(--border);
    /* Opaque on purpose: rows scroll underneath it. */
    background: var(--surface);
    color: var(--text-3);
    font-size: var(--fs-caption);
    font-weight: var(--fw-regular);
    text-align: left;
    white-space: nowrap;
}

.app-table td {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

/* The first column carries the name of the row and is set a shade heavier. */
.app-table td:first-child {
    font-weight: var(--fw-medium);
}

.app-table tbody tr:last-child td {
    border-bottom: 0;
}

/*
 * A figure is aligned to the right so that digits line up between rows — but only where the
 * column is wide enough for the heading to sit above its own numbers. In a narrow column the
 * heading ends up beside a neighbouring column and nothing says which figures are its own, so
 * there both the heading and the figures are centred.
 */
.app-table__num {
    text-align: right;
    white-space: nowrap;
}

.app-table th.app-table__narrow,
.app-table td.app-table__narrow {
    width: 1%;
    text-align: center;
    white-space: nowrap;
}

/*
 * A narrow column is given a width instead of being left to the browser.
 *
 * A column sized by its content changes width from page to page, and in a table where one
 * column is a comment the browser gives that column everything and pushes the figures to the
 * far edge — the eye then walks the row (core.md §5.1). Every short column of the project is
 * sized here, so the same data stands in the same place on every page. Add the columns this
 * project has beside them; do not size a column from a page stylesheet.
 */
.app-table th.app-table__col--date,
.app-table td.app-table__col--date {
    width: 112px;
    text-align: center;
    white-space: nowrap;
}

.app-table th.app-table__col--moment,
.app-table td.app-table__col--moment {
    width: 150px;
    text-align: center;
    white-space: nowrap;
}

.app-table th.app-table__col--state,
.app-table td.app-table__col--state {
    width: 110px;
    text-align: center;
}

/*
 * The badges that sort a list of products: its type and its status. Sized for the longest word
 * each column is given («Browser extension», «In development») and centred like the state beside
 * them, so the three badge columns stand in one place whatever rows the page holds and the name
 * takes the rest (core.md §5.1, §5.2).
 */
.app-table th.app-table__col--type,
.app-table td.app-table__col--type {
    width: 184px;
    text-align: center;
    white-space: nowrap;
}

.app-table th.app-table__col--status,
.app-table td.app-table__col--status {
    width: 164px;
    text-align: center;
    white-space: nowrap;
}

/*
 * The name of a row among fixed columns: it takes what they leave, but never less than a short
 * field, and wraps by words inside that — squeezed to its longest word it would stand one word a
 * line. When the sum is wider than the screen, the box scrolls sideways, not the page (core.md §5.5).
 */
.app-table th.app-table__col--name,
.app-table td.app-table__col--name {
    min-width: var(--w-field-short);
}

/* Actions sit next to their own row (core.md §4.7), pinned to the right edge. */
.app-table__actions {
    width: 1%;
    white-space: nowrap;
}

.app-table__actions > div {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-0);
}

/*
 * A place in an order: the number and the two step buttons in one cell.
 *
 * Centred on the line of the row, so the figure stands level with the buttons instead of on their
 * baseline; the figure keeps a fixed width, so the buttons of every row stand in the same column.
 */
.app-table__order {
    width: 1%;
    white-space: nowrap;
}

.app-table__order > div {
    display: flex;
    align-items: center;
    gap: var(--space-0);
}

.app-table__order > div > span:first-child {
    min-width: 2ch;
    margin-right: var(--space-1);
    text-align: right;
}

/* An archived row keeps its colour and its text stays legible on it (core.md §5.8). */
.app-table tbody tr.app-row--archived td {
    color: var(--text-4);
}

/*
 * The row the page is about: the one open in the pane beside the list, the one picked in a window.
 *
 * Marked by aria-selected, so that what the eye sees and what a screen reader says are the same
 * fact (core.md §19.5). A soft fill and a bar on the leading edge: the bar survives where the
 * fill is too faint to tell from a neighbouring archived row. It sets only the background, so an
 * archived row keeps its quiet text and a badge in the row keeps its own colours; the pointer
 * goes one step deeper in the same hue instead of competing with it.
 */
.app-table tbody tr[aria-selected="true"] td {
    background: var(--accent-soft);
}

.app-table tbody tr[aria-selected="true"]:hover td {
    background: var(--accent-soft-2);
}

.app-table tbody tr[aria-selected="true"] td:first-child {
    box-shadow: inset var(--stroke-strong) 0 0 var(--accent);
}

/*
 * A row that lists images: the thumbnail first, then the caption, then the place of the row in
 * the order and the button that removes it. A modifier of the ordinary row, not a grid of its own,
 * so the columns of an image list stand where they stand in every other table (core.md §20.3).
 */
.app-table th.app-table__col--thumb,
.app-table td.app-table__col--thumb {
    width: 1%;
    padding-right: 0;
}

.app-table__thumb {
    display: block;
    width: calc(var(--control-lg) * 2);
    aspect-ratio: 4 / 3;
    border: 1px solid var(--border);
    border-radius: var(--radius-control);
    background: var(--surface-2);
    object-fit: cover;
}

.app-row--image td {
    padding-block: var(--space-2);
}

/* The empty state prints a sentence, not an illustration. */
.app-empty {
    padding: var(--space-6) var(--space-4);
    color: var(--text-3);
    text-align: center;
}

/* --- Pager --------------------------------------------------------------------------- */

/*
 * Pagination as the kit draws it: the position on the left, the pages on the right.
 *
 * The current page carries the soft fill of a pressed filter button and nothing louder —
 * there is no accent background in pagination.
 */
.app-pager {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    /* Continuation of the table above it, so the small step. */
    padding-top: var(--space-2);
}

.app-pager__info {
    color: var(--text-3);
    font-size: var(--fs-caption);
    font-variant-numeric: var(--numeric);
}

.app-pager__pages {
    display: flex;
    align-items: center;
    gap: var(--space-0);
}

.app-pager__page {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: var(--control-sm);
    height: var(--control-sm);
    padding: 0 var(--space-1);
    border-radius: var(--radius-control);
    color: var(--text-2);
    font-size: var(--fs-body);
    font-variant-numeric: var(--numeric);
    text-decoration: none;
    transition: background var(--transition);
}

a.app-pager__page:hover {
    background: var(--surface-2);
    color: var(--text-2);
    text-decoration: none;
}

.app-pager__page--on {
    background: var(--accent-soft-2);
    color: var(--accent);
    font-weight: var(--fw-semibold);
}

/* At the edge the step stays in place as a dead glyph: the row must not shift under the hand. */
.app-pager__page--off {
    color: var(--text-disabled);
}

.app-pager__gap {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: var(--control-sm);
    color: var(--text-4);
}

/*
 * Touch target of a link in a cell (core.md §19.1): the one rule for every table of the admin,
 * not one per screen. A button-like link keeps its own height; a link in running text is not here.
 * Below --bp-unfolded, written as the number the measurement uses (< 720).
 */
@media (max-width: 719px) {
    .app-table td a:not(.app-btn, .app-icon-btn) {
        display: inline-flex;
        align-items: center;
        min-height: var(--field);
    }
}
