def unpad_pkcs7(data):
    """
    Strips PKCS#7 padding from data.
    Raises ValueError if padding is invalid.
    """
    if len(data) == 0:
        raise ValueError("Error: Empty input.")
    pad_value = data[-1]
    if pad_value == 0 or pad_value > 16:
        raise ValueError("Error: Invalid padding.")
    for i in range(1, pad_value + 1):
        if data[-i] != pad_value:
            raise ValueError("Error: Invalid padding.")
    unpadded = data[: (len(data) - pad_value)]
    return unpadded