/*
 * Phone layout of the lists and read-only tables.
 *
 * On a narrow screen a row of six columns is unreadable: each row becomes a small card, one
 * line per column, labelled with the heading of that column (set by /js/responsive.js).
 */
@media (max-width: 767.98px) {
    /* Lists built from .list-group rows of columns */
    .rl > .rl-head,
    .rl-nested > .rl-head {
        display: none !important;
    }

    .rl > .list-group-item {
        padding-top: .75rem !important;
        padding-bottom: .75rem !important;
    }

    .rl > .list-group-item > .row {
        display: block;
    }

    .rl > .list-group-item > .row > [class*="col"] {
        display: flex;
        flex-wrap: wrap;
        align-items: baseline;
        justify-content: space-between;
        width: 100%;
        max-width: 100% !important;
        min-width: 0 !important;
        padding: .125rem 15px !important;
        overflow: visible;
        white-space: normal;
        text-align: right;
        overflow-wrap: anywhere;
    }

    .rl > .list-group-item > .row > [class*="col"]:empty {
        display: none;
    }

    .rl > .list-group-item > .row > [class*="col"] .text-truncate,
    .rl > .list-group-item > .row > [class*="col"] > span,
    .rl > .list-group-item > .row > [class*="col"] > a {
        white-space: normal !important;
        overflow: visible;
        text-overflow: clip;
        max-width: 100% !important;
    }

    .rl [data-label]::before {
        content: attr(data-label);
        flex: 0 0 auto;
        max-width: 45%;
        margin-right: 1rem;
        color: #6c757d;
        font-size: .875rem;
        font-weight: 400;
        text-align: left;
        white-space: normal;
    }

    /* Lists nesting their own grid: nothing is cut, a long name wraps and its badge follows it. */
    .rl-nested > .list-group-item .text-truncate {
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .rl-nested > .list-group-item .row .d-flex.text-truncate {
        flex-wrap: wrap;
        row-gap: .25rem;
    }

    .rl-nested > .list-group-item .row .d-flex.text-truncate > a:last-child {
        flex: 1 1 0;
        min-width: 0;
    }

    .rl-nested > .list-group-item .row .d-flex.text-truncate > .badge {
        white-space: nowrap;
    }

    /* The first column names the row: it reads as its title. */
    .rl > .list-group-item > .row > .rl-title {
        justify-content: flex-start;
        font-weight: 500;
        text-align: left;
        padding-bottom: .25rem !important;
    }

    .rl > .list-group-item > .row > .rl-title::before {
        display: none;
    }

    /* The last column holds the actions. */
    .rl > .list-group-item > .row > .rl-actions {
        justify-content: flex-end;
        padding-top: .375rem !important;
    }
}

@media (max-width: 575.98px) {
    /* A page title is never cut: a card number wraps instead of losing its last digits. */
    h1.fs-3xl {
        font-size: 1.5rem !important;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    /* A long label wraps inside its badge instead of pushing the page wider than the screen. */
    .badge {
        max-width: 100%;
        white-space: normal;
        text-align: left;
    }

    /* The cookie notice shows its whole sentence. */
    #cookie-banner .text-truncate {
        white-space: normal;
        font-size: .875rem;
    }

    /* Page headers: the main button goes under the title instead of squeezing it. */
    .container > .row.mx-n2.mb-4 > .col-auto {
        margin-top: .5rem;
    }
}

/*
 * Read-only tables become labelled cards on a phone, and on any wider screen where they do not
 * fit (/js/responsive.js sets .rl-stack on their wrapper).
 */
.table-responsive.rl-wrap.rl-stack {
    overflow-x: visible;
}

.rl-stack > .rl-table,
.rl-stack > .rl-table tbody,
.rl-stack > .rl-table tr,
.rl-stack > .rl-table td {
    display: block;
    width: 100%;
}

.rl-stack > .rl-table thead {
    display: none;
}

.rl-stack > .rl-table tr {
    padding: .625rem 0;
    border-top: 1px solid rgba(0, 0, 0, .08);
}

.rl-stack > .rl-table tbody tr:first-child {
    border-top: 0;
}

.rl-stack > .rl-table td {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    max-width: none !important;
    min-width: 0 !important;
    padding: .125rem 0 !important;
    border: 0 !important;
    text-align: right !important;
    white-space: normal !important;
    overflow-wrap: anywhere;
}

.rl-stack > .rl-table td:empty {
    display: none;
}

.rl-stack > .rl-table td .text-truncate {
    white-space: normal !important;
    overflow: visible;
    max-width: 100% !important;
}

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

.rl-stack > .rl-table td[data-label]::before {
    content: attr(data-label);
    flex: 0 0 auto;
    max-width: 45%;
    margin-right: 1rem;
    color: #6c757d;
    font-size: .875rem;
    font-weight: 400;
    text-align: left;
    white-space: normal;
}

/* On a tablet the card of a row takes two columns, so the label stays close to its value. */
@media (min-width: 768px) {
    .rl-stack > .rl-table tr {
        display: grid;
        grid-template-columns: 1fr 1fr;
        column-gap: 2.5rem;
    }

    .rl-stack > .rl-table td:not([data-label]) {
        grid-column: 1 / -1;
    }
}

/* Wide lists on a desktop: the columns share the width and long values end with an ellipsis. */
@media (min-width: 1200px) {
    .table-fit {
        table-layout: fixed;
    }

    .table-fit th {
        white-space: normal;
    }
}
