/* The one style sheet of the front end (docs/FRONTEND_ARCHITECTURE.md section 3, rule 13). */

:root {
  font-family: system-ui, sans-serif;
  font-size: 15px;
  color: #1f2933;
  background: #f3f5f8;
}
body { margin: 0; }
/* The switch between the views: an element with the attribute is never shown, whatever its class says. */
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; }

button, input, select, textarea { font: inherit; }
button { padding: 0.45rem 0.8rem; border: 1px solid #b6c0cc; border-radius: 6px; background: #fff; cursor: pointer; }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: #1d5fd1; border-color: #1d5fd1; color: #fff; }
button.danger { background: #fff; border-color: #b3261e; color: #b3261e; }
/* Where the keyboard is: the same ring on every button and link */
button:focus-visible, a:focus-visible { outline: 2px solid #1d5fd1; outline-offset: 2px; }
input, select, textarea { padding: 0.45rem; border: 1px solid #b6c0cc; border-radius: 6px; width: 100%; box-sizing: border-box; }
label { display: grid; gap: 0.25rem; font-size: 0.85rem; color: #52606d; }
.error { color: #b3261e; margin: 0; min-height: 1.2em; overflow-wrap: anywhere; }

/* The login */
.login { max-width: 20rem; margin: 12vh auto 0; padding: 1.5rem; background: #fff; border-radius: 10px; box-shadow: 0 1px 4px #0002; }
.login h1 { font-size: 1.4rem; }
.login form { display: grid; gap: 0.9rem; margin-top: 1rem; }

/* The frame: the header with who is signed in, the navigation, the screen */
.bar { display: flex; align-items: center; gap: 0.75rem; padding: 0.6rem 1rem; background: #1f2933; color: #fff; }
.bar .who { margin-left: auto; min-width: 0; font-size: 0.85rem; text-align: right; overflow-wrap: anywhere; }
.bar .role { opacity: 0.75; }
.bar .sign-out { flex: none; }
.nav { display: flex; gap: 0.25rem; padding: 0 1rem; background: #fff; border-bottom: 1px solid #d9dee5; overflow-x: auto; }
.nav:empty { display: none; }
.nav-link { padding: 0.6rem 0.75rem; color: #52606d; text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap; }
.nav-link[aria-current="page"] { color: #1d5fd1; border-bottom-color: #1d5fd1; font-weight: 600; }
.screen { padding: 1rem; }

/* The week: the toolbar, the failure, the time zone, the legend */
.week-screen { --hour: 3.25rem; /* the height of one hour in a day column */ }
.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; }
.toolbar h2 { font-size: 1.05rem; margin-left: 0.5rem; }
.toolbar .loading { color: #52606d; font-size: 0.85rem; }
.week-screen .failure, .appointments-screen .failure { margin-top: 0.5rem; }
/* The banner of an appointment being moved: it stays in sight while the week scrolls under it */
.moving { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem 1rem; margin-top: 0.5rem; padding: 0.5rem 0.75rem; border: 1px solid #1d5fd1; border-radius: 6px; background: #e8f0fd; }
.moving p { margin: 0; min-width: 0; flex: 1 1 14rem; overflow-wrap: anywhere; }
.zone { margin: 0.5rem 0 0.25rem; font-size: 0.8rem; color: #52606d; }
.legend { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; list-style: none; margin: 0.25rem 0 0.5rem; padding: 0; font-size: 0.8rem; }
.legend li { overflow-wrap: anywhere; }
.legend li::before { content: ''; display: inline-block; width: 0.8em; height: 0.8em; margin-right: 0.35em; border-radius: 3px; background: hsl(var(--c)); }

/* The colours of the availability types: the logic layer gives a type its number, 0 to 5 */
.type-0 { --c: 215 70% 45%; }
.type-1 { --c: 160 65% 32%; }
.type-2 { --c: 28 85% 42%; }
.type-3 { --c: 280 50% 48%; }
.type-4 { --c: 345 65% 45%; }
.type-5 { --c: 190 75% 33%; }

/* The week itself: the hours on the left, then one column per day. min-width: 0 lets the days
   scroll sideways inside the page instead of making the page wider. */
.week { display: grid; grid-template-columns: 3.2rem minmax(0, 1fr); transition: opacity 0.15s; }
.week.stale { opacity: 0.5; }
.hours { list-style: none; margin: 2rem 0 0; padding: 0; }
.hours li { height: var(--hour); box-sizing: border-box; padding-right: 0.4rem; text-align: right; font-size: 0.7rem; color: #7b8794; transform: translateY(-0.5em); }
.days { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(7.5rem, 1fr); gap: 3px; overflow-x: auto; }
.day h3 { height: 2rem; line-height: 2rem; font-size: 0.8rem; font-weight: 600; text-align: center; color: #52606d; }
.day.today h3 { color: #1d5fd1; }
/* --hours, the number of hours shown, is set on each day by the script. */
.day-body {
  position: relative;
  height: calc(var(--hours) * var(--hour));
  background: #fff repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--hour) - 1px), #e4e7eb calc(var(--hour) - 1px), #e4e7eb var(--hour));
}
.day.today .day-body { box-shadow: inset 0 2px 0 #1d5fd1; }

/* A block of a day: its top and height are set by the script, as percentages of the day */
.block { position: absolute; left: 0; right: 0; box-sizing: border-box; padding: 0.15rem 0.35rem; overflow: hidden; font-size: 0.72rem; line-height: 1.25; overflow-wrap: anywhere; }
.window { background: hsl(var(--c) / 0.14); color: hsl(var(--c)); text-align: right; font-size: 0.65rem; }
.busy, .slot, .appointment { left: 4px; right: 4px; border-radius: 5px; }
.busy { color: #52606d; background: repeating-linear-gradient(135deg, #d9dee5 0 6px, #eceff3 6px 12px); }
.slot { border: 1px dashed hsl(var(--c)); background: #fff; color: hsl(var(--c)); }
.appointment { border: 1px solid #fff; background: hsl(var(--c)); color: #fff; }
.appointment .note { opacity: 0.85; }
/* Two blocks in the same place on the clock, the night the clocks go back: half the width each */
.block.lane-0-of-2 { right: 50%; }
.block.lane-1-of-2 { left: 50%; }
/* A slot and an appointment are buttons. A button does not stretch between left and right as a
   plain element does, so its width is said; its text starts at the top left like the others'. */
button.block { display: flex; flex-wrap: wrap; align-content: flex-start; column-gap: 0.3em; width: calc(100% - 8px); text-align: left; }
button.block.lane-0-of-2, button.block.lane-1-of-2 { width: calc(50% - 4px); }
button.block:hover { filter: brightness(0.95); }
button.block:focus-visible { outline-offset: 1px; z-index: 1; }

/* "My appointments": the two modes, the period of the history, the list */
.toolbar button[aria-pressed="true"] { background: #1f2933; border-color: #1f2933; color: #fff; }
.period { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 0.5rem 0.75rem; margin-top: 0.75rem; }
.period label { flex: 0 1 11rem; min-width: 0; }
.period .refusal { flex-basis: 100%; }
.period .refusal:empty { display: none; }
.empty { margin: 1rem 0 0; color: #52606d; }
.list { list-style: none; margin: 0.75rem 0 0; padding: 0; display: grid; gap: 0.4rem; transition: opacity 0.15s; }
.list.stale { opacity: 0.5; }
/* A row is one button: on a desktop its five texts are columns, the note taking what is left */
.row { display: grid; grid-template-columns: 7rem 8rem minmax(4rem, 10rem) minmax(0, 1fr) 6rem; gap: 0.25rem 0.75rem; align-items: baseline; width: 100%; padding: 0.6rem 0.75rem; text-align: left; }
.row span { min-width: 0; overflow-wrap: anywhere; }
.row .date { font-weight: 600; }
.row .note { color: #52606d; white-space: pre-wrap; }
.row .status { justify-self: end; font-size: 0.8rem; font-weight: 600; color: #1d5fd1; }
.row:hover { filter: brightness(0.97); }
/* What is over is quieter than what is to come */
.row.is-ended, .row.is-cancelled, .row.is-changed { background: #f3f5f8; }
.row.is-ended .status, .row.is-changed .status { color: #52606d; }
.row.is-cancelled .status { color: #b3261e; }

/* The settings: one narrow form; a field with its range and, when in fault, its refusal */
.toolbar h2:first-child { margin-left: 0; }
.unread { display: grid; gap: 0.5rem; justify-items: start; margin-top: 0.75rem; }
.settings { display: grid; gap: 1rem; max-width: 26rem; margin-top: 0.75rem; }
.field { display: grid; gap: 0.25rem; }
.field p, .settings p { margin: 0; }
.field .range, .field .hint, .settings .about { font-size: 0.8rem; color: #52606d; overflow-wrap: anywhere; }
.field .refusal:empty, .settings .failure:empty { display: none; }
.field input[aria-invalid="true"] { border-color: #b3261e; }
.field input:disabled { background: #eceff3; }
input[type="checkbox"] { width: auto; margin: 0; }
label.check { display: flex; align-items: center; gap: 0.4rem; }
.settings .saved { color: #1b6e3c; }
.settings .actions { justify-content: flex-start; }

/* The users: the form that creates one, then the list, a row with its button */
.create { display: grid; gap: 0.75rem; max-width: 26rem; margin-top: 0.75rem; }
.create p { margin: 0; }
.create .failure:empty { display: none; }
.create .actions { justify-content: flex-start; }
/* The refusal of the username says what the hint says: while it shows, the hint does not */
.field:has(.refusal:not(:empty)) .hint { display: none; }
.users-screen .list { max-width: 26rem; }
.user-row { display: flex; align-items: center; gap: 0.75rem; padding: 0.4rem 0.4rem 0.4rem 0.75rem; border: 1px solid #d9dee5; border-radius: 6px; background: #fff; }
.user-row .username { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.user-row button { flex: none; }
/* The generated password: a fixed-width face, large enough to tell l from 1 and O from 0; one
   click selects it whole, to be copied by hand */
dialog .password { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-size: 1.35rem; letter-spacing: 0.06em; user-select: all; }
/* The heading that takes the keyboard when the password dialog opens shows no ring */
dialog h3:focus { outline: none; }
dialog .question { overflow-wrap: anywhere; }

/* The availability: the types and the weekly patterns, each a form that creates one and its
   list. The six fields of a pattern stand side by side while there is room, and wrap. */
.availability-screen > section > h3 { margin-top: 1.5rem; font-size: 1rem; }
.availability-screen .list, .availability-screen .groups, .create-pattern { max-width: 40rem; }
.create-pattern { display: grid; gap: 0.75rem; margin-top: 0.75rem; }
.create-pattern p { margin: 0; }
.create-pattern .failure:empty { display: none; }
.create-pattern .actions { justify-content: flex-start; }
.pattern-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: 0.75rem; align-items: start; }
.field select[aria-invalid="true"] { border-color: #b3261e; }
.field .hint:empty { display: none; }
.type-row, .pattern-row { align-items: center; gap: 0.15rem 0.75rem; padding: 0.4rem 0.4rem 0.4rem 0.75rem; border: 1px solid #d9dee5; border-radius: 6px; background: #fff; }
.type-row { display: flex; flex-wrap: wrap; }
.type-row .name { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.type-row button { flex: none; }
/* A pattern's row: its hours and its type on a first line with "ended" and the two buttons,
   its validity below the hours */
.pattern-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto auto; }
.pattern-group h4 { margin: 1rem 0 0; font-size: 0.9rem; color: #52606d; }
.pattern-group .list { margin-top: 0.4rem; }
.pattern-row .time { font-weight: 600; white-space: nowrap; }
.pattern-row .type-name { min-width: 0; overflow-wrap: anywhere; }
.pattern-row .validity { grid-column: 1 / 3; grid-row: 2; min-width: 0; font-size: 0.85rem; color: #52606d; }
.pattern-row .ended { grid-column: 3; grid-row: 1; }
.pattern-row .ask-change { grid-column: 4; grid-row: 1 / 3; }
.pattern-row .ask-delete { grid-column: 5; grid-row: 1 / 3; }
/* A pattern whose validity is over is quieter, and says so */
.pattern-row.is-ended { background: #f3f5f8; }
.pattern-row .ended { font-size: 0.8rem; font-weight: 600; color: #52606d; }
/* The appointments in the way of a change of availability: a sentence, then one line each */
.conflicts { display: grid; gap: 0.3rem; }
.conflicts-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.2rem; font-size: 0.9rem; }
.conflicts-list li { display: flex; flex-wrap: wrap; gap: 0 0.75rem; overflow-wrap: anywhere; }
.conflicts-list .username { font-weight: 600; }

/* A single date: the date's form, then the day, its parts one under the other. A window is a
   row like a type's: its hours, its type, and its button when it has one. */
.one-date .loading { margin-left: 0.75rem; color: #52606d; font-size: 0.85rem; }
.choose { display: flex; align-items: flex-start; flex-wrap: wrap; gap: 0.5rem 0.75rem; max-width: 40rem; margin-top: 0.75rem; }
.choose .field { flex: 0 1 12rem; min-width: 0; }
/* The button stands beside the field's box, below the line of its label */
.choose .actions { margin-top: 1.3rem; }
.shown { display: grid; gap: 1rem; max-width: 40rem; margin-top: 1rem; }
.shown p { margin: 0; }
.shown h4 { margin: 0; font-size: 0.9rem; color: #52606d; }
.shown > div { display: grid; gap: 0.5rem; }
.shown .list { margin-top: 0; }
.shown .list:empty, .shown p:empty { display: none; }
.shown .actions { justify-content: flex-start; }
.date-words { font-size: 1.05rem; font-weight: 600; overflow-wrap: anywhere; }
.window-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.15rem 0.75rem; padding: 0.4rem 0.4rem 0.4rem 0.75rem; border: 1px solid #d9dee5; border-radius: 6px; background: #fff; }
.window-row .time { font-weight: 600; white-space: nowrap; }
.window-row .type-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.window-row button { flex: none; }
/* The windows being put together stand apart from the day as it is: nothing of them is saved yet */
.draft { padding: 0.75rem; border: 1px solid #1d5fd1; border-radius: 6px; background: #e8f0fd; }
.add-draft, .add-window { display: grid; gap: 0.5rem; }
.add-draft .failure:empty, .add-window .failure:empty { display: none; }
.window-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr)); gap: 0.75rem; align-items: start; }

/* The dialogs: as wide as a phone allows, scrolling inside when taller than the screen */
dialog { width: min(24rem, calc(100vw - 2rem)); max-height: calc(100dvh - 2rem); box-sizing: border-box; overflow-y: auto; border: 0; border-radius: 10px; padding: 1.25rem; box-shadow: 0 8px 30px #0004; color: inherit; }
dialog::backdrop { background: #1f293380; }
dialog[open], dialog form, dialog .choices, dialog .user { display: grid; gap: 0.8rem; }
dialog h3 { font-size: 1.05rem; }
dialog p { margin: 0; }
dialog p:empty { display: none; }
dialog .what { font-weight: 600; overflow-wrap: anywhere; }
dialog .times { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; }
dialog .users-message, dialog .booked, dialog .hint { font-size: 0.85rem; color: #52606d; }
dialog textarea { resize: vertical; }
dialog dl { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0.3rem 1rem; margin: 0; }
dialog dt { color: #52606d; font-size: 0.85rem; }
dialog dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
/* The note as a text to read: one element to show and hide, its two parts still cells of the list */
dialog .noted { display: contents; }
dialog .note-form .submit { justify-self: end; }
dialog .old { overflow-wrap: anywhere; }
.actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 0.5rem; }

/* A phone: the login takes the width, the header's parts get closer, the week shows one day */
@media (max-width: 40rem) {
  .login { margin: 1rem; max-width: none; }
  .bar { gap: 0.5rem; padding: 0.5rem 0.75rem; }
  .bar .who { font-size: 0.8rem; }
  .bar .role { display: block; }
  .screen { padding: 0.75rem; }
  .toolbar h2 { flex-basis: 100%; margin-left: 0; order: 1; }
  /* A row: the date, the time and the status on a first line, the type and the note below */
  .row { grid-template-columns: auto minmax(0, 1fr) auto; }
  .row .status { grid-column: 3; grid-row: 1; }
  .row .type-name { grid-column: 1 / -1; }
  .row .note { grid-column: 1 / -1; }
  .row .note:empty { display: none; }
  /* A pattern's row: its two buttons on a line of their own, so that a long name has the width */
  .pattern-row { grid-template-columns: auto minmax(0, 1fr) auto; }
  .pattern-row .ask-change { grid-column: 1 / 3; grid-row: 3; justify-self: end; }
  .pattern-row .ask-delete { grid-column: 3; grid-row: 3; }
  /* One day at a time, the others a swipe away */
  .days { grid-auto-columns: 82%; scroll-snap-type: x mandatory; }
  .day { scroll-snap-align: start; }
}
