/*
 * Elements (docs/requirements/frontend-conventions.md): what the sections of a page are filled with, on every page alike:
 * form fields and buttons, lists, tables, notes, notices, hints, forms and messages.
 * Tokens come from tokens.css, the sections around the elements from layout.css.
 */

/* --- states --- */
/* something that is switched off (an inactive course, a cancelled event) stays visible, but steps back */
.is-inactive {
    opacity: 0.6;
}

/*
 * --- form fields and buttons: one size on every page ---
 * pico fixes them to 1rem and a matching height; here they follow the text size around them (page, filters,
 * navbar), with spacing that fits it. checkboxes and radios keep their own size, without it they collapse to a line.
 * a plain selector list instead of :is(), so a class on a single button still outweighs it.
 * the type selectors match pico's own [type=submit] etc.: with button alone pico's 1rem would win on every
 * <button type="submit">, so it would be larger than a link button next to it
 */
input:not([type="checkbox"], [type="radio"]),
select,
textarea,
button,
[type="submit"],
[type="button"],
[type="reset"],
[role="button"] {
    font-size: inherit;
    height: auto;
}

/* only the page content; the navbar's menu keeps pico's spacing */
main {
    --pico-form-element-spacing-vertical: 0.6rem;
    --pico-form-element-spacing-horizontal: var(--cf-field-spacing-horizontal);
}

/*
 * compact button: every button in a table, and .button-compact in lists and pop-ups.
 * as wide as its label and in the text size around it; a label over two lines would make the row tall
 */
td :is(button, [role="button"]),
.button-compact {
    width: auto;
    margin: 0;
    padding: 0.3rem 0.9rem;
    white-space: nowrap;
}

/* checkboxes aren't round */
input[type="checkbox"] {
    --pico-border-radius: var(--cf-radius-sm);
}

/* --- lists --- */
/* key-value lists: centered lines, bullets would no longer line up */
.key-value-list {
    padding: 0;
    text-align: center;
}

.key-value-list li {
    list-style: none;
}

/*
 * feature box: the yes/no properties that apply (e.g. covered by health insurance), each in its own
 * tinted box with a check mark; a box takes at most a third of the row, so three fit side by side
 */
.feature-box {
    --feature-gap: 1rem;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: var(--feature-gap);
    margin: 0 0 1.5rem;
    padding: 0;
}

.feature-box li {
    flex: 0 1 calc((100% - 2 * var(--feature-gap)) / 3);
    margin: 0;
    padding: 0.6rem 0.9rem;
    list-style: none;
    border-radius: var(--pico-border-radius);
    background: var(--cf-sage-100);
    color: var(--cf-sage-900);
    font-weight: 600;
    text-align: center;
}

/* phones: a third would break every word, so one box per row */
@media (max-width: 640px) {
    .feature-box li {
        flex-basis: 100%;
    }
}

.feature-box li::before {
    content: "✓";
    margin-right: 0.4rem;
    color: var(--cf-sage-700);
}

/*
 * --- action list: one row per entry, text on the left, its button (.button-compact) on the right ---
 * e.g. the cohorts of a course in the pop-up of the course page
 */
.action-list {
    margin: 0;
    padding: 0;
    font-size: var(--cf-text-md);
}

.action-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin: 0;
    padding-block: 0.5rem;
    list-style: none;
    border-bottom: 1px solid var(--pico-muted-border-color);
}

.action-list li:last-child {
    border-bottom: none;
}

/* --- tables --- */
/* tables: pico sizes cells and buttons on its own, both have to follow the text size */
.page-narrow :is(th, td) {
    font-size: inherit;
}

/* all table columns centered, titles included (docs/requirements/frontend-conventions.md); pico aligns them left */
th,
td {
    text-align: center;
}

/* numbers never broken, "120 €" over two lines is hard to read */
.page-narrow :is(th, td).cell-number {
    white-space: nowrap;
}

/*
 * phones: several columns don't fit, so each row turns into a centered key-value list.
 * the column titles are hidden visually but stay for screen readers; each cell repeats its title from data-label
 */
@media (max-width: 640px) {
    .page-narrow :is(table, tbody, tr, td) {
        display: block;
    }

    .page-narrow thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
    }

    .page-narrow tr {
        padding-block: 0.75rem;
        text-align: center;
        border-bottom: 1px solid var(--pico-table-border-color);
    }

    .page-narrow td,
    .page-narrow td.cell-number {
        padding: 0.15rem 0;
        text-align: center;
        border: none;
    }

    .page-narrow td[data-label]::before {
        content: attr(data-label) ": ";
        font-weight: bold;
    }

    /* a cell without a value would leave its title alone on a line, e.g. "Companion:" */
    .page-narrow td[data-label]:empty {
        display: none;
    }

    /* cells with only a button sit side by side below the values */
    .page-narrow td:not([data-label]) {
        display: inline-block;
        padding: 0.5rem 0.5rem 0;
    }
}

/* --- notes, notices and hints --- */
/* short text that stands alone, e.g. the message of a list without entries or a sentence on an account page */
.page-note {
    text-align: center;
}

/*
 * notice: something the user has to know before reading on (a cancelled booking, log in to book).
 * the only card on a page (pico's article look), centered like the content around it
 */
.page-notice {
    text-align: center;
}

/* short hint next to an action, e.g. the legal notice above "Confirm Booking": smaller and muted, so it doesn't compete with the button */
.page-hint {
    margin-bottom: 1rem;
    color: var(--pico-muted-color);
    font-size: var(--cf-text-sm);
    text-align: center;
}

/* --- forms (common/components/form_grid.html): size and width come from .page-narrow, the fields share rows on a 12-column grid --- */
/* a little more room between the last field and the buttons */
.form-grid + .page-actions {
    margin-top: 0.5rem;
}

/* a note below the form, e.g. the link to the registration below the login */
.page-narrow > form + .page-note {
    margin-top: 1.5rem;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    column-gap: 1rem;
}

/* small screens: one field per row */
.form-grid > * {
    grid-column: 1 / -1;
}

/*
 * the rows: salutation, first and last name | street and number | zip code, city and country | telephone.
 * only from 1024px on, below that "Hausnummer" and "Divers" do not fit their narrow columns.
 */
@media (min-width: 1024px) {
    .form-grid > .field-gender,
    .form-grid > .field-number,
    .form-grid > .field-zip_code {
        grid-column: span 2;
    }

    .form-grid > .field-first_name,
    .form-grid > .field-last_name {
        grid-column: span 5;
    }

    .form-grid > .field-street {
        grid-column: span 10;
    }

    .form-grid > .field-city,
    .form-grid > .field-telephone,
    .form-grid > .field-email,
    .form-grid > .field-login,
    .form-grid > .field-password,
    .form-grid > .field-current_email,
    .form-grid > .field-new_email,
    .form-grid > .field-password1,
    .form-grid > .field-password2 {
        grid-column: span 6;
    }

    .form-grid > .field-country {
        grid-column: span 4;
    }

    /* the only field of the form (password reset) */
    .form-grid > :only-child {
        grid-column: 1 / -1;
    }
}

/* .page-narrow sets all inputs to automatic height, a checkbox needs its own size */
.form-grid input[type="checkbox"] {
    height: 1.25em;
    margin-bottom: 0;
}

/* hints below a field, e.g. the password rules */
.form-grid .field-help {
    margin: -0.5rem 0 0.75rem;
    color: var(--pico-muted-color);
    font-size: var(--cf-text-sm);
}

.form-grid .field-help ul {
    margin: 0;
    padding-left: 1rem;
    color: inherit;
}

.form-grid .field-help li {
    margin: 0;
    color: inherit;
}

/* the narrowest select: pico's room for the arrow would cut off "Divers" */
.form-grid > .field-gender select {
    padding-right: 1.75rem;
    background-position: center right 0.4rem;
}

/* validation messages of django forms; the message sits close to its field instead of below the field's margin */
.errorlist {
    margin: -0.75rem 0 1rem;
    padding: 0;
    color: var(--pico-del-color);
    font-size: var(--cf-text-sm);
    list-style: none;
}

.errorlist li {
    margin: 0;
    list-style: none;
}

/* errors of the whole form, e.g. a wrong password at the login */
form > .errorlist {
    margin: 0 0 1rem;
}

/* a checkbox label has no field margin the message could move into */
.form-grid label:has(input[type="checkbox"]) + .errorlist {
    margin-top: 0.25rem;
}

/* --- messages as toasts (docs/requirements/frontend-conventions.md) --- */

/* top right corner, a little below the sticky navbar; above the page, so nothing moves */
.toasts {
    position: fixed;
    top: calc(var(--cf-header-height) + 0.7rem);
    right: 1rem;
    z-index: 90;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: min(22rem, calc(100% - 2rem));
}

.message {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    font-size: var(--cf-text-md);
    border-left: 4px solid var(--pico-primary);
    border-radius: var(--pico-border-radius);
    background-color: var(--pico-card-background-color);
    box-shadow: var(--cf-shadow-md);
}

.message > span {
    flex: 1;
}

.message.error,
.message.danger {
    border-left-color: var(--pico-del-color);
}

.message.success {
    border-left-color: var(--pico-ins-color);
}

.message.warning {
    border-left-color: var(--pico-mark-background-color);
}

/* success and info fade out by themselves; warnings and errors stay until they are closed */
.message:is(.success, .info, .debug) {
    animation: message-fade-out 0.4s ease 5s forwards;
}

@keyframes message-fade-out {
    to {
        opacity: 0;
        visibility: hidden;
    }
}

/* a plain cross instead of pico's button look */
.message__close {
    width: auto;
    margin: 0;
    padding: 0 0.25rem;
    border: none;
    background: none;
    color: var(--pico-muted-color);
    font-size: 1.25rem;
    line-height: 1;
}

.message__close:is(:hover, :focus) {
    background: none;
    color: var(--pico-color);
}

/* --- print --- */
/* what only the printout shows, e.g. the signature list */
.print-only {
    display: none;
}

@media print {
    /* the frame of the page, messages and buttons are of no use on paper; important, they are utilities for any element */
    .site-header,
    .site-footer,
    .toasts,
    .page-actions,
    .no-print {
        display: none !important;
    }

    .print-only {
        display: block;
    }

    /* the paper sets the width */
    main.container,
    .page-narrow {
        max-width: none;
    }

    /* a box around every cell and room for a signature; pico only draws a faint line below each row */
    .page-narrow :is(th, td) {
        border: 1px solid var(--pico-color);
    }

    .page-narrow td {
        height: 3rem;
    }

    /* a row is never split over two pages */
    .page-narrow tr {
        break-inside: avoid;
    }
}
