// $news-bg: #fffbeb;
// $news-accent-bg: #f8e8b1;

@import './mixins.scss';

@layer component {
    //
    // Components - for complex parts of the UI like search bars or compound buttons
    //

    .material-symbols-outlined {
        font-family: 'Material Symbols Outlined Variable';
        font-weight: normal;
        font-style: normal;
        line-height: 1;
        text-transform: none;
        letter-spacing: normal;
        word-wrap: normal;
        white-space: nowrap;
        direction: ltr;

        display: inline-grid;
        place-content: center;

        font-size: 24px;
        font-variation-settings:
            'FILL' 0,
            'wght' 300,
            'GRAD' 0,
            'opsz' 24;

        max-width: 32px;
    }

    .title {
        font-family: 'Iosevka', monospace;
        font-weight: 700;
        font-size: 28px;
    }

    .search {
        width: 100%;
        height: 2.5rem;

        @include neo-brutalist-card;

        display: grid;
        grid-template-columns: 1fr auto;
        align-items: center;

        cursor: pointer;

        background: #fff;

        &:hover,
        &:hover input[type='text'] {
            background: #f8f8f8;
        }

        input[type='text'] {
            border: none;
            box-shadow: none;
            outline: none;
            height: 100%;

            padding: 0;
            padding-left: 0.35rem;
        }

        .material-symbols-outlined {
            padding: 0 0.5rem;
        }
    }

    .flex-column {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }

    .flex-row {
        display: flex;
        flex-direction: row;
        gap: 1rem;
    }

    // just to know for reference
    .fake-masonry {
        display: grid;
        grid-template-columns: repeat(var(--columns), 1fr);
        grid-auto-flow: dense;

        & > * {
            grid-row: span var(--masonry-height);
        }
    }

    .search-results {
        width: 100%;

        display: flex;
        flex-direction: column;
        gap: 1rem;

        .search-result {
            width: 100%;

            display: grid;
            grid-template-columns: auto auto 1fr auto;
            grid-template-areas: 'icon text . right';

            align-items: center;

            gap: 0.5rem;

            padding: 0.5rem;

            background: #fff;

            @include neo-brutalist-card;

            a {
                display: contents;
            }

            & > .icon {
                grid-area: icon;
                display: grid;
            }

            & > .text {
                grid-area: text;
                display: grid;
            }

            & > .right {
                grid-area: right;
                display: grid;
            }
        }
    }

    .appunti-scrollable {
        display: flex;
        overflow-x: auto;

        .appunti-list {
            padding: 2px;
            padding-bottom: 1rem;
        }
    }

    .appunti-list {
        display: grid;
        grid-auto-flow: column;

        gap: 3rem;

        overflow-x: auto;

        max-width: 100%;
    }

    .appunti-item {
        display: flex;
        flex-direction: column;
        gap: 0.25rem;

        color: #444;

        & > .thumbnail {
            width: 10rem;
            aspect-ratio: 10 / 14;
            background: #e0e0e0;

            @include neo-brutalist-card($hoverable: true);
        }

        & > .thumbnail + * {
            font-weight: 700;
            padding-top: 0.25rem;
        }

        & > .title,
        & > .course,
        & > .author,
        & > .course-year {
            padding-left: 0.5rem;
            font-size: 16px;
        }
    }

    .article-list {
        display: grid;
        grid-auto-flow: row;

        max-width: 100%;

        gap: 2rem;
        grid-template-columns: repeat(auto-fill, minmax(25rem, 1fr));
        grid-auto-rows: auto;

        .article {
            display: grid;
            grid-template-rows: auto auto auto;

            background: var(--card-bg, $project-card-bg);
            color: #000e;

            @include neo-brutalist-card($size: 3px, $offset: 9px);

            row-gap: 0.5rem;
            padding: 1rem;

            .description {
                font-size: 16px;
            }

            .tags {
                display: flex;
                gap: 0.5rem;
                flex-wrap: wrap;
                font-size: 14px;
                font-weight: 600;
                color: #555;
            }
        }
    }

    .news-list {
        display: grid;
        grid-auto-flow: column;

        // .news-item {
        //     background: $news-bg;
        //     color: #111;

        //     @include neo-brutalist-card($size: 3px, $offset: 9px);

        //     display: flex;
        //     flex-direction: column;

        //     width: 22rem;
        //     max-height: 27rem;

        //     overflow: hidden;

        //     ::-webkit-scrollbar {
        //         width: 10px;
        //     }

        //     ::-webkit-scrollbar-thumb {
        //         background-color: #c67e14;
        //         border: 2px solid #222;

        //         &:hover {
        //             background-color: #e69419;
        //         }
        //     }

        //     a {
        //         font-weight: 600;
        //         text-decoration: none;
        //         color: #c67e14;

        //         &:hover {
        //             text-decoration: underline solid 2px;
        //         }
        //     }

        //     & > .title {
        //         padding: 1rem;
        //         background: $news-accent-bg;
        //         line-height: 1;
        //         font-size: 26px;
        //     }

        //     a.title {
        //         color: #83530c;
        //     }

        //     & > .abstract {
        //         flex-grow: 1;

        //         padding: 1rem;

        //         overflow-y: auto;

        //         @extend .text;
        //     }

        //     & > .content {
        //         display: flex;
        //         padding: 1rem;
        //         flex-direction: column;
        //         gap: 0.5rem;

        //         background: #fff8da;

        //         & > .continue {
        //             padding: 1rem;

        //             display: grid;
        //             align-items: end;
        //             justify-content: end;
        //         }

        //         & > .description {
        //             font-size: 16px;
        //             line-height: 1.5;

        //             flex-grow: 1;
        //         }

        //         & > .tags {
        //             display: flex;
        //             gap: 0.5rem;
        //             flex-wrap: wrap;
        //             font-size: 14px;
        //             color: #555;
        //         }

        //         & > .date {
        //             font-size: 14px;
        //             font-style: italic;
        //             font-weight: 600;
        //             color: #0008;
        //         }

        //         & > .author {
        //             font-weight: 600;
        //             font-size: 15px;
        //             color: #555;
        //         }
        //     }
        // }
    }

    .timeline {
        display: grid;

        --timeline-track-size: 6rem;
        --timeline-thickness: 6px;
        --timeline-color: #333;

        grid-template-columns: 1fr var(--timeline-track-size) 1fr;

        @media screen and (max-width: $screen-desktop-min) {
            --timeline-track-size: 3rem;
            grid-template-columns: var(--timeline-track-size) 1fr;
        }

        max-width: 120ch;

        & > .timeline-item {
            position: relative;
            display: grid;

            & > .content {
                padding: 2rem 1rem;

                @media screen and (max-width: $screen-desktop-min) {
                    padding: 1rem 1rem 1rem 0;
                }

                display: grid;
                grid-template-columns: auto;

                & > .title {
                    font-size: 20px;
                    font-weight: 700;
                }

                & > .date {
                    font-size: 32px;
                    font-weight: 400;
                    color: #555;
                }
            }

            // timeline vertical line
            &::before {
                content: '';

                position: absolute;
                top: 0;
                bottom: 0;
                left: 50%;
                transform: translateX(-50%);
                width: var(--timeline-thickness);

                background: var(--timeline-color);
            }

            &:first-child::before {
                top: 50%;
            }

            &:last-child::before {
                bottom: 50%;
            }

            // timeline circle
            &::after {
                content: '';

                position: absolute;
                top: 50%;
                left: 50%;
                transform: translate(-50%, -50%);
                width: 1rem;
                height: 1rem;
                border-radius: 50%;

                background: var(--timeline-color);
            }

            &::before,
            &::after {
                grid-column: 1 / span 1;
            }

            @media screen and (min-width: $screen-desktop-min) {
                &:nth-child(odd)::before {
                    grid-column: 2 / span 1;
                }

                &:nth-child(even)::before {
                    grid-column: 1 / span 1;
                }

                &:nth-child(odd)::after {
                    grid-column: 2 / span 1;
                }

                &:nth-child(even)::after {
                    grid-column: 1 / span 1;
                }
            }

            .dropdown {
                @include neo-brutalist-card;

                max-width: 15rem;
                position: absolute;
                bottom: calc(-10rem - 1px);
                left: 50%;
                transform: translateX(calc(-50% - var(--timeline-track-size) / 2));
                border-top: none;
                border-radius: 0 0 0.5rem 0.5rem;

                @media screen and (max-width: $screen-desktop-min) {
                    @include neo-brutalist-card;

                    position: static;
                    transform: none;
                    margin-left: auto;
                    margin-right: auto;
                }
            }
            @media screen and (min-width: $screen-desktop-min) {
                &:nth-child(odd) {
                    grid-column: 1 / span 2;
                    grid-template-columns: 1fr var(--timeline-track-size);

                    & > .content {
                        grid-column: 1;
                    }

                    .dropdown {
                        left: auto;
                        right: 50%;
                        transform: translateX(calc(50% - var(--timeline-track-size) / 2));
                    }
                }

                &:nth-child(even) {
                    grid-column: 2 / span 2;
                    grid-template-columns: var(--timeline-track-size) 1fr;

                    & > .content {
                        grid-column: 2;
                    }

                    .dropdown {
                        left: 50%;
                        transform: translateX(calc(-50% + var(--timeline-track-size) / 2));
                    }
                }
            }

            @media screen and (max-width: $screen-desktop-min) {
                grid-column: 1 / span 2;

                grid-template-columns: var(--timeline-track-size) 1fr;

                & > .content {
                    grid-column: 2;
                }
            }
        }
    }

    //
    // Cards
    //

    .card {
        display: grid;

        --card-base-internal: var(--card-base, #f8f8f8);

        background: var(--card-base-internal);
        color: color-mix(in srgb, var(--card-base-internal), #000 80%);

        @include neo-brutalist-card($size: 3px, $offset: 9px);

        row-gap: 0.5rem;
        padding: 1rem;

        // Variants

        &.large {
            padding: 2rem;

            @include neo-brutalist-card($size: 4px, $offset: 8px);

            row-gap: 1rem;

            & > .title {
                font-size: 36px;
                font-weight: 700;
            }

            & > .text {
                font-size: 18px;
            }
        }

        // Child Items

        & > .title {
            color: color-mix(in srgb, var(--card-base-internal), #000 75%);
            font-size: 26px;
            font-weight: 700;
        }

        & > .text {
            font-size: 16px;

            &.small {
                color: color-mix(in srgb, var(--card-base-internal), #000 75%);
                font-size: 14px;
                font-weight: 600;
            }

            &.dimmed {
                color: color-mix(in srgb, var(--card-base-internal), #000 50%);
            }
        }

        & > .tags {
            display: flex;
            gap: 0.5rem;
            flex-wrap: wrap;
            font-size: 14px;
            font-weight: 600;
            color: #555;

            a {
                color: color-mix(in srgb, var(--card-base-internal), #000 60%);
                font-weight: 600;

                &:hover {
                    text-decoration: underline solid 2px;
                }
            }
        }

        a:hover {
            text-decoration: underline solid 2px;
        }

        a.title {
            &:hover {
                text-decoration: underline solid 3px;
            }
        }

        @media screen and (max-width: $screen-desktop-min) {
            padding: 0.8rem;

            &.large {
                padding: 1.25rem;

                & > .title {
                    font-size: 32px;
                }
            }
        }
    }

    //
    // Card List
    //

    .card-list {
        display: grid;
        grid-auto-flow: row;

        max-width: 100%;

        gap: 2rem;
        grid-template-columns: repeat(auto-fit, minmax(25rem, 1fr));
        grid-auto-rows: auto;

        & > .card {
            max-width: 25rem;
        }

        @media screen and (max-width: $screen-desktop-min) {
            grid-template-columns: 1fr;
        }
    }

    .show-more {
        place-self: center;
    }

    .search-bar {
        display: grid;
        grid-template-columns: auto 1fr;

        width: 100%;

        gap: 1rem;

        @media screen and (max-width: $screen-desktop-min) {
            grid-template-columns: 1fr;

            & > .search {
                grid-row: 1;
            }
        }
    }

    /* .filter-select {
        width: 100%;
        height: 2.5rem;

        @include neo-brutalist-card;

        display: grid;
        align-items: center;
        grid-auto-flow: column;

        cursor: pointer;

        --filter-bg-color-hover: color-mix(in srgb, var(--filter-bg-color, #ddd), #000 10%);

        background: var(--filter-bg-color, #ddd);

        &:hover,
        &:hover select {
            background: var(--filter-bg-color-hover);
        }

        .material-symbols-outlined {
            padding: 0 0.35rem;
        }

        select {
            border: none;
            box-shadow: none;
            outline: none;
            height: 100%;
            appearance: none;

            cursor: pointer;

            padding: 0;

            background: var(--filter-bg-color, #ddd);
        }
    } */

    .combobox {
        width: 100%;
        height: 2.5rem;
        position: relative;
        padding: 0 0.25rem 0 0.25rem;

        @include neo-brutalist-card;

        cursor: pointer;

        --filter-bg-color-hover: color-mix(in srgb, var(--filter-bg-color, #ddd), #000 10%);

        background: var(--filter-bg-color, #ddd);

        .material-symbols-outlined {
            padding: 0 0.35rem;
        }

        .selected {
            height: 100%;
            gap: 0.25rem;
            display: grid;
            grid-auto-flow: column;
            grid-template-columns: 1fr auto;
            align-items: center;

            .content {
                display: grid;
                grid-auto-flow: column;
                align-items: center;
                justify-content: start;
            }
        }

        .dropdown {
            position: absolute;
            z-index: 10;
            top: calc(100% + 8px);
            left: -3px;

            @include neo-brutalist-card;

            background: #fff;

            .option {
                height: 2rem;
                padding: 0 0.5rem 0 0.25rem;
                display: grid;
                grid-auto-flow: column;
                align-items: center;
                justify-content: start;
                &:hover {
                    background: #ddd;
                }
            }
        }

        @media screen and (max-width: $screen-desktop-min) {
            .dropdown {
                left: 3px;
                right: 3px;

                top: calc(100% + 9px);
            }
        }
    }

    .gallery-collage {
        display: flex;

        place-content: center;
        align-items: center;
        gap: 1rem;

        flex-wrap: wrap;

        width: 100%;

        max-width: 64rem;

        & > .card {
            padding: 3px;

            overflow: hidden;

            @media screen and (max-width: $screen-desktop-min) {
                max-width: 100%;
            }

            img {
                display: grid;

                max-width: 25rem;
                max-height: 25rem;

                border-radius: 3px;

                @media screen and (max-width: $screen-desktop-min) {
                    max-height: none;

                    width: 25rem;
                    max-width: 100%;
                }
            }
        }
    }
}
