:root {
    --text: #1f2328;
    --muted: #59636e;
    --border: #d1d9e0;
    --background: #ffffff;
    --surface: #f6f8fa;
    --accent: #0969da;
    --accent-text: #ffffff;
    --error: #cf222e;
    --warning: #9a6700;
    --warning-background: #fff8c5;
    --preferred: #2da44e;
    --possible: #a8e0b5;
    --teacher-off: rgba(130, 80, 223, 0.18);
    --course: #ddf4ff;
    --course-border: #0969da;
    --course-unavailable: #ffebe9;
    --course-unavailable-border: #cf222e;
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --text: #e6edf3;
        --muted: #9198a1;
        --border: #3d444d;
        --background: #0d1117;
        --surface: #151b23;
        --accent: #4493f8;
        --accent-text: #0d1117;
        --error: #f85149;
        --warning: #d29922;
        --warning-background: #272115;
        --preferred: #3fb950;
        --possible: #1b4721;
        --teacher-off: rgba(163, 113, 247, 0.22);
        --course: #121d2f;
        --course-border: #4493f8;
        --course-unavailable: #2d1517;
        --course-unavailable-border: #f85149;
    }
}

* {
    box-sizing: border-box;
}

/* Even for the elements whose 'display' is set below. */
[hidden] {
    display: none !important;
}

body {
    margin: 0 auto;
    max-width: 88rem;
    padding: 1rem;
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    line-height: 1.5;
    color: var(--text);
    background: var(--background);
}

header p,
.note {
    color: var(--muted);
}

.page-title {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem 1rem;
}

.language {
    font-weight: 600;
}

.select-with-flag {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.select-with-flag select {
    padding-right: 3rem;
    /* As wide as the selected language, for the flag to be next to its
       name (where supported). */
    field-sizing: content;
}

.flag {
    position: absolute;
    /* Before the arrow of the select. */
    right: 1.7rem;
    display: inline-flex;
    pointer-events: none;
}

.flag svg {
    width: 1.75rem;
    height: 1.17rem;
    border-radius: 3px;
    /* The white of the flags on a white background. */
    box-shadow: 0 0 0 1px var(--border);
}

section {
    margin: 1.5rem 0;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 6px;
}

h1, h2, h3 {
    margin-top: 0;
}

label {
    display: inline-flex;
    flex-direction: column;
    gap: 0.25rem;
    margin: 0 1rem 0.75rem 0;
}

label.inline {
    flex-direction: row;
    align-items: center;
    gap: 0.4rem;
}

fieldset {
    margin: 0 0 0.75rem;
    padding: 0.25rem 0.75rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
}

fieldset label {
    margin-bottom: 0;
}

input, select, button {
    font: inherit;
    color: inherit;
}

input[type=text], input[type=number], input[type=time], select {
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--background);
    min-width: 0;
}

input.short {
    width: 6rem;
}

button {
    padding: 0.3rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    cursor: pointer;
}

button:hover:not(:disabled) {
    border-color: var(--muted);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

button.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
    font-weight: 600;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.row,
.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.5rem;
}

.row > label {
    margin-right: 0.5rem;
}

/* Aligned with the fields of the labels (which have a bottom margin). */
.row > button {
    margin-bottom: 0.75rem;
}

.toolbar {
    align-items: center;
    margin: 0.5rem 0;
}

.toolbar label {
    margin: 0;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.warning {
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    color: var(--warning);
    background: var(--warning-background);
}

.info {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1rem;
    margin: 0.5rem 0;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--accent);
    border-radius: 6px;
    background: var(--surface);
}

label.block {
    display: flex;
    width: 100%;
    max-width: 48rem;
    margin-right: 0;
}

textarea {
    font: inherit;
    color: inherit;
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--background);
    resize: vertical;
}

.link-row {
    display: flex;
    gap: 0.5rem;
}

.link-row input {
    flex: 1;
    min-width: 0;
    font-family: ui-monospace, monospace;
    font-size: 0.85rem;
}

#poll-section h3 {
    margin: 1.25rem 0 0.25rem;
    font-size: 1rem;
}

#poll-summary ul {
    margin: 0.25rem 0;
    padding-left: 1.25rem;
}

.participant-comment {
    display: block;
    margin-top: 0.2rem;
    font-size: 0.85rem;
    color: var(--muted);
}

.intro {
    font-size: 1.1rem;
}

blockquote {
    margin: 0.5rem 0;
    padding: 0.5rem 0.75rem;
    border-left: 4px solid var(--accent);
    background: var(--surface);
    white-space: pre-wrap;
}

.info.sent {
    display: block;
}

.info.sent p {
    margin: 0.25rem 0;
}

.sync-status {
    font-size: 0.85rem;
    color: var(--muted);
}

.sync-status.problem {
    color: var(--warning);
}

.messages {
    margin: 0.5rem 0;
    padding-left: 1.25rem;
}

.messages:empty {
    display: none;
}

.messages.error {
    color: var(--error);
}

.messages.warning {
    background: none;
    padding: 0 0 0 1.25rem;
}

/* Tables */

.table-wrapper,
.grid-wrapper {
    /* Positioned: clips the absolutely positioned content too (the
       visually hidden headers). */
    position: relative;
    overflow-x: auto;
    margin-bottom: 0.75rem;
}

table {
    border-collapse: collapse;
    width: 100%;
}

th, td {
    padding: 0.3rem 0.5rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

th {
    color: var(--muted);
    font-weight: 600;
}

td input[type=text] {
    width: 100%;
    min-width: 8rem;
}

table.compact {
    width: auto;
}

.ranges {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem 0.75rem;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.1rem 0.15rem 0.1rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    font-variant-numeric: tabular-nums;
}

.chip button {
    padding: 0 0.45rem;
    border: none;
    border-radius: 999px;
    background: none;
    line-height: 1.4;
}

.chip button:hover {
    background: var(--border);
}

.error-text {
    color: var(--error);
}

td.actions {
    white-space: nowrap;
    text-align: right;
}

td.actions button + button {
    margin-left: 0.4rem;
}

td.missing {
    color: var(--error);
    font-weight: 600;
}

.participants-picker summary {
    cursor: pointer;
}

.participants-picker > div {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 0.75rem;
    padding: 0.4rem 0;
}

.participants-picker label {
    margin: 0;
}

.unavailable-participant {
    color: var(--error);
    font-weight: 600;
}

/* Availability grid */

.brushes {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1rem;
    align-items: center;
}

.brush {
    flex-direction: row;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
}

.swatch {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 1px solid var(--border);
    border-radius: 3px;
}

.swatch.preferred {
    background: var(--preferred);
}

.swatch.possible {
    background: var(--possible);
}

.swatch.unavailable {
    background: var(--background);
}

.availability {
    --slot-width: 4.5rem;
    display: grid;
    min-width: max-content;
    user-select: none;
}

.availability .day-header .short {
    display: none;
}

/* Small screens: the week fits in the width. */
@media (max-width: 40rem) {
    .availability {
        --slot-width: 2.6rem;
    }

    .availability .day-header {
        font-size: 0.85rem;
    }

    .availability .day-header .long {
        display: none;
    }

    .availability .day-header .short {
        display: inline;
    }
}

.availability .day-header {
    padding: 0.2rem;
    text-align: center;
    font-weight: 600;
}

.availability .time-label {
    padding-right: 0.5rem;
    font-size: 0.8rem;
    line-height: 1;
    color: var(--muted);
    text-align: right;
    transform: translateY(-0.4rem);
}

.availability .slot {
    height: 1.25rem;
    min-width: var(--slot-width);
    padding: 0;
    border: none;
    border-left: 1px solid var(--border);
    border-top: 1px dotted var(--border);
    border-radius: 0;
    background: var(--background);
    touch-action: none;
}

.availability .off-hours {
    border-left: 1px solid var(--border);
    background: var(--surface);
}

.availability .slot.hour {
    border-top: 1px solid var(--border);
}

.availability .slot.teacher-off {
    background-image: repeating-linear-gradient(
        45deg, var(--teacher-off) 0 4px, transparent 4px 8px);
}

.availability .slot.preferred {
    background-color: var(--preferred);
}

.availability .slot.possible {
    background-color: var(--possible);
}

/* The example: shown as is, but can't be painted. */
.availability .slot:disabled {
    opacity: 1;
    cursor: default;
}

.availability .slot:hover:not(:disabled) {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

/* Timetable */

.timetable {
    display: grid;
    min-width: max-content;
    /* Room for the label of the last hour. */
    padding-bottom: 0.75rem;
}

.timetable .day-header {
    padding: 0.2rem;
    text-align: center;
    font-weight: 600;
}

.timetable .hours {
    position: relative;
    width: 3.5rem;
}

.timetable .hours div {
    position: absolute;
    right: 0.5rem;
    font-size: 0.8rem;
    line-height: 1;
    color: var(--muted);
    transform: translateY(-0.4rem);
}

.timetable .day {
    position: relative;
    min-width: 7rem;
    border-left: 1px solid var(--border);
    background-image: linear-gradient(to bottom, var(--border) 1px, transparent 1px);
}

.timetable .course {
    position: absolute;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0.1rem 0.3rem;
    border: 1px solid var(--course-border);
    border-left-width: 4px;
    border-radius: 4px;
    background: var(--course);
    font-size: 0.8rem;
    line-height: 1.2;
}

.timetable .course.has-unavailable {
    border-color: var(--course-unavailable-border);
    background: var(--course-unavailable);
}

.timetable .course strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Printing: only the timetable. */

@media print {
    header,
    main > section:not(#result-section),
    #result-section .toolbar,
    #result-outdated {
        display: none !important;
    }

    #result-section {
        border: none;
        padding: 0;
    }

    .grid-wrapper,
    .table-wrapper {
        overflow: visible;
    }
}

#calendar-table th {
    color: var(--text);
    padding-right: 1.5rem;
}
