/**
 * Grouped table (project, Suomen Jättikasvisyhdistys): a core table whose
 * first column names the group on the group's first row only, such as the
 * competition list (Ryhmä | Kasvi | Sarjat | Merkinnät on /kilpailu/). One
 * table is easy to update every year. A row that starts a group gets a
 * stronger line above it; on phones the rows stack: the group as a small
 * heading, the plant with its marks, then its classes.
 *
 * className: grouped-table (core/table, Additional CSS class)
 *
 * Structure:
 *   figure.wp-block-table.grouped-table > table
 *     thead > tr > th ×4
 *     tbody > tr > td ×4   td:first-child = the group, empty on its other rows
 *
 * Front end and editor. The table may be wider than a reading column, so it
 * keeps to --grouped-table-width.
 */

.wp-block-table.grouped-table {
    --grouped-table-width: 980px;
    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;
}

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

.grouped-table thead th {
    border-bottom: 2px solid var(--accent-clr);
    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;
}

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

@media only screen and (max-width: 767px) {
    .grouped-table thead {
        display: none;
    }

    .grouped-table tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas:
            "ryhma ryhma"
            "kasvi merkit"
            "sarjat sarjat";
        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 th,
    .grouped-table td,
    .grouped-table tbody tr:has(> td:first-child:not(:empty)) > td {
        padding: 0;
        border: 0;
    }

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

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

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

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

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