/*
 * Week calendar (common/components/calendar/week/): the week with one column per day and a card per event.
 * Tokens (text sizes, shadows, radii, --course-color) come from tokens.css.
 */

/* --- week: header with title and week buttons --- */

/* the calendar is as high as its content and scrolls with the page, no second scroll area inside it */
.calendar-week {
    display: flex;
    flex-direction: column;
}

/* title left, week buttons right */
.calendar-week__header {
    flex-shrink: 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

/* phones: title and buttons don't fit in one row, both centered one below the other */
@media (max-width: 640px) {
    .calendar-week__header {
        flex-direction: column;
    }
}

/* without pico's margin below headings, so the title sits on the line of the buttons */
.calendar-week__title {
    margin: 0;
    font-size: 1.25rem;
    line-height: 1.2;
}

/* the same size as the filter fields and buttons (.filters in layout.css), so the calendar matches the filters above it */
.calendar-week__header [role="group"] {
    /* only the room its buttons need, pico stretches the group to the full width and adds a margin below */
    width: auto;
    margin-bottom: 0;
    font-size: var(--cf-text-sm);
}

/* set on the buttons themselves: pico widens the side padding of buttons inside a group */
.calendar-week__header [role="group"] button {
    --pico-form-element-spacing-horizontal: var(--cf-field-spacing-horizontal);
    width: auto;
}

/* the day tabs only exist for small screens (see the end of the file); the radios behind them are never shown */
.calendar-week__tab-radio,
.calendar-week__mobile-nav {
    display: none;
}

/* --- week: board with the day columns --- */

/* seven day columns; no overflow, so the board doesn't scroll on its own and the details may reach past its edge */
.calendar-week__board {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 0;
    width: 100%;
    position: relative;
    border: 1px solid var(--pico-muted-border-color);
    border-radius: var(--pico-border-radius);
}

/* weekday above the date; the stronger line sets the heads apart from the columns */
.calendar-week__day-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.5rem 0.25rem;
    font-size: var(--cf-text-md);
    background: var(--pico-background-color);
    border-bottom: 2px solid var(--pico-muted-border-color);
}

/* the column grows with its cards; the minimum keeps a short or empty week from collapsing to a thin strip */
.calendar-week__day-col {
    display: flex;
    flex-direction: column;
    min-height: 10rem;
    padding: 0.5rem 0.35rem;
    position: relative;
}

/* a line between the days, not around the board, which has its own border */
.calendar-week__day-col + .calendar-week__day-col,
.calendar-week__day-header + .calendar-week__day-header {
    border-left: 1px solid var(--pico-muted-border-color);
}

/* one list per day, earliest start on top (sorted in the view); no time grid, which left large gaps between the cards */
.calendar-week__events {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    position: relative;
}

/* --- event card --- */

/* the course color as an accent on the left, like on the course cards */
.calendar-card {
    border-radius: var(--cf-radius-sm);
    border: 1px solid var(--pico-muted-border-color);
    border-left: 3px solid var(--course-color, var(--pico-primary));
    background: var(--pico-card-background-color);
    box-shadow: var(--cf-shadow-sm);
    line-height: 1.2;
}

/* a mouse over a tile shows that it can be clicked */
.calendar-card:hover {
    box-shadow: var(--cf-shadow-md);
}

/* a card that is a link as a whole (occupancy plan) */
a.calendar-card,
a.calendar-card:is(:hover, :active, :focus) {
    --pico-color: inherit;
    display: block;
    color: inherit;
    text-decoration: none;
}

/*
 * time below the title; the card is as high as its text, so the title may wrap instead of being cut off.
 * the padding sits here, not on the card: on the calendar widget the preview is the button, so it fills the whole tile
 */
.calendar-card__preview {
    display: flex;
    flex-direction: column;
    row-gap: 0.1rem;
    padding: 0.35rem 0.4rem;
    font-size: var(--cf-text-xs);
}

/*
 * the preview of the calendar widget is a button that opens the details; pico's button look is undone, so the tile
 * reads like the linked tile of the occupancy plan. --pico-color: pico gives a button the inverse text color, which
 * the seats would take over
 */
button.calendar-card__preview {
    --pico-color: inherit;
    --pico-box-shadow: none;
    width: 100%;
    border: none;
    border-radius: inherit;
    background: none;
    color: inherit;
    font-weight: inherit;
    line-height: inherit;
    text-align: left;
}

/* pico sets its colors again on hover, click and focus; one class more, so these stay */
button.calendar-card__preview:is(:hover, :active, :focus) {
    --pico-color: inherit;
    --pico-box-shadow: none;
}

/* the keyboard still shows which tile it is on */
button.calendar-card__preview:focus-visible {
    outline: 2px solid var(--pico-primary-focus);
    outline-offset: 1px;
}

/* the title leads; long words break, the columns are narrow */
.calendar-card__title {
    font-size: var(--cf-text-xs);
    font-weight: 600;
    overflow-wrap: anywhere;
}

/* seats left, in the text color and bold, so it reads apart from the muted time */
.calendar-card__seats {
    font-size: var(--cf-text-2xs);
    font-weight: 600;
    color: var(--pico-color);
}

/* the time on one line; in a very narrow column it is cut off rather than wrapped; the instructor reads the same */
.calendar-card__time,
.calendar-card__instructor {
    color: var(--pico-muted-color);
    font-size: var(--cf-text-2xs);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --- pop-up with the details of an event --- */

/*
 * a popover of the browser (the popover attribute): the button of the tile opens it, a tap outside, Esc or "Close"
 * closes it. the browser shows it above everything, centered in the window, on every screen alike; only the look is
 * set here. the details follow docs/requirements/frontend-conventions.md: page text size, everything centered
 */
.calendar-card__popup {
    width: 18rem;
    max-width: calc(100% - 2rem);
    padding: 0.75rem;
    font-size: var(--cf-text-md);
    line-height: 1.4;
    text-align: center;
    color: var(--pico-color);
    background: var(--pico-card-background-color);
    border: 1px solid var(--pico-muted-border-color);
    border-radius: var(--pico-border-radius);
    box-shadow: var(--cf-shadow-lg);
}

/* the page behind steps back as behind every other pop-up (pico's dialog overlay); a tap on it closes the details */
.calendar-card__popup::backdrop {
    background: var(--pico-modal-overlay-background-color);
}

/* like an h3 of the page content: 1rem, centered */
.calendar-card__popup-title {
    margin: 0 0 0.5rem;
    font-size: 1rem;
}

/* the shared centered key-value list from elements.css, only without pico's list spacing */
.calendar-card__popup .key-value-list,
.calendar-card__popup .key-value-list li {
    margin: 0;
}

/* actions row: "Book" and "Close" (.button-compact in elements.css) side by side, centered below the values */
.calendar-card__popup-actions {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

/* --- desktop: the week fills the window --- */

/*
 * after the scroll hint the week fills the window down to its bottom edge, whatever the screen height;
 * --cf-anchor-offset (tokens.css) is the navbar gap above the section; 17rem: the section's top padding on the start page,
 * the filter row with the space below it, the calendar header, the day headers and a margin below; at least 10rem,
 * so the lowest notebooks (1280×560) still fit
 */
@media (min-width: 1024px) {
    .calendar-week__day-col {
        min-height: max(10rem, calc(100dvh - var(--cf-anchor-offset) - 17rem));
        padding: 0.6rem 0.5rem;
    }

    .calendar-week__events {
        gap: 0.6rem;
    }

    .calendar-week__day-header {
        padding-block: 0.75rem;
        font-size: 1rem;
    }

    .calendar-card__preview {
        row-gap: 0.2rem;
        padding: 0.5rem 0.6rem;
    }

    .calendar-card__title {
        font-size: var(--cf-text-md);
    }

    .calendar-card__time,
    .calendar-card__instructor,
    .calendar-card__seats {
        font-size: var(--cf-text-sm);
    }
}

/* --- tablet and phone (down to 360px): one day at a time, chosen with the day tabs --- */

@media (max-width: 768px) {
    /* seven columns don't fit; the tabs above the board choose the day */
    .calendar-week__mobile-nav {
        display: flex;
        justify-content: space-around;
        gap: 0.25rem;
        margin-bottom: 0.75rem;
    }

    /* weekday above the day of the month, all seven tabs equally wide */
    .calendar-week__tab-label {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 0.3rem 0.2rem;
        font-size: var(--cf-text-xs);
        border: 1px solid var(--pico-muted-border-color);
        border-radius: var(--pico-border-radius);
        cursor: pointer;
    }

    .calendar-week__board {
        grid-template-columns: 1fr;
    }

    /* every day is hidden, the rules below show the chosen one */
    .calendar-week__day-col,
    .calendar-week__day-header {
        display: none;
    }

    /* without javascript: each tab is the label of a radio, the checked radio shows head and column of its day (data-day) */
    #day-tab-0:checked ~ .calendar-week__board [data-day="0"],
    #day-tab-1:checked ~ .calendar-week__board [data-day="1"],
    #day-tab-2:checked ~ .calendar-week__board [data-day="2"],
    #day-tab-3:checked ~ .calendar-week__board [data-day="3"],
    #day-tab-4:checked ~ .calendar-week__board [data-day="4"],
    #day-tab-5:checked ~ .calendar-week__board [data-day="5"],
    #day-tab-6:checked ~ .calendar-week__board [data-day="6"] {
        display: flex;
    }

    /* the tab of the chosen day is filled like a forward button */
    #day-tab-0:checked ~ .calendar-week__mobile-nav label[for="day-tab-0"],
    #day-tab-1:checked ~ .calendar-week__mobile-nav label[for="day-tab-1"],
    #day-tab-2:checked ~ .calendar-week__mobile-nav label[for="day-tab-2"],
    #day-tab-3:checked ~ .calendar-week__mobile-nav label[for="day-tab-3"],
    #day-tab-4:checked ~ .calendar-week__mobile-nav label[for="day-tab-4"],
    #day-tab-5:checked ~ .calendar-week__mobile-nav label[for="day-tab-5"],
    #day-tab-6:checked ~ .calendar-week__mobile-nav label[for="day-tab-6"] {
        border-color: var(--pico-primary);
        background: var(--pico-primary);
        color: var(--pico-primary-inverse);
    }

    /* a single day has no neighbour to be set apart from */
    .calendar-week__day-col + .calendar-week__day-col,
    .calendar-week__day-header + .calendar-week__day-header {
        border-left: none;
    }
}
