/* USER PAGES (login, register, password reset, edit): same look as the
   contact page (.form-page / .form-card in style.css). The webform field
   styles are scoped to .webform-submission-form there, so they are restated
   here for the Drupal user forms.

   @todo Review these values against the FORMS section of style.css, which
     now applies to every form (main form): hard-coded sizes and colours
     (labels 13px, fields 15.5px, background #f9f7ff, 20px spacing) instead of
     its tokens (--fs-sm, --fs-base, --bs-tertiary-bg...), and
     var(--tenderz-font-family), which is not defined. Keep only what differs
     on purpose, so that the account and tender forms look the same. */
.form-page--user {
  .form-card {
    /* Local tasks (Log in / Create account / Reset password). */
    ul.nav,
    .tabs ul {
      list-style: none;
      display: flex;
      flex-wrap: wrap;
      gap: 8px 22px;
      margin: 0 0 26px;
      padding: 0 0 14px;
      border-bottom: 1px solid var(--tz-border-2);
    }

    ul.nav a,
    .tabs a {
      font-size: 13px;
      font-weight: 600;
      color: var(--tz-ink-2);
      text-decoration: none;
      padding: 0;

      &:hover,
      &.is-active,
      &.active {
        color: var(--bs-primary);
      }
    }

    form {
      padding: 0 !important;

      .form-group,
      .form-item {
        margin-bottom: 20px;
      }

      label {
        font-size: var(--fs-sm);
        font-weight: 600;
        letter-spacing: .01em;
        color: var(--bs-body-color);
        margin-bottom: 8px;
        display: inline-block;
      }

      .form-required::after {
        content: " *";
        color: var(--bs-primary);
      }

      .form-control,
      .form-select {
        height: 54px;
        padding: 0 16px;
        border-radius: var(--bs-border-radius);
        border: 1px solid var(--tz-border-2);
        background: #f9f7ff;
        font-family: var(--tenderz-font-family);
        font-size: 15.5px;
        color: var(--bs-body-color);
        box-shadow: none;
        transition: border-color .18s;

        &:focus {
          border-color: var(--bs-primary);
          box-shadow: none;
        }

        &.is-invalid,
        &.is-invalid:focus {
          border-color: var(--bs-form-invalid-border-color);
          background-image: none;
          padding-right: 16px;
        }
      }

      textarea.form-control {
        height: auto;
        min-height: 156px;
        padding: 14px 16px;
        line-height: 1.6;
        resize: vertical;
      }

      .invalid-feedback {
        font-family: var(--tenderz-font-family);
        font-size: 13px;
        font-weight: 500;
      }

      /* Help texts: .description has the global style (style.css), the
         same as this one. */
      .form-item__description {
        font-size: var(--fs-xs);
        color: var(--bs-tertiary-color);
        margin-top: 6px;
      }

      /* Same checkbox as the contact consent field. */
      .form-checkbox-group {
        display: flex;
        flex-wrap: wrap;
        align-items: flex-start;
        gap: 12px;

        .invalid-feedback {
          margin-top: 0;
        }

        .form-check-input {
          appearance: none;
          flex: none;
          width: 22px;
          height: 22px;
          margin: 1px 0 0 !important;
          border-radius: var(--bs-border-radius) !important;
          border: 1px solid var(--tz-border-2) !important;
          background: #fff;
          cursor: pointer;
          transition: background .18s, border-color .18s, box-shadow .18s;

          &:checked {
            background-color: var(--bs-primary) !important;
            border-color: var(--bs-primary) !important;
            background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14'%3e%3cpath fill='none' stroke='%23ffffff' stroke-linecap='round' stroke-linejoin='round' stroke-width='2.2' d='M3 7.4l2.6 2.6L11 4.4'/%3e%3c/svg%3e");
            background-repeat: no-repeat;
            background-position: center;
            background-size: 13px;
          }

          &:focus {
            box-shadow: 0 0 0 4px rgba(var(--bs-primary-rgb), .14);
          }
        }

        /* Help text style, as the descriptions of the other fields. */
        .description {
          flex: 1 1 0%;
          min-width: 200px;
          margin-top: 0;
          font-size: var(--fs-xs);
          line-height: 1.5;
          color: var(--bs-tertiary-color);
        }

        /* With a visible label: below it (see style.css). */
        > label:not(.visually-hidden):has(~ .description) {
          margin-bottom: 0;
        }

        > label:not(.visually-hidden) ~ .description {
          flex-basis: 100%;
          margin-top: -8px;
          padding-left: 34px;
        }
      }

      .form-submit {
        margin-top: 12px;
      }
    }

    a:not(.btn):not(.cta-btn) {
      color: var(--bs-primary);
      font-weight: 600;
      text-underline-offset: 3px;

      &:hover {
        color: var(--tz-accent-dark);
      }
    }
  }
}

/* Login form: "Remember me" checkbox on the left, "Forgot your password?"
   link on its row's right (wraps below on narrow screens). */
.form-page--user .form-card form.user-login-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  column-gap: 16px;

  .form-item-name,
  .form-item-pass,
  .form-actions {
    flex: 0 0 100%;
  }

  .form-item-persistent-login {
    flex: 0 1 auto;
    margin-bottom: 20px;

    label {
      margin: 0;
      font-size: var(--fs-sm);
      font-weight: 400;
      color: var(--tz-ink-2);
      cursor: pointer;
    }
  }

  .forgot-password {
    margin: 0 0 20px;
    font-size: 13.5px;
  }
}

/* Customer registration: two-column grid, paired fields share a row.
   The account block (e-mail, phone, passwords) is flattened into the grid. */
.form-page--user .form-card form.user-register-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 20px;

  > *,
  .tz-flat > *,
  > div:not(.form-row-half) > .form-item,
  .form-item-pass .description {
    grid-column: 1 / -1;
  }

  /* The profile wrappers add no box: their fields sit in the grid. */
  .tz-flat {
    display: contents;
  }

  .form-row-half {
    grid-column: auto;
  }

  /* Flattened account block: single-column items. */
  .form-item-mail,
  .field--name-field-phone {
    grid-column: 1 / -1;
  }

  .form-item-pass .description {
    margin-bottom: 20px;
  }

  /* Fieldset legends and the date field title look like the other labels. */
  legend,
  .fieldset-legend,
  .field--name-field-incorporation-date h4 {
    float: none;
    width: auto;
    padding: 0;
    margin: 0 0 8px;
    font-family: inherit;
    font-size: var(--fs-sm);
    font-weight: 600;
    letter-spacing: .01em;
    line-height: inherit;
    color: var(--bs-body-color);
  }

  /* Account block and password pair are laid out by the grid. */
  > div:has(> .form-item-mail),
  .form-item-pass {
    display: contents;
  }

  .form-item-pass-pass1,
  .form-item-pass-pass2,
  > div:not(.form-row-half) > .form-item-pass-pass1,
  > div:not(.form-row-half) > .form-item-pass-pass2 {
    grid-column: auto;
  }

  /* Sub-services hidden by the script must not take space. */
  .form-item[hidden] {
    display: none;
  }

  @media (max-width: 640px) {
    grid-template-columns: minmax(0, 1fr);

    .form-row-half,
    .form-item-pass-pass1,
    .form-item-pass-pass2,
    > div:not(.form-row-half) > .form-item-pass-pass1,
    > div:not(.form-row-half) > .form-item-pass-pass2 {
      grid-column: 1 / -1;
    }
  }
}

.form-page--user .form-card form {
  /* Restated: the user pages' .form-select padding above outranks the one
     of style.css. */
  .tz-select select.form-select {
    appearance: none;
    background-image: none;
    padding-right: 44px;
  }

  /* Invalid state set by the registration script (same as the contact form). */
  .form-select.is-invalid {
    border-color: var(--bs-form-invalid-border-color);
  }

  .invalid-feedback {
    font-family: var(--tenderz-font-family);
    font-size: 13px;
    font-weight: 500;
    margin-top: 6px;
  }
}

/* Partner registration: progress indicator, section titles and service groups. */
.form-page--user .form-card form.partner-register-form {
  .partner-section-title {
    margin: 12px 0 20px;
    font-size: 18px;
    font-weight: 700;
  }

  /* Checkbox groups of service families / sub-services. */
  .partner-group {
    border-radius: var(--bs-border-radius);

    &.is-invalid {
      outline: 1px solid var(--bs-form-invalid-border-color);
      outline-offset: 6px;
    }
  }

  fieldset[hidden],
  .partner-subservices fieldset[hidden] {
    display: none;
  }

  /* Actions on the right, as on the tender form; "Previous" is set apart on
     the left. */
  .form-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    margin-top: clamp(32px, 4vw, 48px);

    .btn {
      margin-top: 0;
    }

    .partner-previous {
      margin-right: auto;
    }
  }

  @media (max-width: 640px) {
    .form-actions .btn {
      flex-basis: 100%;
    }

    .form-actions .partner-previous {
      margin-right: 0;
    }
  }
}

/* International phone input (intl-tel-input): full width like the other fields. */
.form-page--user .form-card form.user-register-form,
.webform-submission-form {
  .iti {
    display: block;
    width: 100%;

    /* The typed number and the dial code share the same typography, so that
       they sit on the same baseline. */
    input.tenderz-phone,
    .iti__selected-dial-code {
      font-family: var(--tenderz-font-family);
      font-size: 15.5px;
      line-height: normal;
      color: var(--bs-body-color);
    }

    input.tenderz-phone {
      padding-top: 0;
      padding-bottom: 0;
    }
  }
}
