/**
 * CD Form component
 *
 * Some classes are sourced from Drupal 9 core. If you're not using Drupal, try
 * either adding the classes to the markup using the CD Demo as your reference,
 * or as a last resort modifying the selectors to match the markup of your form.
 */

input[type="text"],
input[type="number"],
input[type="password"],
input[type="email"],
input[type="search"],
input[type="tel"],
input[type="url"],
input[type="date"],
input[type="time"],
input[type="file"],
textarea {
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  padding: 0.5rem 0.75rem;
  color: var(--cd-grey--dark);
  border: 2px solid var(--brand-grey);
  background: white;
  font-size: 1rem;
}

select {
  width: 100%;
  max-width: 100%;
  padding: 0.5rem 0.75rem;
  color: var(--cd-grey--dark);
  font-size: 1rem;
}

textarea {
  resize: vertical;
  /* Better readability similar to paragraphs. */
  line-height: 1.5;
}

@media (min-width: 576px) {
  input[type="date"],
  input[type="time"],
  select {
    width: auto;
  }
}

@media (min-width: 768px) {
  input[type="text"],
  input[type="number"],
  input[type="password"],
  input[type="email"],
  input[type="search"],
  input[type="tel"],
  input[type="url"],
  input[type="file"] {
    max-width: 50ch;
  }
}

label,
fieldset legend,
.label {
  display: block;
  color: var(--cd-black);
  font-weight: 700;
}

input.error,
textarea.error,
select.error {
  border-color: var(--cd-highlight-red);
}

input:focus,
select:focus,
textarea:focus {
  position: relative;
  z-index: 10;
  outline: 3px solid var(--brand-primary);
  outline-offset: -2px;
}

input::-webkit-input-placeholder {
  color: var(--cd-grey--dark);
  font-style: italic;
}

input:-ms-input-placeholder {
  color: var(--cd-grey--dark);
  font-style: italic;
}

input::-webkit-search-cancel-button {
  position: relative;
  right: 10px;
}

/* Safari fix */
input::-webkit-search-decoration {
  -webkit-appearance: none;
}

form fieldset {
  position: relative;
  margin: 0;
  padding: 0;
  border: none;
}
form fieldset legend {
  margin: 0;
  padding: 0;
}

.cd-form {
  --cd-flow-space: 2rem;
}

.cd-form--inline {
  margin-bottom: 1rem;
}

.cd-form--inline,
.cd-form--inline .cd-form__item {
  display: flex;
}

.cd-form--inline label {
  margin-top: 0.25rem;
  margin-inline-end: 0.5rem;
}

.cd-form__item > label {
  margin-inline-end: 0.5rem;
}

/* Nested fields */
.cd-form__item .cd-form__item {
  padding-bottom: 1rem;
}

.cd-form__item h4.label {
  margin-bottom: 0;
}

.cd-form__description,
form .description {
  padding-top: 0.5rem;
  font-size: var(--cd-font-size--small);
}

/* For IE11 */
@media all and (-ms-high-contrast: none) {
  [dir="ltr"] .cd-form--inline label {
    margin-right: 0.5rem;
  }

  [dir="rtl"] .cd-form--inline label {
    margin-left: 0.5rem;
  }
}

.cd-form--inline select {
  width: auto;
}

form .form-type-checkbox,
form .form-checkboxes .form-type-checkbox,
form .form-radios .form-type-radio {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  margin-inline-end: 1rem;
}
form .form-type-checkbox label,
form .form-type-radio label {
  margin-inline-start: 0.5rem;
  font-weight: normal;
}
/* Break line and span 100% */
form .form-type-checkbox > .cd-form__description {
  flex: 1 0 100%;
}
/* Multiple checkboxes, displayed vertically */
form .fieldset-wrapper > .form-type-checkbox + .form-type-checkbox {
  margin-top: 1rem;
}
