/*
 * Page layout (docs/requirements/frontend-conventions.md): the frame of every page (navbar, main area, footer),
 * the page types and the page sections (title, first screen, filters, actions).
 * Tokens come from tokens.css, the elements inside the sections from elements.css.
 */

/* --- page layout: the main area grows, so the footer sits at the bottom even on short pages --- */
body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
}

/* in a flex column, centered containers would shrink to their content; full width keeps pico's max-width centering */
/* only the page's own blocks, overlays such as the debug toolbar keep their own sizing */
body > header,
body > .container,
body > main,
body > footer {
    width: 100%;
}

body > main {
    flex: 1 0 auto;
}

/* --- navbar: separated from the page and always visible --- */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background-color: var(--pico-background-color);
    border-bottom: 1px solid var(--pico-muted-border-color);
    box-shadow: var(--cf-shadow-md);
    margin-bottom: 2rem;
    /* the text color for the entries below; resolved here, because pico redefines --pico-color as the primary color inside links */
    --cf-nav-color: var(--pico-color);
}

.site-header nav {
    /* compact bar: smaller text and little vertical spacing */
    /* the buttons set the bar height, the entries need no extra spacing */
    --pico-nav-element-spacing-vertical: 0;
    --pico-nav-link-spacing-vertical: 0.1rem;
    /* same proportions as the page buttons: rectangle with rounded corners, not a pill */
    --pico-border-radius: var(--cf-radius-sm);
    font-size: var(--cf-text-md);
    /* full window width with a small side margin */
    width: 100%;
    padding-inline: 1rem;
    /* keep the chapters next to the home icon instead of spreading them */
    justify-content: flex-start;
    align-items: center;
}

/* flush to the edges: no outer padding instead of pico's negative margins, which would overflow the window on the right */
.site-header nav > ul:first-child {
    margin-left: 0;
}

.site-header nav > ul:first-child > li:first-child {
    padding-left: 0;
}

.site-header nav > ul:last-child > li:last-child {
    padding-right: 0;
}

/* push the language select to the right */
.site-header nav > ul:last-child {
    margin-left: auto;
    margin-right: 0;
}

/* every entry centered on the same line, icons included */
/* only the bar itself, the dropdown list keeps pico's own layout */
.site-header nav > ul,
.site-header nav > ul > li {
    display: flex;
    align-items: center;
}

.site-header nav li > a,
.site-header .nav-burger summary {
    display: inline-flex;
    align-items: center;
    line-height: 1;
}

/* all entries in the text color and bold, also on hover */
.site-header a,
.site-header a:is(:hover, :focus),
.site-header summary,
.site-header select {
    color: var(--cf-nav-color);
    font-weight: bold;
}

/* icons scale with the text instead of a fixed pixel size */
.site-header svg {
    display: block;
    width: 1.5em;
    height: 1.5em;
}

.site-header form {
    margin-bottom: 0;
}

/* language select in pico's default look; only the form margin below it is removed */
.site-header select {
    margin-bottom: 0;
    /* the select sets the bar height: little padding and a tight line keep the bar low */
    padding-block: 0.2rem;
    line-height: 1.2;
    /* no frame and no fill; only the color is cleared, the arrow is pico's background image and stays */
    border: none;
    background-color: transparent;
}

/* hamburger without pico's dropdown arrow */
.site-header .nav-burger summary::after {
    display: none;
}

/* pico gives dropdown summaries a fixed form-field height, which would make the bar tall on small screens */
.site-header .nav-burger summary {
    height: auto;
    padding: 0;
    border: none;
    background: none;
}

/* desktop: chapters inline, no hamburger */
.site-header .nav-burger {
    display: none;
}

/* small screens: chapters move into the hamburger menu */
@media (max-width: 768px) {
    .site-header .nav-chapters {
        display: none;
    }

    .site-header .nav-burger {
        display: flex;
    }
}

/* --- footer: plain area at the end of the page, set apart by a tinted background --- */
.site-footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem 1.5rem;
    margin-top: 4rem;
    padding: 1.5rem 1rem;
    background-color: var(--pico-card-sectioning-background-color);
    font-size: var(--cf-text-md);
    /* the text color for the links below; resolved here for the same reason as in the header */
    --cf-footer-color: var(--pico-color);
}

.site-footer nav {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
}

/* links in the text color instead of pico's primary */
.site-footer a,
.site-footer a:is(:hover, :focus) {
    color: var(--cf-footer-color);
}

/* --- title section of every page: centered, with more room between title, subtitle and the content that follows (2rem) --- */
.page-intro {
    margin-bottom: 2rem;
    text-align: center;
}

.page-intro > :not(:first-child) {
    margin-top: 0.75rem;
}

/* --- page headings: on desktop all pages use the same, 20 % larger title and subtitle --- */
/* only on tall windows: on wide but low ones (notebooks) the larger title would push the first screen apart */
@media (min-width: 1024px) and (min-height: 901px) {
    h1 {
        --pico-font-size: 2.4rem;
    }

    /* subtitle of the title section; the selector follows pico's own rule for it */
    .page-intro > :not(:first-child):last-child {
        font-size: 1.2rem;
    }
}

/* --- first screen (start page, course page): fills the window below the navbar --- */
/*
 * the title starts at the same height as on every other page; the area still fills the window,
 * so the calendar below only shows after scrolling. the free space sits at the bottom.
 * 3rem are the navbar's bottom margin (2rem) and main's top padding (1rem) above the area.
 */
.hero {
    min-height: calc(100vh - var(--cf-header-height) - 3rem);
    min-height: calc(100dvh - var(--cf-header-height) - 3rem);
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    margin-bottom: 2rem;
}

/*
 * --- scroll hint: bottom of the first screen, points to the calendar below ---
 * margin-top auto puts it at the bottom of .hero; sticky keeps it just above the window's lower edge
 * while the first screen is in view, also when the content fills more than the window, and lets it
 * scroll away with the first screen. the background keeps it readable when it floats over content
 */
.scroll-hint {
    position: sticky;
    bottom: 0.5rem;
    align-self: center;
    margin-top: auto;
    padding: 0.25rem 0.75rem 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    border-radius: var(--pico-border-radius);
    /* the page white directly: inside links pico sets --pico-background-color to transparent */
    background: var(--cf-white);
    color: var(--pico-muted-color);
    font-size: var(--cf-text-sm);
    text-decoration: none;
}

.scroll-hint:is(:hover, :focus) {
    color: var(--pico-color);
    text-decoration: none;
}

.scroll-hint svg {
    width: 1.5rem;
    height: 1.5rem;
    animation: scroll-hint-bob 2s ease-in-out infinite;
}

/* a slow nudge downwards; off for people who asked their system for less motion */
@keyframes scroll-hint-bob {
    0%, 100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(0.25rem);
    }
}

@media (prefers-reduced-motion: reduce) {
    .scroll-hint svg {
        animation: none;
    }
}

/* the click on the hint glides to the calendar; the target stops below the sticky navbar */
@media (prefers-reduced-motion: no-preference) {
    html {
        scroll-behavior: smooth;
    }
}

:is(#upcoming, #calendar) {
    scroll-margin-top: var(--cf-anchor-offset);
}

/* --- narrow page type (docs/requirements/frontend-conventions.md): one column for text, forms and tables --- */
.page-narrow {
    width: 100%;
    max-width: 48rem;
    margin-inline: auto;
    font-size: var(--cf-text-md);
}

/* space between the sections of a page, the same as below the title group */
.page-narrow > section:not(:last-child) {
    margin-bottom: 2rem;
}

/* centered like the key-value lists below it */
.page-narrow h3 {
    --pico-font-size: 1rem;
    text-align: center;
}

/* filters without a card, smaller than the page text, centered; the fields follow this size */
.filters {
    /* 2rem to the list or calendar below, like between all sections */
    margin-bottom: 2rem;
    font-size: var(--cf-text-sm);
    --pico-spacing: 0.8rem;
}

/* two fields side by side fit this width; the narrow page type and the start page use their full width instead */
.filters form {
    max-width: 36rem;
    margin-inline: auto;
}

/* a filter that is only a checkbox has no field that fills the row, so it sits centered like the section */
.filters form > label {
    margin: 0 auto;
}

/* 2rem above the reset button, the same space as between the title group and the filters; the fields bring --pico-spacing */
.filters .filter-actions {
    margin-top: calc(2rem - var(--pico-spacing));
    text-align: center;
}

/* filters fill the narrow column instead of their own default width */
.page-narrow .filters form {
    max-width: none;
}

/* --- actions section: compact buttons side by side, equally high, centered --- */
.page-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1rem;
}

/* the attribute selector outweighs pico's full width for submit buttons */
.page-actions > :is(button, [role="button"]) {
    width: auto;
    margin: 0;
}
