def order_columns(df, *, first_cols, last_cols=None):
    """Reorder DataFrame columns by first/middle/last grouping."""
    if last_cols:
        middle_cols = [
            col for col in df
            if col not in set().union(first_cols, last_cols)
        ]
    else:
        middle_cols = []
        last_cols = [col for col in df.columns if col not in first_cols]
    cols = first_cols + middle_cols + last_cols
    return df[cols]