/* ==========================================================================
   Font
   ========================================================================== */

@font-face {
  font-display: swap;
  font-family: Figtree;
  font-style: normal;
  font-weight: 400;
  src: url('../../font/Figtree/figtree-latin-400-normal.woff2') format('woff2');
}

@font-face {
  font-display: swap;
  font-family: Figtree;
  font-style: normal;
  font-weight: 700;
  src: url('../../font/Figtree/figtree-latin-700-normal.woff2') format('woff2');
}

/* ==========================================================================
   Global styles
   ========================================================================== */

body {
  font-family: Figtree, sans-serif;
}

button,
input[type='date'],
label,
select {
  cursor: pointer;
}

/* Page header: always visible at the top, without hiding the content
   ========================================================================== */

header {
  position: sticky;
  top: 0;
  z-index: 1;
}

/* Back link
   ========================================================================== */

p:has(> .back-link) {
  font-weight: 700;
  margin: 0 0 20px;
}

.back-link {
  color: #007cb7;
  text-decoration: none;
}

.back-link:hover {
  color: #005680;
}

/* ==========================================================================
   Containers
   ========================================================================== */

.admission,
.form-container {
  border-radius: 5px;
  padding: 20px;
}

.admission {
  background-color: #f6f7f8;
  border: 1px solid #d6d8db;
  margin-bottom: 20px;
}

/* Transparent border: same width as the "Admission" border, so the content
   of both containers stays aligned, without a visible frame */
.form-container {
  background-color: #fff;
  border: 1px solid transparent;
}

.admission p {
  hyphens: auto;
  text-align: justify;
}

.admission p:last-child {
  margin-bottom: 0;
}

.form-container h2 {
  margin-bottom: 40px;
  text-align: center;
}

/* ==========================================================================
   Form grid
   ========================================================================== */

form {
  display: grid;
  gap: 20px;
  grid-template-columns: repeat(2, 160px minmax(0, 1fr));
}

/* A field: title on the left, control on the right */
.field {
  align-items: center;
  border: 0;
  column-gap: 20px;
  display: grid;
  grid-column: span 2;
  grid-template-columns: 160px minmax(0, 1fr);
  margin: 0;
  min-width: 0;
  padding: 0;
}

/* A floated legend is no longer drawn on the border of its fieldset:
   it becomes a grid item like the labels */
legend {
  float: left;
}

/* Titles of the fields and of the groups (blue labels) */
.field > label,
legend {
  color: #007cb7;
  font-weight: 700;
  padding: 0;
  text-align: right;
}

.comment {
  grid-column: 1 / -1;
}

.optional {
  color: #5c6166;
  display: block;
  font-weight: 400;
}

/* Radio buttons and checkboxes
   ========================================================================== */

.option {
  align-items: center;
  display: flex;
  gap: 10px;
}

.option input {
  margin: 0;
}

.option + .option {
  margin-top: 5px;
}

/* Postal code and locality
   ========================================================================== */

.postal-locality {
  display: grid;
  gap: 5px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
  margin-top: 5px;
}

/* ==========================================================================
   Form fields
   ========================================================================== */

input:not([type='radio'], [type='checkbox']),
select,
textarea {
  background-color: #fff;
  border: 1px solid #868e96;
  border-radius: 5px;
  padding: 5px 8px;
  width: 100%;
}

input[type='number'] {
  appearance: textfield;
}

select {
  appearance: none;
  background: #fff url('../../img/icon-arrow-down.svg') no-repeat right 8px
    center / 16px;
  padding-right: 32px;
}

textarea {
  min-height: 150px;
  resize: vertical;
}

button {
  background-color: #007cb7;
  border: 2px solid #000;
  border-radius: 5px;
  color: #fff;
  font-weight: 700;
  grid-column: 1 / -1;
  justify-self: center;
  margin-top: 20px;
  padding: 10px 60px;
}

button:hover {
  background-color: #005680;
}

/* ==========================================================================
   Validation (HTML and CSS only)
   ========================================================================== */

/* Grey indicator until the user changes the field or submits the form */
input:not([type='radio'], [type='checkbox']):required,
select:required {
  border-left-width: 5px;
}

input:not([type='radio'], [type='checkbox']):required:user-valid,
select:required:user-valid {
  border-left-color: #218838;
}

input:not([type='radio'], [type='checkbox']):required:user-invalid,
select:required:user-invalid {
  border-left-color: #c82333;
}

/* Help text and error messages
   ========================================================================== */

.hint,
.error {
  font-size: 1.4rem;
  margin: 5px 0 0;
}

.hint {
  color: #5c6166;
}

.error {
  color: #c82333;
  display: none;
}

/* Message of a single field: shown when the field is invalid */
:user-invalid ~ .error {
  display: block;
}

/* Message of a group: shown when one of its fields is invalid */
fieldset:has(:user-invalid) .error {
  display: block;
}

/* ==========================================================================
   Medium screen
   ========================================================================== */

@media (width <= 768px) {
  /* Two fields per line, title above the field */
  form {
    align-items: start;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .field {
    grid-column: span 1;
    grid-template-columns: minmax(0, 1fr);
    row-gap: 5px;
  }

  .comment {
    grid-column: 1 / -1;
  }

  .field > label,
  legend {
    text-align: left;
  }
}

/* ==========================================================================
   Small screen
   ========================================================================== */

@media (width <= 480px) {
  /* One field per line, title on the left of the field */
  form {
    grid-template-columns: minmax(0, 1fr);
  }

  .field {
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
  }

  /* Remark: title above the text area */
  .comment {
    grid-template-columns: minmax(0, 1fr);
    row-gap: 20px;
  }
}

@media (width <= 430px) {
  /* Title above the field */
  .field {
    grid-template-columns: minmax(0, 1fr);
  }

  .comment {
    row-gap: 5px;
  }

  .optional {
    display: inline;
  }

  h1 {
    font-size: 2.8rem;
  }
}
