@layer components {
    products-table {
        scroll-margin-block: var(--size-6);

        font-size: var(--font-size-00);

        > header {
            display: flex;
            flex-direction: column;
            gap: var(--size-3);
            padding: var(--size-3) var(--size-4);
            border: 1px solid var(--color-border-grey);

            & .result-settings {
                display: flex;
                gap: var(--size-2);
                align-items: center;
                justify-content: space-between;
                list-style-type: none;
                padding: 0;
                margin: 0;

                & .view-settings {
                    display: flex;
                    align-items: center;
                    gap: var(--size-2);

                    & .view-modes {
                        padding: 0;
                        form {
                            display: flex;
                            gap: var(--size-1);

                            :is(input[type="radio"]) {
                                display: none;

                                &:checked+label {
                                    color: var(--color-button-blue);
                                }
                            }

                            :is(label):hover {
                                color: var(--color-button-blue);
                                cursor: pointer;
                            }
                        }
                    }
                }
            }

            /* tablet and up */
            @media screen and (min-width: 768px) {
                flex-direction: row;
                justify-content: space-between;
                align-items: center;

                & .result-settings .view-settings {
                    gap: var(--size-3);

                    & .view-modes form {
                        gap: var(--size-2);
                    }
                }
            }
        }

        sorting-controls {
            position: relative;
            display: inline-flex;

            .sort-by {
                padding: var(--size-1) var(--size-2) var(--size-1) var(--size-5) !important;
                gap: var(--size-0);
                /* width: 100px; */
                /* flex: 0 0 100px; */

                color: var(--color-blue);

                background: none;
                border-radius: 100px;

                anchor-name: --sort;

                & .icon-wrapper {
                    width: 24px;
                    height: 24px;
                    display: flex;
                    align-items: center;
                    justify-content: center;
                }

                &:is(:hover, :has(+ :popover-open)) {
                    background-color: var(--color-blue);
                    color: white;
                }

                div:has(> &) {
                    position: relative;
                }
            }

            #sorting {
                position-anchor: --sort;
                position-area: end center;
                position: absolute;
                margin: 5px 0 0;
                padding: 0;
                width: max-content;

                list-style-type: none;

                background: white;
                border: 1px solid var(--color-border-grey);
                border-radius: var(--radius-2);

                @supports not (position-anchor: --search) {
                    inset: 0;
                    top: var(--anchor-top);
                    right: var(--anchor-right);
                    left: unset;
                }

                &::backdrop {
                    background: none;
                }

                li a {
                    display: flex;
                    align-items: center;
                    gap: var(--size-1);

                    padding: calc(var(--size-1) * 1.4) var(--size-2);

                    text-decoration: none;
                    transition: none;

                    &:hover {
                        background: var(--color-blue);
                        color: white;
                    }

                    &:before {
                        content: "";
                        display: inline-block;
                        width: 16px;
                        height: 16px;
                    }

                    &:is([aria-selected]):before {
                        content: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="m4.5 12.75 6 6 9-13.5" /></svg>');
                        /* content: url('/images/icons.svg#check'); */
                        color: red;
                    }
                }
            }
        }

        & .no-products {
            display: flex;
            align-items: center;
            justify-content: center;
            height: 200px;
            padding: var(--size-3);
            color: var(--color-text);
        }

        &[view-mode="list"] filter-status-bar {
            border: 1px solid var(--color-border-grey);
        }

        &[view-mode="list"] product-list {
            display: flex;
            flex-direction: column;

            > product-info {
                grid-template-columns: clamp(80px, 40vw, 110px) 1fr;
                grid-template-rows: max-content min-content min-content;
                grid-template-areas: "image title" "image price" "footer cart";

                gap: 0 var(--size-3);
                padding-inline: var(--size-3);
                /* In list view padding is added to the top grid areas instead of the card to allow image and badge to align with the top of the card */
                padding-top: 0;

                & .product-image-container {
                    position: relative;
                    /* In list view padding is added to the top grid areas instead of the card to allow image and badge to align with the top of the card */
                    padding-top: var(--size-10);
                    padding-right: var(--size-3);

                    :is(picture, img) {
                        margin-inline: unset;
                        width: 100px;
                        height: 100px;
                    }
                }

                & .promo-badges {
                    position: absolute;
                    top: 0;
                    right: 0;
                }

                > .shipping {
                    display: none;
                }

                & .header-container {
                    /* In list view padding is added to the top grid areas instead of the card to allow image and badge to align with the top of the card */
                    padding-top: var(--size-8);
                    gap: var(--size-3);
                    display: flex;
                    flex-direction: column;
                }

                & .product-category {
                    display: none;
                }

                & .price-section {
                    /* In list view padding is added to the top grid areas instead of the card to allow image and badge to align with the top of the card */
                    padding: var(--size-3) 0;
                    display: flex;
                    flex-direction: column;
                    gap: var(--size-3);

                    & .stock-levels {
                        display: block;
                    }

                    & .shipping {
                        display: block;
                    }
                }

                footer {
                    justify-content: center;
                    margin: 0 var(--size-3) 0 0;

                    & .stock {
                        display: none;
                    }
                }
            }

            /* tablet and up */
            @media screen and (min-width: 768px) {

                > product-info {
                    grid-template-columns: clamp(80px, 40vw, 160px) 1fr clamp(80px, 40vw, 180px);
                    grid-template-rows: max-content min-content min-content;
                    grid-template-areas: "image title price" "image . footer" "brand delivery cart";

                    gap: 0 var(--size-7);
                    padding-inline: var(--size-7);
                    padding-bottom: var(--size-8);

                    & .product-image-container {
                        padding-top: var(--size-8);
                        padding-right: var(--size-7);

                        :is(picture, img) {
                            width: 160px;
                            height: 160px;
                        }
                    }


                    & .manufacturer-details {
                        display: flex;
                        justify-content: flex-start;
                        align-items: center;
                    }

                    & .product-brief {
                        text-align: left;
                    }

                    & .brand-logo {
                        display: flex;
                        justify-content: center;
                        margin-right: var(--size-6);
                    }

                    & .add-to-cart {
                        display: grid;
                        align-items: end;
                    }

                    & .delivery-options {
                        display: flex;
                        gap: var(--size-3);
                        align-items: flex-end;

                        :is(strong) {
                            color: var(--color-green);
                        }
                    }

                    & footer {
                        justify-content: flex-end;
                        align-items: flex-start;
                        margin: 0;

                        & .stock {
                            display: none;
                        }
                    }

                    & .price-section {
                        padding-top: var(--size-8);

                        display: grid;
                        grid-template-columns: auto;
                        grid-template-rows: min-content min-content min-content min-content;
                        grid-template-areas: "price" "shipping" "stock" "bulk-buy-price";

                        gap: var(--size-2);
                        text-align: right;

                        & .shipping {
                            display: flex;
                            justify-content: flex-end;
                        }

                        & .discount {
                            display: flex;
                            justify-content: flex-end;
                        }
                    }
                }
            }

            /* desktop and up */
            @media screen and (min-width: 960px) {
                > product-info {
                    grid-template-columns: clamp(80px, 40vw, 230px) 1fr clamp(80px, 40vw, 220px);
                    gap: 0 var(--size-9);

                    & .product-image-container {
                        padding-right: var(--size-9);

                        :is(picture, img) {
                            width: 180px;
                            height: 180px;
                        }
                    }

                    & .brand-logo {
                        margin-right: var(--size-9);
                    }
                }
            }
        }

        products-table-body > footer {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: var(--size-2);
            padding: var(--size-3) var(--size-4);
            border: var(--border-size-1) solid var(--color-border-grey);

            /* tablet and up */
            @media screen and (min-width: 768px) {
                flex-direction: row;
                justify-content: space-between;
                align-items: center;

                & nav {
                    flex-grow: 1;
                }
            }
        }

        products-table-body.loading {
            opacity: 0.5;
            pointer-events: none;
        }

        & .outlined-sides {
            position: relative;

            box-shadow: -1px 0 0 var(--color-border-grey);

            &::after {
                content: '';
                display: block;
                position: absolute;
                top: 0;
                right: 0;
                width: 1px;
                height: 100%;
                box-shadow: 1px 0 0 var(--color-border-grey);
            }

        }
    }
}
