/*
* Gruppuppgift: E-shop
* Grupp 4 / FaceRoots
* Oscar Nilsson
* oscar.nilsson@medieinstitutet.se
*/

@import url(styleguide.css);
@import url(cart.css);
@import url(footer.css);

:root {
    --pageWidth: 1200px; /* Desktop */
    --tabletWidth: 960px;
    --mobileWidth: 768px;
    --sidebarWidth: minmax(150px, 200px);
    --footerHeight: 300px;

    --pageAlignment: center;

    --gridColGap: 2rem;
    --gridRowGap: 2rem;

    --pageBg: var(--color-white);
    --contentBg: var(--color-white);

    --color: var(--color-brown-dark);
    --linkColor: rgba(64, 48, 34, 1);
    --linkHoverColor: rgba(64, 48, 34, 1);
    --linkTextDecoration: none;
    --linkHoverTextDecoration: underline;
    
    --btnColor: var(--color-white);
    --btnBgColor: rgba(64, 48, 34, 1);
    --btnHoverColor: #333;
    --btnHoverBgColor: rgba(64, 48, 34, .9);
    --btnBorderRadius: var(--borderRadius);

    --accentColor: var(--color-brown-dark);

    --borderRadius: var(--radius-sm);

    --productCardBoxShadow: 
        rgba(0, 0, 0, 0.1) 0px 4px 6px -1px, 
        rgba(0, 0, 0, 0.06) 0px 2px 4px -1px;
}

@media screen and (max-width: 960px) {
    :root {
        --pageWidth: auto;
        --gridColGap: 1rem;
        --gridRowGap: 1rem;

        font-size: 14px;
    }
}

:root * {
    box-sizing: border-box;
}

body {
    background-color: var(--contentBg);
    color: var(--color);
    min-height: 100svh;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: var(--pageAlignment);
}

/* Must have if body is display: flex; */
body > header, body > footer {
    width: 100%;
}

/* Main container: containing sidebar and main */
div#mainContainer {
    max-width: var(--pageWidth);
    flex: 1;
    display: grid;
    align-items: start;
    grid-template-areas: "heading heading"
    "sidebar main";
    grid-template-columns: var(--sidebarWidth) auto;
    grid-template-rows: auto 1fr;
    gap: var(--gridRowGap) var(--gridColGap);
    padding: 4rem var(--gridColGap);

    & h2 {
        font-size: 3rem;
        margin-bottom: calc(2.5rem - var(--gridRowGap));
        grid-area: heading;
    }

    & h3 {
        grid-column: 1 / span 3;
        margin: 0;
        margin-bottom: calc(var(--gridRowGap) / 2 * -1);
    }

    & a {
        color: var(--linkColor);
        text-decoration: var(--linkTextDecoration);

        &:hover {
            color: var(--linkHoverColor);
            text-decoration: var(--linkHoverTextDecoration);
        }
    }

    & button {
        background-color: var(--btnBgColor);
        color: var(--btnColor);
        border: none;
        border-radius: var(--btnBorderRadius);
        cursor: pointer;
        font-family: 'Epiloque', sans-serif;
        font-weight: 300;

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

/* Main: containing product cards */
main {
    grid-area: main;
    display: grid;
    gap: var(--gridRowGap) var(--gridColGap);
    grid-template-columns: 1fr 1fr 1fr;
}

/* Product card */
article.productCard {
    background-color: #fff;
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: center;
    justify-items: start;
    opacity: 0;
    animation-name: productCard;
    animation-duration: .5s;
    animation-fill-mode: forwards;
    border-radius: var(--borderRadius);
    overflow: hidden;
    grid-row-gap: calc(var(--gridRowGap) / 2); 
    padding: var(--gridRowGap) var(--gridColGap);
    box-shadow: var(--productCardBoxShadow);

    & > *:not(.action) {
        grid-column: 1 / span 2;
    }

    &:not(.filtered) {
        display: none;
    }

    & header {
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-areas: 
            "productImage productImage"
            "productName productName"
            "productBrand productPrice"
            "productCategory productPrice";

        & figure {
            
            margin: 0;
            width: 100%;
            grid-area: productImage;

            & a {
                display: block;
            }

            & img {
                display: block;
                width: 100%;
                height: auto;
                /* aspect-ratio: 4/3;
                object-fit: cover; */
            }

            & figcaption {
                display: none;
            }
            
            margin-bottom: 1rem;
        }

        & h4.productName {
            grid-area: productName;
            margin: 0;
            font-size: 1em;
            white-space: wrap;
            margin-bottom: .5em;
        }

        & span.productPrice {
            grid-area: productPrice;
            text-align: right;
            font-size: 1em;
            white-space: nowrap;
        }

        & span.productBrand {
            grid-area: productBrand;
            font-size: .8em;
        }

        & span.productCategory {
            grid-area: productCategory;
            opacity: .75;
            font-size: .8em;
        }
    }

    & ul {
       padding-left: 1.25em; 
    }

    /* & *.productDescription {
        display: none;
    } */

    & p.productDetails {
        display: none;
    }

    /* & a.action {
        text-decoration: underline;
    } */

    & button.addToCart {
        font-size: 1rem;
        padding: .5em .75em;
        white-space: nowrap;
        justify-self: end;
    }
}

/* Sidebar */
aside {
    position: sticky;
    top: var(--gridRowGap);
    align-self: start;

    grid-area: sidebar;
    display: flex;
    flex-direction: column;
    gap: var(--gridColGap);

    &.fixed {
        position: fixed;
    }

    & > * {
        border-radius: var(--borderRadius);
        background-color: var(--contentBg); /* var(--contentBg); */
    }

    & nav {
        display: flex;
        flex-direction: column;
        gap: var(--gridRowGap);

        & ul {
            margin: 0;
            list-style: none;
            padding: 0;
        }

        & > ul {
            display: flex;
            flex-direction: column;
            gap: .5rem;
            /* font-weight: bold; */

            & ul {
                font-weight: normal;
                margin: .5rem;
                display: none;
            }
        }

        & label {
            cursor: pointer;
            -webkit-user-select: none;
            -ms-user-select: none;
            user-select: none;
        }

        & input[type="checkbox"] {
            margin-right: .5em;
            vertical-align: .1em;
            accent-color: var(--accentColor);
        }

        & label {
            color: var(--linkColor);

            &:hover {
                color: var(--linkHoverColor);
                text-decoration: var(--linkHoverTextDecoration);
            }
        }
    }
}

/* Responsiveness: tablet */
@media screen and (max-width: 960px) {
    body {
        & a {
            &:hover {
                text-decoration: none;
            }
        }
    }

    div#mainContainer {
        padding: var(--gridRowGap) var(--gridColGap);
        width: 100%;
        grid-template-areas: 
            "sidebar"
            "heading"
            "main";
        grid-template-columns: auto;
        grid-template-rows: auto auto 1fr;

        & h2 {
            margin-bottom: calc((2.5rem - var(--gridRowGap)) / 2);
        }

        & main {
            grid-template-columns: 1fr 1fr 1fr;

            & h3 {
                grid-column: 1 / span 3;
            }

            & article.productCard {
                padding: var(--gridRowGap) var(--gridColGap);
                grid-row-gap: var(--gridRowGap); 
            }
        }

        & aside {
            margin: 
                calc(var(--gridRowGap) * -1) 
                calc(var(--gridColGap) * -1) 
                0 
                calc(var(--gridColGap) * -1); /* To compensate for grid gap and horizontal padding */
            top: 0;
            box-shadow: var(--productCardBoxShadow);
            max-width: 100vw;
            background-color: var(--contentBg);

            & nav {
                padding: var(--gridRowGap) var(--gridColGap) 0 var(--gridColGap);
                gap: 0;

                &::before, &::after {
                    opacity: 0;
                    position: absolute;
                    content: "<";
                    left: calc(var(--gridColGap)/2);
                    transform: translateX(-50%);
                    bottom: calc(var(--gridRowGap));
                    transition: opacity 1s ease;
                }

                &::after {
                    right: 0;
                    left: auto;
                    right: calc(var(--gridColGap)/2);
                    transform: translateX(50%);
                    content: ">"
                }

                &.scrollLeft::before, &.scrollRight::after {
                    opacity: 1;
                }

                & > ul {
                    position: relative;
                    flex-direction: row;
                    overflow-x: scroll;
                    padding: var(--gridRowGap) 0;
                }

                & input[type="checkbox"] {
                    position: absolute;
                    opacity: 0;

                    &:checked + label {
                        background-color: var(--accentColor);
                        color: var(--contentBg);

                        &:hover {
                            background-color: var(--btnHoverBgColor);
                            text-decoration: none;
                        }
                    }
                }

                & label {
                    color: var(--linkColor);
                    padding: .33em .5em .25em .5em;
                    border-radius: 6px;
                    white-space: nowrap;

                    &:hover {
                        color: var(--linkHoverColor);
                        text-decoration: none;
                    }
                }
            }
        }
    }
}

/* Responsiveness: mobile */
@media screen and (max-width: 768px) {
    div#mainContainer {
        & main {
            grid-template-columns: 1fr 1fr;

            & h3 {
                grid-column: 1 / span 2;
            }
        }
    }
}

/* Animation: fade-in mockup product cards */
@keyframes productCard {
    0% { opacity: 0; }
    100% { opacity: 1; }
}

