/**
 * Grouped table: a core table whose first column names the group on the
 * group's first row only, such as a price list or a competition list
 * (Ryhmä | Palvelu | Sisältää | Hinta). One table is easy to update, and a
 * row that starts a group gets a stronger line above it. On phones the rows
 * stack: the group as a small heading, the item with its note on the right,
 * then its details.
 *
 * className: grouped-table (core/table, Additional CSS class)
 *
 * Structure:
 *   figure.wp-block-table.grouped-table > table
 *     thead > tr > th ×4                 hidden on phones
 *     tbody > tr > td ×4
 *       td:first-child                   the group, empty on the group's other rows
 *       td:nth-child(2)                  the item (bold)
 *       td:nth-child(3)                  details (on phones under the item)
 *       td:nth-child(4)                  a short note such as a price (on phones
 *                                        right of the item); may be left out
 *
 * Tuning: --grouped-table-width (980px, the table may be wider than a
 *         reading column)
 *
 * Pages only: inside an article (.post-content) the article table style in
 * css/article.css loads later and wins.
 *
 * Front end and editor.
 */

:root {
    --grouped-table-width: 980px;
}

.wp-block-table.grouped-table {
    max-width: var(--grouped-table-width);
    margin: 0;
}

.wp-block-table.grouped-table table {
    width: 100%;
    table-layout: auto;
    border: 0;
    border-collapse: collapse;
    font-size: 0.95em;
    line-height: 1.45;
}

/* Core draws a 3px line under thead, which would hide the header cells' own
   accent line (the wider border wins in a collapsed table). */
.grouped-table thead {
    border: 0;
}

.grouped-table th,
.grouped-table td {
    padding: 0;
    border: 0;
    text-align: left;
    vertical-align: top;
}

.grouped-table thead th {
    font-size: 0.8em;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--heading-clr);
}

.grouped-table td:first-child {
    font-family: var(--title-font);
    color: var(--heading-clr);
}

.grouped-table td:nth-child(2) {
    font-weight: 600;
}

/* Phones: no header row, every row stacks */
.grouped-table thead {
    display: none;
}

.grouped-table tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
        "group group"
        "item note"
        "detail detail";
    gap: 2px 12px;
    padding: 10px 0;
    border-bottom: 1px solid color-mix(in srgb, currentColor 12%, transparent);
}

.grouped-table tbody tr:has(> td:first-child:not(:empty)) {
    margin-top: 12px;
    border-top: 2px solid color-mix(in srgb, currentColor 22%, transparent);
}

.grouped-table td:first-child {
    grid-area: group;
    padding-bottom: 6px;
    font-size: 1.1em;
}

.grouped-table td:first-child:empty {
    display: none;
}

.grouped-table td:nth-child(2) {
    grid-area: item;
}

.grouped-table td:nth-child(3) {
    grid-area: detail;
    font-size: 0.9em;
}

.grouped-table td:nth-child(4) {
    grid-area: note;
    font-size: 0.85em;
    text-align: right;
}

/* From 768px: a table again */
@media only screen and (min-width: 768px) {
    .grouped-table thead {
        display: table-header-group;
    }

    .grouped-table tr,
    .grouped-table tbody tr:has(> td:first-child:not(:empty)) {
        display: table-row;
        margin-top: 0;
        padding: 0;
        border: 0;
    }

    .grouped-table td:first-child:empty {
        display: table-cell;
    }

    .grouped-table th,
    .grouped-table td,
    .grouped-table td:first-child {
        padding: 10px 20px 10px 0;
        border-bottom: 1px solid color-mix(in srgb, currentColor 12%, transparent);
    }

    .grouped-table thead th {
        border-bottom: 2px solid var(--accent-clr);
    }

    .grouped-table td:first-child,
    .grouped-table td:nth-child(3),
    .grouped-table td:nth-child(4) {
        font-size: inherit;
        text-align: left;
    }

    .grouped-table tbody tr:has(> td:first-child:not(:empty)) > td {
        border-top: 2px solid color-mix(in srgb, currentColor 22%, transparent);
    }
}
