@charset "utf-8";

$header-z-index: 100;

body > header {
    position: sticky;
    top: 0;
    z-index: $header-z-index;
    height: var(--header-height);
    overflow: hidden;

    background-color: var(--primary-background-color);
    font-size: var(--nav-font-size);
    color: var(--primary-text-color);
    display: flex;
    flex-direction: row;
    padding-right: 10px;

    box-shadow: 0 0 2px var(--shadow-color-light);

    margin: 0;

    a, a:visited {
        text-decoration: none;
        color: var(--primary-text-color);

        // Vertically center text
        display: flex;
        align-items: center;
    }

    #short_title {
        display: none;
    }

    #toggle_sidebar_btn {
        margin-right: 10px;
        background-color: var(--primary-background-color);
    }

    @media print {
        #toggle_sidebar_btn {
            display: none;
        }

        box-shadow: none;
        border-bottom: 1px solid var(--line-color-light);
    }
}

@mixin only-short-title {
    body > header {
        #long_title {
            display: none !important;
            color: red;
        }

        #short_title {
            display: block;
        }
    }
}

:root.minimizedNavHeader {
    @include only-short-title;
}

@media screen and (max-width: $site-content-preferred-width) {
    @include only-short-title;
}

:root {
    --header-effective-height: var(--header-height);
}

:root.minimizedNavHeader {
    --header-effective-height: 0px;
}

:root.minimizedNavHeader body > header {
    > *:not(#toggle_sidebar_btn) {
        opacity: 0;
        display: inline-block;
        transition: opacity 0.5s ease;
    }

    #toggle_sidebar_btn {
        padding-left: 4px;
        width: var(--header-height);
    }

    word-wrap: break-word;
    width: var(--header-height);
    padding: 0;
    transition: width 0.5s ease;

    position: fixed;

    // The minimizedNavHeader class is added after page load. Make the
    // transition less jarring.
    animation: grow-in 0.5s ease 1;
}

:root.minimizedNavHeader.hasOpenSidebar body > header {
    > *:not(#toggle_sidebar_btn) {
        opacity: 1;
    }

    width: calc(var(--nav-width) + #{2 * $navbar-padding});
}

nav.sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;

    width: var(--nav-width);

    display: flex;
    flex-direction: column;

    opacity: 0;
    transform: scale(0, 1) translate(-30px, 0);

    color: var(--primary-text-color);
    box-shadow: 0 0 2px var(--shadow-color-light);
    padding: $navbar-padding;

    z-index: $header-z-index - 1;

    &.open {
        transform: scale(1, 1);
        opacity: 1;
    }

    transform-origin: left;
    transition: opacity 0.5s ease, transform 0.5s ease, width 0.5s ease;

    // Work around a rendering bug in Safari — apply the background color to both
    // the results pane and the container.
    //
    // Without this, Safari may display elements of pinned-pages in the same
    // location as the search results.
    &, .search-results {
        background-color: var(--primary-background-color);
    }


    // Container with search box and button
    > .search-container {
        display: flex;
        flex-direction: row;

        input {
            flex-grow: 1;
            flex-shrink: 1;

            // Allow it to shrink
            min-width: 20px;
        }
    }

    & > .pinned-pages {
        flex-grow: 1;
        flex-shrink: 1;

        min-height: 30px;
    }

    & > .search-results-container, & > .pinned-pages {
        overflow: auto;
    }

    & > .search-results-container > .search-results {
        &.hidden {
            display: none;
        }

        .results-description {
            color: var(--text-color-faint);
            border-bottom: 1px solid var(--line-color-light);
            margin-right: 30px;
        }

        // Context for each result.
        .context {
            margin-left: 15px;
            margin-right: 20px;
            padding-left: 5px;

            color: var(--text-color-faint);
            border-left: 1px solid var(--line-color-light);
            text-decoration: none;

            word-wrap: anywhere;
        }

        // Search result link
        a {
            background-color: transparent;
            transition: background-color 0.2s ease;
            display: list-item;
            padding: 5px;
            color: var(--primary-text-color);
        }

        a:hover, a:focus-visible {
            background-color: var(--selected-item-bg-color);
        }
    }

    & > .search-results-container > ul.search-results, & > ul.pinned-pages {
        list-style: none;
        padding-left: 0;

        a {
            text-decoration: none;
            display: block;
            color: var(--primary-text-color);
        }


        li, & > a {
            padding: 4px;
            border-bottom: 1px solid var(--line-color-light);

            a:hover {
                text-decoration: underline;
            }

            &.current_page {
                background-color: var(--selected-item-bg-color);
            }

            &.current_page a {
                color: var(--selected-item-fg-color);
                font-weight: bold;
                text-align: end;
            }
        }
    }

    footer {
        font-style: italic;
        margin-left: 22px;
        margin-right: 22px;
        margin-top: 30px;

        color: var(--text-color-faint);
    }
}

// To make space for the navigation bar, add padding to
// hash links. See
// https://gomakethings.com/how-to-prevent-anchor-links-from-scrolling-behind-a-sticky-header-with-one-line-of-css/
.main-container * {
    scroll-margin-top: 2.5em;
}


.recent-posts {
    display: flex;
    flex-direction: column;
    padding-left: 0;
    align-items: center;

    flex-wrap: wrap;
    overflow-x: auto;

    li {
        ::before {
            content: "";
        }

        list-style: none;

        border: 1px solid var(--line-color-light);
        border-radius: 4px;
        padding-left: 12px;
        padding-right: 12px;
        margin-bottom: 4px;

        h2 {
            font-variant: small-caps;
        }

        .post-date {
            float: right;
            color: var(--text-color-faint);

            // Ensure that there is space between the date and
            // the post title.
            margin-left: 30px;
        }

        .post-description {
            color: var(--text-color-faint);
            font-style: italic;
            font-weight: 200;
        }

        .tags {
            opacity: 0.7;
            font-size: 0.8em;
        }
    }
}

// Scrollable grid layout for the recent posts widget.
.recent-posts-grid {
    max-height: 500px;

    li {
        max-width: Min(50vw, 500px);
    }

    @media screen and (max-width: 500px) {
        max-height: 100vh;

        li {
            max-width: unset;
        }
    }
}

@media print {
    .recent-posts {
        display: none;

        // Should we decide to show the recent posts,
        // ensure that they're in a list format.
        max-height: unset;
        max-width: unset;
        overflow-x: hidden;

        li {
            max-width: unset;
            border: none;
        }
    }
}