/* Switch layouts using the space inside the modal. */
.purchase-items-table {
    container-type: inline-size;
}

.purchase-items-table :is(label[data-purchase-field="bonus"], [data-purchase-field="bonus"] > label) {
    justify-content: center;
}

.purchase-items-table--manual input[type="number"] {
    appearance: textfield;
    font-variant-numeric: tabular-nums;
}

.purchase-items-table--manual input[type="number"]::-webkit-inner-spin-button,
.purchase-items-table--manual input[type="number"]::-webkit-outer-spin-button {
    appearance: none;
    margin: 0;
}

.purchase-items-table--manual input[type="date"] {
    padding-inline: 0.375rem;
}

.purchase-items-table--manual [data-purchase-field="cost"] input {
    padding-right: 0.5rem;
}

.purchase-items-table > table > :is(thead, tbody) > tr > :is(th, td) {
    padding-inline: 0.65rem;
}

.purchase-items-table > table > thead > tr > th {
    color: var(--text-secondary);
    font-size: 0.75rem;
    letter-spacing: 0.01em;
    text-transform: none;
}

.purchase-items-table > table > tbody > tr:has(> td > [data-purchase-bonus="true"]) {
    background-color: rgb(16 185 129 / 0.08);
}

.purchase-item-mobile-label {
    display: none;
}

.purchase-item-amount {
    overflow-wrap: anywhere;
    font-variant-numeric: tabular-nums;
}

.purchase-item-bonus-label {
    position: absolute;
    width: 1px;
    height: 1px;
    clip-path: inset(50%);
    overflow: hidden;
    white-space: nowrap;
}

@container (max-width: 900px) {
    .purchase-items-table :is(label[data-purchase-field="bonus"], [data-purchase-field="bonus"] > label) {
        justify-content: start;
    }

    .purchase-items-table > table,
    .purchase-items-table > table > tbody {
        display: block;
        width: 100%;
    }

    .purchase-items-table > table > thead {
        position: absolute;
        width: 1px;
        height: 1px;
        clip-path: inset(50%);
        overflow: hidden;
        white-space: nowrap;
    }

    .purchase-items-table > table > tbody > tr:has(> td > [data-purchase-field]) {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: end;
        gap: 0.4rem 0.75rem;
        padding: 0.65rem;
    }

    .purchase-items-table--manual > table > tbody > tr:has(> td > [data-purchase-field]) {
        grid-template-areas:
            "product product"
            "quantity bonus"
            "cost subtotal"
            "validity actions";
    }

    .purchase-items-table--detail > table > tbody > tr:has(> td > [data-purchase-field]) {
        grid-template-areas:
            "product product"
            "quantity bonus"
            "invoice invoice"
            "invoice-total status";
        align-items: start;
    }

    .purchase-items-table > table > tbody > tr > td {
        /* The column widths are inline on the desktop table. */
        width: auto !important;
        min-width: 0;
        padding: 0;
        text-align: left;
    }

    .purchase-items-table > table > tbody > tr > td:has(> [data-purchase-field="product"]) { grid-area: product; }
    .purchase-items-table > table > tbody > tr > td:has(> [data-purchase-field="quantity"]) { grid-area: quantity; }
    .purchase-items-table > table > tbody > tr > td:has(> [data-purchase-field="bonus"]) { grid-area: bonus; }
    .purchase-items-table > table > tbody > tr > td:has(> [data-purchase-field="cost"]) { grid-area: cost; }
    .purchase-items-table > table > tbody > tr > td:has(> [data-purchase-field="subtotal"]) { grid-area: subtotal; }
    .purchase-items-table > table > tbody > tr > td:has(> [data-purchase-field="validity"]) { grid-area: validity; }
    .purchase-items-table > table > tbody > tr > td:has(> [data-purchase-field="actions"]) { grid-area: actions; justify-self: end; }
    .purchase-items-table > table > tbody > tr > td:has(> [data-purchase-field="invoice"]) { grid-area: invoice; }
    .purchase-items-table > table > tbody > tr > td:has(> [data-purchase-field="invoice-total"]) { grid-area: invoice-total; }
    .purchase-items-table > table > tbody > tr > td:has(> [data-purchase-field="status"]) { grid-area: status; }

    .purchase-item-mobile-label {
        display: block;
        margin-bottom: 0.15rem;
        font-size: 0.75rem;
        color: var(--text-secondary);
    }

    .purchase-item-bonus-label {
        position: static;
        width: auto;
        height: auto;
        clip-path: none;
        overflow: visible;
        white-space: normal;
    }
}

@container (max-width: 410px) {
    .purchase-items-table--manual > table > tbody > tr:has(> td > [data-purchase-field]) {
        grid-template-areas:
            "product product"
            "quantity bonus"
            "cost cost"
            "validity validity"
            "subtotal actions";
    }
}
