/* SPDX-License-Identifier: AGPL-3.0-or-later */

/* ---------------------------------------------------------------------------
 * Carnet — the visual identity of the interface.
 *
 * Simple and impactful while remaining polished: warm paper, one blue accent,
 * soft status pills, almost no shadow. The site is read on a phone, standing
 * up, by a parent who wants one thing: find their evening and book it.
 *
 * No inline style, no third-party asset: the Content-Security-Policy is
 * `default-src 'self'` and stays that way.
 * ------------------------------------------------------------------------- */

/* Atkinson Hyperlegible, self-hosted. Chosen because its letterforms are
 * designed to be distinguished from one another, which matters on a form read
 * in a school corridor. The licence is in static/fonts/LICENSE.md. */
@font-face {
  font-family: "Atkinson Hyperlegible";
  src: url("/static/fonts/atkinson-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Atkinson Hyperlegible";
  src: url("/static/fonts/atkinson-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #fffdf7;
  --surface: #ffffff;
  /* Decorative separator between blocks: never the only cue for a control. */
  --divider: #ece6d8;
  --tint: #f4efe3;

  /* Border of an input, a select or a textarea. 3.66:1 on white, which is what
   * WCAG 1.4.11 asks of the boundary of a control. A tint of the same warm
   * family as the divider, darkened until it passes. */
  --field-border: #8c8576;
  /* The same rule for a control whose background is not white. */
  --field-border-on-tint: #7a7466;

  --ink: #1e2a3a;
  --ink-soft: #3b4657;
  --ink-faint: #5b6575;

  --accent: #1f4e8c;
  --accent-hover: #163b6b;

  --free-bg: #ffffff;
  --taken-bg: #eef0f3;
  /* 3.0:1 against the tile background, 3.4:1 against the card. */
  --taken-border: #858b96;

  --open-bg: #e6f2e8;
  --open-ink: #1f5130;
  --draft-bg: #faf0d4;
  --draft-ink: #5c4708;
  --closed-bg: #ebedf0;
  --closed-ink: #3b4657;
  --danger-bg: #fbeaea;
  --danger-ink: #8c1d1d;

  --focus: #b45309;

  --radius-tile: 10px;
  --radius-head: 14px;
  --radius-card: 12px;

  --font-body: "Atkinson Hyperlegible", -apple-system, "Segoe UI", sans-serif;

  --gutter: 1rem;
  /* Reading measure. 36rem keeps a comfortable line length and gives the page
   * enough presence on a desktop without stretching it. */
  --measure: 36rem;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.55;
  /* Digits line up in the slot grid and the tables, which are columns of
   * times. */
  font-variant-numeric: tabular-nums;
}

a {
  color: var(--accent);
  text-underline-offset: 0.15em;
}

a:hover {
  color: var(--accent-hover);
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  padding: 0.6rem 1rem;
  background: var(--surface);
  color: var(--ink);
  z-index: 10;
}

.skip-link:focus {
  left: 0.5rem;
  top: 0.5rem;
}

/* --- Structure ---------------------------------------------------------- */

.site-header {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 1.25rem var(--gutter) 0.75rem;
}

.site-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.site-title a {
  color: var(--ink);
  text-decoration: none;
}

.site-tagline {
  margin: 0.1rem 0 0;
  color: var(--ink-faint);
  font-size: 0.85rem;
}

main {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 var(--gutter) 2.5rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--divider);
  border-radius: var(--radius-card);
  padding: 1.1rem 1.15rem;
  margin: 0 0 0.9rem;
}

h1 {
  font-size: 1.55rem;
  line-height: 1.2;
  font-weight: 700;
  margin: 0 0 0.6rem;
}

h2 {
  font-size: 1.1rem;
  line-height: 1.3;
  font-weight: 700;
  margin: 0 0 0.5rem;
}

p {
  margin: 0 0 0.7rem;
}

p:last-child {
  margin-bottom: 0;
}

.muted {
  color: var(--ink-faint);
  font-size: 0.95rem;
}

.hint {
  display: block;
  color: var(--ink-faint);
  font-size: 0.85rem;
  margin-top: 0.3rem;
}

.breadcrumb {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
}

/* --- Controls ----------------------------------------------------------- */

.button,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  /* A touch target is 44px high, even when the label is short. */
  min-height: 44px;
  padding: 0.65rem 1.1rem;
  background: var(--accent);
  color: #ffffff;
  border: 1.5px solid var(--accent);
  border-radius: var(--radius-tile);
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease;
}

.button:hover,
button:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #ffffff;
}

.button-secondary {
  background: var(--surface);
  color: var(--accent);
  /* A button's outline is its visible boundary: the accent reaches 8.3:1 on
   * white, so it is used here rather than the pale divider. */
  border-color: var(--accent);
}

.button-secondary:hover {
  background: var(--tint);
  color: var(--accent-hover);
  border-color: var(--accent);
}

/* Destructive actions are outlined in red, not filled: deleting a slot is not
 * the thing a teacher is here to do, and a solid red block would shout. */
.button-danger {
  background: var(--surface);
  color: var(--danger-ink);
  border-color: var(--danger-ink);
}

.button-danger:hover {
  background: var(--danger-bg);
  color: var(--danger-ink);
  border-color: var(--danger-ink);
}

.button-small {
  min-height: 38px;
  padding: 0.4rem 0.8rem;
  font-size: 0.9rem;
}

.button-block {
  width: 100%;
}

.field {
  margin: 0 0 0.9rem;
}

label {
  display: block;
  font-weight: 700;
  font-size: 0.92rem;
  margin-bottom: 0.3rem;
}

input,
select,
textarea {
  width: 100%;
  font: inherit;
  /* 16px keeps iOS from zooming on focus. */
  font-size: 1rem;
  padding: 0.6rem 0.7rem;
  /* 1.5px so the boundary reads as a boundary, in a colour that reaches 3:1. */
  border: 1.5px solid var(--field-border);
  border-radius: var(--radius-tile);
  background: var(--surface);
  color: var(--ink);
  min-height: 44px;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  border-color: var(--accent);
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.row .field {
  flex: 1 1 7rem;
}

.inline {
  display: inline-block;
  margin: 0 0.5rem 0.5rem 0;
}

fieldset {
  border: 1px solid var(--divider);
  border-radius: var(--radius-tile);
  padding: 0.8rem 1rem;
  margin: 0 0 0.9rem;
}

legend {
  font-weight: 700;
  padding: 0 0.35rem;
}

/* Anti-robot field: in the DOM for the bot, invisible on screen, to a screen
 * reader and to the keyboard. */
.honeypot {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  pointer-events: none;
  left: 0;
  top: 0;
}

.honeypot label {
  margin: 0;
}

/* --- Messages ----------------------------------------------------------- */

.notice {
  border-radius: var(--radius-tile);
  padding: 0.75rem 0.9rem;
  margin: 0 0 0.9rem;
  border: 1px solid transparent;
}

.notice-ok {
  background: var(--open-bg);
  color: var(--open-ink);
  border-color: #cfe3d4;
}

.notice-error {
  background: var(--danger-bg);
  color: var(--danger-ink);
  border-color: #f0cfcf;
}

/* --- Status pills ------------------------------------------------------- */

.badge {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.badge-open {
  background: var(--open-bg);
  color: var(--open-ink);
}

.badge-draft {
  background: var(--draft-bg);
  color: var(--draft-ink);
}

.badge-closed {
  background: var(--closed-bg);
  color: var(--closed-ink);
}

.badge-danger {
  background: var(--danger-bg);
  color: var(--danger-ink);
}

/* --- Parent page -------------------------------------------------------- */

/* The header block names the teacher: a square initial tile, the school and
 * the class, then the name. It is what tells a parent they are on the right
 * page before they read anything else. */
.teacher-head {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--divider);
  margin-bottom: 1rem;
}

.teacher-initial {
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  border-radius: var(--radius-head);
  background: var(--accent);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1;
}

.teacher-meta {
  min-width: 0;
}

.teacher-school {
  margin: 0;
  color: var(--ink-faint);
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.teacher-name {
  margin: 0.1rem 0 0;
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.booking-intro {
  margin: 0 0 0.3rem;
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1.2;
  /* The hyphen in "rendez-vous" is a break opportunity; `nowrap` on that word
   * keeps the title from splitting inside it. */
  text-wrap: balance;
}

.booking-lead {
  margin: 0 0 1rem;
  color: var(--ink-soft);
}

/* One block per day. The day number is the anchor a parent scans for. */
.day-heading {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  margin: 0 0 0.7rem;
  font-weight: 400;
}

.day-number {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}

.day-label {
  color: var(--ink-soft);
  font-size: 0.98rem;
}

.slot-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.slot-tile {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.1rem;
  min-height: 54px;
  padding: 0.5rem 0.7rem;
  border-radius: var(--radius-tile);
  text-decoration: none;
  transition: background-color 120ms ease, border-color 120ms ease;
}

.slot-tile-free {
  background: var(--free-bg);
  border: 1.5px solid var(--accent);
  color: var(--accent);
}

.slot-tile-free:hover {
  background: var(--tint);
  border-color: var(--accent-hover);
  color: var(--accent-hover);
}

.slot-tile-free:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.slot-time {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.15;
}

.slot-until {
  font-size: 0.75rem;
  color: var(--ink-soft);
}

.slot-tile-taken {
  background: var(--taken-bg);
  /* The tile is not interactive, but its outline is still what tells a parent
   * where one slot ends and the next begins: 3.0:1 against its own background
   * and 3.4:1 against the card. */
  border: 1.5px solid var(--taken-border);
  color: var(--ink-faint);
}

.slot-tile-taken .slot-time {
  text-decoration: line-through;
  font-weight: 400;
}

.slot-taken-note {
  font-size: 0.75rem;
}

/* The booking's own slot on the move page: it stays in the grid so the parent
 * sees where they are, but it is not a destination, so it reads as "this is
 * you" rather than as a choice. The dashed border says "not actionable"
 * without the grey of a taken slot, which would say "someone else has it". */
.slot-tile-current {
  background: var(--tint);
  border: 1.5px dashed var(--accent);
  color: var(--accent-hover);
}

.slot-tile-current .slot-time {
  font-weight: 700;
}

.slot-tile-current .slot-until {
  color: var(--ink-soft);
}

.encart {
  background: var(--tint);
  border-radius: var(--radius-card);
  padding: 0.9rem 1rem;
  color: var(--ink-soft);
  font-size: 0.92rem;
  margin: 0 0 0.9rem;
}

.encart p {
  margin: 0;
}

.privacy-note {
  background: var(--tint);
  border-radius: var(--radius-tile);
  padding: 0.8rem 0.9rem;
  margin: 0 0 1rem;
  font-size: 0.88rem;
  color: var(--ink-soft);
}

.privacy-note p {
  margin: 0;
}

/* The slot being booked, recalled above the form. */
.slot-recap {
  background: var(--tint);
  border-radius: var(--radius-card);
  padding: 0.9rem 1rem;
  margin: 0 0 1.1rem;
}

.slot-recap-label {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.slot-recap-day {
  margin: 0.15rem 0 0;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink);
}

.slot-recap-time {
  margin: 0.1rem 0 0;
  color: var(--ink-soft);
}

/* --- Teacher pages ------------------------------------------------------ */

.link-box {
  margin: 0 0 0.9rem;
  padding: 0.8rem 0.9rem;
  background: var(--tint);
  border-radius: var(--radius-tile);
}

.link-box label {
  font-size: 0.85rem;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.link-box input {
  background: var(--surface);
  font-size: 0.9rem;
}

.event-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0 0 0.5rem;
}

.event-actions form {
  margin: 0;
}

.slots-scroll {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table.slots {
  width: 100%;
  max-width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

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

table.slots thead th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
  border-bottom: 1px solid var(--ink-faint);
}

table.slots tbody th {
  font-weight: 700;
  white-space: nowrap;
}

table.slots form {
  margin: 0;
}

/* The action column must not be sized by the "Placer" form: a text input's
 * default intrinsic width is 20 characters, wider than the card has room for. */
table.slots td:last-child {
  width: 1%;
  white-space: nowrap;
}

table.slots .assign form input {
  width: 100%;
  min-width: 0;
}

.slot-day-group {
  margin: 0 0 1.1rem;
}

/* The day heading must read above the table's own column headers: same weight
 * as a section, one step down from the page title, with the accent rule that
 * separates the days at a glance. */
.slot-day-group h3 {
  margin: 1.25rem 0 0.5rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
  border-bottom: 2px solid var(--accent);
  padding-bottom: 0.3rem;
  /* Only the first letter is upper-cased: `capitalize` would also turn
   * "novembre" into "Novembre". */
  text-transform: none;
  font-variant-caps: normal;
}

.slot-day-group:first-of-type h3 {
  margin-top: 0;
}

.assign {
  display: inline-block;
  margin: 0 0.35rem 0 0;
}

.assign summary {
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--accent);
  padding: 0.4rem 0.2rem;
  min-height: 38px;
}

.assign form {
  margin: 0.5rem 0 0;
  padding: 0.7rem;
  border: 1px solid var(--divider);
  border-radius: var(--radius-tile);
  background: var(--paper);
  min-width: 14rem;
}

.assign .field {
  margin: 0 0 0.5rem;
}

/* One row of the generator: a day and a window. On a phone the three fields
 * stack; from 34rem they sit side by side, the day wider than the hours. */
.range-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.5rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--divider);
}

.range-row:last-child {
  border-bottom: none;
}

.range-row .field {
  margin: 0;
}

@media (min-width: 34rem) {
  .range-row {
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr);
    align-items: end;
  }
}

.add-range {
  margin: 0.7rem 0 0.9rem;
}

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

/* --- Lists and recaps --------------------------------------------------- */

.event-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
}

.event-list li {
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--divider);
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: baseline;
}

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

.event-list a {
  font-weight: 700;
}

.recap {
  margin: 0 0 1rem;
}

.recap dt {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.recap dd {
  margin: 0 0 0.55rem;
}

/* --- Footer ------------------------------------------------------------- */

.site-footer {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 1.25rem var(--gutter) 2.5rem;
  border-top: 1px solid var(--divider);
  color: var(--ink-faint);
  font-size: 0.85rem;
}

.site-footer p {
  margin: 0 0 0.35rem;
}

/* --- Print -------------------------------------------------------------- */

.print-sheet {
  background: var(--surface);
  border: 1px solid var(--divider);
  border-radius: var(--radius-card);
  padding: 1.1rem;
  margin: 0 0 0.9rem;
}

.print-header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.3rem;
}

.print-header p {
  margin: 0 0 0.2rem;
  color: var(--ink-soft);
}

.print-summary {
  font-weight: 700;
}

.print-day {
  margin: 1.25rem 0 0;
}

.print-day-heading {
  margin: 0 0 0.35rem;
  padding-bottom: 0.25rem;
  border-bottom: 2px solid var(--ink);
  font-size: 1.05rem;
  text-transform: none;
}

.print-day-year {
  font-weight: 400;
  color: var(--ink-faint);
  text-transform: none;
}

.print-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.25rem 0 0;
}

.print-table th,
.print-table td {
  text-align: left;
  padding: 0.45rem 0.4rem;
  border-bottom: 1px solid var(--divider);
}

.print-table thead th {
  border-bottom: 2px solid var(--ink);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.print-table tbody th {
  white-space: nowrap;
  font-weight: 700;
}

.print-free td,
.print-free th {
  color: var(--ink-faint);
}

.print-footer {
  margin-top: 1rem;
  font-size: 0.85rem;
  color: var(--ink-faint);
}

/* --- Responsive --------------------------------------------------------- */

@media (min-width: 600px) {
  .slot-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 40rem) {
  .slots-scroll {
    overflow-x: visible;
  }

  table.slots thead {
    display: none;
  }

  table.slots tr {
    display: block;
    border-bottom: 1px solid var(--divider);
    padding: 0.5rem 0;
  }

  table.slots th,
  table.slots td {
    display: block;
    border: none;
    padding: 0.15rem 0;
    text-align: left;
  }

  table.slots td:last-child {
    width: auto;
    white-space: normal;
    padding-top: 0.4rem;
  }

  table.slots td[data-label]::before {
    content: attr(data-label) " : ";
    font-weight: 700;
    color: var(--ink-faint);
  }

  /* A free slot has no parent, child or address: three rows of "Parent :" with
   * nothing after them are noise on a phone, where every row costs a line. The
   * cell stays in the DOM for the table semantics; only the empty ones are
   * hidden, and `:empty` matches exactly that. */
  table.slots td[data-label]:empty {
    display: none;
  }
}

@media (max-width: 30rem) {
  .site-header,
  main,
  .site-footer {
    padding-left: 0.85rem;
    padding-right: 0.85rem;
  }

  .card {
    padding: 0.95rem;
  }

  .button-block-mobile {
    width: 100%;
  }
}

/* --- Motion ------------------------------------------------------------- */

/* Transitions exist on hover and focus only, and are removed for anyone who
 * asked the system to reduce motion. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* --- Print media -------------------------------------------------------- */

@media print {
  .site-header,
  .site-footer,
  .skip-link,
  .print-actions,
  .event-actions {
    display: none;
  }

  body {
    background: #ffffff;
    color: #000000;
  }

  main {
    max-width: none;
    padding: 0;
  }

  .print-sheet {
    border: none;
    border-radius: 0;
    padding: 0;
    margin: 0;
  }

  /* A day starts on a new page: a sheet pinned on a door is consulted one
   * evening at a time, and splitting a day makes the second half easy to
   * miss. */
  .print-day {
    break-inside: avoid;
    page-break-inside: avoid;
    margin-top: 0;
  }

  .print-day + .print-day {
    break-before: page;
    page-break-before: always;
  }

  .print-table tr {
    page-break-inside: avoid;
  }

  .print-free {
    display: none;
  }

  a {
    color: inherit;
    text-decoration: none;
  }
}
/* The copy button sits under the link field, aligned left. */
.copy-row {
  margin: 0.55rem 0 0;
}

/* A hyphen inside a word is a break opportunity the browser will take if the
 * line is tight. Keeping these words whole means a title breaks at a space,
 * where it reads. */
.booking-intro,
.day-heading {
  word-break: keep-all;
  overflow-wrap: break-word;
}

@media (max-width: 26rem) {
  .booking-intro {
    font-size: 1.4rem;
  }
}

/* The day headings start a sentence, so their first letter is upper-cased.
 * ::first-letter does that without touching the month. */
.slot-day-group h3::first-letter,
.print-day-heading::first-letter {
  text-transform: uppercase;
}
