/* ==========================================================================
   Registration form of Nicolas Pujalte
   ========================================================================== */

/* Font: Manrope, regular and bold (SIL Open Font License)
   ========================================================================== */

@font-face {
  font-display: swap;
  font-family: Manrope;
  font-style: normal;
  font-weight: 400;
  src: url('../../font/manrope/manrope-400.woff2') format('woff2');
}

@font-face {
  font-display: swap;
  font-family: Manrope;
  font-style: normal;
  font-weight: 700;
  src: url('../../font/manrope/manrope-700.woff2') format('woff2');
}

/* Global styles
   ========================================================================== */

/* A field that receives the focus stays visible below the sticky header */
html {
  scroll-padding-top: 114px;
}

body {
  font-family: Manrope, 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

a {
  color: #007cb7;
  text-decoration: none;
}

a:hover {
  color: #005680;
}

/* Page header
   ========================================================================== */

/* The header stays at the top of the window while the page scrolls */
header {
  position: sticky;
  top: 0;
  z-index: 1;
}

/* Page content
   ========================================================================== */

nav {
  font-weight: 700;
  margin: 5px 0 22px;
}

/* The two containers have the same box, so that their contents are aligned:
   only the first one has a visible border */
section {
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 20px;
}

section + section {
  margin-top: 20px;
}

/* Introduction
   ========================================================================== */

.admission {
  background-color: #f6f7f8;
  border-color: #d6d8db;
}

.admission p {
  hyphens: auto;
  margin: 0 0 20px;
  text-align: justify;
}

.admission p:last-child {
  margin-bottom: 0;
}

/* Registration form
   ========================================================================== */

.registration h2 {
  margin-bottom: 40px;
  text-align: center;
}

/* Grid of the form: two pairs of columns (label and control) on desktop */
form {
  align-items: center;
  display: grid;
  gap: 20px;
  grid-template-columns: 3fr 5fr 3fr 5fr;
}

/* A field is a label (or a legend) and its control: without a box of its
   own, its two elements are placed directly in the grid of the form */
.field {
  display: contents;
}

/* Default styles of a group of fields */
fieldset {
  border: 0;
  margin: 0;
  min-width: 0;
  padding: 0;
}

legend {
  padding: 0;
}

label {
  cursor: pointer;
}

/* Title of a field */
.field > label,
legend {
  color: #007cb7;
  font-weight: 700;
  text-align: right;
}

.optional {
  color: #5c6166;
  font-weight: 400;
}

/* Controls
   ========================================================================== */

/* Fields, hint and error message of a control, one below the other */
.control {
  display: grid;
  row-gap: 5px;
}

/* Hint and error message: on the whole width of the control */
.hint,
.error {
  font-size: 1.4rem;
  grid-column: 1 / -1;
  margin: 0;
}

.hint {
  color: #5c6166;
}

/* An error message is hidden as long as its control is not invalid */
.error {
  color: #c82333;
  display: none;
}

/* Text fields and drop-down list: same appearance in every browser */
[type='date'],
[type='email'],
[type='number'],
[type='text'],
select,
textarea {
  appearance: none;
  background-color: #fff;
  border: 1px solid #868e96;
  border-radius: 5px;
  color: inherit;
  padding: 5px 8px;
  width: 100%;
}

::placeholder {
  color: #757575;
  opacity: 1;
}

/* Same height as the other fields: the date editor of the browser is higher
   than a line of text */
[type='date'] {
  cursor: pointer;
  height: calc(1.15em + 12px);
}

/* Same look as a text field: no arrows displayed permanently in Firefox */
[type='number'] {
  appearance: textfield;
}

select {
  background-image: url('../../img/icon-arrow-down.svg');
  background-position: right 8px center;
  background-repeat: no-repeat;
  background-size: 16px;
  cursor: pointer;
  padding-right: 32px;
}

/* The comment can only be resized in height */
textarea {
  height: 150px;
  resize: vertical;
}

/* Street on the first row, postal code and locality on the second one */
.address {
  column-gap: 5px;
  grid-template-columns: 90px 1fr;
}

.address :first-child {
  grid-column: 1 / -1;
}

/* Radio buttons and checkboxes: one option per row, label on the right */
.options {
  align-items: center;
  grid-template-columns: auto 1fr;
}

.options input {
  margin-right: 10px;
}

.options label {
  justify-self: start;
}

/* Validation
   ========================================================================== */

/* Indicator on the left of the required fields: grey until the user changes
   the field or tries to send the form, then red (invalid) or green (valid) */
[type='date'],
[type='email'],
[type='number'],
[type='text'],
select {
  border-left-width: 5px;
}

input:user-invalid,
select:user-invalid {
  border-left-color: #c82333;
}

input:user-valid,
select:user-valid {
  border-left-color: #218838;
}

/* The error message of a control is displayed when one of its fields is
   invalid: the colour alone is not enough to report an error */
:user-invalid ~ .error {
  display: block;
}

/* Comment and button
   ========================================================================== */

.comment .control {
  grid-column: 2 / -1;
}

button {
  background-color: #007cb7;
  border: 2px solid #000;
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  grid-column: 1 / -1;
  justify-self: center;
  margin-top: 20px;
  padding: 10px 50px;
}

button:hover {
  background-color: #005680;
}

/* ==========================================================================
   Tablet and smartphone (768px and less)
   ========================================================================== */

@media (width <= 768px) {
  .field > label,
  legend {
    text-align: left;
  }

  .comment .control {
    grid-column: 1 / -1;
  }
}

/* Label above its control: tablet and smartphone landscape (481px to 768px),
   small smartphone portrait (430px and less)
   ========================================================================== */

@media (480px < width <= 768px), (width <= 430px) {
  form {
    align-items: start;
    grid-template-columns: 1fr;
    row-gap: 5px;
  }

  /* 5px between a label and its control, 25px before the next label */
  .control {
    margin-bottom: 20px;
  }

  button {
    margin-top: 15px;
  }
}

/* Tablet and smartphone landscape (481px to 768px): two columns of fields
   ========================================================================== */

@media (480px < width <= 768px) {
  /* The label and the control of a field are in the same column, on two
     consecutive rows: the dense flow fills the second column */
  form {
    grid-auto-flow: dense;
    grid-template-columns: 1fr 1fr;
  }

  .field:nth-child(odd) > * {
    grid-column: 1;
  }

  .field:nth-child(even) > * {
    grid-column: 2;
  }

  .field.comment > * {
    grid-column: 1 / -1;
  }

  /* The mention of an optional group is below its title, as on the model */
  legend .optional {
    display: block;
  }
}

/* Smartphone portrait (431px to 480px): label on the left of its control
   ========================================================================== */

@media (430px < width <= 480px) {
  form {
    grid-template-columns: 1fr 2fr;
  }
}
