﻿/*
 * List tables: a real <table class="ga-table"> inside a `.ga-table-scroll` area, virtualized by rows with
 * <Virtualize SpacerElement="tr"> so the spacers are table rows. The page gives each data row a class: `row-odd` /
 * `row-even` computed in C# (not :nth-of-type, which also counts the spacers and swaps the colors while scrolling),
 * `row-link` for a clickable row (with tabindex="0" and Enter), `group-row` for a title row spanning the table and
 * `total-row`. The column widths go in a <colgroup>: the fixed layout keeps them stable whatever rows are rendered.
 * The borders are those of the former grids (`.grid-bg`); they are separate, not collapsed, because a collapsed
 * border is not drawn on a sticky header cell once the table scrolls.
 *
 * `.ga-table-scroll` is deliberately not a scroll container: the page scrolls, as with the former grids, so there is a
 * single vertical scrollbar, the header sticks to the top of the window and Virtualize follows the window scroll.
 * An overflow (even overflow-x) here would make it the scroll container of both and bring back a second scrollbar.
 * A table wider than the screen (a min-width below which it would squeeze its columns) scrolls the page sideways.
 *
 * Shared by the staff app and the back office (GreenAdmin.UI.Common): link it after the color sheet, which defines the
 * --main-color-*, --bg-* and --fs-* variables. The other variables carry a fallback, the staff app value.
 */

.ga-table {
    width: 100%;
    overflow: visible;
    border-collapse: separate;
    border-spacing: 0;
    table-layout: fixed;
    border-top: var(--grid-border-width, 1px) solid var(--gray, #808080);
    border-left: var(--grid-border-width, 1px) solid var(--gray, #808080);
}

    .ga-table :is(th, td) {
        font-size: var(--fs-400);
        vertical-align: middle;
        padding-inline: .5rem;
        padding-block: .4em;
        text-align: left;
        border-right: var(--grid-border-width, 1px) solid var(--gray, #808080);
        border-bottom: var(--grid-border-width, 1px) solid var(--gray, #808080);
    }

    .ga-table > thead th {
        position: sticky;
        top: 0;
        z-index: 1;
        color: white;
        background-color: var(--main-color-2);
    }

    /* In a dialog the header sticks to the scrolling content box, whose 12px padding (Syncfusion) would
       otherwise leave a gap above it where the rows show through: stick it to the visible edge instead. */
    .e-dlg-content > .ga-table > thead th,
    .e-dlg-content > .ga-table-scroll > .ga-table > thead th {
        top: -12px;
    }

    .ga-table td {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .ga-table .align-right {
        text-align: right;
        font-variant-numeric: tabular-nums;
    }

    .ga-table .align-center {
        text-align: center;
    }

    .ga-table .row-odd {
        background-color: white;
    }

    .ga-table .row-even {
        background-color: var(--bg-light);
    }

    .ga-table tr.row-link {
        cursor: pointer;
    }

        /* A pale green, never the white of a group title */
        .ga-table tr.row-link:is(:hover, :focus-visible) {
            background-color: color-mix(in oklab, var(--main-color-2) 10%, white);
        }

        .ga-table tr.row-link:focus-visible {
            outline: 2px solid var(--main-color-2);
            outline-offset: -2px;
        }

    /*
     * Group title row (`group-row-title` + `group-row-count`): the title stands on the page, outside the frame, and each
     * group is a framed block of its own, as on the former grids. A table with groups therefore draws its left edge on
     * the first cell of each row instead of on the table, so the title row can leave it out; the bottom border of the
     * title is the top of its block. :where() keeps these rules below the phone cards ones.
     */
    .ga-table:has(> tbody > tr.group-row) {
        border-left: none;
    }

        .ga-table:where(:has(> tbody > tr.group-row)) :where(tr) > :first-child {
            border-left: var(--grid-border-width, 1px) solid var(--gray, #808080);
        }

        .ga-table tr.group-row > th {
            padding-top: .9em;
            padding-bottom: .4em;
            font-size: var(--fs-600);
            font-weight: 600;
            line-height: 1.2;
            color: var(--main-color-1);
            background-color: transparent;
            border-left: none;
            border-right: none;
        }

        .ga-table .group-row-count {
            display: inline-block;
            margin-left: .5rem;
            padding: .1em .6em;
            font-size: var(--fs-200);
            font-weight: 600;
            font-variant-numeric: tabular-nums;
            line-height: 1.3;
            vertical-align: .1em;
            color: var(--main-color-1);
            background-color: white;
            border: 1px solid color-mix(in oklab, var(--main-color-1) 22%, transparent);
            border-radius: var(--r-pill, 999px);
        }

    .ga-table tr.total-row > :is(th, td) {
        background-color: var(--bg-dark);
        font-weight: bold;
    }

    /* The row whose details are shown (a period, a theme...): the --selected-color of the former `bg-selected` rows */
    .ga-table tr.row-selected > td {
        font-weight: bold;
        background-color: var(--selected-color, #B6E77C);
    }

    /* A sortable column title: the title then its SortListCpt arrow; `th-sort-right` above a figure column */
    .ga-table .th-sort {
        display: flex;
        align-items: center;
    }

    .ga-table .th-sort-right {
        justify-content: flex-end;
    }

/*
 * A short statistics table beside its chart: as wide as its content, not stretched across the column. Its long labels
 * (task or category names) wrap rather than widen the column past the screen, as the cells of the former grids did.
 */
.ga-table.side-table {
    width: auto;
    min-width: 18rem;
    table-layout: auto;
}

    .ga-table.side-table td {
        white-space: normal;
    }

        /* A figure ("0,02 %", "1 012,13") reads as one block */
        .ga-table.side-table td.align-right {
            white-space: nowrap;
        }

/*
 * Phone layout of a list table: add `mobile-cards-table` to the table and,
 * below 810px, every row becomes a card. A cell with `data-label` shows that label on the left and its value on the
 * right, a cell without label is a title, empty cells and `data-card-hide` cells are hidden, `data-card-actions` cells
 * join the action line. Only the rows with a class are styled: the Virtualize spacer rows have none and keep their height.
 */
@media (max-width: 809.98px) {
    .mobile-cards-table,
    .mobile-cards-table > :is(tbody, tfoot) {
        display: flex;
        flex-direction: column;
        gap: .6rem;
        border: none;
    }

        .mobile-cards-table > :is(colgroup, thead) {
            display: none;
        }

        .mobile-cards-table tr[class] {
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            padding: .6rem .9rem;
            color: var(--main-color-1);
            border: 1px solid var(--gray-light, #DCDCDC);
            border-left: 4px solid var(--main-color-2);
            border-radius: var(--r-md, .7rem);
            overflow-wrap: anywhere;
        }

        .mobile-cards-table tr.group-row {
            padding: 0;
            border: none;
            background: none;
        }

            /* Between the cards, a group reads as a heading with its count in the same pill: the room above sets it apart */
            .mobile-cards-table tr.group-row > th {
                flex: 1 1 100%;
                display: flex;
                align-items: center;
                gap: .5rem;
                margin-top: .9rem;
                padding: 0 .1rem;
                font-size: var(--fs-500);
                border: none;
                background: none;
            }

            .mobile-cards-table > tbody:first-of-type > tr.group-row:first-child > th {
                margin-top: 0;
            }

                .mobile-cards-table tr.group-row > th .group-row-count {
                    margin-left: 0;
                }

        .mobile-cards-table tr.total-row {
            background-color: var(--bg-dim, #E0E1E0);
            border-left-color: var(--main-color-1);
        }

        .mobile-cards-table tr[class] > td {
            flex: 1 1 100%;
            display: flex;
            justify-content: flex-start;
            align-items: baseline;
            gap: .8rem;
            padding: .1rem 0;
            font-size: var(--fs-300);
            font-weight: bold;
            white-space: normal;
            overflow: visible;
            border: none;
            background: none;
        }

            .mobile-cards-table tr[class] > td:first-child:not([data-label]) {
                font-size: var(--fs-500);
            }

            .mobile-cards-table tr[class] > td[data-label] {
                justify-content: flex-end;
                text-align: right;
                font-weight: normal;
            }

                .mobile-cards-table tr[class] > td[data-label]::before {
                    content: attr(data-label);
                    flex: 0 0 auto;
                    margin-right: auto;
                    text-align: left;
                    font-size: var(--fs-200);
                    color: var(--gray-dark, #696969);
                }

            .mobile-cards-table tr[class] > td:is(:empty, :has(> :is(span, div):only-child:empty), [data-card-hide]) {
                display: none;
            }

            .mobile-cards-table tr[class] > td[data-card-actions] {
                flex: 0 0 auto;
                order: 1;
                margin-left: auto;
                padding-top: .4rem;
            }

    /*
     * Opt-in `mobile-sort-chips`: the sortable column titles (a `.th-sort` holding a SortListCpt) stay above the cards
     * as a row of chips, the other titles are hidden. The arrow stretches its hit area over the whole chip, so the
     * title sorts too and the target is no longer the 14px arrow alone.
     */
    .mobile-cards-table.mobile-sort-chips > thead {
        display: block;
        position: static;
    }

        .mobile-sort-chips > thead > tr {
            display: flex;
            flex-wrap: wrap;
            gap: .4rem;
        }

            .mobile-sort-chips > thead th {
                position: relative;
                display: flex;
                align-items: center;
                box-sizing: border-box;
                min-height: 2.2rem;
                padding: .2rem .5rem .2rem .8rem;
                font-size: var(--fs-300);
                border: none;
                border-radius: var(--r-pill, 999px);
            }

                .mobile-sort-chips > thead th:not(:has(> .th-sort)) {
                    display: none;
                }

                .mobile-sort-chips > thead th .sort-button::after {
                    content: "";
                    position: absolute;
                    inset: 0;
                    border-radius: inherit;
                }
}

/*
 * Tablet portrait (600-809px): cards spanning the whole width left a long gap between each label and its value. They sit
 * two by two instead; a group or total row still spans the line. Not for a virtualized list: Virtualize sizes its spacer
 * rows for one card per line, so a tbody holding spacers (rows without class) keeps the single column.
 */
@media (min-width: 600px) and (max-width: 809.98px) {
    .mobile-cards-table > tbody:not(:has(> tr:not([class]))) {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: start;
    }

        .mobile-cards-table > tbody:not(:has(> tr:not([class]))) > tr:is(.group-row, .total-row) {
            grid-column: 1 / -1;
        }
}
