import re


def to_valid_filename(filename: str) -> str:
    """Given any string, return a valid filename.

    For this purpose, filenames are expected to be all lower-cased,
    and we err on the side of being more restrictive with allowed characters,
    including not allowing space.

    Args:
        filename (str): The input filename.

    Returns:
        str: A valid filename.
    """
    return re.sub(r'[^a-z0-9.%_-]+', '-', filename.lower())